refactor: hard-fork GSD -> MSD (Make Software Done)
Mechanical rename produced by scripts/msd-rename.cjs: gsd/Gsd/GSD -> msd/Msd/MSD across contents and paths, upstream package/repo coordinates -> @golem15/msd-core and golem15com/msd-core. Deep links into upstream history, sibling upstream packages, the GSD-2 import feature, CHANGELOG.md and .changeset/ are kept as-is. Hand edits on top: MSD block-letter banner and logos, LICENSE copyright line, package/plugin identity, regenerated lockfile, install-tree fixtures, derived registries and benchmark baseline; migration checksum baseline re-locked (MSD keeps its own install state, so no install had applied the old sums); sort-order and regex-escaped expectations in tests adjusted.
This commit is contained in:
@@ -9,16 +9,16 @@
|
||||
* upgrades kimi contributes as part of the imperative-adapter migration:
|
||||
*
|
||||
* UPGRADE 1 — native hook bus: `hooksSurface` moved from `"none"` to
|
||||
* `"kimi-hooks-toml"`. GSD's lifecycle hook scripts (session-state,
|
||||
* `"kimi-hooks-toml"`. MSD's lifecycle hook scripts (session-state,
|
||||
* phase-boundary, graphify, context monitor, the prompt/read/workflow/
|
||||
* worktree guards, commit validation) are now registered as `[[hooks]]`
|
||||
* array-of-tables entries inside Kimi's own native config.toml (default
|
||||
* `~/.kimi/config.toml`, overridable via Kimi's `KIMI_SHARE_DIR`), wrapped
|
||||
* in `# GSD Hooks BEGIN`/`END` marker comments so a reinstall only ever
|
||||
* rewrites GSD's own block (idempotency contract). `hooks/`, `hooks/lib/`,
|
||||
* in `# MSD Hooks BEGIN`/`END` marker comments so a reinstall only ever
|
||||
* rewrites MSD's own block (idempotency contract). `hooks/`, `hooks/lib/`,
|
||||
* and the CommonJS `package.json` marker now also install for kimi — but
|
||||
* SELF-CONTAINED under `~/.kimi/` (alongside config.toml), never under the
|
||||
* generic Agent-Skills configDir GSD installs skills/agents into. Kimi's
|
||||
* generic Agent-Skills configDir MSD installs skills/agents into. Kimi's
|
||||
* contract forbids hooks/ or package.json under that generic root (see
|
||||
* capabilities/kimi/capability.json hostBehaviors.skipSharedHooksInstall,
|
||||
* and tests/kimi-imperative-reference.test.cjs's source-grep guard).
|
||||
@@ -47,15 +47,15 @@ const { cleanup, createTempDir, toPosixPath } = require('./helpers.cjs');
|
||||
const {
|
||||
negotiateHostCapabilities,
|
||||
shouldFlattenDispatch,
|
||||
} = require('../gsd-core/bin/lib/host-integration.cjs');
|
||||
} = require('../msd-core/bin/lib/host-integration.cjs');
|
||||
const {
|
||||
stripKimiHooksTomlBlock,
|
||||
writeKimiHooksToml,
|
||||
removeKimiHooksToml,
|
||||
KIMI_HOOKS_TOML_MARKER_BEGIN,
|
||||
KIMI_HOOKS_TOML_MARKER_END,
|
||||
} = require('../gsd-core/bin/lib/runtime-hooks-surface.cjs');
|
||||
const { COMMONJS_MARKER_CONTENT } = require('../gsd-core/bin/lib/commonjs-marker.cjs');
|
||||
} = require('../msd-core/bin/lib/runtime-hooks-surface.cjs');
|
||||
const { COMMONJS_MARKER_CONTENT } = require('../msd-core/bin/lib/commonjs-marker.cjs');
|
||||
const fc = require('fast-check');
|
||||
|
||||
const KIMI_CAP = JSON.parse(
|
||||
@@ -72,21 +72,21 @@ test('kimi --global: native config.toml [[hooks]] bus wired at <HOME>/.kimi/conf
|
||||
|
||||
// FACTS: root === sandbox HOME for this helper (env HOME/USERPROFILE are
|
||||
// both pointed at `root`), and Kimi's native hook config is a sibling of
|
||||
// the generic-agents-root GSD installs skills/agents into: <HOME>/.kimi/config.toml.
|
||||
// the generic-agents-root MSD installs skills/agents into: <HOME>/.kimi/config.toml.
|
||||
const tomlPath = path.join(root, '.kimi', 'config.toml');
|
||||
assert.ok(fs.existsSync(tomlPath), `${tomlPath} must exist`);
|
||||
|
||||
const toml = fs.readFileSync(tomlPath, 'utf8');
|
||||
|
||||
// Idempotency contract: GSD's block is delimited by these exact markers so
|
||||
// Idempotency contract: MSD's block is delimited by these exact markers so
|
||||
// a reinstall can strip-and-rewrite only its own content.
|
||||
assert.match(toml, /^# GSD Hooks BEGIN — managed by GSD, do not edit between these markers$/m,
|
||||
'config.toml must carry the GSD Hooks BEGIN marker');
|
||||
assert.match(toml, /^# GSD Hooks END$/m,
|
||||
'config.toml must carry the GSD Hooks END marker');
|
||||
assert.match(toml, /^# MSD Hooks BEGIN — managed by MSD, do not edit between these markers$/m,
|
||||
'config.toml must carry the MSD Hooks BEGIN marker');
|
||||
assert.match(toml, /^# MSD Hooks END$/m,
|
||||
'config.toml must carry the MSD Hooks END marker');
|
||||
|
||||
const beginIdx = toml.indexOf('# GSD Hooks BEGIN');
|
||||
const endIdx = toml.indexOf('# GSD Hooks END');
|
||||
const beginIdx = toml.indexOf('# MSD Hooks BEGIN');
|
||||
const endIdx = toml.indexOf('# MSD Hooks END');
|
||||
assert.ok(beginIdx !== -1 && endIdx !== -1 && beginIdx < endIdx,
|
||||
'both markers must be present and correctly ordered');
|
||||
const managedBlock = toml.slice(beginIdx, endIdx);
|
||||
@@ -101,45 +101,45 @@ test('kimi --global: native config.toml [[hooks]] bus wired at <HOME>/.kimi/conf
|
||||
|
||||
// A SessionStart [[hooks]] entry must exist inside the markers.
|
||||
assert.match(managedBlock, /\[\[hooks\]\]\nevent = "SessionStart"/,
|
||||
'a [[hooks]] block with event = "SessionStart" must be inside the GSD markers');
|
||||
'a [[hooks]] block with event = "SessionStart" must be inside the MSD markers');
|
||||
|
||||
// At least one hook command references an installed hook script path.
|
||||
assert.match(managedBlock, /command = ".*gsd-check-update\.js.*"/,
|
||||
'a hook command must reference the installed gsd-check-update.js script');
|
||||
assert.match(managedBlock, /command = ".*msd-check-update\.js.*"/,
|
||||
'a hook command must reference the installed msd-check-update.js script');
|
||||
|
||||
// The hooks/ scripts themselves are installed under Kimi's OWN native hook
|
||||
// root (~/.kimi/hooks) — NOT under the generic Agent-Skills configDir
|
||||
// (targetDir) GSD installs skills/agents into. Kimi's contract forbids
|
||||
// (targetDir) MSD installs skills/agents into. Kimi's contract forbids
|
||||
// hooks/ or package.json under that generic root (capabilities/kimi/
|
||||
// capability.json declares hostBehaviors.skipSharedHooksInstall:true), so
|
||||
// the shared hook bundle is self-contained alongside config.toml instead.
|
||||
const hooksDir = path.join(root, '.kimi', 'hooks');
|
||||
assert.ok(fs.existsSync(path.join(hooksDir, 'gsd-check-update.js')),
|
||||
'hooks/gsd-check-update.js must be installed under ~/.kimi/hooks — the command above references it by path');
|
||||
assert.ok(fs.existsSync(path.join(hooksDir, 'msd-check-update.js')),
|
||||
'hooks/msd-check-update.js must be installed under ~/.kimi/hooks — the command above references it by path');
|
||||
assert.ok(fs.existsSync(path.join(hooksDir, 'lib')),
|
||||
'hooks/lib/ helpers must also install for kimi, under ~/.kimi/hooks/lib');
|
||||
assert.ok(!fs.existsSync(path.join(root, 'hooks')),
|
||||
'hooks/ must NOT be installed under the generic Agent-Skills configDir for kimi');
|
||||
assert.ok(!fs.existsSync(path.join(root, 'package.json')),
|
||||
'package.json (CommonJS marker) must NOT be installed under the generic Agent-Skills configDir for kimi');
|
||||
// #2544: the marker moved INSIDE hooks/ — the directory GSD itself creates
|
||||
// #2544: the marker moved INSIDE hooks/ — the directory MSD itself creates
|
||||
// and fills — so kimi's own config home (~/.kimi) is never written to. The
|
||||
// pre-#2544 root marker is retired by uninstall; a fresh install writes none.
|
||||
assert.ok(fs.existsSync(path.join(hooksDir, 'package.json')),
|
||||
'package.json (CommonJS marker) must be installed inside ~/.kimi/hooks — the GSD-owned dir (#2544)');
|
||||
'package.json (CommonJS marker) must be installed inside ~/.kimi/hooks — the MSD-owned dir (#2544)');
|
||||
assert.ok(!fs.existsSync(path.join(root, '.kimi', 'package.json')),
|
||||
'package.json (CommonJS marker) must NOT be written at ~/.kimi root — kimi\'s config home is not GSD territory (#2544)');
|
||||
'package.json (CommonJS marker) must NOT be written at ~/.kimi root — kimi\'s config home is not MSD territory (#2544)');
|
||||
});
|
||||
|
||||
test('kimi --global: reinstalling is idempotent — the GSD [[hooks]] block is not duplicated', (t) => {
|
||||
test('kimi --global: reinstalling is idempotent — the MSD [[hooks]] block is not duplicated', (t) => {
|
||||
const { root } = runMinimalInstall({ runtime: 'kimi', scope: 'global' });
|
||||
t.after(() => cleanup(root));
|
||||
|
||||
const tomlPath = path.join(root, '.kimi', 'config.toml');
|
||||
const first = fs.readFileSync(tomlPath, 'utf8');
|
||||
|
||||
const beginMarkers = (content) => (content.match(/# GSD Hooks BEGIN/g) || []).length;
|
||||
const endMarkers = (content) => (content.match(/# GSD Hooks END/g) || []).length;
|
||||
const beginMarkers = (content) => (content.match(/# MSD Hooks BEGIN/g) || []).length;
|
||||
const endMarkers = (content) => (content.match(/# MSD Hooks END/g) || []).length;
|
||||
assert.equal(beginMarkers(first), 1, 'exactly one BEGIN marker after a fresh install');
|
||||
assert.equal(endMarkers(first), 1, 'exactly one END marker after a fresh install');
|
||||
|
||||
@@ -160,7 +160,7 @@ test('kimi --global: reinstalling is idempotent — the GSD [[hooks]] block is n
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Code-review regression: stripKimiHooksTomlBlock must never glue two user
|
||||
// TOML sections together when the GSD block sits between them, and must
|
||||
// TOML sections together when the MSD block sits between them, and must
|
||||
// never delete to EOF when the marker pair is malformed (BEGIN without a
|
||||
// matching END). Exercised directly against the exported pure function
|
||||
// (unit-level) and via writeKimiHooksToml/removeKimiHooksToml (the real
|
||||
@@ -168,26 +168,26 @@ test('kimi --global: reinstalling is idempotent — the GSD [[hooks]] block is n
|
||||
// covered.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function gsdHooksBlock(entry = '[[hooks]]\nevent = "SessionStart"\ncommand = "x"') {
|
||||
function msdHooksBlock(entry = '[[hooks]]\nevent = "SessionStart"\ncommand = "x"') {
|
||||
return `${KIMI_HOOKS_TOML_MARKER_BEGIN}\n\n${entry}\n\n${KIMI_HOOKS_TOML_MARKER_END}`;
|
||||
}
|
||||
|
||||
describe('stripKimiHooksTomlBlock (code-review regression)', () => {
|
||||
test('block at EOF is stripped cleanly (existing idempotent case still works)', () => {
|
||||
const input = `[providers]\nx = 1\n\n${gsdHooksBlock()}\n`;
|
||||
const input = `[providers]\nx = 1\n\n${msdHooksBlock()}\n`;
|
||||
const result = stripKimiHooksTomlBlock(input);
|
||||
assert.equal(result, '[providers]\nx = 1');
|
||||
});
|
||||
|
||||
test('block BETWEEN two user sections is stripped WITHOUT gluing the sections together', () => {
|
||||
const input = `[providers]\nx = 1\n\n${gsdHooksBlock()}\n\n[models]\ny = 2\n`;
|
||||
const input = `[providers]\nx = 1\n\n${msdHooksBlock()}\n\n[models]\ny = 2\n`;
|
||||
const result = stripKimiHooksTomlBlock(input);
|
||||
assert.equal(result, '[providers]\nx = 1\n\n[models]\ny = 2\n');
|
||||
assert.doesNotMatch(result, /x = 1\[models\]/, 'the two user sections must not be glued onto one line');
|
||||
});
|
||||
|
||||
test('block at START with user content after is stripped without a stray leading blank line', () => {
|
||||
const input = `${gsdHooksBlock()}\n\n[models]\ny = 2\n`;
|
||||
const input = `${msdHooksBlock()}\n\n[models]\ny = 2\n`;
|
||||
const result = stripKimiHooksTomlBlock(input);
|
||||
assert.equal(result, '[models]\ny = 2\n');
|
||||
});
|
||||
@@ -210,11 +210,11 @@ describe('writeKimiHooksToml / removeKimiHooksToml (code-review regression: surr
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kimi-hooksdir-'));
|
||||
t.after(() => cleanup(dir));
|
||||
fs.mkdirSync(path.join(dir, 'hooks'), { recursive: true });
|
||||
fs.writeFileSync(path.join(dir, 'hooks', 'gsd-check-update.js'), '// stub');
|
||||
fs.writeFileSync(path.join(dir, 'hooks', 'msd-check-update.js'), '// stub');
|
||||
return dir;
|
||||
}
|
||||
|
||||
test('reinstall over a config.toml with user sections BEFORE and AFTER the GSD block preserves both, un-glued', (t) => {
|
||||
test('reinstall over a config.toml with user sections BEFORE and AFTER the MSD block preserves both, un-glued', (t) => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'kimi-toml-'));
|
||||
t.after(() => cleanup(tmp));
|
||||
const configPath = path.join(tmp, 'config.toml');
|
||||
@@ -223,7 +223,7 @@ describe('writeKimiHooksToml / removeKimiHooksToml (code-review regression: surr
|
||||
const hookOpts = { platform: 'linux', node: 'node', bash: '/bin/bash' };
|
||||
|
||||
writeKimiHooksToml(configPath, hooksDir, { hookOpts });
|
||||
// Re-seed a user section AFTER the newly-written GSD block, mirroring a
|
||||
// Re-seed a user section AFTER the newly-written MSD block, mirroring a
|
||||
// hand-edited config.toml, then reinstall on top of it.
|
||||
fs.appendFileSync(configPath, '\n[extra]\nz = 3\n');
|
||||
writeKimiHooksToml(configPath, hooksDir, { hookOpts });
|
||||
@@ -231,14 +231,14 @@ describe('writeKimiHooksToml / removeKimiHooksToml (code-review regression: surr
|
||||
const content = fs.readFileSync(configPath, 'utf8');
|
||||
assert.match(content, /\[providers\]\s*\nx = 1/, 'the earlier [providers] section must survive');
|
||||
assert.match(content, /\[extra\]\s*\nz = 3/, 'the later [extra] section must survive');
|
||||
assert.doesNotMatch(content, /GSD Hooks END\s*\[extra\]/, 'GSD Hooks END must not glue directly onto [extra]');
|
||||
assert.doesNotMatch(content, /MSD Hooks END\s*\[extra\]/, 'MSD Hooks END must not glue directly onto [extra]');
|
||||
});
|
||||
|
||||
test('uninstall (removeKimiHooksToml) with user content on both sides of the block preserves it, un-glued', (t) => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'kimi-toml-remove-'));
|
||||
t.after(() => cleanup(tmp));
|
||||
const configPath = path.join(tmp, 'config.toml');
|
||||
const block = gsdHooksBlock();
|
||||
const block = msdHooksBlock();
|
||||
fs.writeFileSync(configPath, `[providers]\nx = 1\n\n${block}\n\n[models]\ny = 2\n`);
|
||||
|
||||
const result = removeKimiHooksToml(configPath);
|
||||
@@ -283,7 +283,7 @@ test('UPGRADE 2: a corrupted/undeclared dispatch still fails closed to inline (s
|
||||
// /kimi-cli/en/customization/agents.html) is only reachable through a root
|
||||
// agent whose YAML `tools:` list actually grants kimi_cli.tools.agent:Agent.
|
||||
// This is the installer-testable proxy for UPGRADE 2: a real `--kimi --global`
|
||||
// install (which generates subagents from GSD's own agents/ dir) must emit
|
||||
// install (which generates subagents from MSD's own agents/ dir) must emit
|
||||
// that tool grant on the root agent. Exercising the actual run_in_background
|
||||
// call is Kimi's own runtime behavior, out of the installer's test scope (see
|
||||
// docs/reference/host-integration-capability-matrix.md's kimi EoS-status
|
||||
@@ -295,8 +295,8 @@ test('UPGRADE 2: a corrupted/undeclared dispatch still fails closed to inline (s
|
||||
|
||||
// #3547 — the root agent lives under the runtime's real global config
|
||||
// home (<root>/.config/agents), not the sandbox HOME itself.
|
||||
const rootYamlPath = path.join(configDir, 'agents', 'gsd.yaml');
|
||||
assert.ok(fs.existsSync(rootYamlPath), 'kimi: agents/gsd.yaml must exist');
|
||||
const rootYamlPath = path.join(configDir, 'agents', 'msd.yaml');
|
||||
assert.ok(fs.existsSync(rootYamlPath), 'kimi: agents/msd.yaml must exist');
|
||||
const rootYaml = fs.readFileSync(rootYamlPath, 'utf8');
|
||||
|
||||
// Sanity: subagents must actually be present, otherwise this assertion
|
||||
@@ -344,8 +344,8 @@ test('kimi: the secret read guard is wired on the native bus with the translated
|
||||
const toml = fs.readFileSync(path.join(root, '.kimi', 'config.toml'), 'utf8');
|
||||
// One [[hooks]] table per entry: event, then matcher, then command. Locate
|
||||
// the guard's table by its command and read its matcher from the same table.
|
||||
const tables = toml.split('[[hooks]]').filter((t) => t.includes('gsd-secret-read-guard.js'));
|
||||
assert.equal(tables.length, 1, 'exactly one [[hooks]] table must reference gsd-secret-read-guard.js');
|
||||
const tables = toml.split('[[hooks]]').filter((t) => t.includes('msd-secret-read-guard.js'));
|
||||
assert.equal(tables.length, 1, 'exactly one [[hooks]] table must reference msd-secret-read-guard.js');
|
||||
assert.match(tables[0], /event = "PreToolUse"/, 'the secret read guard is a PreToolUse hook');
|
||||
assert.match(tables[0], /matcher = "ReadFile\|Grep\|Shell"/,
|
||||
'Kimi vocabulary: Read -> ReadFile, Bash -> Shell; Grep keeps its name');
|
||||
@@ -356,11 +356,11 @@ test('kimi: the secret read guard is wired on the native bus with the translated
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Whether GSD's managed block is present, decided by the module's OWN parser
|
||||
* Whether MSD'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) {
|
||||
function hasMsdHooksBlock(tomlPath) {
|
||||
if (!fs.existsSync(tomlPath)) return false;
|
||||
const content = fs.readFileSync(tomlPath, 'utf8');
|
||||
return stripKimiHooksTomlBlock(content) !== content;
|
||||
@@ -383,7 +383,7 @@ function runKimiInstall(root, runtime, { extraEnv = {}, uninstall = false, extra
|
||||
});
|
||||
}
|
||||
|
||||
function sandboxHome(t, prefix = 'gsd-2755-') {
|
||||
function sandboxHome(t, prefix = 'msd-2755-') {
|
||||
const root = createTempDir(prefix);
|
||||
t.after(() => cleanup(root));
|
||||
return root;
|
||||
@@ -394,8 +394,8 @@ describe('kimi vs kimi-code hooks-TOML root (#2755)', () => {
|
||||
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(hasMsdHooksBlock(path.join(root, '.kimi-code', 'config.toml')),
|
||||
"the MSD [[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");
|
||||
});
|
||||
@@ -405,7 +405,7 @@ describe('kimi vs kimi-code hooks-TOML root (#2755)', () => {
|
||||
runKimiInstall(root, 'kimi-code');
|
||||
|
||||
const hooksDir = path.join(root, '.kimi-code', 'hooks');
|
||||
assert.ok(fs.existsSync(path.join(hooksDir, 'gsd-check-update.js')),
|
||||
assert.ok(fs.existsSync(path.join(hooksDir, 'msd-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');
|
||||
@@ -433,7 +433,7 @@ describe('kimi vs kimi-code hooks-TOML root (#2755)', () => {
|
||||
const root = sandboxHome(t);
|
||||
runKimiInstall(root, 'kimi');
|
||||
|
||||
assert.ok(hasGsdHooksBlock(path.join(root, '.kimi', 'config.toml')),
|
||||
assert.ok(hasMsdHooksBlock(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");
|
||||
@@ -441,26 +441,26 @@ describe('kimi vs kimi-code hooks-TOML root (#2755)', () => {
|
||||
|
||||
test('KIMI_CODE_HOME redirects the kimi-code hooks destination', (t) => {
|
||||
const root = sandboxHome(t);
|
||||
const altHome = sandboxHome(t, 'gsd-2755-kch-');
|
||||
const altHome = sandboxHome(t, 'msd-2755-kch-');
|
||||
runKimiInstall(root, 'kimi-code', { extraEnv: { KIMI_CODE_HOME: altHome } });
|
||||
|
||||
assert.ok(hasGsdHooksBlock(path.join(altHome, 'config.toml')),
|
||||
assert.ok(hasMsdHooksBlock(path.join(altHome, 'config.toml')),
|
||||
'KIMI_CODE_HOME must redirect the hooks block');
|
||||
// #3547 — <root>/.kimi-code legitimately exists as kimi-code's GSD config
|
||||
// #3547 — <root>/.kimi-code legitimately exists as kimi-code's MSD config
|
||||
// home in the harness's real global shape; what must NOT happen is the
|
||||
// DEFAULT hooks root receiving the GSD block while the override is set.
|
||||
assert.ok(!hasGsdHooksBlock(path.join(root, '.kimi-code', 'config.toml')),
|
||||
'the default kimi-code hooks root must not receive the GSD hooks block when the env var is set');
|
||||
// DEFAULT hooks root receiving the MSD block while the override is set.
|
||||
assert.ok(!hasMsdHooksBlock(path.join(root, '.kimi-code', 'config.toml')),
|
||||
'the default kimi-code hooks root must not receive the MSD hooks block 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-');
|
||||
const altHome = sandboxHome(t, 'msd-2755-ksd-');
|
||||
runKimiInstall(root, 'kimi', { extraEnv: { KIMI_SHARE_DIR: altHome } });
|
||||
|
||||
assert.ok(hasGsdHooksBlock(path.join(altHome, 'config.toml')),
|
||||
assert.ok(hasMsdHooksBlock(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");
|
||||
@@ -479,7 +479,7 @@ describe('kimi vs kimi-code hooks-TOML root (#2755)', () => {
|
||||
|
||||
assert.equal(fs.readFileSync(kimiToml, 'utf8'), kimiBefore,
|
||||
"a --kimi-code uninstall must leave Kimi CLI's config.toml byte-identical");
|
||||
assert.ok(!hasGsdHooksBlock(kimiCodeToml),
|
||||
assert.ok(!hasMsdHooksBlock(kimiCodeToml),
|
||||
"kimi-code's own block must be removed by its own uninstall");
|
||||
});
|
||||
|
||||
@@ -496,7 +496,7 @@ describe('kimi vs kimi-code hooks-TOML root (#2755)', () => {
|
||||
|
||||
assert.equal(fs.readFileSync(kimiCodeToml, 'utf8'), kimiCodeBefore,
|
||||
"a --kimi uninstall must leave Kimi Code's config.toml byte-identical");
|
||||
assert.ok(!hasGsdHooksBlock(kimiToml),
|
||||
assert.ok(!hasMsdHooksBlock(kimiToml),
|
||||
"kimi's own block must be removed by its own uninstall");
|
||||
});
|
||||
|
||||
@@ -505,23 +505,23 @@ describe('kimi vs kimi-code hooks-TOML root (#2755)', () => {
|
||||
// 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 kimiAlt = sandboxHome(t, 'msd-2755-both-kimi-');
|
||||
const codeAlt = sandboxHome(t, 'msd-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')),
|
||||
assert.ok(hasMsdHooksBlock(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')),
|
||||
assert.ok(hasMsdHooksBlock(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 hooks root may be used when both overrides are set');
|
||||
// #3547 — <root>/.kimi-code is kimi-code's GSD config home now; assert the
|
||||
// #3547 — <root>/.kimi-code is kimi-code's MSD config home now; assert the
|
||||
// hooks BLOCK stayed off the default root instead of directory absence.
|
||||
assert.ok(!hasGsdHooksBlock(path.join(root, '.kimi-code', 'config.toml')),
|
||||
'neither default hooks root may receive the GSD block when both overrides are set');
|
||||
assert.ok(!hasMsdHooksBlock(path.join(root, '.kimi-code', 'config.toml')),
|
||||
'neither default hooks root may receive the MSD block when both overrides are set');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -531,15 +531,15 @@ describe('kimi vs kimi-code hooks-TOML root (#2755)', () => {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The GSD hook script name the bundle really installs, so seeded wreckage
|
||||
* The MSD hook script name the bundle really installs, so seeded wreckage
|
||||
* matches what the pre-#2755 installer actually left behind.
|
||||
*/
|
||||
const SEEDED_GSD_HOOK = 'gsd-check-update.js';
|
||||
const SEEDED_MSD_HOOK = 'msd-check-update.js';
|
||||
const RECLAIM_FLAG = '--reclaim-kimi-legacy';
|
||||
|
||||
/**
|
||||
* Seed a sandbox HOME with exactly what a pre-#2755 `--kimi-code` install left
|
||||
* in `~/.kimi`: GSD's managed block in the native config.toml, a hook script,
|
||||
* in `~/.kimi`: MSD's managed block in the native config.toml, a hook script,
|
||||
* and the CommonJS marker inside hooks/.
|
||||
*/
|
||||
function seedLegacyKimiRoot(home, { userTomlPre = '', userTomlPost = '' } = {}) {
|
||||
@@ -552,38 +552,38 @@ function seedLegacyKimiRoot(home, { userTomlPre = '', userTomlPost = '' } = {})
|
||||
'',
|
||||
'[[hooks]]',
|
||||
'event = "SessionStart"',
|
||||
`command = "node \\"${toPosixPath(root)}/hooks/${SEEDED_GSD_HOOK}\\""`,
|
||||
`command = "node \\"${toPosixPath(root)}/hooks/${SEEDED_MSD_HOOK}\\""`,
|
||||
'',
|
||||
KIMI_HOOKS_TOML_MARKER_END,
|
||||
].join('\n');
|
||||
|
||||
const parts = [userTomlPre, block, userTomlPost].filter((part) => part !== '');
|
||||
fs.writeFileSync(path.join(root, 'config.toml'), `${parts.join('\n\n')}\n`);
|
||||
fs.writeFileSync(path.join(hooksDir, SEEDED_GSD_HOOK), '// GSD hook\n');
|
||||
fs.writeFileSync(path.join(hooksDir, SEEDED_MSD_HOOK), '// MSD hook\n');
|
||||
fs.writeFileSync(path.join(hooksDir, 'package.json'), COMMONJS_MARKER_CONTENT);
|
||||
|
||||
return { root, hooksDir, tomlPath: path.join(root, 'config.toml') };
|
||||
}
|
||||
|
||||
describe('#3031 — opt-in reclaim of orphaned ~/.kimi GSD artifacts', () => {
|
||||
test('reclaims the legacy ~/.kimi GSD artifacts when --reclaim-kimi-legacy is passed', (t) => {
|
||||
const root = sandboxHome(t, 'gsd-3031-');
|
||||
describe('#3031 — opt-in reclaim of orphaned ~/.kimi MSD artifacts', () => {
|
||||
test('reclaims the legacy ~/.kimi MSD artifacts when --reclaim-kimi-legacy is passed', (t) => {
|
||||
const root = sandboxHome(t, 'msd-3031-');
|
||||
const legacy = seedLegacyKimiRoot(root);
|
||||
|
||||
runKimiInstall(root, 'kimi-code', { extraArgs: [RECLAIM_FLAG] });
|
||||
|
||||
assert.ok(!hasGsdHooksBlock(legacy.tomlPath),
|
||||
'the stale GSD [[hooks]] block must be gone from ~/.kimi/config.toml');
|
||||
assert.ok(!fs.existsSync(path.join(legacy.hooksDir, SEEDED_GSD_HOOK)),
|
||||
'the orphaned GSD hook script must be removed from ~/.kimi/hooks/');
|
||||
assert.ok(!hasMsdHooksBlock(legacy.tomlPath),
|
||||
'the stale MSD [[hooks]] block must be gone from ~/.kimi/config.toml');
|
||||
assert.ok(!fs.existsSync(path.join(legacy.hooksDir, SEEDED_MSD_HOOK)),
|
||||
'the orphaned MSD hook script must be removed from ~/.kimi/hooks/');
|
||||
assert.ok(!fs.existsSync(path.join(legacy.hooksDir, 'package.json')),
|
||||
'the orphaned CommonJS marker must be removed from ~/.kimi/hooks/');
|
||||
assert.ok(hasGsdHooksBlock(path.join(root, '.kimi-code', 'config.toml')),
|
||||
'the kimi-code install itself must still have written its own GSD block');
|
||||
assert.ok(hasMsdHooksBlock(path.join(root, '.kimi-code', 'config.toml')),
|
||||
'the kimi-code install itself must still have written its own MSD block');
|
||||
});
|
||||
|
||||
test('leaves ~/.kimi untouched without the flag (cleanup is opt-in)', (t) => {
|
||||
const root = sandboxHome(t, 'gsd-3031-');
|
||||
const root = sandboxHome(t, 'msd-3031-');
|
||||
const legacy = seedLegacyKimiRoot(root);
|
||||
const before = fs.readFileSync(legacy.tomlPath, 'utf8');
|
||||
|
||||
@@ -591,12 +591,12 @@ describe('#3031 — opt-in reclaim of orphaned ~/.kimi GSD artifacts', () => {
|
||||
|
||||
assert.equal(fs.readFileSync(legacy.tomlPath, 'utf8'), before,
|
||||
'~/.kimi/config.toml must be byte-identical when the flag is absent');
|
||||
assert.ok(fs.existsSync(path.join(legacy.hooksDir, SEEDED_GSD_HOOK)),
|
||||
assert.ok(fs.existsSync(path.join(legacy.hooksDir, SEEDED_MSD_HOOK)),
|
||||
'the hook bundle must survive when the flag is absent');
|
||||
});
|
||||
|
||||
test('preserves user-authored config.toml sections and non-GSD hook files', (t) => {
|
||||
const root = sandboxHome(t, 'gsd-3031-');
|
||||
test('preserves user-authored config.toml sections and non-MSD hook files', (t) => {
|
||||
const root = sandboxHome(t, 'msd-3031-');
|
||||
const legacy = seedLegacyKimiRoot(root, {
|
||||
userTomlPre: '[providers.moonshot]\napi_key = "USER-OWNED"',
|
||||
userTomlPost: '[ui]\ntheme = "dark"',
|
||||
@@ -607,19 +607,19 @@ describe('#3031 — opt-in reclaim of orphaned ~/.kimi GSD artifacts', () => {
|
||||
runKimiInstall(root, 'kimi-code', { extraArgs: [RECLAIM_FLAG] });
|
||||
|
||||
const after = fs.readFileSync(legacy.tomlPath, 'utf8');
|
||||
assert.ok(!hasGsdHooksBlock(legacy.tomlPath), 'the GSD block must be gone');
|
||||
assert.ok(!hasMsdHooksBlock(legacy.tomlPath), 'the MSD block must be gone');
|
||||
assert.match(after, /api_key = "USER-OWNED"/, 'user provider section must survive');
|
||||
assert.match(after, /theme = "dark"/, 'user ui section must survive');
|
||||
assert.ok(fs.existsSync(userHook), 'a user-authored hook script must never be removed');
|
||||
});
|
||||
|
||||
test('never reclaims when the install runtime is kimi itself', (t) => {
|
||||
const root = sandboxHome(t, 'gsd-3031-');
|
||||
const root = sandboxHome(t, 'msd-3031-');
|
||||
const legacy = seedLegacyKimiRoot(root);
|
||||
|
||||
runKimiInstall(root, 'kimi', { extraArgs: [RECLAIM_FLAG] });
|
||||
|
||||
assert.ok(hasGsdHooksBlock(legacy.tomlPath),
|
||||
assert.ok(hasMsdHooksBlock(legacy.tomlPath),
|
||||
'a --kimi install must never reclaim ~/.kimi — that is its own hooks root');
|
||||
});
|
||||
|
||||
@@ -627,15 +627,15 @@ describe('#3031 — opt-in reclaim of orphaned ~/.kimi GSD artifacts', () => {
|
||||
// Both overrides pointed at ONE directory collapse "the legacy root" onto
|
||||
// "the root this install just wrote". An unguarded reclaim would delete its
|
||||
// own output.
|
||||
const root = sandboxHome(t, 'gsd-3031-');
|
||||
const shared = sandboxHome(t, 'gsd-3031-shared-');
|
||||
const root = sandboxHome(t, 'msd-3031-');
|
||||
const shared = sandboxHome(t, 'msd-3031-shared-');
|
||||
|
||||
runKimiInstall(root, 'kimi-code', {
|
||||
extraArgs: [RECLAIM_FLAG],
|
||||
extraEnv: { KIMI_SHARE_DIR: shared, KIMI_CODE_HOME: shared },
|
||||
});
|
||||
|
||||
assert.ok(hasGsdHooksBlock(path.join(shared, 'config.toml')),
|
||||
assert.ok(hasMsdHooksBlock(path.join(shared, 'config.toml')),
|
||||
'reclaim must not delete the hooks block this very install just wrote');
|
||||
});
|
||||
|
||||
@@ -644,15 +644,15 @@ describe('#3031 — opt-in reclaim of orphaned ~/.kimi GSD artifacts', () => {
|
||||
// `--kimi --kimi-code` — falsifies that, and selectRuntimesFromArgs puts
|
||||
// `kimi` BEFORE `kimi-code` in both, so an unguarded reclaim installs Kimi
|
||||
// CLI's hooks and deletes them moments later in the same run, exiting 0.
|
||||
const root = sandboxHome(t, 'gsd-3031-');
|
||||
const root = sandboxHome(t, 'msd-3031-');
|
||||
|
||||
// Adding `--kimi` to a kimi-code install makes selectRuntimesFromArgs
|
||||
// return BOTH runtimes, exactly as `--all` does.
|
||||
runKimiInstall(root, 'kimi-code', { extraArgs: ['--kimi', RECLAIM_FLAG] });
|
||||
|
||||
assert.ok(hasGsdHooksBlock(path.join(root, '.kimi', 'config.toml')),
|
||||
assert.ok(hasMsdHooksBlock(path.join(root, '.kimi', 'config.toml')),
|
||||
'Kimi CLI hooks installed by this same run must survive the reclaim');
|
||||
assert.ok(hasGsdHooksBlock(path.join(root, '.kimi-code', 'config.toml')),
|
||||
assert.ok(hasMsdHooksBlock(path.join(root, '.kimi-code', 'config.toml')),
|
||||
'the kimi-code install itself must still succeed');
|
||||
});
|
||||
|
||||
@@ -665,7 +665,7 @@ describe('#3031 — opt-in reclaim of orphaned ~/.kimi GSD artifacts', () => {
|
||||
t.skip('symlink creation requires elevated privileges on Windows');
|
||||
return;
|
||||
}
|
||||
const root = sandboxHome(t, 'gsd-3031-');
|
||||
const root = sandboxHome(t, 'msd-3031-');
|
||||
const real = path.join(root, 'realkimi');
|
||||
const link = path.join(root, 'linkkimi');
|
||||
fs.mkdirSync(real, { recursive: true });
|
||||
@@ -676,12 +676,12 @@ describe('#3031 — opt-in reclaim of orphaned ~/.kimi GSD artifacts', () => {
|
||||
extraEnv: { KIMI_CODE_HOME: real, KIMI_SHARE_DIR: link },
|
||||
});
|
||||
|
||||
assert.ok(hasGsdHooksBlock(path.join(real, 'config.toml')),
|
||||
assert.ok(hasMsdHooksBlock(path.join(real, 'config.toml')),
|
||||
'a symlinked alias of the install root must not be reclaimed');
|
||||
});
|
||||
|
||||
test('skips reclaim when the two roots differ only by case on a case-insensitive filesystem', (t) => {
|
||||
const root = sandboxHome(t, 'gsd-3031-');
|
||||
const root = sandboxHome(t, 'msd-3031-');
|
||||
const real = path.join(root, 'casekimi');
|
||||
const upper = path.join(root, 'CASEKIMI');
|
||||
fs.mkdirSync(real, { recursive: true });
|
||||
@@ -698,23 +698,23 @@ describe('#3031 — opt-in reclaim of orphaned ~/.kimi GSD artifacts', () => {
|
||||
extraEnv: { KIMI_CODE_HOME: real, KIMI_SHARE_DIR: upper },
|
||||
});
|
||||
|
||||
assert.ok(hasGsdHooksBlock(path.join(real, 'config.toml')),
|
||||
assert.ok(hasMsdHooksBlock(path.join(real, 'config.toml')),
|
||||
'a case-variant alias of the install root must not be reclaimed');
|
||||
});
|
||||
|
||||
test('is a no-op when no legacy ~/.kimi root exists', (t) => {
|
||||
const root = sandboxHome(t, 'gsd-3031-');
|
||||
const root = sandboxHome(t, 'msd-3031-');
|
||||
|
||||
runKimiInstall(root, 'kimi-code', { extraArgs: [RECLAIM_FLAG] });
|
||||
|
||||
assert.ok(!fs.existsSync(path.join(root, '.kimi')),
|
||||
'reclaim must not create a legacy root that never existed');
|
||||
assert.ok(hasGsdHooksBlock(path.join(root, '.kimi-code', 'config.toml')),
|
||||
assert.ok(hasMsdHooksBlock(path.join(root, '.kimi-code', 'config.toml')),
|
||||
'the kimi-code install itself must still succeed');
|
||||
});
|
||||
|
||||
test('is idempotent across repeated reclaims', (t) => {
|
||||
const root = sandboxHome(t, 'gsd-3031-');
|
||||
const root = sandboxHome(t, 'msd-3031-');
|
||||
const legacy = seedLegacyKimiRoot(root);
|
||||
const read = () => (fs.existsSync(legacy.tomlPath)
|
||||
? fs.readFileSync(legacy.tomlPath, 'utf8')
|
||||
@@ -735,7 +735,7 @@ describe('#3031 — opt-in reclaim of orphaned ~/.kimi GSD artifacts', () => {
|
||||
const wrongRuntime = runMinimalInstall({
|
||||
runtime: 'claude',
|
||||
scope: 'global',
|
||||
root: sandboxHome(t, 'gsd-3031-'),
|
||||
root: sandboxHome(t, 'msd-3031-'),
|
||||
extraArgs: [RECLAIM_FLAG],
|
||||
});
|
||||
assert.match(`${wrongRuntime.stdout}${wrongRuntime.stderr}`, /--reclaim-kimi-legacy ignored/,
|
||||
@@ -747,7 +747,7 @@ describe('#3031 — opt-in reclaim of orphaned ~/.kimi GSD artifacts', () => {
|
||||
const localScope = runMinimalInstall({
|
||||
runtime: 'kimi-code',
|
||||
scope: 'local',
|
||||
root: sandboxHome(t, 'gsd-3031-'),
|
||||
root: sandboxHome(t, 'msd-3031-'),
|
||||
extraArgs: [RECLAIM_FLAG],
|
||||
});
|
||||
assert.match(`${localScope.stdout}${localScope.stderr}`, /--reclaim-kimi-legacy ignored/,
|
||||
@@ -755,7 +755,7 @@ describe('#3031 — opt-in reclaim of orphaned ~/.kimi GSD artifacts', () => {
|
||||
});
|
||||
|
||||
test('does not warn on the happy path', (t) => {
|
||||
const root = sandboxHome(t, 'gsd-3031-');
|
||||
const root = sandboxHome(t, 'msd-3031-');
|
||||
seedLegacyKimiRoot(root);
|
||||
|
||||
const result = runKimiInstall(root, 'kimi-code', { extraArgs: [RECLAIM_FLAG] });
|
||||
@@ -764,7 +764,7 @@ describe('#3031 — opt-in reclaim of orphaned ~/.kimi GSD artifacts', () => {
|
||||
'the warning must not fire when the reclaim actually runs');
|
||||
});
|
||||
|
||||
test('property: stripping the GSD block never destroys user content', () => {
|
||||
test('property: stripping the MSD block never destroys user content', () => {
|
||||
const userText = fc.stringMatching(/^[A-Za-z0-9_= ."[\]]{1,40}$/);
|
||||
|
||||
fc.assert(
|
||||
|
||||
Reference in New Issue
Block a user