* wip(#3217): rule-4 scope withholding — parked, two open findings Implemented but NOT shippable. An isolated review found buildStateFrontmatter still hardcodes SCOPE.COMPLETE, so state json reports percent 0 where roadmap analyze, stats and query progress all correctly report null on the same disk state - rule 4 reintroduced at a site this phase claims to close. Also: roadmap analyze emits scope complete beside progress_percent null with nothing explaining it. Parked to build Phase 4 (#3186) first, which is unblocked. Findings recorded in .gsd/phase/refactor-3217-completion-ratio-scoping/60-review.json. * fix(#3217): withhold the sync percentage on a non-complete scope The parked blocker is fixed - buildStateFrontmatter no longer hardcodes SCOPE.COMPLETE, and the prose Progress fallback is gated too, which was a second leak found while tracing the first. roadmap analyze exposes progress_scope so a consumer can tell WHY a percentage is absent from the JSON alone. Then a residual gap was reproduced rather than assumed. cmdStateSync carried the same hardcode behind a written reason claiming it did not reproduce. It did: on a TRUNCATED window and on UNSCOPED row 4, state sync wrote Progress 0 percent to 100 percent while state json, roadmap analyze, stats and query progress all withheld - and it persisted a self-contradictory file, body claiming 100 percent while its own frontmatter correctly omitted percent. The excuse was also wrong. syncRoadmapRaw is already parsed in that function and is exactly what produces a real scope, so there was a scope to pass. Threaded through listMilestonePhaseDirs; a non-complete scope now skips the write with a reason in changes. milestoneBounded stays as the orthogonal 1761 guard for row 5. Second time this epic a does-not-reproduce claim was too generous. Recorded in ADR Amendment 8 as a correction rather than a quiet rewrite. Verified on the remote runner. * test(#3217): give the withholding fixtures a resolvable scope 40 matrix failures, all fixture drift - no code regression. My own hypothesis that this was over-withholding was wrong and is recorded as such: the worry case, a plain ROADMAP with Phase entries and no version heading, resolves to complete exactly as ADR 7.1 says it should. The real causes were two fixture shapes. Most had no ROADMAP.md at all, which is unreadable via a pre-existing graceful path, and asserted a numeric percent. The five vscode, pi-extension, mcp-server and shell-projection failures were that shape - bare temp dirs using progress json as a reachability proxy while asserting typeof percent is number, which under rule 4 is now null. The rest had a version token in a title or heading with no STATE.md milestone pointer to resolve it, which is classification row 4, versioned but unresolved, so withholding is correct per the contract. Verified on the remote runner. * test(#3217): make the LM-tools reachability tests dispatch against their fixture The gsd_progress reachability test was never testing its fixture. invoke() resolves cwd from vscode.workspace.workspaceFolders by design (the real LanguageModelToolInvocationOptions has no cwd field, per the 2103 fix in extension.js), the mock had no workspace at all, and the test passed a cwd option nothing reads - so it dispatched against the repo working directory. Writing a ROADMAP into the temp dir had no effect. Rule 4 only made it visible. Fixed by mocking workspaceFolders. The two siblings in the same file carried the identical dead cwd and were dispatching against the repo too; they were not failing only because their assertions did not touch scope-dependent output. Both now use their own fixture with assertions unchanged - the no-planning fallback paths already satisfy them honestly. Re-scanned the other five reachability files: no further instances. They thread cwd into parameters that genuinely read it, not through an options shape that ignores it. Verified on the remote runner. * chore(#3217): backfill changeset PR number pr:0 placeholder replaced with the real number now that #3318 exists. * ci(#3217): give the coverage merge enough heap for the merged shards The coverage gate OOMed at exit 134. c8 report merges three shard artifacts, roughly 358MB of V8 dumps in coverage/tmp, and died holding their per-file position maps at the ~4GB default heap. Verified as this branch's delta rather than pre-existing: the same job succeeded on next at 14:18, after phases 4 and 5 merged. Both coverage-gate steps get the bump because both re-slice the same merged data. 8192 doubles what failed and leaves headroom on a 16GB ubuntu runner, matching the idiom the shard step already uses at 6144. This is a memory bound, not a change to what is measured. No threshold was touched. The test file was checked for gratuitous subprocess spawning and is already reasonable at 43 spawns, each a distinct fixture-by-surface pairing. Verified on the remote runner. --------- Co-authored-by: sim <sim@local>
136 lines
6.3 KiB
JavaScript
136 lines
6.3 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* pi extension reachability test — ADR-1239 Phase D / #1944, upgraded #2102.
|
|
*
|
|
* Proves the pi extension is keystone-WIRED: the registered /gsd command's
|
|
* `handler(args, ctx)` (pi's REAL ExtensionAPI shape — NOT the `execute(ctx)`
|
|
* shape the original #1944 cut used) dispatches through gsd-tools.cjs
|
|
* (subprocess-reuse — dispatchGsdCommand) and returns real output, not just a
|
|
* registration on a mock. This is the "user can invoke X" proof.
|
|
*
|
|
* Dispatch is exercised with a real read-only family/subcommand
|
|
* (progress/json) against a real temp project, matching the sibling
|
|
* tests/vscode-extension-reachability.test.cjs pattern — no fake dispatcher
|
|
* injected, because the whole point of "reachability" is that the real
|
|
* engine is reached.
|
|
*/
|
|
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const gsdPiExtension = require('../pi/gsd.cjs');
|
|
const { _internals } = require('../pi/gsd.cjs');
|
|
const { createTempDir, cleanup } = require('./helpers.cjs');
|
|
|
|
function mockPi() {
|
|
const recorded = { commands: {}, tools: {}, events: {} };
|
|
return {
|
|
registerCommand(name, def) { recorded.commands[name] = def; },
|
|
registerTool(def) { if (def && def.name) recorded.tools[def.name] = def; },
|
|
on(event, handler) { (recorded.events[event] = recorded.events[event] || []).push(handler); },
|
|
_recorded: recorded,
|
|
};
|
|
}
|
|
|
|
test('the pi extension registers /gsd (with getArgumentCompletions + handler) + gsd_invoke + the event surface via ExtensionAPI', () => {
|
|
const pi = mockPi();
|
|
gsdPiExtension(pi);
|
|
const gsdCommand = pi._recorded.commands['gsd'];
|
|
assert.ok(gsdCommand, 'registers /gsd command');
|
|
assert.equal(typeof gsdCommand.handler, 'function', '/gsd registers a handler(args, ctx) — pi\'s REAL ExtensionAPI shape, not execute(ctx)');
|
|
assert.equal(typeof gsdCommand.getArgumentCompletions, 'function', '/gsd registers getArgumentCompletions');
|
|
assert.ok(pi._recorded.tools['gsd_invoke'], 'registers gsd_invoke tool');
|
|
assert.equal(typeof pi._recorded.tools['gsd_invoke'].execute, 'function');
|
|
assert.ok(pi._recorded.events['tool_call'], 'subscribes to tool_call');
|
|
assert.ok(pi._recorded.events['before_provider_request'], 'subscribes to before_provider_request');
|
|
});
|
|
|
|
test('REACHABILITY: parseGsdCommandArgs tokenizes a raw args string into {family, subcommand, args}', () => {
|
|
const parsed = _internals.parseGsdCommandArgs('phase add --name test');
|
|
assert.deepEqual(parsed, { family: 'phase', subcommand: 'add', args: ['--name', 'test'] });
|
|
});
|
|
|
|
test('REACHABILITY: empty args dispatch a working default (gsd-tools.cjs --help), not the broken "query help"', () => {
|
|
const parsed = _internals.parseGsdCommandArgs('');
|
|
assert.equal(parsed.family, '--help');
|
|
assert.equal(parsed.subcommand, undefined);
|
|
});
|
|
|
|
test('REACHABILITY: the /gsd handler dispatches a real family through gsd-tools.cjs and returns real output (keystone wired)', async () => {
|
|
const pi = mockPi();
|
|
gsdPiExtension(pi);
|
|
const dir = createTempDir();
|
|
try {
|
|
// #3217 (ADR-3180 §7.6 rule 4): a free-form ROADMAP.md (no version
|
|
// token) is COMPLETE scope for windowing (§7.1) — without this, a
|
|
// bare temp dir has no ROADMAP.md at all (UNREADABLE) and `percent`
|
|
// is withheld (null), breaking this reachability proxy.
|
|
fs.mkdirSync(path.join(dir, '.planning'), { recursive: true });
|
|
fs.writeFileSync(path.join(dir, '.planning', 'ROADMAP.md'), '# Roadmap\n');
|
|
const result = await pi._recorded.commands['gsd'].handler('progress json', { cwd: dir });
|
|
// #2991: handler returns { content: [{ type: 'text', text }] } (Pi's display shape), not a bare string.
|
|
assert.ok(result && Array.isArray(result.content) && result.content[0].type === 'text',
|
|
`/gsd handler must return Pi's display shape { content: [{ type: 'text', text }] }; got: ${JSON.stringify(result).slice(0, 200)}`);
|
|
const parsed = JSON.parse(result.content[0].text);
|
|
assert.equal(typeof parsed.percent, 'number', '/gsd dispatch reached gsd-tools.cjs for real (the engine was reached)');
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('REACHABILITY: an unknown family surfaces a clear GSD error, not a throw', async () => {
|
|
const pi = mockPi();
|
|
gsdPiExtension(pi);
|
|
const dir = createTempDir();
|
|
try {
|
|
const result = await pi._recorded.commands['gsd'].handler('no-such-family-8675309', { cwd: dir });
|
|
// #2991: handler returns { content: [{ type: 'text', text }] } (Pi's display shape).
|
|
assert.ok(result && Array.isArray(result.content) && result.content[0].type === 'text',
|
|
`error result must carry Pi's display shape; got: ${JSON.stringify(result).slice(0, 200)}`);
|
|
const text = result.content[0].text;
|
|
assert.match(text, /GSD error:/);
|
|
assert.match(text, /no-such-family-8675309|Unknown command/);
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('REACHABILITY: the gsd_invoke tool dispatches through the engine and returns real content', async () => {
|
|
const pi = mockPi();
|
|
gsdPiExtension(pi);
|
|
const dir = createTempDir();
|
|
try {
|
|
// #3217 (ADR-3180 §7.6 rule 4): see the /gsd handler reachability test
|
|
// above — a bare temp dir has no ROADMAP.md (UNREADABLE), withholding
|
|
// `percent`.
|
|
fs.mkdirSync(path.join(dir, '.planning'), { recursive: true });
|
|
fs.writeFileSync(path.join(dir, '.planning', 'ROADMAP.md'), '# Roadmap\n');
|
|
const result = await pi._recorded.tools['gsd_invoke'].execute(
|
|
'call-1',
|
|
{ family: 'progress', subcommand: 'json' },
|
|
null,
|
|
null,
|
|
{ cwd: dir },
|
|
);
|
|
assert.ok(result && Array.isArray(result.content), 'gsd_invoke returns {content:[...]}');
|
|
const parsed = JSON.parse(result.content[0].text);
|
|
assert.equal(typeof parsed.percent, 'number', 'gsd_invoke dispatch reached gsd-tools.cjs for real');
|
|
} finally {
|
|
cleanup(dir);
|
|
}
|
|
});
|
|
|
|
test('gsd_invoke rejects a missing "family" without dispatching', async () => {
|
|
const pi = mockPi();
|
|
gsdPiExtension(pi);
|
|
const result = await pi._recorded.tools['gsd_invoke'].execute('call-2', {}, null, null, {});
|
|
assert.match(result.content[0].text, /requires a non-empty string "family"/);
|
|
});
|
|
|
|
test('gsdPiExtension throws without pi ExtensionAPI (fail-closed)', () => {
|
|
assert.throws(() => gsdPiExtension(null), /ExtensionAPI is required/);
|
|
});
|