fix: show update prompt for unrecognized orca.yaml keys (#454)
This commit is contained in:
@@ -144,6 +144,62 @@ describe('parseOrcaYaml', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('hasUnrecognizedOrcaYamlKeys', () => {
|
||||
it('returns true when the file contains only keys this version does not handle', async () => {
|
||||
const fs = await import('fs')
|
||||
vi.mocked(fs.readFileSync).mockReturnValue('futureFeature: |\n some config\n')
|
||||
|
||||
const { hasUnrecognizedOrcaYamlKeys } = await import('./hooks')
|
||||
expect(hasUnrecognizedOrcaYamlKeys('/test/repo')).toBe(true)
|
||||
})
|
||||
|
||||
it('returns true when an unknown key has no trailing space (block-value form)', async () => {
|
||||
const fs = await import('fs')
|
||||
vi.mocked(fs.readFileSync).mockReturnValue('futureFeature:\n nested: value\n')
|
||||
|
||||
const { hasUnrecognizedOrcaYamlKeys } = await import('./hooks')
|
||||
expect(hasUnrecognizedOrcaYamlKeys('/test/repo')).toBe(true)
|
||||
})
|
||||
|
||||
it('returns true when the file mixes recognised and unrecognised keys', async () => {
|
||||
const fs = await import('fs')
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||
'scripts:\n setup: |\n pnpm install\nnewFeature: enabled\n'
|
||||
)
|
||||
|
||||
const { hasUnrecognizedOrcaYamlKeys } = await import('./hooks')
|
||||
expect(hasUnrecognizedOrcaYamlKeys('/test/repo')).toBe(true)
|
||||
})
|
||||
|
||||
it('returns false when the file contains only recognised keys', async () => {
|
||||
const fs = await import('fs')
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(
|
||||
'scripts:\n setup: |\n pnpm install\nissueCommand: |\n claude -p "test"\n'
|
||||
)
|
||||
|
||||
const { hasUnrecognizedOrcaYamlKeys } = await import('./hooks')
|
||||
expect(hasUnrecognizedOrcaYamlKeys('/test/repo')).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false when the file is empty or has no top-level keys', async () => {
|
||||
const fs = await import('fs')
|
||||
vi.mocked(fs.readFileSync).mockReturnValue('# just a comment\n')
|
||||
|
||||
const { hasUnrecognizedOrcaYamlKeys } = await import('./hooks')
|
||||
expect(hasUnrecognizedOrcaYamlKeys('/test/repo')).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false when the file cannot be read', async () => {
|
||||
const fs = await import('fs')
|
||||
vi.mocked(fs.readFileSync).mockImplementation(() => {
|
||||
throw new Error('ENOENT')
|
||||
})
|
||||
|
||||
const { hasUnrecognizedOrcaYamlKeys } = await import('./hooks')
|
||||
expect(hasUnrecognizedOrcaYamlKeys('/test/repo')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('readIssueCommand', () => {
|
||||
it('prefers the local override over the shared orca.yaml command', async () => {
|
||||
const fs = await import('fs')
|
||||
|
||||
@@ -131,6 +131,32 @@ export function hasHooksFile(repoPath: string): boolean {
|
||||
return existsSync(join(repoPath, 'orca.yaml'))
|
||||
}
|
||||
|
||||
// Why: when a newer Orca release adds a top-level key to `orca.yaml` (like
|
||||
// `issueCommand` was added here), older versions that don't recognise it will
|
||||
// return `null` from `parseOrcaYaml` and show a confusing "could not be parsed"
|
||||
// error. Detecting well-formed but unrecognised keys lets the UI suggest an
|
||||
// update instead of implying the file is broken.
|
||||
const RECOGNIZED_ORCA_YAML_KEYS = new Set(['scripts', 'issueCommand'])
|
||||
|
||||
/**
|
||||
* Return true when `orca.yaml` contains at least one top-level key that this
|
||||
* version of Orca does not handle.
|
||||
*/
|
||||
export function hasUnrecognizedOrcaYamlKeys(repoPath: string): boolean {
|
||||
try {
|
||||
const content = readFileSync(join(repoPath, 'orca.yaml'), 'utf-8')
|
||||
return content.split(/\r?\n/).some((line) => {
|
||||
// Why: bare `key:` at end-of-line (no trailing space) is valid YAML for
|
||||
// a mapping with a block value on the next line. Match both forms so
|
||||
// newer keys like `futureFeature:\n nested` are still detected.
|
||||
const m = line.match(/^([A-Za-z][A-Za-z0-9_-]*):(\s|$)/)
|
||||
return m != null && !RECOGNIZED_ORCA_YAML_KEYS.has(m[1])
|
||||
})
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Issue command files ────────────────────────────────────────────────
|
||||
// Why: `orca.yaml` is the tracked, project-wide defaults surface, while
|
||||
// `.orca/issue-command` remains the per-user override. Keeping the local file in
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
readIssueCommand,
|
||||
runHook,
|
||||
hasHooksFile,
|
||||
hasUnrecognizedOrcaYamlKeys,
|
||||
shouldRunSetupForCreate,
|
||||
writeIssueCommand
|
||||
} from '../hooks'
|
||||
@@ -301,14 +302,20 @@ export function registerWorktreeHandlers(mainWindow: BrowserWindow, store: Store
|
||||
ipcMain.handle('hooks:check', (_event, args: { repoId: string }) => {
|
||||
const repo = store.getRepo(args.repoId)
|
||||
if (!repo || isFolderRepo(repo)) {
|
||||
return { hasHooks: false, hooks: null }
|
||||
return { hasHooks: false, hooks: null, mayNeedUpdate: false }
|
||||
}
|
||||
|
||||
const has = hasHooksFile(repo.path)
|
||||
const hooks = has ? loadHooks(repo.path) : null
|
||||
// Why: when a newer Orca version adds a top-level key to `orca.yaml`, older
|
||||
// versions that don't recognise it return null and show "could not be parsed".
|
||||
// Detecting well-formed but unrecognised keys lets the UI suggest updating
|
||||
// instead of implying the file is broken.
|
||||
const mayNeedUpdate = has && !hooks && hasUnrecognizedOrcaYamlKeys(repo.path)
|
||||
return {
|
||||
hasHooks: has,
|
||||
hooks
|
||||
hooks,
|
||||
mayNeedUpdate
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Vendored
+3
-1
@@ -241,7 +241,9 @@ export type PreloadApi = {
|
||||
}
|
||||
browser: BrowserApi
|
||||
hooks: {
|
||||
check: (args: { repoId: string }) => Promise<{ hasHooks: boolean; hooks: OrcaHooks | null }>
|
||||
check: (args: {
|
||||
repoId: string
|
||||
}) => Promise<{ hasHooks: boolean; hooks: OrcaHooks | null; mayNeedUpdate: boolean }>
|
||||
readIssueCommand: (args: { repoId: string }) => Promise<{
|
||||
localContent: string | null
|
||||
sharedContent: string | null
|
||||
|
||||
@@ -357,7 +357,9 @@ const api = {
|
||||
},
|
||||
|
||||
hooks: {
|
||||
check: (args: { repoId: string }): Promise<{ hasHooks: boolean; hooks: unknown }> =>
|
||||
check: (args: {
|
||||
repoId: string
|
||||
}): Promise<{ hasHooks: boolean; hooks: unknown; mayNeedUpdate: boolean }> =>
|
||||
ipcRenderer.invoke('hooks:check', args),
|
||||
|
||||
readIssueCommand: (args: {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable max-lines -- Why: the YAML status card, issue-command editor, policy grid, and legacy-hook section form one cohesive settings surface; splitting them across files would scatter tightly coupled state and prop drilling. */
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import type { OrcaHooks, Repo, SetupRunPolicy } from '../../../../shared/types'
|
||||
import { AlertTriangle } from 'lucide-react'
|
||||
@@ -9,6 +10,7 @@ type RepositoryHooksSectionProps = {
|
||||
repo: Repo
|
||||
yamlHooks: OrcaHooks | null
|
||||
hasHooksFile: boolean
|
||||
mayNeedUpdate: boolean
|
||||
copiedTemplate: boolean
|
||||
onCopyTemplate: () => void
|
||||
onClearLegacyHooks: () => void
|
||||
@@ -35,6 +37,40 @@ const EXAMPLE_TEMPLATE = `scripts:
|
||||
issueCommand: |
|
||||
claude -p "Read issue #{{issue}} and write a design doc to docs/design-{{issue}}.md covering the approach, edge cases, and test plan." && codex exec "Review docs/design-{{issue}}.md for gaps, missing edge cases, or unclear requirements. Add feedback at the bottom."`
|
||||
|
||||
const YAML_STATE_STYLES: Record<
|
||||
string,
|
||||
{ card: string; title: string; heading: string; description: string }
|
||||
> = {
|
||||
loaded: {
|
||||
card: 'border-emerald-500/20 bg-emerald-500/5',
|
||||
title: 'text-emerald-700 dark:text-emerald-300',
|
||||
heading: 'Using `orca.yaml`',
|
||||
description:
|
||||
'Shared hook and issue-automation defaults are defined in the repo and available to everyone who uses it.'
|
||||
},
|
||||
'update-available': {
|
||||
card: 'border-amber-500/20 bg-amber-500/5',
|
||||
title: 'text-amber-700 dark:text-amber-300',
|
||||
heading: '`orca.yaml` could not be parsed',
|
||||
description:
|
||||
'The file contains configuration keys that this version of Orca does not recognize. You may need to update Orca, or check the file for typos.'
|
||||
},
|
||||
invalid: {
|
||||
card: 'border-amber-500/20 bg-amber-500/5',
|
||||
title: 'text-amber-700 dark:text-amber-300',
|
||||
heading: '`orca.yaml` could not be parsed',
|
||||
description:
|
||||
'The core configuration file exists in the repo root, but Orca could not parse the supported hook definitions yet.'
|
||||
},
|
||||
missing: {
|
||||
card: 'border-border/50 bg-muted/20',
|
||||
title: 'text-foreground',
|
||||
heading: 'No `orca.yaml` detected',
|
||||
description:
|
||||
'Add an `orca.yaml` file to enable shared setup, archive, or issue-automation defaults for this repo. Example template:'
|
||||
}
|
||||
}
|
||||
|
||||
/** Shared button grid for setup run-policy selectors. */
|
||||
function PolicyOptionGrid<P extends string>({
|
||||
options,
|
||||
@@ -86,7 +122,7 @@ function ExampleTemplateCard({
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<p className="text-[10px] tracking-[0.18em] text-muted-foreground">
|
||||
Example `orca.yaml` template
|
||||
Example <code className="rounded bg-muted px-1 py-0.5">orca.yaml</code> template
|
||||
</p>
|
||||
<div className="relative rounded-lg border border-border/50 bg-background/70">
|
||||
<Button
|
||||
@@ -112,12 +148,22 @@ export function RepositoryHooksSection({
|
||||
repo,
|
||||
yamlHooks,
|
||||
hasHooksFile,
|
||||
mayNeedUpdate,
|
||||
copiedTemplate,
|
||||
onCopyTemplate,
|
||||
onClearLegacyHooks,
|
||||
onUpdateSetupRunPolicy
|
||||
}: RepositoryHooksSectionProps): React.JSX.Element {
|
||||
const yamlState = yamlHooks ? 'loaded' : hasHooksFile ? 'invalid' : 'missing'
|
||||
// Why: distinguish "file has unrecognised top-level keys" from "file is
|
||||
// genuinely malformed" so users see a helpful update prompt instead of a
|
||||
// confusing parse-error when a newer Orca version adds keys to `orca.yaml`.
|
||||
const yamlState = yamlHooks
|
||||
? 'loaded'
|
||||
: hasHooksFile
|
||||
? mayNeedUpdate
|
||||
? 'update-available'
|
||||
: 'invalid'
|
||||
: 'missing'
|
||||
const hs = repo.hookSettings
|
||||
const legacyHookEntries = (['setup', 'archive'] as const)
|
||||
.map((hookName) => [hookName, hs?.scripts[hookName]?.trim() ?? ''] as const)
|
||||
@@ -206,37 +252,13 @@ export function RepositoryHooksSection({
|
||||
description="Shared setup, archive, and issue automation commands for this repository."
|
||||
keywords={['hooks', 'setup', 'archive', 'yaml']}
|
||||
>
|
||||
<div
|
||||
className={`space-y-3 rounded-xl border p-4 ${
|
||||
yamlState === 'loaded'
|
||||
? 'border-emerald-500/20 bg-emerald-500/5'
|
||||
: yamlState === 'invalid'
|
||||
? 'border-amber-500/20 bg-amber-500/5'
|
||||
: 'border-border/50 bg-muted/20'
|
||||
}`}
|
||||
>
|
||||
<div className={`space-y-3 rounded-xl border p-4 ${YAML_STATE_STYLES[yamlState].card}`}>
|
||||
<div className="space-y-1">
|
||||
<p
|
||||
className={`text-sm font-medium ${
|
||||
yamlState === 'loaded'
|
||||
? 'text-emerald-700 dark:text-emerald-300'
|
||||
: yamlState === 'invalid'
|
||||
? 'text-amber-700 dark:text-amber-300'
|
||||
: 'text-foreground'
|
||||
}`}
|
||||
>
|
||||
{yamlState === 'loaded'
|
||||
? 'Using `orca.yaml`'
|
||||
: yamlState === 'invalid'
|
||||
? '`orca.yaml` could not be parsed'
|
||||
: 'No `orca.yaml` detected'}
|
||||
<p className={`text-sm font-medium ${YAML_STATE_STYLES[yamlState].title}`}>
|
||||
{YAML_STATE_STYLES[yamlState].heading}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{yamlState === 'loaded'
|
||||
? 'Shared hook and issue-automation defaults are defined in the repo and available to everyone who uses it.'
|
||||
: yamlState === 'invalid'
|
||||
? 'The core configuration file exists in the repo root, but Orca could not parse the supported hook definitions yet.'
|
||||
: 'Add an `orca.yaml` file to enable shared setup, archive, or issue-automation defaults for this repo. Example template:'}
|
||||
{YAML_STATE_STYLES[yamlState].description}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -251,6 +273,8 @@ export function RepositoryHooksSection({
|
||||
Edit `orca.yaml` in the repository if you need to change these shared commands.
|
||||
</p>
|
||||
</div>
|
||||
) : yamlState === 'update-available' ? (
|
||||
<ExampleTemplateCard copiedTemplate={copiedTemplate} onCopyTemplate={onCopyTemplate} />
|
||||
) : yamlState === 'invalid' ? (
|
||||
<div className="space-y-5">
|
||||
<div className="flex items-start gap-3 rounded-xl border border-amber-500/20 bg-background/60 p-4">
|
||||
|
||||
@@ -18,6 +18,7 @@ type RepositoryPaneProps = {
|
||||
repo: Repo
|
||||
yamlHooks: OrcaHooks | null
|
||||
hasHooksFile: boolean
|
||||
mayNeedUpdate: boolean
|
||||
updateRepo: (repoId: string, updates: Partial<Repo>) => void
|
||||
removeRepo: (repoId: string) => void
|
||||
}
|
||||
@@ -95,6 +96,7 @@ export function RepositoryPane({
|
||||
repo,
|
||||
yamlHooks,
|
||||
hasHooksFile,
|
||||
mayNeedUpdate,
|
||||
updateRepo,
|
||||
removeRepo
|
||||
}: RepositoryPaneProps): React.JSX.Element {
|
||||
@@ -273,6 +275,7 @@ export function RepositoryPane({
|
||||
repo={repo}
|
||||
yamlHooks={yamlHooks}
|
||||
hasHooksFile={hasHooksFile}
|
||||
mayNeedUpdate={mayNeedUpdate}
|
||||
copiedTemplate={copiedTemplate}
|
||||
onCopyTemplate={() => void handleCopyTemplate()}
|
||||
onClearLegacyHooks={handleClearLegacyHooks}
|
||||
|
||||
@@ -69,7 +69,7 @@ function Settings(): React.JSX.Element {
|
||||
const setSettingsSearchQuery = useAppStore((s) => s.setSettingsSearchQuery)
|
||||
|
||||
const [repoHooksMap, setRepoHooksMap] = useState<
|
||||
Record<string, { hasHooks: boolean; hooks: OrcaHooks | null }>
|
||||
Record<string, { hasHooks: boolean; hooks: OrcaHooks | null; mayNeedUpdate: boolean }>
|
||||
>({})
|
||||
const systemPrefersDark = useSystemPrefersDark()
|
||||
const [scrollbackMode, setScrollbackMode] = useState<'preset' | 'custom'>('preset')
|
||||
@@ -155,19 +155,24 @@ function Settings(): React.JSX.Element {
|
||||
const results = await Promise.all(
|
||||
repos.map(async (repo) => {
|
||||
if (isFolderRepo(repo)) {
|
||||
return [repo.id, { hasHooks: false, hooks: null }] as const
|
||||
return [repo.id, { hasHooks: false, hooks: null, mayNeedUpdate: false }] as const
|
||||
}
|
||||
try {
|
||||
const result = await window.api.hooks.check({ repoId: repo.id })
|
||||
return [repo.id, result] as const
|
||||
} catch {
|
||||
return [repo.id, { hasHooks: false, hooks: null }] as const
|
||||
return [repo.id, { hasHooks: false, hooks: null, mayNeedUpdate: false }] as const
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
if (!stale) {
|
||||
setRepoHooksMap(Object.fromEntries(results))
|
||||
setRepoHooksMap(
|
||||
Object.fromEntries(results) as Record<
|
||||
string,
|
||||
{ hasHooks: boolean; hooks: OrcaHooks | null; mayNeedUpdate: boolean }
|
||||
>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,6 +483,7 @@ function Settings(): React.JSX.Element {
|
||||
repo={repo}
|
||||
yamlHooks={repoHooksState?.hooks ?? null}
|
||||
hasHooksFile={repoHooksState?.hasHooks ?? false}
|
||||
mayNeedUpdate={repoHooksState?.mayNeedUpdate ?? false}
|
||||
updateRepo={updateRepo}
|
||||
removeRepo={removeRepo}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user