* test(#2755): failing-first coverage for per-runtime kimi hooks root Install/uninstall filesystem-shape rows over a sandbox HOME (no permission tricks) plus resolver unit rows. Covers both uninstall directions, which is where a fix applied only to the install call site would drift. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(#2755): resolve the kimi hooks-TOML root per runtime resolveKimiHooksTomlDir took no runtime argument and hardcoded ~/.kimi, but both kimi and kimi-code route through the single hooksSurface=kimi-hooks-toml branch. A --kimi-code install therefore wrote its [[hooks]] block, hook bundle and CommonJS marker into Kimi CLI's config file, and a --kimi-code uninstall stripped Kimi CLI's block. Adds a runtime selector to the resolver -- kimi keeps ~/.kimi + KIMI_SHARE_DIR, kimi-code gets ~/.kimi-code + KIMI_CODE_HOME, per Kimi Code's own upstream data-locations and hooks docs -- and passes the runtime at both the install and uninstall call sites. An omitted or unrecognized runtime still resolves ~/.kimi, so the exported no-arg contract is unchanged. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * test(#2755): use centralized helpers and add a divergence guard Review findings, all fixed in-PR: - The new test block reimplemented runMinimalInstall, createTempDir and toPosixPath. Extends runMinimalInstall with optional root/extraEnv instead (back-compat: every existing caller passes neither) and uses the centralized helpers, per CONTRIBUTING's Use Centralized Test Helpers rule. - Adds a parity assertion between the capability registry and the resolver: a third runtime declaring hooksSurface kimi-hooks-toml would silently inherit ~/.kimi, re-creating this very defect. The guard fires the moment those two surfaces drift. - Adds an installer-level test proving KIMI_SHARE_DIR and KIMI_CODE_HOME do not interfere when both are set, which only the resolver unit covered before. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * test(#2755): track the kimi-code hooks root in the emitted-artifact gates The remote runner caught a real ripple: moving kimi-code hooks to ~/.kimi-code made 31 emitted paths unattributable and 58 emitted hashes unexplained, because three parallel surfaces keyed on the literal .kimi path. - HOOK_CONFIG_RELATIVE_PATHS excluded only .kimi/config.toml, so kimi-code's config.toml became manifest-visible; it embeds a platform-varying node-runner command and must stay out for both products. - HOOKS_ROOTS, the package.json-marker branch and the synthesized-install-metadata pattern each named .kimi only. - tests/fixtures/install-tree/kimi-code.json still recorded the old paths; regenerated via gen:install-tree. Adds the per-PR drift acknowledgment for the 58 paths whose bytes are unchanged but whose destination moved - a ripple no source diff can show, since no hook script was edited. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(#2755): clear production-tree security advisories The remote runner's npm-integrity gate reported 2 high advisories in the production dependency tree. My diff touches neither package.json nor package-lock.json, so these come from the base -- but a red gate is not something to wave off as pre-existing, so it is fixed here rather than deferred. Lockfile-only, semver-in-range, via npm audit fix: fast-uri 3.1.4 -> 3.1.5 (host confusion via backslash authority introducer) ip-address 10.2.0 -> 10.4.0 (three SSRF / trust-boundary bypasses) hono 4.12.31 -> 4.13.0 (moderate; reverting it traded a high for a moderate, so the full remedy is taken) npm audit now reports 0 vulnerabilities at every severity, npm ci installs clean from the updated lockfile, and the build and the kimi behavior both re-verified afterwards. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * chore(#2755): backfill changeset pr numbers Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -41,7 +41,7 @@ const path = require('node:path');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
|
||||
const { runMinimalInstall, INSTALL_SCRIPT, installerEnv } = require('./helpers/install-shared.cjs');
|
||||
const { cleanup } = require('./helpers.cjs');
|
||||
const { cleanup, createTempDir, toPosixPath } = require('./helpers.cjs');
|
||||
const {
|
||||
negotiateHostCapabilities,
|
||||
shouldFlattenDispatch,
|
||||
@@ -324,3 +324,166 @@ test('boundary: every capability-declared extendedHookEvent is wired as a real e
|
||||
`base claude-dialect event ${event} must also be wired for kimi`);
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// #2755: the hooks-TOML root is per-runtime, not a shared ~/.kimi
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Whether GSD's managed block is present, decided by the module's OWN parser
|
||||
* rather than a substring probe: stripping is a no-op exactly when there is no
|
||||
* block to strip.
|
||||
*/
|
||||
function hasGsdHooksBlock(tomlPath) {
|
||||
if (!fs.existsSync(tomlPath)) return false;
|
||||
const content = fs.readFileSync(tomlPath, 'utf8');
|
||||
return stripKimiHooksTomlBlock(content) !== content;
|
||||
}
|
||||
|
||||
/** Spawn the real installer for one Kimi variant against a shared sandbox HOME. */
|
||||
function runKimiInstall(root, runtime, { extraEnv = {}, uninstall = false } = {}) {
|
||||
return runMinimalInstall({
|
||||
runtime,
|
||||
scope: 'global',
|
||||
root,
|
||||
extraEnv,
|
||||
extraArgs: uninstall ? ['--uninstall'] : [],
|
||||
});
|
||||
}
|
||||
|
||||
function sandboxHome(t, prefix = 'gsd-2755-') {
|
||||
const root = createTempDir(prefix);
|
||||
t.after(() => cleanup(root));
|
||||
return root;
|
||||
}
|
||||
|
||||
describe('kimi vs kimi-code hooks-TOML root (#2755)', () => {
|
||||
test('--kimi-code --global writes its hooks into ~/.kimi-code and never creates ~/.kimi', (t) => {
|
||||
const root = sandboxHome(t);
|
||||
runKimiInstall(root, 'kimi-code');
|
||||
|
||||
assert.ok(hasGsdHooksBlock(path.join(root, '.kimi-code', 'config.toml')),
|
||||
"the GSD [[hooks]] block must land in Kimi Code's own config.toml");
|
||||
assert.ok(!fs.existsSync(path.join(root, '.kimi')),
|
||||
"a --kimi-code install must not create Kimi CLI's ~/.kimi root at all");
|
||||
});
|
||||
|
||||
test('--kimi-code --global installs its hook bundle under ~/.kimi-code/hooks', (t) => {
|
||||
const root = sandboxHome(t);
|
||||
runKimiInstall(root, 'kimi-code');
|
||||
|
||||
const hooksDir = path.join(root, '.kimi-code', 'hooks');
|
||||
assert.ok(fs.existsSync(path.join(hooksDir, 'gsd-check-update.js')),
|
||||
'the shared hook bundle must be self-contained under the kimi-code root');
|
||||
assert.ok(fs.existsSync(path.join(hooksDir, 'lib')),
|
||||
'hooks/lib must ship alongside it');
|
||||
assert.ok(fs.existsSync(path.join(hooksDir, 'package.json')),
|
||||
"the CommonJS marker must sit under kimi-code's hooks/ dir (#2544 shape)");
|
||||
|
||||
// The emitted [[hooks]] command paths must reference the same root the
|
||||
// bundle was installed into, or every hook resolves to a missing script.
|
||||
const toml = fs.readFileSync(path.join(root, '.kimi-code', 'config.toml'), 'utf8');
|
||||
const managed = toml.slice(
|
||||
toml.indexOf(KIMI_HOOKS_TOML_MARKER_BEGIN),
|
||||
toml.indexOf(KIMI_HOOKS_TOML_MARKER_END),
|
||||
);
|
||||
const commandPaths = [...managed.matchAll(/^command = "(.*)"$/gm)].map((m) => m[1]);
|
||||
assert.ok(commandPaths.length > 0, 'the managed block must emit at least one command');
|
||||
for (const cmd of commandPaths) {
|
||||
assert.ok(toPosixPath(cmd).includes('/.kimi-code/hooks/'),
|
||||
`hook command must reference the kimi-code hooks dir: ${cmd}`);
|
||||
assert.ok(!toPosixPath(cmd).includes('/.kimi/hooks/'),
|
||||
`hook command must not reference Kimi CLI's hooks dir: ${cmd}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('--kimi --global still writes into ~/.kimi and never creates ~/.kimi-code', (t) => {
|
||||
const root = sandboxHome(t);
|
||||
runKimiInstall(root, 'kimi');
|
||||
|
||||
assert.ok(hasGsdHooksBlock(path.join(root, '.kimi', 'config.toml')),
|
||||
"kimi's own destination must be unchanged by #2755");
|
||||
assert.ok(!fs.existsSync(path.join(root, '.kimi-code')),
|
||||
"a --kimi install must not create Kimi Code's root");
|
||||
});
|
||||
|
||||
test('KIMI_CODE_HOME redirects the kimi-code hooks destination', (t) => {
|
||||
const root = sandboxHome(t);
|
||||
const altHome = sandboxHome(t, 'gsd-2755-kch-');
|
||||
runKimiInstall(root, 'kimi-code', { extraEnv: { KIMI_CODE_HOME: altHome } });
|
||||
|
||||
assert.ok(hasGsdHooksBlock(path.join(altHome, 'config.toml')),
|
||||
'KIMI_CODE_HOME must redirect the hooks block');
|
||||
assert.ok(!fs.existsSync(path.join(root, '.kimi-code')),
|
||||
'the default kimi-code root must not be used when the env var is set');
|
||||
assert.ok(!fs.existsSync(path.join(root, '.kimi')),
|
||||
"Kimi CLI's root must not be touched either");
|
||||
});
|
||||
|
||||
test('KIMI_SHARE_DIR still redirects the kimi hooks destination', (t) => {
|
||||
const root = sandboxHome(t);
|
||||
const altHome = sandboxHome(t, 'gsd-2755-ksd-');
|
||||
runKimiInstall(root, 'kimi', { extraEnv: { KIMI_SHARE_DIR: altHome } });
|
||||
|
||||
assert.ok(hasGsdHooksBlock(path.join(altHome, 'config.toml')),
|
||||
"KIMI_SHARE_DIR must keep redirecting kimi's hooks block");
|
||||
assert.ok(!fs.existsSync(path.join(root, '.kimi-code')),
|
||||
"kimi-code's root must not be touched");
|
||||
});
|
||||
|
||||
test('uninstalling kimi-code leaves kimi hooks intact', (t) => {
|
||||
const root = sandboxHome(t);
|
||||
runKimiInstall(root, 'kimi');
|
||||
runKimiInstall(root, 'kimi-code');
|
||||
|
||||
const kimiToml = path.join(root, '.kimi', 'config.toml');
|
||||
const kimiCodeToml = path.join(root, '.kimi-code', 'config.toml');
|
||||
const kimiBefore = fs.readFileSync(kimiToml, 'utf8');
|
||||
|
||||
runKimiInstall(root, 'kimi-code', { uninstall: true });
|
||||
|
||||
assert.equal(fs.readFileSync(kimiToml, 'utf8'), kimiBefore,
|
||||
"a --kimi-code uninstall must leave Kimi CLI's config.toml byte-identical");
|
||||
assert.ok(!hasGsdHooksBlock(kimiCodeToml),
|
||||
"kimi-code's own block must be removed by its own uninstall");
|
||||
});
|
||||
|
||||
test('uninstalling kimi leaves kimi-code hooks intact', (t) => {
|
||||
const root = sandboxHome(t);
|
||||
runKimiInstall(root, 'kimi');
|
||||
runKimiInstall(root, 'kimi-code');
|
||||
|
||||
const kimiToml = path.join(root, '.kimi', 'config.toml');
|
||||
const kimiCodeToml = path.join(root, '.kimi-code', 'config.toml');
|
||||
const kimiCodeBefore = fs.readFileSync(kimiCodeToml, 'utf8');
|
||||
|
||||
runKimiInstall(root, 'kimi', { uninstall: true });
|
||||
|
||||
assert.equal(fs.readFileSync(kimiCodeToml, 'utf8'), kimiCodeBefore,
|
||||
"a --kimi uninstall must leave Kimi Code's config.toml byte-identical");
|
||||
assert.ok(!hasGsdHooksBlock(kimiToml),
|
||||
"kimi's own block must be removed by its own uninstall");
|
||||
});
|
||||
|
||||
test('KIMI_SHARE_DIR and KIMI_CODE_HOME set together do not interfere', (t) => {
|
||||
// Both products' overrides live in one environment in practice. Each must
|
||||
// honor only its own variable — proven through the real installer, not just
|
||||
// the resolver unit.
|
||||
const root = sandboxHome(t);
|
||||
const kimiAlt = sandboxHome(t, 'gsd-2755-both-kimi-');
|
||||
const codeAlt = sandboxHome(t, 'gsd-2755-both-code-');
|
||||
const both = { KIMI_SHARE_DIR: kimiAlt, KIMI_CODE_HOME: codeAlt };
|
||||
|
||||
runKimiInstall(root, 'kimi', { extraEnv: both });
|
||||
runKimiInstall(root, 'kimi-code', { extraEnv: both });
|
||||
|
||||
assert.ok(hasGsdHooksBlock(path.join(kimiAlt, 'config.toml')),
|
||||
'kimi must honor KIMI_SHARE_DIR while KIMI_CODE_HOME is also set');
|
||||
assert.ok(hasGsdHooksBlock(path.join(codeAlt, 'config.toml')),
|
||||
'kimi-code must honor KIMI_CODE_HOME while KIMI_SHARE_DIR is also set');
|
||||
assert.ok(!fs.existsSync(path.join(root, '.kimi')),
|
||||
'neither default root may be used when both overrides are set');
|
||||
assert.ok(!fs.existsSync(path.join(root, '.kimi-code')),
|
||||
'neither default root may be used when both overrides are set');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user