Skip to content

Commit b88c5a7

Browse files
committed
fix(doctor): warn when Copilot version is unavailable but disableAllHooks is active
1 parent faf5388 commit b88c5a7

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

dist/bin/cc-safety-net.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4080,9 +4080,12 @@ function _checkCopilotEnabled(homeDir, cwd, copilotCliVersion, errors) {
40804080
repoSettings: _collectCopilotInlineConfig(join3(repoConfigDir, "settings.json"), inlineErrors),
40814081
localSettings: _collectCopilotInlineConfig(join3(repoConfigDir, "settings.local.json"), inlineErrors)
40824082
};
4083-
if (inlineSupport === true) {
4083+
if (inlineSupport !== false) {
40844084
const disableSource = _resolveCopilotInlineDisableSource(inlineSources);
40854085
if (disableSource) {
4086+
if (inlineSupport === null) {
4087+
errors.push(`Copilot CLI version unavailable; treating disableAllHooks in ${disableSource} as active`);
4088+
}
40864089
return { activeConfigPaths: [], disabledBy: disableSource };
40874090
}
40884091
}

src/bin/doctor/hooks.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,14 @@ function _checkCopilotEnabled(
593593
),
594594
};
595595

596-
if (inlineSupport === true) {
596+
if (inlineSupport !== false) {
597597
const disableSource = _resolveCopilotInlineDisableSource(inlineSources);
598598
if (disableSource) {
599+
if (inlineSupport === null) {
600+
errors.push(
601+
`Copilot CLI version unavailable; treating disableAllHooks in ${disableSource} as active`,
602+
);
603+
}
599604
return { activeConfigPaths: [], disabledBy: disableSource };
600605
}
601606
}

tests/bin/doctor/hooks.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,31 @@ describe('detectAllHooks', () => {
826826
}
827827
});
828828

829+
test('Copilot CLI: unknown version still honors inline disableAllHooks over repo hook files', () => {
830+
const tmpBase = join(tmpdir(), `doctor-copilot-${Date.now()}`);
831+
const homeDir = join(tmpBase, 'home');
832+
const projectDir = join(tmpBase, 'project');
833+
const hooksDir = join(projectDir, '.github', 'hooks');
834+
const configDir = join(projectDir, '.github', 'copilot');
835+
mkdirSync(hooksDir, { recursive: true });
836+
mkdirSync(configDir, { recursive: true });
837+
_writeCopilotHook(join(hooksDir, 'safety-net.json'));
838+
writeFileSync(join(configDir, 'settings.json'), JSON.stringify({ disableAllHooks: true }));
839+
840+
try {
841+
const hooks = detectAllHooks(projectDir, { homeDir });
842+
const copilot = hooks.find((hook) => hook.platform === 'copilot-cli');
843+
844+
expect(copilot?.status).toBe('disabled');
845+
expect(copilot?.configPath).toBe(join(configDir, 'settings.json'));
846+
expect(copilot?.configPaths).toEqual([join(configDir, 'settings.json')]);
847+
expect(copilot?.errors?.some((e) => e.includes('version unavailable'))).toBe(true);
848+
expect(copilot?.selfTest).toBeUndefined();
849+
} finally {
850+
rmSync(tmpBase, { recursive: true, force: true });
851+
}
852+
});
853+
829854
test('Copilot CLI: repository settings can override user disableAllHooks', () => {
830855
const tmpBase = join(tmpdir(), `doctor-copilot-${Date.now()}`);
831856
const homeDir = join(tmpBase, 'home');

0 commit comments

Comments
 (0)