diff --git a/scripts/git-hooks/install.test.ts b/scripts/git-hooks/install.test.ts index 01875cee..8941d315 100644 --- a/scripts/git-hooks/install.test.ts +++ b/scripts/git-hooks/install.test.ts @@ -69,6 +69,29 @@ describe('installPrePushHook', () => { } }) + test('disables stale live smoke settings during default install', () => { + const tempDir = mkdtempSync(join(tmpdir(), 'git-hook-install-test-')) + try { + runGit(tempDir, ['init']) + runGit(tempDir, ['config', '--local', 'quality.prePushLive', 'true']) + runGit(tempDir, ['config', '--local', 'quality.prePushProviderModels', 'codingplan:main:codingplan-main']) + const sourcePath = join(tempDir, 'source-pre-push') + writeFileSync(sourcePath, '#!/usr/bin/env bash\necho default\n') + + const result = installPrePushHook({ + rootDir: tempDir, + sourcePath, + }) + + expect(result.liveConfigured).toBe(false) + expect(readFileSync(result.hookPath, 'utf8')).toContain('echo default') + expect(runGit(tempDir, ['config', '--local', '--get', 'quality.prePushLive'])).toBe('false') + expect(runGit(tempDir, ['config', '--local', '--get', 'quality.prePushProviderModels'])).toBe('codingplan:main:codingplan-main') + } finally { + rmSync(tempDir, { recursive: true, force: true }) + } + }) + test('stores live gate settings in local git config', () => { const tempDir = mkdtempSync(join(tmpdir(), 'git-hook-install-test-')) try { diff --git a/scripts/git-hooks/install.ts b/scripts/git-hooks/install.ts index 317854d9..50cc2f79 100755 --- a/scripts/git-hooks/install.ts +++ b/scripts/git-hooks/install.ts @@ -82,13 +82,14 @@ export function installPrePushHook(options: InstallPrePushHookOptions = {}): Ins gitConfig(rootDir, 'quality.allowMissingTests', 'true') } - if (options.live === false) { - gitConfig(rootDir, 'quality.prePushLive', 'false') - } + const shouldWriteGitConfig = !options.hookPath + const shouldEnableLive = options.live !== false && Boolean(options.liveProviderModels?.length) - if (options.liveProviderModels && options.liveProviderModels.length > 0) { + if (shouldWriteGitConfig && shouldEnableLive) { gitConfig(rootDir, 'quality.prePushLive', 'true') - gitConfig(rootDir, 'quality.prePushProviderModels', options.liveProviderModels.join(' ')) + gitConfig(rootDir, 'quality.prePushProviderModels', options.liveProviderModels?.join(' ') ?? '') + } else if (shouldWriteGitConfig) { + gitConfig(rootDir, 'quality.prePushLive', 'false') } if (options.liveMode) { @@ -162,11 +163,12 @@ function printHelp() { console.log(`Install the repository pre-push quality gate. Usage: - bun run hooks:install [-- --force] [-- --live-provider-model ] [-- --live-mode smoke|baseline] + bun run hooks:install [-- --force] [-- --no-live] [-- --live-provider-model ] [-- --live-mode smoke|baseline] bun run hooks:install -- --allow-cli-core-change --allow-coverage-baseline-change Examples: bun run hooks:install + bun run hooks:install -- --no-live bun run quality:providers bun run hooks:install -- --live-provider-model codingplan:main:codingplan-main bun run hooks:install -- --live-provider-model codingplan:main:codingplan-main --live-mode baseline