Introduce `runtime-slash.cjs` as the single source of truth for emitting GSD slash-command references in user-facing runtime output and persisted artifacts. `formatGsdSlash(commandName, runtime)` produces `/gsd-<cmd>` for skills-based runtimes (Claude/Cursor/OpenCode/Kilo/etc.) and `$gsd-<cmd>` for Codex. The deprecated `/gsd:<cmd>` colon form is never emitted — pasting a recommended-action command into Claude Code now routes correctly instead of failing with `Unknown command`. Wired into the high-impact emitters identified in #3584: - `init.cjs` `cmdInitManager` recommended_actions[].command (the original failure path in the bug report) plus the no-ROADMAP / no-STATE error hints. - `phase.cjs` `cmdPhaseAdd`, `cmdPhaseAddBatch`, `cmdPhaseInsert` — ROADMAP.md `Plans:` references now persist the routable form instead of the legacy colon form. - `verify.cjs` `cmdValidateHealth` — every fix-hint addIssue() call (E001/E002/E003/E004/E005, W002/W003/W008/W009/W011/W016/W018) and the persisted STATE.md regenerate / MILESTONES.md backfill notes. - `milestone.cjs` `cmdMilestoneComplete` — Operator Next Steps tail rewrite. - `validate-command-router.cjs` — `validate context` recommendation strings for WARNING/CRITICAL utilization bands. - `workstream.cjs` — missing .planning hint. - `profile-output.cjs` — `generate-claude-md` workflow enforcement block, project/skills fallbacks, profile placeholder, and the dev-preferences refresh hints. - `drift.cjs`, `gsd2-import.cjs`, `commands.cjs scaffold context` — remaining one-off persisted references. Runtime detection: `resolveRuntime(projectDir)` reads `process.env.GSD_RUNTIME` first, then a side-effect-free direct read of `.planning/config.json` (NOT `loadConfig`, which would normalize legacy keys and re-write the file just to read the runtime name). Tests: - `tests/bug-3584-runtime-slash-formatter.test.cjs` — 22 unit tests covering the pure formatter and resolver (hyphen vs codex, prefix normalization, defensive returns, env/config/default chain). - `tests/bug-3584-runtime-slash-emitters.test.cjs` — 6 integration tests exercising `init manager`, `phase add` (via the structured `roadmap get-phase` payload to avoid raw-text matching on the on-disk artifact), `validate health`, `validate context`, and the codex variant. - Existing tests updated to assert the new contract: validate-context recommendations, claude-md workflow block, milestone complete Operator Next Steps. Copilot-install engine-conversion test now asserts against a synthetic input since bin/lib/*.cjs no longer contains literal `/gsd:` references for the install-time converter to rewrite. INVENTORY.md and INVENTORY-MANIFEST.json updated for the new module (64 CLI modules shipped, +1). Fixes #3584 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
91 lines
4.0 KiB
JavaScript
91 lines
4.0 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* SDK CLI integration tests for `gsd-tools validate context`.
|
|
*
|
|
* The pure classifier's behavior is covered by
|
|
* tests/context-utilization.test.cjs — these tests focus on what the CLI
|
|
* adds on top: argument parsing, JSON vs human-readable rendering,
|
|
* recommendation-string formatting, and exit-code semantics.
|
|
*/
|
|
|
|
const { describe, test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { runGsdTools } = require('./helpers.cjs');
|
|
|
|
describe('gsd-tools validate context — CLI argument errors', () => {
|
|
test('missing --tokens-used fails with named flag in stderr', () => {
|
|
const r = runGsdTools(['validate', 'context', '--context-window', '200000']);
|
|
assert.strictEqual(r.success, false);
|
|
assert.match(r.error, /tokens-used/i);
|
|
});
|
|
|
|
test('missing --context-window fails with named flag in stderr', () => {
|
|
const r = runGsdTools(['validate', 'context', '--tokens-used', '100000']);
|
|
assert.strictEqual(r.success, false);
|
|
assert.match(r.error, /context-window/i);
|
|
});
|
|
|
|
test('non-numeric --tokens-used reports the offending flag', () => {
|
|
const r = runGsdTools(['validate', 'context', '--tokens-used', 'abc', '--context-window', '200000']);
|
|
assert.strictEqual(r.success, false);
|
|
assert.match(r.error, /tokens-used/i);
|
|
});
|
|
|
|
test('negative --tokens-used reports the offending flag', () => {
|
|
const r = runGsdTools(['validate', 'context', '--tokens-used', '-1', '--context-window', '200000']);
|
|
assert.strictEqual(r.success, false);
|
|
assert.match(r.error, /tokens-used/i);
|
|
});
|
|
});
|
|
|
|
describe('gsd-tools validate context — JSON vs human rendering', () => {
|
|
test('--json emits the classifier result plus a recommendation field', () => {
|
|
// Single round-trip test confirms (a) classifier integration,
|
|
// (b) JSON serialization, and (c) recommendation lookup. Per-state
|
|
// classifier behavior is covered by context-utilization.test.cjs.
|
|
const r = runGsdTools(['validate', 'context', '--tokens-used', '50000', '--context-window', '200000', '--json']);
|
|
assert.strictEqual(r.success, true, `expected success, got: ${r.error}`);
|
|
const obj = JSON.parse(r.output);
|
|
assert.deepStrictEqual(Object.keys(obj).sort(), ['percent', 'recommendation', 'state']);
|
|
assert.strictEqual(obj.percent, 25);
|
|
assert.strictEqual(obj.state, 'healthy');
|
|
assert.strictEqual(obj.recommendation, null);
|
|
});
|
|
|
|
test('human mode (default) prints percent, state, and recommendation', () => {
|
|
const r = runGsdTools(['validate', 'context', '--tokens-used', '140000', '--context-window', '200000']);
|
|
assert.strictEqual(r.success, true);
|
|
assert.match(r.output, /70%/);
|
|
assert.match(r.output, /critical/);
|
|
assert.match(r.output, /\/gsd-thread/);
|
|
});
|
|
|
|
test('human mode omits the recommendation line for healthy state', () => {
|
|
const r = runGsdTools(['validate', 'context', '--tokens-used', '40000', '--context-window', '200000']);
|
|
assert.strictEqual(r.success, true);
|
|
assert.match(r.output, /20%/);
|
|
assert.match(r.output, /healthy/);
|
|
assert.doesNotMatch(r.output, /\/gsd-thread/, 'healthy output must not nag the user');
|
|
});
|
|
});
|
|
|
|
describe('gsd-tools validate context — recommendation copy per state', () => {
|
|
// The CLI owns the recommendation strings (the classifier does not).
|
|
// These tests pin the wording so a regression to the prose is caught.
|
|
test('warning state recommends /gsd-thread', () => {
|
|
const r = runGsdTools(['validate', 'context', '--tokens-used', '130000', '--context-window', '200000', '--json']);
|
|
const obj = JSON.parse(r.output);
|
|
assert.strictEqual(obj.state, 'warning');
|
|
assert.match(obj.recommendation, /\/gsd-thread/);
|
|
});
|
|
|
|
test('critical state names the fracture-point reasoning risk', () => {
|
|
const r = runGsdTools(['validate', 'context', '--tokens-used', '160000', '--context-window', '200000', '--json']);
|
|
const obj = JSON.parse(r.output);
|
|
assert.strictEqual(obj.state, 'critical');
|
|
assert.match(obj.recommendation, /\/gsd-thread/);
|
|
assert.match(obj.recommendation, /reasoning|degrade|fracture/i);
|
|
});
|
|
});
|