Adds the spec-time prohibition probe (spec-phase Step 5.6) — the second adapter of the probe-core resolution model. Surfaces unwritten must-NOT constraints as negative SPEC acceptance criteria with test/judgment verification tiers; fail-closed at verify time. Per ADR-550. Closes #644.
This commit is contained in:
@@ -13,6 +13,9 @@
|
||||
* preserves key-value pairs for simple flat string values
|
||||
* (d) spliceFrontmatter never throws on any string/object combination
|
||||
* (e) extractFrontmatter returns {} for content without a leading ---...--- block
|
||||
* (f) prohibitions bijection (#644): over a generated must_haves.prohibitions block,
|
||||
* parseMustHavesBlock(spliceFrontmatter(doc, parseFrontmatter(doc)), 'prohibitions')
|
||||
* deepEquals the original parse — the new parse ↔ splice path is identity-preserving.
|
||||
*/
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
@@ -23,6 +26,8 @@ const {
|
||||
extractFrontmatter,
|
||||
reconstructFrontmatter,
|
||||
spliceFrontmatter,
|
||||
parseFrontmatter,
|
||||
parseMustHavesBlock,
|
||||
} = require('../gsd-core/bin/lib/frontmatter.cjs');
|
||||
|
||||
// ─── Arbitraries ─────────────────────────────────────────────────────────────
|
||||
@@ -192,3 +197,69 @@ describe('frontmatter: spliceFrontmatter properties', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── (f) prohibitions bijection (#644) ────────────────────────────────────────
|
||||
// Locks the new parseMustHavesBlock(…, 'prohibitions') ↔ spliceFrontmatter path that
|
||||
// the prohibition probe adds. The example-based version lives in
|
||||
// tests/prohibition-probe.schema.test.cjs; this generalizes it over generated blocks.
|
||||
|
||||
// YAML-safe scalar: starts with a letter, no colon/quote/hash/newline (so it parses as a
|
||||
// plain string and is never coerced to a number by the parser's /^\d+$/ check).
|
||||
const safeScalar = fc.stringMatching(/^[A-Za-z][A-Za-z0-9 ._-]{0,50}$/);
|
||||
|
||||
// One prohibition item with structurally realistic key shape per ADR-550 D7a:
|
||||
// resolved → carries a verification tier (test|judgment)
|
||||
// dismissed → carries a non-empty reason (+ a tier)
|
||||
// unresolved→ neither
|
||||
const prohibitionItem = fc.oneof(
|
||||
fc.record({ statement: safeScalar, status: fc.constant('resolved'),
|
||||
verification: fc.constantFrom('test', 'judgment') }),
|
||||
fc.record({ statement: safeScalar, status: fc.constant('dismissed'),
|
||||
verification: fc.constantFrom('test', 'judgment'), reason: safeScalar }),
|
||||
fc.record({ statement: safeScalar, status: fc.constant('unresolved') })
|
||||
);
|
||||
|
||||
// Emit a frontmatter doc with a must_haves.prohibitions sibling block (keys in a fixed
|
||||
// order: statement, status, verification?, reason?). Quoted strings carry the values.
|
||||
function buildDoc(items) {
|
||||
const lines = ['---', 'phase: 01-x', 'plan: 01', 'must_haves:',
|
||||
' truths:', ' - "User sees a daily reminder"', ' prohibitions:'];
|
||||
for (const it of items) {
|
||||
lines.push(` - statement: "${it.statement}"`);
|
||||
lines.push(` status: ${it.status}`);
|
||||
if (it.verification !== undefined) lines.push(` verification: ${it.verification}`);
|
||||
if (it.reason !== undefined) lines.push(` reason: "${it.reason}"`);
|
||||
}
|
||||
lines.push('---', '', 'Body text unchanged.', '');
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
describe('frontmatter: prohibitions parse ↔ splice bijection (#644)', () => {
|
||||
test('property: generated prohibitions parse back with their statement and status', () => {
|
||||
fc.assert(
|
||||
fc.property(fc.array(prohibitionItem, { minLength: 1, maxLength: 5 }), (items) => {
|
||||
const doc = buildDoc(items);
|
||||
const parsed = parseMustHavesBlock(doc, 'prohibitions');
|
||||
assert.equal(parsed.length, items.length, 'every prohibition item must parse out');
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
assert.equal(parsed[i].statement, items[i].statement, `statement[${i}] mismatch`);
|
||||
assert.equal(parsed[i].status, items[i].status, `status[${i}] mismatch`);
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('property: parse -> splice -> re-parse is identity-preserving for prohibitions', () => {
|
||||
fc.assert(
|
||||
fc.property(fc.array(prohibitionItem, { minLength: 1, maxLength: 5 }), (items) => {
|
||||
const doc = buildDoc(items);
|
||||
const before = parseMustHavesBlock(doc, 'prohibitions');
|
||||
const parsed = parseFrontmatter(doc);
|
||||
const spliced = spliceFrontmatter(doc, parsed.frontmatter ?? parsed);
|
||||
const after = parseMustHavesBlock(spliced, 'prohibitions');
|
||||
assert.deepEqual(after, before,
|
||||
'prohibitions must survive a splice/re-parse round-trip unchanged');
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user