* fix(#3850): surface gaps_found VERIFICATION files in audit-uat cmdAuditUat admits `human_needed` OR `gaps_found`, but parseVerificationItems had a body only for the first and returned an empty array for the second — standing on a comment deferring to `plan-phase --gaps`, a different command audit-uat never reaches. Since cmdAuditUat pushes a file into `results` only when `items.length > 0`, a `gaps_found` report did not under-report: it vanished, taking its phase's `by_phase` row with it, so a clean-looking total gave the reader no cue anything was skipped. Eligibility now has one owner (the caller) and parseVerificationItems reports what the file says. The closed-entry filter could not be built on extractFrontmatter: its array-item parser keeps only each `- ` entry's FIRST line and has no notion of nested key/value objects, so an entry's `status:`/ `resolution:` siblings never reach its output and a closed entry is indistinguishable from an open one downstream. Rather than grow a competing object-list parser — or change extractFrontmatter, whose blast radius is every frontmatter consumer in the repo — this reads the raw segment BEFORE the flattening, via the existing anchored sliceTopLevelFrontmatterSegments, and hands it to the `## Gaps` machinery that already parses exactly this `- `-opened, indentation- continued shape. The human_needed path is byte-for-byte unchanged: same reader, same display names, same numbering, no resolved-entry filtering — pinned by a test and verified by identical CLI output on base and head. parseGapsItems keeps its narrower `status: resolved` rule so no *-UAT.md behaviour moves. Closes #3850 * chore(#3850): backfill changeset pr number for #3879 * fix(#3850): one parse per entry, one fence parser, one resolved-entry rule Adversarial review on #3879: B1, B2, M3, m5, m8 and n9. B1 — `sliceFrontmatterArrayEntries` hand-rolled a second frontmatter fence regex, which re-asserted the byte-0 rule #2977 removed: a BOM'd file (PowerShell 5.1 `>`/`Out-File` writes one by default) sliced nothing, so a `gaps_found` report vanished from the audit exactly as it did before this fix — this issue's own symptom, on a platform the repo already has a named defect class for. `extractFrontmatter`'s BOM+fence logic is now factored out as `frontmatterRegion` and shared. One fence parser, not two. B2 — the resolved-entry skip paired two DIFFERENT parsers by array index: `parseYamlRegion` is indent-blind, `splitGapsEntries` is indent-anchored. A block sequence written at its key's indent — ordinary, legal YAML — makes them disagree about entry count, and from the first disagreement every index names a different entry, so an OPEN entry inherits a CLOSED one's resolution and is silently dropped. That is the defect this PR exists to fix, reintroduced inside the fix. Display name and sibling fields now come from ONE parse of the raw slice; `frontmatterEntryDisplayName` applies `parseQuotedScalar` exactly as `parseYamlRegion` does, so the string is byte-identical to what `extractFrontmatter` produced. The flattened array remains the #2286 GATE, but is no longer the source of items. `sliceFrontmatterArrayEntries` also takes the LAST duplicate key, matching `parseYamlRegion`'s last-wins assignment. M3 — `frontmatterEntryToUatItem` is the single entry->UatItem mapper both readers use, rather than two copies differing only in `result`. m8 — closed entries are skipped on BOTH statuses. The earlier asymmetry cited an acceptance criterion #3850 does not contain: the issue has no AC section, and its suggested fix (2) states the skip unconditionally, naming a file with 14 of 16 entries resolved. That file is `human_needed`, so the asymmetry left the reporter's own scenario over-reporting by 14. m5 — `sliceTopLevelFrontmatterSegments`' contract doc names both consumers and says the column-0 boundary rule is now a cross-module contract. n9 — the vestigial bare block is gone and its body de-indented. Tests: the B1 BOM case, B2's nested-sequence and bare-bullet repros, a CRLF fixture (M4 — it survived by accident, now pinned) and the unified skip rule. Fail-first verified by running the new tests against the pre-fix build: the BOM, nested-sequence and unified-skip cases are red there. * fix(#3850): read the entries as objects, not as re-parsed display text Rebased onto `next`, which changed the ground this fix stood on. ADR-3473 §8.1 (#3881) replaced the hand-rolled frontmatter scanner with the vendored js-yaml: `parseQuotedScalar` and `parseYamlRegion` no longer exist, and an object entry now flattens to `test: A, resolution: R` rather than to its first line. The original mechanism existed ONLY to work around that lossy first-line flattening — it sliced the raw frontmatter segment and re-parsed each entry by hand so a `resolution:` sibling was visible at all. With a real parser upstream that workaround is obsolete, so it is deleted rather than repaired: `sliceFrontmatterArrayEntries`, `frontmatterEntryDisplayName`, the `splitGapsEntries`/`extractGapEntryFields` reuse and the second fence regex are all gone. `frontmatter.cts` instead exposes `frontmatterObjectListEntries(content, key)` — the same parse `extractFrontmatter` runs (same BOM strip, same byte-0 fence, same anchor/alias and sentinel guards, same ambiguous-colon repair), stopping one step before the display flattening. `flattenObjectListItem` is exposed alongside it so a caller deriving a display name produces the byte-identical string `extractFrontmatter` would have. That collapses the review's blockers into properties of the parse rather than things this fix has to get right: - B1 (BOM) — shares `extractFrontmatter`'s strip; verified through the CLI. - B2 (index pairing) — there is no second reader. Display name and sibling fields come from one object. - M3 (duplicate mapper) — one `frontmatterEntryToUatItem` for both readers. - M4 (CRLF) — js-yaml's, not ours; verified through the CLI. Also confirmed on the rebased base, per review: #3850 still reproduces on `next` after #3707 landed (`total_files: 0`, `total_items: 0` on a `gaps_found` fixture), so this PR is still doing work #3707 did not do. Nothing was dropped as redundant. One behaviour note: `entryField` returns a present value verbatim and treats only whitespace-only as absent. Trimming would rewrite an author's `truth:` on its way to becoming the display name. * fix(#3850): keep every frontmatter list entry at its own row Review round 3's Blocker. `frontmatterObjectListEntries` filtered its result to objects, and filtering COMPACTS: `parseHumanVerificationItems` then numbered the survivors by their position in the compacted array. On a list mixing object and non-object entries the non-object rows disappeared outright and the rest were renumbered — #3850's own vanishing-row defect, reached through entry SHAPE instead of file STATUS. Base never had it: it walked the display array, so every row surfaced at its own position. Renamed to `frontmatterListEntries` and it no longer filters (the name now matches what it returns). Deciding what a non-object entry MEANS is a caller's judgement; dropping it is nobody's. Both readers now walk the DISPLAY array — one element per row, the array #2286 already gates on — and consult the parsed array only for "does this entry carry a closure field?". `parsedEntriesFor` owns that pairing and checks the two lengths agree before trusting an index; all-null is the correct degradation, since over-reporting a closed row is recoverable and closing the wrong one is not. Names stay byte-identical to base for every entry shape, including a nested sequence (`[nested]`, not `["nested"]`). Same class closed in the gaps reader: a non-object `gaps:` entry surfaced nothing at all and now surfaces as `unknown`, which is this module's documented fail-safe direction (`parseGapsItems`) on a false-negative bug. Also restores the shared fence parser round 2 accepted. The ADR-3473 rebase dropped `frontmatterRegion` and left the BOM strip and byte-0 fence rule inlined twice; `extractFrontmatter` now routes through it, so "one fence parser" is enforced rather than asserted in a comment. Minors: `frontmatterEntryToUatItem`'s dead `forcedResult` option deleted and its "shared by both readers" comment corrected — it has one call site, and the two readers differ deliberately, each mirroring its own established sibling (`parseGapsItems` vs #2286). Documented at the divergence. Tests: `B2` asserted a name substring, so it passed while the row was mis-numbered and would have passed through outright loss; it now asserts positions and count. B2b pins the reviewer's 6-entry mixed fixture verbatim, B2c the survivors' file positions across skipped rows, B2d the gaps reader. All four fail-first against the reviewed head; 332/332 green with the fix. * fix(#3850): make status authoritative, and let the two gaps readers agree Round 4 review, all five findings. Major. `isFrontmatterEntryResolved` treated a non-empty `resolution:` as closure regardless of `status:`, so `status: failed` + `resolution: "attempted retry, still failing"` vanished from the report — the silently-vanishing-item defect #3850 exists to close, reached by field combination instead of file status. Closure is now per key, because the two keys have different conventions and one rule cannot serve both: `gaps:` `status: resolved` only, byte-identical to the rule `parseGapsItems` applies to a `## Gaps` markdown section, so one authored entry cannot read closed in one reader and open in the other. `human_verification:` a bare `resolution:` still closes, since that is how verifier-written entries record it — but a readable `status:` that contradicts it wins. A single unified rule was the first draft and is wrong: it closes a frontmatter `gaps:` entry carrying `resolution:` and no `status:`, which `parseGapsItems` surfaces, and `parseVerificationGapsItems`' own docstring claims it mirrors that reader's fail-safe status handling. The contradiction guard is not a judgment call about YAML. It is the rule this codebase already applies to the same field pair: `validateResolution` (probe-core.cts) rejects a populated `resolution:` on a non-resolved status outright — "a populated payload is an authoring mistake ... Reject it so the mistake surfaces." A reporter cannot throw, so it surfaces the item. Minor 1. Direct unit tests for `frontmatterListEntries` and `flattenObjectListItem` in `tests/frontmatter.unit.test.cjs`, the file that historically co-changes with `frontmatter.cts`. They were reachable only through `uat.cts`' readers before. Minor 2. `parsedEntriesFor`'s degrade-to-all-null branch is asserted directly. Verified unreachable through content rather than assumed: both readers enter through `frontmatterRegion`, `extractFrontmatter`'s only extra argument gates a warning, and `normalizeParsedValue`'s `value.map` is 1:1. It is a drift alarm for a future edit to either parser, so the helper is exported for tests rather than left as the one unpinned branch. Minor 3. The vestigial `const skipResolved = true` and its dead conditional are gone. Minor 4. `frontmatterEntryToUatItem` no longer reads `test:`. A `gaps:` entry has no `test:` in its vocabulary — the template's entries carry truth/status/reason/artifacts/missing — so it was speculative support for a field the shape does not have, and it collided with the 1..N row numbers `parseHumanVerificationItems` assigns by array position. Not reading it makes the collision impossible; an offset would have rewritten an authored value, against `entryField`'s verbatim contract. Docs, changeset and the dispatcher docstring all stated the unconditional rule and are corrected — three prior rounds here were comment/code drift. Fail-first proven: restoring the universal rule reddens all three new unit tests and both rewritten properties. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H3eK225hgcnEDZsnmtaP1U --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
This commit is contained in:
@@ -24,6 +24,8 @@ const {
|
||||
stripFrontmatter,
|
||||
noOpObjectListSetError,
|
||||
parseMustHavesBlock,
|
||||
frontmatterListEntries,
|
||||
flattenObjectListItem,
|
||||
FRONTMATTER_SCHEMAS,
|
||||
agentScalarNeedsDoubleQuoting,
|
||||
escapeDoubleQuotedScalar,
|
||||
@@ -1857,3 +1859,100 @@ describe('#3742: propagateCommentChannel — merge, root filter, trailing dedupe
|
||||
assert.deepEqual(ch.trailing, ['# trail']);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── frontmatterListEntries (#3850) ───────────────────────────────────────────
|
||||
//
|
||||
// Direct coverage for the two exports #3850 added (#3879 review round 4, Minor
|
||||
// 1). They were previously exercised only through `uat.cts`' readers, so a
|
||||
// change in either primitive could only be caught by a test about something
|
||||
// else.
|
||||
|
||||
describe('frontmatterListEntries: returns parsed entries, not display strings', () => {
|
||||
const doc = ['---',
|
||||
'gaps:',
|
||||
' - truth: "The widget renders"',
|
||||
' status: failed',
|
||||
' reason: "only on one platform"',
|
||||
' - truth: "The other thing"',
|
||||
' status: resolved',
|
||||
'---',
|
||||
'',
|
||||
'# Body',
|
||||
''].join('\n');
|
||||
|
||||
test('object entries come back as objects with their fields intact', () => {
|
||||
const entries = frontmatterListEntries(doc, 'gaps');
|
||||
assert.equal(entries.length, 2);
|
||||
assert.equal(entries[0].status, 'failed');
|
||||
assert.equal(entries[0].truth, 'The widget renders');
|
||||
assert.equal(entries[0].reason, 'only on one platform');
|
||||
assert.equal(entries[1].status, 'resolved');
|
||||
});
|
||||
|
||||
test('a field is readable as a field, not recoverable only from prose', () => {
|
||||
// The whole reason this export exists: `extractFrontmatter` flattens the
|
||||
// same entry to a display string in which a real `resolution:` field and
|
||||
// the same text quoted inside `truth:` are indistinguishable.
|
||||
const trap = ['---',
|
||||
'gaps:',
|
||||
' - truth: "the report said resolution: done"',
|
||||
' status: failed',
|
||||
'---',
|
||||
''].join('\n');
|
||||
const [entry] = frontmatterListEntries(trap, 'gaps');
|
||||
assert.equal(entry.resolution, undefined, 'prose inside truth is not a resolution field');
|
||||
assert.equal(entry.status, 'failed');
|
||||
});
|
||||
|
||||
test('EVERY element is returned at its own index, whatever its type', () => {
|
||||
// #3850 review round 3, Blocker: filtering to objects compacted the array
|
||||
// and renumbered a caller iterating by position.
|
||||
const mixed = ['---',
|
||||
'gaps:',
|
||||
' - truth: "an object"',
|
||||
' - a bare scalar',
|
||||
' -',
|
||||
' - - nested',
|
||||
' - sequence',
|
||||
'---',
|
||||
''].join('\n');
|
||||
const entries = frontmatterListEntries(mixed, 'gaps');
|
||||
assert.equal(entries.length, 4);
|
||||
assert.equal(typeof entries[0], 'object');
|
||||
assert.equal(entries[1], 'a bare scalar');
|
||||
assert.equal(entries[2], null);
|
||||
assert.ok(Array.isArray(entries[3]));
|
||||
});
|
||||
|
||||
test('null for every "nothing to iterate" case, never a throw', () => {
|
||||
assert.equal(frontmatterListEntries('no frontmatter here', 'gaps'), null);
|
||||
assert.equal(frontmatterListEntries('---\ngaps:\n - a\n', 'gaps'), null, 'unterminated');
|
||||
assert.equal(frontmatterListEntries('---\nother: 1\n---\n', 'gaps'), null, 'key absent');
|
||||
assert.equal(frontmatterListEntries('---\ngaps: not-an-array\n---\n', 'gaps'), null, 'not an array');
|
||||
assert.equal(frontmatterListEntries('---\n : : :\n---\n', 'gaps'), null, 'unparseable');
|
||||
});
|
||||
|
||||
test('agrees index-for-index with extractFrontmatter\'s display array', () => {
|
||||
// `parsedEntriesFor` in uat.cts pairs these two by index and degrades to
|
||||
// all-null if their lengths ever disagree. Pin the agreement here, where
|
||||
// the two parsers actually live.
|
||||
const display = extractFrontmatter(doc).gaps;
|
||||
const parsed = frontmatterListEntries(doc, 'gaps');
|
||||
assert.equal(display.length, parsed.length);
|
||||
});
|
||||
});
|
||||
|
||||
describe('flattenObjectListItem (#3850)', () => {
|
||||
test('renders an object entry the way extractFrontmatter displays it', () => {
|
||||
const entry = { test: 'Do the thing', expected: 'it works' };
|
||||
const rendered = flattenObjectListItem(entry);
|
||||
const viaExtract = extractFrontmatter(['---',
|
||||
'human_verification:',
|
||||
' - test: "Do the thing"',
|
||||
' expected: "it works"',
|
||||
'---',
|
||||
''].join('\n')).human_verification[0];
|
||||
assert.equal(rendered, viaExtract,
|
||||
'a caller naming an item from the parsed object must produce the byte-identical string');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,6 +22,8 @@ const {
|
||||
parseUatItemsWithStats,
|
||||
DEFERRED_MARKER_ALT,
|
||||
DEFERRED_BULLET_MARKERS,
|
||||
parseVerificationItems,
|
||||
parsedEntriesFor,
|
||||
} = require('../gsd-core/bin/lib/uat.cjs');
|
||||
const { iterateBullets } = require('../gsd-core/bin/lib/markdown-sectionizer.cjs');
|
||||
|
||||
@@ -815,6 +817,128 @@ All checks passed.
|
||||
assert.strictEqual(output.summary.total_items, 0);
|
||||
assert.strictEqual(output.summary.total_files, 0);
|
||||
});
|
||||
|
||||
// ─── #3879 review round 4, Major: `status:` is authoritative ──────────────
|
||||
//
|
||||
// A `resolution:` note beside a status that is not `resolved` is an
|
||||
// authoring mistake, not a closure assertion — the rule `validateResolution`
|
||||
// (probe-core.cts) already applies to this same field pair, where it rejects
|
||||
// the combination outright rather than counting the item as closed. A
|
||||
// reporter cannot throw, so the fail-safe equivalent is to SURFACE the item.
|
||||
// Dropping it would be the silently-vanishing-item defect #3850 exists to
|
||||
// close, reached by field COMBINATION instead of file STATUS.
|
||||
|
||||
test('a human_verification entry whose status contradicts its resolution still surfaces', () => {
|
||||
const items = parseVerificationItems(`---
|
||||
status: human_needed
|
||||
human_verification:
|
||||
- test: "Retry the upload"
|
||||
status: failed
|
||||
resolution: "attempted retry, still failing"
|
||||
---
|
||||
`, 'human_needed');
|
||||
assert.strictEqual(items.length, 1);
|
||||
});
|
||||
|
||||
test('a gaps entry carrying only a resolution note surfaces — gaps closes on status alone', () => {
|
||||
// `parseGapsItems`, the `## Gaps` markdown reader, closes on
|
||||
// `status: resolved` and nothing else. This frontmatter reader takes that
|
||||
// rule verbatim so the same authored entry cannot read closed in one and
|
||||
// open in the other.
|
||||
const items = parseVerificationItems(`---
|
||||
status: gaps_found
|
||||
gaps:
|
||||
- truth: "The widget renders"
|
||||
resolution: "a note, not a closure assertion"
|
||||
---
|
||||
`, 'gaps_found');
|
||||
assert.strictEqual(items.length, 1);
|
||||
assert.strictEqual(items[0].result, 'unknown');
|
||||
});
|
||||
|
||||
test('a gaps entry whose status contradicts its resolution still surfaces', () => {
|
||||
const items = parseVerificationItems(`---
|
||||
status: gaps_found
|
||||
gaps:
|
||||
- truth: "The widget renders"
|
||||
status: failed
|
||||
resolution: "attempted retry, still failing"
|
||||
---
|
||||
`, 'gaps_found');
|
||||
assert.strictEqual(items.length, 1);
|
||||
assert.strictEqual(items[0].result, 'failed');
|
||||
});
|
||||
|
||||
// ─── #3879 review round 4, Minor 2: the alignment guard ──────────────────
|
||||
//
|
||||
// `parsedEntriesFor` pairs the display array with the parsed array BY INDEX
|
||||
// and degrades to all-null if their lengths disagree, so a mis-paired index
|
||||
// can never close the wrong row. That branch is unreachable through the two
|
||||
// readers — both parsers share `frontmatterRegion`, and the display step is
|
||||
// 1:1 — so it is asserted against the function directly. Called with the
|
||||
// real content the readers pass, plus a `flattened` array of the wrong
|
||||
// length, which is exactly the drift the guard exists to catch.
|
||||
|
||||
describe('parsedEntriesFor: index pairing and its degradation', () => {
|
||||
const doc = `---
|
||||
status: gaps_found
|
||||
gaps:
|
||||
- truth: "first"
|
||||
status: failed
|
||||
- truth: "second"
|
||||
status: resolved
|
||||
---
|
||||
`;
|
||||
|
||||
test('pairs each display entry with its own parsed object', () => {
|
||||
const paired = parsedEntriesFor(doc, 'gaps', ['first-display', 'second-display']);
|
||||
assert.equal(paired.length, 2);
|
||||
assert.equal(paired[0].truth, 'first');
|
||||
assert.equal(paired[1].truth, 'second');
|
||||
});
|
||||
|
||||
test('a length disagreement degrades to all-null — no entry is skipped as closed', () => {
|
||||
// Over-reporting is the correct degradation: a wrong index would name a
|
||||
// DIFFERENT entry's fields and close the wrong row.
|
||||
const shorter = parsedEntriesFor(doc, 'gaps', ['only-one']);
|
||||
assert.deepEqual(shorter, [null]);
|
||||
const longer = parsedEntriesFor(doc, 'gaps', ['a', 'b', 'c']);
|
||||
assert.deepEqual(longer, [null, null, null]);
|
||||
});
|
||||
|
||||
test('a non-object entry is null at its own index, not dropped', () => {
|
||||
const mixed = `---
|
||||
gaps:
|
||||
- truth: "an object"
|
||||
- a bare scalar
|
||||
---
|
||||
`;
|
||||
const paired = parsedEntriesFor(mixed, 'gaps', ['x', 'y']);
|
||||
assert.equal(paired.length, 2);
|
||||
assert.equal(paired[0].truth, 'an object');
|
||||
assert.equal(paired[1], null);
|
||||
});
|
||||
|
||||
test('an absent key degrades to all-null rather than throwing', () => {
|
||||
assert.deepEqual(parsedEntriesFor('---\nother: 1\n---\n', 'gaps', ['a', 'b']), [null, null]);
|
||||
});
|
||||
});
|
||||
|
||||
test('both closure spellings still close a human_verification entry', () => {
|
||||
const items = parseVerificationItems(`---
|
||||
status: human_needed
|
||||
human_verification:
|
||||
- test: "Answered"
|
||||
resolution: "RESOLVED"
|
||||
- test: "Also answered"
|
||||
status: resolved
|
||||
- test: "Still open"
|
||||
status: partial
|
||||
---
|
||||
`, 'human_needed');
|
||||
assert.strictEqual(items.length, 1);
|
||||
assert.strictEqual(items[0].test, 3, 'the surfaced entry keeps its original row');
|
||||
});
|
||||
});
|
||||
|
||||
// Regression: #2286 — parseVerificationItems never read the frontmatter's
|
||||
@@ -8289,3 +8413,514 @@ describe('#3781: acknowledge supports the heading-delimited entry shape', () =>
|
||||
'the pre-existing headless splice shape must be untouched');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── #3850: gaps_found VERIFICATION files ────────────────────────────────────
|
||||
//
|
||||
// cmdAuditUat admits `human_needed` OR `gaps_found`, but parseVerificationItems
|
||||
// honoured only the first and returned [] for the second. Because cmdAuditUat
|
||||
// pushes a file into `results` only when `items.length > 0`, a `gaps_found`
|
||||
// report did not under-report — the whole file, and its phase's `by_phase` row,
|
||||
// VANISHED. Every test below fails on base: the gate returns [] regardless of
|
||||
// what the frontmatter holds.
|
||||
describe('#3850 gaps_found VERIFICATION files', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => { tmpDir = createTempProject(); });
|
||||
afterEach(() => { cleanup(tmpDir); });
|
||||
|
||||
/** Write one VERIFICATION file and return the parsed audit-uat payload. */
|
||||
const auditWith = (body, phase = '01-demo') => {
|
||||
const phaseDir = path.join(tmpDir, '.planning', 'phases', phase);
|
||||
fs.mkdirSync(phaseDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(phaseDir, `${phase.split('-')[0]}-VERIFICATION.md`), body);
|
||||
const result = runGsdTools('audit-uat --raw', tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
return JSON.parse(result.output);
|
||||
};
|
||||
|
||||
const HV_TWO = `---
|
||||
phase: 01-demo
|
||||
status: gaps_found
|
||||
human_verification:
|
||||
- test: "Confirm the widget renders on a physical device"
|
||||
expected: "Widget appears within 2s"
|
||||
why_human: "Needs real hardware"
|
||||
- test: "Confirm the audible alert fires"
|
||||
expected: "Alert is audible"
|
||||
why_human: "Needs a human ear"
|
||||
---
|
||||
|
||||
# Verification
|
||||
`;
|
||||
|
||||
test('surfaces a gaps_found file\'s human_verification array (the #3850 defect)', () => {
|
||||
const output = auditWith(HV_TWO);
|
||||
assert.strictEqual(output.summary.total_items, 2);
|
||||
assert.strictEqual(output.summary.total_files, 1);
|
||||
assert.strictEqual(output.results[0].type, 'verification');
|
||||
assert.strictEqual(output.results[0].status, 'gaps_found');
|
||||
assert.strictEqual(output.results[0].items[0].category, 'human_uat');
|
||||
// by_phase carries the phase — the omission mechanism this issue is about.
|
||||
assert.strictEqual(output.summary.by_phase['01'], 2);
|
||||
});
|
||||
|
||||
test('the SAME file under human_needed and gaps_found yields identical human_verification items', () => {
|
||||
// The status token alone decided visibility; it must now decide nothing
|
||||
// about the human_verification reading itself.
|
||||
const asGaps = parseVerificationItems(HV_TWO, 'gaps_found');
|
||||
const asHuman = parseVerificationItems(HV_TWO.replace('status: gaps_found', 'status: human_needed'), 'human_needed');
|
||||
assert.deepStrictEqual(asGaps, asHuman);
|
||||
assert.strictEqual(asGaps.length, 2);
|
||||
});
|
||||
|
||||
test('surfaces a gaps_found file\'s frontmatter gaps array', () => {
|
||||
const output = auditWith(`---
|
||||
phase: 02-gaps
|
||||
status: gaps_found
|
||||
gaps:
|
||||
- truth: "The widget renders"
|
||||
status: partial
|
||||
reason: "Only observed on one platform"
|
||||
test: 7
|
||||
---
|
||||
|
||||
# Verification
|
||||
`, '02-gaps');
|
||||
assert.strictEqual(output.summary.total_items, 1);
|
||||
const item = output.results[0].items[0];
|
||||
assert.strictEqual(item.name, 'The widget renders');
|
||||
assert.strictEqual(item.result, 'partial');
|
||||
assert.strictEqual(item.reason, 'Only observed on one platform');
|
||||
// No `test:` number (#3879 review round 4, Minor 4). A `gaps:` entry has no
|
||||
// `test:` in its vocabulary, and reading one collided with the 1..N row
|
||||
// numbers `parseHumanVerificationItems` assigns by array position — two
|
||||
// items numbered 1 in a single file's combined list.
|
||||
assert.strictEqual(item.test, undefined);
|
||||
});
|
||||
|
||||
test('a gaps entry with no parseable status surfaces as unknown, never dropped (fail-safe)', () => {
|
||||
const items = parseVerificationItems(`---
|
||||
status: gaps_found
|
||||
gaps:
|
||||
- truth: "Garbled entry"
|
||||
---
|
||||
`, 'gaps_found');
|
||||
assert.strictEqual(items.length, 1);
|
||||
assert.strictEqual(items[0].result, 'unknown');
|
||||
});
|
||||
|
||||
test('folded >- scalars inside an entry do not break the entry (real verifier shape)', () => {
|
||||
const items = parseVerificationItems(`---
|
||||
status: gaps_found
|
||||
gaps:
|
||||
- truth: "Gate is fail-open on absence of information"
|
||||
status: partial
|
||||
reason: >-
|
||||
The hub learns a collection's schema version only from a push carrying
|
||||
rows, so a zero-row collection is invisible and the RAM-only hub
|
||||
re-blinds itself on every host restart.
|
||||
---
|
||||
`, 'gaps_found');
|
||||
assert.strictEqual(items.length, 1);
|
||||
assert.strictEqual(items[0].name, 'Gate is fail-open on absence of information');
|
||||
assert.strictEqual(items[0].result, 'partial');
|
||||
});
|
||||
|
||||
describe('closed entries are excluded on the gaps_found path', () => {
|
||||
test('skips resolution:-marked human_verification entries, keeping original 1-based positions', () => {
|
||||
const items = parseVerificationItems(`---
|
||||
status: gaps_found
|
||||
human_verification:
|
||||
- test: "Already answered"
|
||||
resolution: "RESOLVED 2026-01-01 by the phase 4 rig run"
|
||||
- test: "Still outstanding"
|
||||
why_human: "Needs real hardware"
|
||||
---
|
||||
`, 'gaps_found');
|
||||
assert.strictEqual(items.length, 1);
|
||||
// Entry 2 keeps position 2 so a surfaced item still names its row.
|
||||
assert.strictEqual(items[0].test, 2);
|
||||
assert.match(items[0].name, /Still outstanding/);
|
||||
});
|
||||
|
||||
test('skips status: resolved gaps entries', () => {
|
||||
const items = parseVerificationItems(`---
|
||||
status: gaps_found
|
||||
gaps:
|
||||
- truth: "Open"
|
||||
status: partial
|
||||
- truth: "Closed"
|
||||
status: resolved
|
||||
---
|
||||
`, 'gaps_found');
|
||||
assert.strictEqual(items.length, 1);
|
||||
assert.strictEqual(items[0].name, 'Open');
|
||||
});
|
||||
|
||||
test('a resolution:-shaped substring MID-LINE is not a closure marker', () => {
|
||||
// extractGapEntryFields anchors a field to the start of its own trimmed
|
||||
// line; a quoted value mentioning "resolution:" must never close an entry.
|
||||
const items = parseVerificationItems(`---
|
||||
status: gaps_found
|
||||
gaps:
|
||||
- truth: "Deferred until the resolution: pending owner ruling"
|
||||
status: partial
|
||||
---
|
||||
`, 'gaps_found');
|
||||
assert.strictEqual(items.length, 1);
|
||||
});
|
||||
|
||||
test('closed entries are excluded on the human_needed path too', () => {
|
||||
// #3850 review m8: an earlier revision skipped closed entries only on
|
||||
// `gaps_found`, citing an acceptance criterion the issue does not
|
||||
// contain. #3850 has no AC section; its suggested fix (2) states the skip
|
||||
// unconditionally, and the file it cites — 14 of 16 entries resolved — is
|
||||
// a `human_needed` one. The asymmetry left the reporter's own scenario
|
||||
// over-reporting by 14. One rule, both statuses.
|
||||
const items = parseVerificationItems(`---
|
||||
status: human_needed
|
||||
human_verification:
|
||||
- test: "Already answered"
|
||||
resolution: "RESOLVED 2026-01-01"
|
||||
- test: "Still outstanding"
|
||||
---
|
||||
`, 'human_needed');
|
||||
assert.strictEqual(items.length, 1);
|
||||
// The display name keeps `extractFrontmatter`'s flattened shape verbatim
|
||||
// (`normalizeHumanVerificationEntry` strips wrapping quotes only) — this
|
||||
// fix derives the SAME string from the raw slice, it does not prettify it.
|
||||
assert.match(items[0].name, /Still outstanding/);
|
||||
// The surfaced entry keeps its ORIGINAL 1-based row, so it still names
|
||||
// its position in the file after a closed sibling was skipped.
|
||||
assert.strictEqual(items[0].test, 2);
|
||||
});
|
||||
|
||||
test('B2: a nested block sequence at key indent does not drop an OPEN entry', () => {
|
||||
// The review's executed repro. `parseYamlRegion` is indent-blind and
|
||||
// `splitGapsEntries` is indent-anchored, so pairing them by ordinal
|
||||
// position made entry B inherit entry C's `resolution:` and disappear.
|
||||
// Both readings now come from one parse, so there is no index to skew.
|
||||
const items = parseVerificationItems(`---
|
||||
status: human_needed
|
||||
human_verification:
|
||||
- test: "A"
|
||||
steps:
|
||||
- s1
|
||||
- test: "B"
|
||||
- test: "C"
|
||||
resolution: "done"
|
||||
---
|
||||
`, 'human_needed');
|
||||
const names = items.map((i) => i.name).join(' | ');
|
||||
// The display rendering comes from `flattenObjectListItem`, which emits
|
||||
// `test: B` — unquoted — where the pre-#3881 flattener emitted `test: "B`.
|
||||
assert.match(names, /\btest: B\b/, `open entry "B" must survive; got ${JSON.stringify(names)}`);
|
||||
assert.ok(!/\btest: C\b/.test(names), `closed entry "C" must be skipped; got ${JSON.stringify(names)}`);
|
||||
});
|
||||
|
||||
test('B2: a bare bullet does not skew the entry list', () => {
|
||||
// Round-3 Blocker. The original assertion matched `test: B` anywhere in a
|
||||
// joined name string, so it passed while "B" was reported at position 2 —
|
||||
// and would still have passed had the bare bullet been dropped entirely.
|
||||
// The defect was never about the NAME surviving; it was about the ROW
|
||||
// number and the row count. Assert both.
|
||||
const items = parseVerificationItems(`---
|
||||
status: human_needed
|
||||
human_verification:
|
||||
- test: "A"
|
||||
-
|
||||
- test: "B"
|
||||
---
|
||||
`, 'human_needed');
|
||||
assert.deepStrictEqual(
|
||||
items.map((i) => [i.test, i.name]),
|
||||
[[1, 'test: A'], [2, ''], [3, 'test: B']],
|
||||
'every row surfaces at its own 1-based position, bare bullet included',
|
||||
);
|
||||
});
|
||||
|
||||
test('B2b: a mixed object/non-object list keeps every row at its true position', () => {
|
||||
// The reviewer's own 6-entry fixture, verbatim. Against the filtered
|
||||
// implementation this returned THREE items — "A", "D", "F" numbered
|
||||
// 1, 2, 3 — with rows 2, 3 and 5 gone and no trace that anything had
|
||||
// been dropped. That is #3850's defect reached through entry SHAPE
|
||||
// rather than file STATUS, so it is pinned on `gaps_found` where the
|
||||
// union path runs.
|
||||
const items = parseVerificationItems(`---
|
||||
status: gaps_found
|
||||
human_verification:
|
||||
- test: "A"
|
||||
-
|
||||
- bare scalar
|
||||
- test: "D"
|
||||
-
|
||||
- nested
|
||||
- test: "F"
|
||||
---
|
||||
`, 'gaps_found');
|
||||
assert.deepStrictEqual(
|
||||
items.map((i) => [i.test, i.name]),
|
||||
[
|
||||
[1, 'test: A'],
|
||||
[2, ''],
|
||||
[3, 'bare scalar'],
|
||||
[4, 'test: D'],
|
||||
[5, '[nested]'],
|
||||
[6, 'test: F'],
|
||||
],
|
||||
'all six rows surface, each at its own position, named as base named them',
|
||||
);
|
||||
});
|
||||
|
||||
test('B2c: skipped-because-resolved rows leave the survivors numbered by FILE row', () => {
|
||||
// The property the positional index exists for, and the one a count-only
|
||||
// assertion cannot see: rows 2 and 4 are closed, so 1, 3 and 5 surface
|
||||
// with their own numbers rather than being renumbered 1, 2, 3.
|
||||
const items = parseVerificationItems(`---
|
||||
status: human_needed
|
||||
human_verification:
|
||||
- test: "A"
|
||||
- test: "B"
|
||||
resolution: done
|
||||
-
|
||||
- test: "D"
|
||||
status: resolved
|
||||
- test: "E"
|
||||
---
|
||||
`, 'human_needed');
|
||||
assert.deepStrictEqual(
|
||||
items.map((i) => [i.test, i.name]),
|
||||
[[1, 'test: A'], [3, ''], [5, 'test: E']],
|
||||
'closed rows are skipped and the survivors keep their file positions',
|
||||
);
|
||||
});
|
||||
|
||||
test('B2d: a non-object gaps entry surfaces instead of vanishing', () => {
|
||||
// Same class, other reader. `gaps:` entries carry their own status, so a
|
||||
// non-object one has none to read — this module's documented fail-safe
|
||||
// (`parseGapsItems`' 'unknown' fallback) is to surface it rather than
|
||||
// drop it. It is named by the same renderer every other reader uses, so
|
||||
// a YAML null reads '' and not the string "null".
|
||||
const items = parseVerificationItems(`---
|
||||
status: gaps_found
|
||||
gaps:
|
||||
- truth: "G1"
|
||||
status: failed
|
||||
-
|
||||
- bare gap
|
||||
- truth: "G3"
|
||||
status: resolved
|
||||
---
|
||||
`, 'gaps_found');
|
||||
assert.deepStrictEqual(
|
||||
items.map((i) => [i.name, i.result]),
|
||||
[['G1', 'failed'], ['', 'unknown'], ['bare gap', 'unknown']],
|
||||
'every unresolved gaps row surfaces; the resolved one is skipped',
|
||||
);
|
||||
});
|
||||
|
||||
test('B1: a BOM does not make a gaps_found report vanish', () => {
|
||||
// #2977's defect class. A hand-rolled fence regex re-asserts the byte-0
|
||||
// rule and slices nothing, which is this issue's symptom verbatim on the
|
||||
// platform the repo already has a named class for.
|
||||
const items = parseVerificationItems(`\uFEFF---
|
||||
status: gaps_found
|
||||
gaps:
|
||||
- truth: "G1"
|
||||
status: partial
|
||||
---
|
||||
`, 'gaps_found');
|
||||
assert.strictEqual(items.length, 1, 'a BOM-prefixed report must still surface its gaps');
|
||||
assert.strictEqual(items[0].name, 'G1');
|
||||
});
|
||||
|
||||
test('M4: CRLF frontmatter surfaces gaps', () => {
|
||||
const crlf = ['---', 'status: gaps_found', 'gaps:', ' - truth: "G1"', ' status: partial', '---', ''].join('\r\n');
|
||||
const items = parseVerificationItems(crlf, 'gaps_found');
|
||||
assert.strictEqual(items.length, 1);
|
||||
assert.strictEqual(items[0].name, 'G1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('array-population boundaries', () => {
|
||||
const build = (hv, gaps) => [
|
||||
'---', 'status: gaps_found',
|
||||
...(hv === null ? [] : ['human_verification:', ...hv.map((t) => ` - test: "${t}"`)]),
|
||||
...(gaps === null ? [] : ['gaps:', ...gaps.map((t) => ` - truth: "${t}"\n status: partial`)]),
|
||||
'---', '',
|
||||
].join('\n');
|
||||
|
||||
test('empty human_verification + populated gaps still surfaces the gaps', () => {
|
||||
const items = parseVerificationItems(build([], ['G1']), 'gaps_found');
|
||||
assert.strictEqual(items.length, 1);
|
||||
assert.strictEqual(items[0].name, 'G1');
|
||||
});
|
||||
|
||||
test('populated human_verification + no gaps key surfaces only the hv entries', () => {
|
||||
const items = parseVerificationItems(build(['H1'], null), 'gaps_found');
|
||||
assert.strictEqual(items.length, 1);
|
||||
assert.strictEqual(items[0].category, 'human_uat');
|
||||
});
|
||||
|
||||
test('both arrays populated surfaces the union, human_verification first', () => {
|
||||
const items = parseVerificationItems(build(['H1', 'H2'], ['G1']), 'gaps_found');
|
||||
assert.strictEqual(items.length, 3);
|
||||
assert.strictEqual(items[0].category, 'human_uat');
|
||||
assert.strictEqual(items[2].name, 'G1');
|
||||
});
|
||||
|
||||
test('neither key present yields zero items', () => {
|
||||
assert.strictEqual(parseVerificationItems(build(null, null), 'gaps_found').length, 0);
|
||||
});
|
||||
|
||||
test('a single entry (N=1) surfaces', () => {
|
||||
assert.strictEqual(parseVerificationItems(build(['H1'], null), 'gaps_found').length, 1);
|
||||
});
|
||||
|
||||
test('every entry closed yields zero items, so the file is omitted — intended, not the #3850 bug', () => {
|
||||
// The omission this issue reports is a file with OUTSTANDING items
|
||||
// vanishing. A file whose every entry is closed has nothing outstanding,
|
||||
// so `items.length > 0` correctly drops it. Pinned to keep the two cases
|
||||
// distinguishable.
|
||||
const output = auditWith(`---
|
||||
phase: 03-allclosed
|
||||
status: gaps_found
|
||||
human_verification:
|
||||
- test: "Answered"
|
||||
resolution: "RESOLVED"
|
||||
gaps:
|
||||
- truth: "Closed"
|
||||
status: resolved
|
||||
---
|
||||
`, '03-allclosed');
|
||||
assert.strictEqual(output.summary.total_items, 0);
|
||||
assert.strictEqual(output.summary.total_files, 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('property: the closed/open partition', () => {
|
||||
// Text that can never be mistaken for a field line or a closure marker.
|
||||
const bodyArb = fc.string({ minLength: 1, maxLength: 24 })
|
||||
.map((s) => s.replace(/["\\\r\n:]/g, ''))
|
||||
.filter((s) => s.trim().length > 0);
|
||||
|
||||
// Closure is PER KEY (#3879 review round 4, Major), so the property is too.
|
||||
// `gaps:` takes `parseGapsItems`' rule verbatim — `status: resolved` and
|
||||
// nothing else — while `human_verification:` also honours a bare
|
||||
// `resolution:`. Generating one spelling set for both keys is what let the
|
||||
// old universal rule read green.
|
||||
//
|
||||
// `contradiction` is the round-4 Major itself: a `status:` that is not
|
||||
// `resolved` sitting beside a `resolution:` note. It is OPEN under both
|
||||
// keys — `status:` is authoritative wherever it is readable.
|
||||
const OPEN_SPELLINGS = {
|
||||
gaps: {
|
||||
plain: [' status: partial'],
|
||||
// No `status:` at all. Under the gaps rule this is not closure, and
|
||||
// `parseGapsItems` already surfaces it via its 'unknown' fallback.
|
||||
resolutionOnly: [' resolution: "a note, not a closure assertion"'],
|
||||
contradiction: [' status: failed', ' resolution: "attempted retry, still failing"'],
|
||||
},
|
||||
human_verification: {
|
||||
plain: [' status: partial'],
|
||||
contradiction: [' status: failed', ' resolution: "attempted retry, still failing"'],
|
||||
},
|
||||
};
|
||||
const CLOSED_SPELLINGS = {
|
||||
gaps: {
|
||||
status: [' status: resolved'],
|
||||
},
|
||||
human_verification: {
|
||||
status: [' status: resolved'],
|
||||
resolutionOnly: [' resolution: "closed upstream"'],
|
||||
},
|
||||
};
|
||||
|
||||
const entryArb = (key) => fc.record({
|
||||
body: bodyArb,
|
||||
closed: fc.boolean(),
|
||||
openSpelling: fc.constantFrom(...Object.keys(OPEN_SPELLINGS[key])),
|
||||
closedSpelling: fc.constantFrom(...Object.keys(CLOSED_SPELLINGS[key])),
|
||||
});
|
||||
|
||||
const renderEntry = (key, e) => {
|
||||
const nameLine = key === 'gaps' ? ` - truth: "${e.name}"` : ` - test: "${e.name}"`;
|
||||
const fields = e.closed
|
||||
? CLOSED_SPELLINGS[key][e.closedSpelling]
|
||||
: OPEN_SPELLINGS[key][e.openSpelling];
|
||||
return [nameLine, ...fields];
|
||||
};
|
||||
|
||||
test('property: a gaps entry surfaces iff its own status is not resolved; surfaced + skipped == total', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.array(entryArb('gaps'), { maxLength: 12 }),
|
||||
(raw) => {
|
||||
// Index-prefix so surfaced names map back unambiguously even when
|
||||
// the generated bodies collide.
|
||||
const entries = raw.map((e, i) => ({ ...e, name: `E${i}_${e.body}` }));
|
||||
const lines = ['---', 'status: gaps_found', 'gaps:'];
|
||||
for (const e of entries) lines.push(...renderEntry('gaps', e));
|
||||
lines.push('---', '');
|
||||
|
||||
const items = parseVerificationItems(lines.join('\n'), 'gaps_found');
|
||||
const surfaced = new Set(items.map((it) => it.name));
|
||||
const open = entries.filter((e) => !e.closed);
|
||||
const closed = entries.filter((e) => e.closed);
|
||||
|
||||
// Partition: surfaced count is exactly the open count...
|
||||
assert.strictEqual(items.length, open.length);
|
||||
// ...every open entry surfaces, INCLUDING the two spellings the old
|
||||
// universal rule swallowed (a bare `resolution:`, and a
|
||||
// `resolution:` beside a non-resolved `status:`)...
|
||||
for (const e of open) assert.ok(surfaced.has(e.name), `open entry missing: ${e.name}`);
|
||||
// ...no closed entry ever does...
|
||||
for (const e of closed) assert.ok(!surfaced.has(e.name), `closed entry surfaced: ${e.name}`);
|
||||
// ...and the two parts account for the whole.
|
||||
assert.strictEqual(open.length + closed.length, entries.length);
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('property: a human_verification entry surfaces iff no readable status contradicts its closure', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.array(entryArb('human_verification'), { maxLength: 12 }),
|
||||
(raw) => {
|
||||
const entries = raw.map((e, i) => ({ ...e, name: `E${i}_${e.body}` }));
|
||||
const lines = ['---', 'status: human_needed', 'human_verification:'];
|
||||
for (const e of entries) lines.push(...renderEntry('human_verification', e));
|
||||
lines.push('---', '');
|
||||
|
||||
const items = parseVerificationItems(lines.join('\n'), 'human_needed');
|
||||
const open = entries.filter((e) => !e.closed);
|
||||
|
||||
// Counts only: this reader names items through
|
||||
// `normalizeHumanVerificationEntry`'s display rendering, so asserting
|
||||
// the partition by NAME would pin that renderer rather than the
|
||||
// closure rule under test.
|
||||
assert.strictEqual(items.length, open.length);
|
||||
// Numbering stays the entry's ORIGINAL 1-based row even when a
|
||||
// closed sibling was skipped (the #3850 round-3 Blocker).
|
||||
const expectedRows = entries
|
||||
.map((e, i) => (e.closed ? null : i + 1))
|
||||
.filter((n) => n !== null);
|
||||
assert.deepStrictEqual(items.map((it) => it.test), expectedRows);
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('property: an all-open array surfaces every entry (no silent cap)', () => {
|
||||
fc.assert(
|
||||
fc.property(fc.array(bodyArb, { minLength: 1, maxLength: 20 }), (bodies) => {
|
||||
const names = bodies.map((b, i) => `E${i}_${b}`);
|
||||
const content = ['---', 'status: gaps_found', 'gaps:',
|
||||
...names.map((n) => ` - truth: "${n}"\n status: partial`), '---', ''].join('\n');
|
||||
assert.strictEqual(parseVerificationItems(content, 'gaps_found').length, names.length);
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user