fix(#4794): decision-coverage answers an unmeasured shape on could-not-parse; a non-file context path fails closed (#4889)

* test(#4794): failing-first — could-not-parse must answer an unmeasured shape; a directory context path fails closed

* fix(#4794): could-not-parse answers an unmeasured shape (null counts, unreadable ids, no uncovered); a non-file context path fails closed

* chore(#4794): backfill changeset PR number (4889)

* test(#4794): skip the directory-identity probe when the platform cannot discriminate (windows runner volume collapse, measured)

Two consecutive windows conformance runs failed the probe with measured identical
(dev, ino) for two distinct mkdtemp directories (dev=3606225537, ino=9007199255243448
for both) — a runner-volume property, not a regression in the guard. On such a
platform the guard's identity containment degrades to refuse-everything (fail-closed,
documented); the probe asserts capability, so the honest response is an explicit
t.skip carrying the measurement (ADR-2719 §6), not a red lane for every PR.

---------

Co-authored-by: sim <sim@local>
This commit is contained in:
Tom Boucher
2026-09-20 02:53:58 -04:00
committed by GitHub
parent 3d2cb1fb01
commit 822934c901
5 changed files with 181 additions and 15 deletions

View File

@@ -761,9 +761,13 @@ describe('FIX B gate-level: parse-miss → passed:false regardless of covered de
msg.includes('could not') || msg.includes('format') || msg.includes('mismatch') || msg.includes('parse'),
`Message must indicate parse/format issue, not D-01 coverage gap. Got: "${parsed.message}"`
);
// Confirm D-01 is NOT in uncovered[] — the failure is parse-miss, not a coverage gap
assert.deepStrictEqual(parsed.uncovered, [],
`uncovered must be empty (D-01 is covered; failure is parse-miss). Got: ${JSON.stringify(parsed.uncovered)}`);
// Confirm the answer is UNMEASURED (#4794): no covered/uncovered fields —
// the failure is parse-miss, not a coverage measurement.
assert.strictEqual(parsed.covered, null, 'covered must be null — nothing was measured');
assert.strictEqual(parsed.total, null, 'total must be null — nothing was measured');
assert.ok(!('uncovered' in parsed), 'uncovered must be OMITTED — the list was never built');
assert.ok(Array.isArray(parsed.unreadable) && parsed.unreadable.includes('D-02'),
`unreadable must carry the malformed bullet's id, got: ${JSON.stringify(parsed.unreadable)}`);
});
test('verify-side: valid D-01 covered + malformed D-02 → verify advisory surfaces could-not-parse', () => {
@@ -3133,3 +3137,103 @@ describe('#4788: code spans in the bold lead-in are opaque to the separator gram
assert.deepEqual(r.decisions.map((d) => d.id), ['D-01', 'D-91', 'D-119', 'D-92']);
});
});
// ─── #4794: a gate that measured nothing must not emit the fields of one that did ──
describe('#4794: decision-coverage answers an unmeasured shape on could-not-parse and a non-file context', () => {
let tmpDir;
let planningDir;
let phaseDir;
const contentWith = (bullets) => `<decisions>\n${bullets.map((b) => '- ' + b).join('\n')}\n</decisions>`;
beforeEach(() => {
tmpDir = createTempProject('gsd-4794-');
planningDir = path.join(tmpDir, '.planning');
phaseDir = path.join(planningDir, 'phases', '01-init');
fs.mkdirSync(phaseDir, { recursive: true });
});
afterEach(() => cleanup(tmpDir));
function writePlanFile4794(name, body) {
fs.writeFileSync(path.join(phaseDir, `${name}-PLAN.md`), body);
}
test('#4794: could-not-parse answers an unmeasured shape — null counts, unreadable ids, no uncovered', () => {
// The issue's repro: D-01 parses; D-02's title carries a second colon in
// plain prose → parse-miss. The gate used to answer covered:0/uncovered:[]
// — the fields of a measurement that never happened.
writeContextFile(phaseDir, [
'# Context',
'',
'<decisions>',
'',
'- **D-01: The list shows one row per contact.** Nothing else changes.',
'- **D-02: Two managers creating a card for the same pair: the second is rejected.** One pair, one card.',
'',
'</decisions>',
].join('\n'));
writePlanFile4794('01', '# Plan\n## Objective\nImplement feature.\n');
const contextPath = path.join(phaseDir, 'CONTEXT.md');
const result = runDecisionCoveragePlan(phaseDir, contextPath, tmpDir);
const parsed = JSON.parse(result.output || '{}');
assert.strictEqual(parsed.passed, false, 'the gate must still block');
assert.strictEqual(parsed.reason, 'could-not-parse');
assert.strictEqual(parsed.total, null, 'total must be null — nothing was measured');
assert.strictEqual(parsed.covered, null, 'covered must be null — nothing was measured');
assert.ok(!('uncovered' in parsed), 'uncovered must be OMITTED — the list was never built');
assert.ok(
Array.isArray(parsed.unreadable) && parsed.unreadable.includes('D-02'),
`the ids that failed to parse must be carried as unreadable, got: ${JSON.stringify(parsed.unreadable)}`,
);
assert.ok(
(parsed.message || '').includes('D-02'),
'the message must name the unreadable id',
);
});
test('#4794: a directory as the context path fails closed naming the path', () => {
// The issue's repro 2: the adjacent same-looking positionals swapped.
// fs.existsSync is true for a directory; the read yields nothing; the gate
// used to certify passed:true on a phase full of decisions.
writeContextFile(phaseDir, [
'# Context',
'',
'<decisions>',
'',
'- **D-01: The list shows one row per contact.** Nothing else changes.',
'',
'</decisions>',
].join('\n'));
writePlanFile4794('01', '# Plan\n## Objective\nImplement feature.\n');
const contextPath = phaseDir; // the DIRECTORY, swapped for the file
const result = runDecisionCoveragePlan(phaseDir, contextPath, tmpDir);
const parsed = JSON.parse(result.output || '{}');
assert.strictEqual(parsed.passed, false, 'must fail closed');
assert.strictEqual(parsed.skipped, false, 'must not be a green skip');
assert.ok(
(parsed.message || '').includes(contextPath) || (parsed.reason || '').includes('not a file'),
`the answer must name the path and what it is, got: ${JSON.stringify(parsed)}`,
);
});
test('#4794: extractDecisions surfaces the ids of bullets that failed to parse', () => {
const { extractDecisions: extract } = require(path.join(__dirname, '..', 'gsd-core', 'bin', 'lib', 'decisions.cjs'));
const md = contentWith([
'**D-01: The list shows one row per contact.** Nothing else changes.',
'**D-02: Two managers creating a card for the same pair: the second is rejected.** One pair, one card.',
'**D4x-01** ratio 3:1',
]);
const r = extract(md);
assert.strictEqual(r.outcome, 'could-not-parse');
assert.ok(Array.isArray(r.unreadableIds) && r.unreadableIds.includes('D-02'),
`unreadableIds must carry the failed bullet's id, got: ${JSON.stringify(r.unreadableIds)}`);
// #4130's phase-prefixed ID_ATTEMPT shape must be captured too.
assert.ok(r.unreadableIds.includes('D4x-01'), `phase-prefixed id must be captured, got: ${JSON.stringify(r.unreadableIds)}`);
assert.ok(!r.unreadableIds.includes('D-01'), 'the parsed bullet is not unreadable');
});
});

View File

@@ -3636,6 +3636,21 @@ describe('#3712 in-process home confinement', () => {
t.after(() => { cleanup(a); cleanup(b); });
const sa = fs.statSync(a);
const sb = fs.statSync(b);
// #4794 fold-in (windows conformance lane, 2 consecutive runs): a runner
// image whose temp volume reports an identical synthesized (dev, ino) for
// two distinct directories cannot discriminate at all. On such a platform
// the guard's identity containment degrades to refuse-everything (fail-
// closed, documented) — there is no behavior this probe can assert, only
// capability to report. Measured evidence rides in the skip reason (the
// ADR-2719 §6 explicit-skip discipline: reported as skipped, never a bare
// return that scores a PASS). When the platform CAN discriminate, the
// original assertions run unchanged.
if (sa.dev === sb.dev && sa.ino === sb.ino) {
t.skip(`this platform reports an identical identity for two distinct directories ` +
`(dev=${sa.dev}, ino=${sa.ino}) — identity-based containment would refuse ` +
'everything here; the guard remains fail-closed but this probe has nothing to assert');
return;
}
assert.ok(sa.dev !== sb.dev || sa.ino !== sb.ino,
`two distinct directories share an identity (dev=${sa.dev}/${sb.dev}, ino=${sa.ino}/${sb.ino}) — ` +
'isInside() would then match its first ancestor and refuse everything');