fix(websearch): install hook for settings profiles

- ensure profile hook injection installs the transformer binary before writing the command

- keep migration marker cleanup in the installer to avoid a circular import

- add a regression test for isolated CCS_HOME settings profiles
This commit is contained in:
Tam Nhu Tran
2026-03-27 17:05:41 -04:00
parent fcc5fad601
commit 39a3e9dfc0
3 changed files with 68 additions and 2 deletions
@@ -0,0 +1,41 @@
import { afterEach, describe, expect, it } from 'bun:test';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { ensureProfileHooks } from '../../../../src/utils/websearch/profile-hook-injector';
import { getHookPath } from '../../../../src/utils/websearch/hook-config';
describe('ensureProfileHooks', () => {
let tempHome: string | undefined;
let originalCcsHome: string | undefined;
afterEach(() => {
if (originalCcsHome !== undefined) {
process.env.CCS_HOME = originalCcsHome;
} else {
delete process.env.CCS_HOME;
}
if (tempHome && fs.existsSync(tempHome)) {
fs.rmSync(tempHome, { recursive: true, force: true });
}
tempHome = undefined;
originalCcsHome = undefined;
});
it('installs the hook binary before writing the profile hook command', () => {
tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'ccs-profile-hook-test-'));
originalCcsHome = process.env.CCS_HOME;
process.env.CCS_HOME = tempHome;
const ensured = ensureProfileHooks('glm');
const hookPath = getHookPath();
const settingsPath = path.join(tempHome, '.ccs', 'glm.settings.json');
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
expect(ensured).toBe(true);
expect(fs.existsSync(hookPath)).toBe(true);
expect(settings.hooks.PreToolUse[0].hooks[0].command).toBe(`node "${hookPath}"`);
});
});