Improve setup settings organization (#2503)
* fix: address review findings * fix: address review findings
This commit is contained in:
@@ -313,7 +313,6 @@ export function getDefaultRepoHookSettings(): RepoHookSettings {
|
||||
return {
|
||||
mode: 'auto',
|
||||
setupRunPolicy: 'run-by-default',
|
||||
commandSourcePolicy: 'shared-only',
|
||||
scripts: {
|
||||
setup: '',
|
||||
archive: ''
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
normalizeHookCommandSourcePolicy,
|
||||
resolveHookCommandSourcePolicy
|
||||
} from './hook-command-source-policy'
|
||||
|
||||
describe('hook command source policy', () => {
|
||||
it('normalizes unknown persisted policies to shared-only', () => {
|
||||
expect(normalizeHookCommandSourcePolicy('shared-first')).toBe('shared-only')
|
||||
})
|
||||
|
||||
it('uses local commands by default when a local script is configured', () => {
|
||||
expect(resolveHookCommandSourcePolicy(undefined, { hasLocalScript: true })).toBe('local-only')
|
||||
})
|
||||
|
||||
it('uses shared commands by default when no local script is configured', () => {
|
||||
expect(resolveHookCommandSourcePolicy(undefined, { hasLocalScript: false })).toBe('shared-only')
|
||||
})
|
||||
|
||||
it('preserves explicit command source choices', () => {
|
||||
expect(resolveHookCommandSourcePolicy('shared-only', { hasLocalScript: true })).toBe(
|
||||
'shared-only'
|
||||
)
|
||||
expect(resolveHookCommandSourcePolicy('run-both', { hasLocalScript: true })).toBe('run-both')
|
||||
})
|
||||
})
|
||||
@@ -9,3 +9,18 @@ export function normalizeHookCommandSourcePolicy(policy: unknown): HookCommandSo
|
||||
// Treat any unknown value as the authoritative committed config policy.
|
||||
return 'shared-only'
|
||||
}
|
||||
|
||||
export function resolveHookCommandSourcePolicy(
|
||||
policy: unknown,
|
||||
{ hasLocalScript }: { hasLocalScript: boolean }
|
||||
): HookCommandSourcePolicy {
|
||||
if (policy === 'local-only' || policy === 'run-both' || policy === 'shared-only') {
|
||||
return policy
|
||||
}
|
||||
|
||||
if (policy === undefined && hasLocalScript) {
|
||||
return 'local-only'
|
||||
}
|
||||
|
||||
return 'shared-only'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user