test(#3333): fold the runtime & install surface fix-* cluster — Wave 1 (#3341)

* test(#3333): fold the runtime & install surface fix-* cluster — Wave 1

Folds 11 legacy tests/fix-*.test.cjs regression files into their module's
main test suite: 6 folded into existing suites (host-integration-descriptors,
effort-surface-axis, trae-imperative-reference, hermes-skills-migration,
gsd-agent-isolation-guard), 5 renamed to become the module's sole suite
(cursor-hook-workspace-roots, cursor-subagent-isolation,
lint-compiled-artifact-sync, hooks-commonjs-marker,
shared-hooks-dir-resolution). All 195 test() blocks preserved with zero
drops; lint-test-file-count.cjs and eslint remain clean. No production code
changed. Wave 1 of 7 in #3315 (H3 of epic #3053).

* test(#3333): replace try/finally with t.after() in isolation-guard tests

CONTRIBUTING.md bans try/finally inside test bodies (masks failures, not an
approved pattern). The fold in the prior commit carried 27 instances forward
verbatim from the deleted fix-3045-dispatch-isolation-resolver.test.cjs into
an otherwise-clean file. Converts each to the approved per-test t.after()
cleanup pattern — same cleanup call, registered instead of finally-wrapped.
No assertion, fixture, or test-name change; test( count unchanged at 50.

Found by the Standards review pass on Wave 1 (#3333, H3 of epic #3053).

* fix(#3333): restore raw NUL byte mangled by the fold in hermes-skills-migration.test.cjs

The prior fold commit copied fix-2284-hermes-agent-delegate-task-projection's
"collision-robust" test via a text-based Read/Write pipeline, which silently
turned a raw NUL byte (0x00) embedded in two string literals into a regular
space character. That corrupted the test's actual purpose (proving a NUL
byte survives a string-rewrite operation untouched) and produced a genuine
gsd-test failure: `24 !== 1` for `out.split(' ').length`, because splitting
on a space finds every space in the sentence instead of the single NUL byte
the test meant to isolate.

Root-caused by diffing the raw bytes (via `git cat-file blob` + `cat -v`)
between the pre-fold source and the folded target — confirmed exactly two
bytes differ. Restored via a byte-precise patch (latin1 round-trip) touching
only those two lines; test( count and every other byte unchanged.

* fix(#3333): use \x00 escape sequence instead of a raw NUL byte in test fixture

The prior commit restored a byte-exact raw NUL byte matching the original
fix-2284 source, and the production function (applyClaudeCodeBrandSwap) was
confirmed correct in a standalone repro. But the same raw byte still failed
through gsd-test's remote pipeline. Root cause is upstream of gsd-core: some
step in that transfer path does not carry a raw 0x00 byte through untouched.

A raw embedded NUL byte was never necessary here — `\x00` as a 4-character
escape sequence in the source text produces the identical runtime character
(U+0000) without ever putting a raw byte in the tracked file, sidestepping
any byte-oriented transfer step. Applied at both call sites (the fixture
string and the split() delimiter). No behavior change; test( count unchanged
at 76.

* fix(#3333): harden copyWithPathReplacement against a source file vanishing mid-copy (TOCTOU)

Surfaced by this PR's own gsd-test run: tests/install-minimal-hooks.test.cjs
and tests/opencode-command-dir-plural.test.cjs intermittently crashed with
ENOENT reading gsd-core/workflows/zzz-e5-drift-fixture.md. Root cause is
unrelated to test-file consolidation — tests/planning-prompt-drift.test.cjs
writes that fixture directly into the real, shared gsd-core/workflows/ tree
(main() hardcodes its scan root to the real repo) and deletes it in
t.after(); copyWithPathReplacement's readdirSync-then-read loop has no
protection against the listed file vanishing before it gets there, so a
concurrently-running install path can crash entirely on what is otherwise a
completely benign race.

Fixed by skipping (not crashing on) a listed entry that no longer exists by
the time the loop reaches it. Added a regression test that deterministically
reproduces the race (readdirSync snapshot still lists the file; it is
deleted immediately after) and proves both outcomes: no throw, and the
vanished entry's destination is never partially written.

Per CLAUDE.md's no-defer rule, a defect surfaced while verifying this PR is
fixed inline rather than deferred — this overrides one-concern-per-PR.

* fix(#3333): fix third NUL-byte-mangled occurrence missed by prior fix passes

The fold originally mangled three raw-NUL-byte occurrences to spaces, not
two — the earlier byte-restore and escape-sequence commits both only
targeted the fixture string and the split() delimiter, missing
out.includes('[ ]') a few lines below (should read out.includes('[\x00]')).
A remote gsd-test run kept failing on this exact assertion even after both
prior fixes, which is what surfaced the miss. Verified via a standalone
repro using the file's real (not retyped) fixture content: all six
assertions in the collision-robust test now pass. Zero raw NUL bytes remain
in the file; test( count unchanged at 76.

* chore(#3333): add changeset for the copyWithPathReplacement TOCTOU fix

Fixed-type fragment for the production defect fixed inline in this PR
(bin/install.js's copyWithPathReplacement). Exempt from docs/ requirements
per CONTRIBUTING.md (only Added/Changed/Deprecated/Removed require it).

* chore(#3333): backfill changeset PR number (pr:0 -> pr:3341)

---------

Co-authored-by: sim <sim@local>
This commit is contained in:
Tom Boucher
2026-08-10 19:02:34 -04:00
committed by GitHub
parent 7a7bf19fc1
commit 33fca50d8a
19 changed files with 1899 additions and 2035 deletions

View File

@@ -10,8 +10,11 @@
* sentinels fail-closed in negotiation (safe documented default, never propagate).
*/
process.env.GSD_TEST_MODE = '1';
const { describe, test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const {
@@ -26,6 +29,38 @@ const {
validateCapability,
} = require(path.join(__dirname, '../gsd-core/bin/lib/capability-validator.cjs'));
// Folded from tests/fix-2598-opencode-background-dispatch.test.cjs and
// tests/fix-2603-kimi-code-host-matrix.test.cjs (#3333, test-hygiene backlog).
const ROOT = path.join(__dirname, '..');
const OPENCODE_DESCRIPTOR = path.join(ROOT, 'capabilities', 'opencode', 'capability.json');
const KIMI_CODE_DESCRIPTOR = path.join(ROOT, 'capabilities', 'kimi-code', 'capability.json');
const HOST_INTEGRATION_MATRIX = path.join(ROOT, 'docs', 'reference', 'host-integration-capability-matrix.md');
function opencodeDispatch() {
const parsed = JSON.parse(fs.readFileSync(OPENCODE_DESCRIPTOR, 'utf8'));
return parsed.runtime.hostIntegration.dispatch;
}
function kimiCodeAxes() {
return JSON.parse(fs.readFileSync(KIMI_CODE_DESCRIPTOR, 'utf8')).runtime.hostIntegration;
}
/** Extract the `## <host>` section body, stopping at the next top-level host heading. */
function matrixSection(host) {
const matrix = fs.readFileSync(HOST_INTEGRATION_MATRIX, 'utf8');
const start = matrix.indexOf(`\n## ${host}\n`);
if (start === -1) return null;
const rest = matrix.slice(start + 1);
const end = rest.indexOf('\n## ');
return end === -1 ? rest : rest.slice(0, end);
}
/** Read the `| <axis> | <value> | …` cell out of a matrix section. */
function matrixValue(section, axis) {
const row = section.split('\n').find((l) => l.startsWith(`| ${axis} |`));
return row ? row.split('|')[2].trim() : null;
}
// All 8 scalar hostIntegration axis keys
const SCALAR_AXES = ['embeddingMode', 'commandSurface', 'modelMode', 'hookBus', 'stateIO', 'transport', 'runtime'];
// All 6 dispatch sub-keys (includes backgroundDispatch added in feat/1679-dispatch-flatten)
@@ -452,3 +487,205 @@ describe('ADR-1239 Phase A: hostIntegration descriptors', () => {
});
});
});
// allow-test-rule: source-text-is-the-product #2598 — the descriptor JSON and the
// host-integration matrix ARE the negotiated contract; asserting their values is behavioral.
describe('#2598: OpenCode does not declare background/concurrent subagent dispatch', () => {
test('descriptor declares background: false', () => {
assert.equal(
opencodeDispatch().background,
false,
'OpenCode subagent dispatch is synchronous unless an experimental opt-in flag is set',
);
});
test('descriptor declares backgroundDispatch: false', () => {
assert.equal(
opencodeDispatch().backgroundDispatch,
false,
'concurrent dispatch requires an opt-in flag, so it must not be declared as available',
);
});
test('the capabilities that ARE real are left intact', () => {
// Narrow the blast radius: this fix must not quietly downgrade neighbouring
// sub-fields that were never in question.
const d = opencodeDispatch();
assert.equal(d.namedDispatch, true, 'named subagent dispatch is genuinely supported');
assert.equal(d.subagentToolkit, 'full', 'the general subagent has full tool access');
assert.equal(d.isolation, 'orchestrator-worktree',
'isolation is orchestrator-managed via `opencode run --dir`, unaffected by #2598');
});
test('the host-integration matrix agrees with the descriptor', () => {
// ADR-1239 designates the matrix the deployment source-of-truth; a
// descriptor/matrix disagreement is how this defect survived in the first
// place (the matrix said true, the ADR binding table said false).
const matrix = fs.readFileSync(HOST_INTEGRATION_MATRIX, 'utf8');
const section = matrix.slice(matrix.indexOf('## opencode'));
const end = section.indexOf('\n## ');
const opencodeSection = end === -1 ? section : section.slice(0, end);
for (const field of ['dispatch.background', 'dispatch.backgroundDispatch']) {
const row = opencodeSection.split('\n').find((l) => l.startsWith(`| ${field} |`));
assert.ok(row, `matrix must document ${field} for opencode`);
const value = row.split('|')[2].trim();
assert.equal(value, 'false', `matrix ${field} must match the descriptor`);
}
});
});
// allow-test-rule: source-text-is-the-product #2603 — the descriptor JSON and the
// host-integration matrix ARE the negotiated contract; asserting their values is behavioral.
describe('#2603: the host-integration matrix documents kimi-code', () => {
test('a `## kimi-code` section exists', () => {
assert.ok(
matrixSection('kimi-code'),
'the matrix is the deployment source-of-truth for every installed runtime; kimi-code must have a section',
);
});
test('every hostIntegration axis kimi-code declares is documented in the matrix', () => {
const section = matrixSection('kimi-code');
const axes = kimiCodeAxes();
const scalarAxes = Object.keys(axes).filter((k) => k !== 'dispatch');
for (const axis of scalarAxes) {
assert.ok(
matrixValue(section, axis),
`matrix must document the "${axis}" axis for kimi-code`,
);
}
// `builtInSubagents` is a GSD-side list, not a negotiated axis — the matrix
// documents it in prose, not as its own row.
const dispatchAxes = Object.keys(axes.dispatch).filter((k) => k !== 'builtInSubagents');
for (const axis of dispatchAxes) {
assert.ok(
matrixValue(section, `dispatch.${axis}`),
`matrix must document the "dispatch.${axis}" sub-axis for kimi-code`,
);
}
});
test('the matrix values agree with the shipped descriptor', () => {
const section = matrixSection('kimi-code');
const axes = kimiCodeAxes();
for (const axis of Object.keys(axes).filter((k) => k !== 'dispatch')) {
assert.equal(
matrixValue(section, axis),
String(axes[axis]),
`matrix "${axis}" must match the descriptor`,
);
}
for (const axis of Object.keys(axes.dispatch).filter((k) => k !== 'builtInSubagents')) {
assert.equal(
matrixValue(section, `dispatch.${axis}`),
String(axes.dispatch[axis]),
`matrix "dispatch.${axis}" must match the descriptor`,
);
}
});
test('the kimi-code section is sourced independently of the kimi section', () => {
// The two are distinct products (Python kimi-cli vs TypeScript Kimi Code CLI);
// the issue's central requirement is that kimi's section was NOT copied. The
// check is scoped to the axis ROWS — the section's prose intro deliberately
// names kimi's Python API to draw the contrast, which is the opposite of a copy.
const rows = matrixSection('kimi-code')
.split('\n')
.filter((l) => l.startsWith('| ') && !l.startsWith('| Axis |') && !l.startsWith('|---'));
assert.ok(rows.length >= 11, 'expected a row per hostIntegration axis');
for (const row of rows) {
assert.ok(
!row.includes('kimi_cli'),
`kimi-code axis row must not cite the Python kimi-cli: ${row.slice(0, 60)}`,
);
assert.ok(
!row.includes('moonshotai.github.io/kimi-cli'),
`kimi-code axis row must not cite kimi-cli docs: ${row.slice(0, 60)}`,
);
}
assert.ok(
rows.some((r) => r.includes('kimi-code/blob/main/docs')),
'kimi-code axes must cite the Kimi Code CLI docs',
);
});
});
describe('#2603: axis values inherited from the Python kimi descriptor are corrected', () => {
test('embeddingMode is declarative — plugins expose no in-process API', () => {
assert.equal(kimiCodeAxes().embeddingMode, 'declarative');
});
test('kimi-code therefore classifies as the declarative-cli profile', () => {
assert.equal(profileOf(kimiCodeAxes()), 'declarative-cli');
});
test('dispatch.nested is true — the coder built-in dispatches nested sub-agents', () => {
assert.equal(kimiCodeAxes().dispatch.nested, true);
});
test('dispatch.maxDepth is the undocumented sentinel, not a guessed integer', () => {
assert.equal(kimiCodeAxes().dispatch.maxDepth, 'undocumented');
});
test('namedDispatch stays false — GSD installs no agent files for this host', () => {
// Guard against a well-meaning "the docs say custom agents exist" edit: flipping
// this makes resolveDispatchType return `gsd-planner` unchanged, which kimi-code
// cannot dispatch (docs/migration/kimi-to-kimi-code.md).
assert.equal(kimiCodeAxes().dispatch.namedDispatch, false);
});
test('the undocumented maxDepth sentinel is reported as a sentinel, not as malformed', () => {
// Surfaced by this change: maxDepth was the ONE dispatch sub-axis with no
// sentinel-specific warning, so the documented fail-closed value was reported
// as "missing or not a number" — indistinguishable from a genuinely broken
// descriptor. kimi-code would have been the sixth runtime to hit that path.
const { warnings } = negotiateHostCapabilities(kimiCodeAxes());
assert.ok(
warnings.some((w) => w.includes('dispatch.maxDepth is undocumented')),
`expected a maxDepth sentinel warning, got: ${JSON.stringify(warnings)}`,
);
assert.ok(
!warnings.some((w) => w.includes('maxDepth is missing or not a number')),
'the documented sentinel must not be reported as a malformed value',
);
});
test('a genuinely malformed maxDepth is still reported as malformed', () => {
// Boundary: the sentinel carve-out must not swallow the real error case.
const axes = kimiCodeAxes();
const malformed = { ...axes, dispatch: { ...axes.dispatch, maxDepth: 'not-a-number' } };
const { warnings } = negotiateHostCapabilities(malformed);
assert.ok(
warnings.some((w) => w.includes('maxDepth is missing or not a number')),
`expected the malformed-value warning, got: ${JSON.stringify(warnings)}`,
);
});
test('both maxDepth paths still degrade the effective value closed to 0', () => {
const axes = kimiCodeAxes();
assert.equal(negotiateHostCapabilities(axes).effective.dispatch.maxDepth, 0);
const malformed = { ...axes, dispatch: { ...axes.dispatch, maxDepth: 'not-a-number' } };
assert.equal(negotiateHostCapabilities(malformed).effective.dispatch.maxDepth, 0);
});
test('the axes that were already correct are left intact', () => {
const axes = kimiCodeAxes();
assert.equal(axes.commandSurface, 'slash-file');
assert.equal(axes.modelMode, 'passive');
assert.equal(axes.hookBus, 'host');
assert.equal(axes.stateIO, 'filesystem');
assert.equal(axes.transport, 'mcp');
assert.equal(axes.runtime, 'node');
assert.equal(axes.dispatch.background, true);
assert.equal(axes.dispatch.backgroundDispatch, true);
assert.equal(axes.dispatch.subagentToolkit, 'built-in-only');
assert.equal(axes.dispatch.isolation, 'orchestrator-worktree');
});
});