* test(#3872): failing-first regressions for what a command reports it wrote Pins ADR-3473 §8.7 at the consumer's output. state planned-phase advances current_phase on disk and never reports it, and reports progress.total_plans which reconcileReportedFields silently drops because it cannot resolve a dotted key against nested frontmatter. Both directions of #3818's own before/after diff, reproduced against the real CLI. Also pins the two properties the change must not break: a fully-failed patch still reports an empty updated array, which is what state.cts:607's success boolean depends on; and two content-identical writes differ in last_updated alone. That second one measured state_head NOT to be ambient — it is recomputed every write but only changes when git HEAD moved — so the provenance exclusion is a one-element set, with a companion test pinning that state_head does change when HEAD moves. Refs #3872 * feat(#3872): derive what a command reports from the transaction diff ADR-3473 §8.7. reconcileReportedFields compared the transform's own output against persisted bytes and then filtered what preservation had restored by its FIELD_CLASSIFICATION policy. Both are replaced by one comparison of persisted against the pre-write state the transaction already holds, surfaced to the command through the same caller-allocates out-param idiom divergedFields established. Both of the old directions fall out of that single comparison: a field the transform reported but the pipeline discarded is persisted-equals-snapshot and drops out, and a field nobody reported but the write moved is different and appears. The classification filter is deleted, not relocated — no policy test remains anywhere in the reporting path. Reporting is at dotted-leaf granularity, enumerated from the progress.* rows FIELD_CLASSIFICATION already declares rather than by walking user data to arbitrary depth. That closes a live defect: plannedPhaseCore already pushed progress.total_plans and reconcileReportedFields silently dropped it, because a flat hasOwnProperty cannot resolve a dotted key against nested frontmatter. Current Position was lost the same way and is fixed in the same place. The exclusion is one field, last_updated, and it is by provenance rather than by classification: it is the only field measured to change on every write regardless of content. state_head was measured NOT to qualify — it is recomputed every write but only changes when git HEAD moved. Without that exclusion state.patch's success boolean, which is updated.length > 0, would be permanently true and a fully-failed patch would report success. Refs #3872 * fix(#3872): cover the matrix, and close a prototype-chain read the coverage found Review found 20 of 29 test-matrix rows uncovered. Covering them found two real defects rather than merely documenting the intended behavior. bodyLabelFor read FRONTMATTER_KEY_TO_BODY_LABEL with a bare bracket index on a plain object literal, so a field named __proto__, constructor or toString resolved to the inherited prototype member and leaked a non-string value into the updated array. Fixed with an own-property check, mirroring the discipline resolveFrontmatterPath already had. The security-relevant matrix row proved it before the fix. applyPostSyncPreservation still carried its own inline copy of the value comparison alongside the new stateFieldValuesDiffer, which is two live copies of one rule introduced by the epic that exists to remove them. Routed through the single owner. Adds the fast-check property that a field appears iff its persisted value differs from the snapshot, the string-versus-number representation boundary, dotted paths into missing parents and into scalars, deleted and added keys, and the preserve-if-placeholder pair that proves no classification test survives in the reporting path. Refs #3872 * docs(#3872): document the transaction diff on the write path The updated array's contract belongs where the write path is described. States the iff rule, leaf granularity, the single provenance exclusion and why state_head is deliberately not one, and closes with the consequence a reader actually needs: these arrays are longer than they used to be, because they used to under-report. Refs #3872 * fix(#3872): a derived leaf materializing is not a change the caller made The remote matrix caught 17 failures with two causes. The substantive one is that progress is source: disk, and the disk cannot change during a STATE.md write — the write only touches STATE.md. So a progress block appearing where the snapshot had none is the scanner populating a document that had never been synced. The bytes moved; nothing the caller did moved them. That is the same shape as last_updated one level up, so the provenance rule is generalized rather than special-cased: a field appears iff its persisted value changed for a reason attributable to this write's action, and two cases are not attributable — a field stamped unconditionally on every save, and a declared derived leaf materializing from a source that did not change. Crucially this does not consult the preservation policy, so the filter §8.7 deleted stays deleted; it uses the declared leaf set to know which keys are derived. This had a second production consumer the earlier review concluded did not exist: cmdStatePlannedPhase gates publishStateContract on updated.length, and its own inline comment predicts exactly this failure. A no-op call was publishing state.json. advancePlanNoOpDoesNotPublish genuinely encoded pre-§8.7 behavior and moves. E2 and E6 had carved out total_plans as reportable-on-materialization, an error introduced earlier on this branch rather than a pre-existing pin, and are corrected with it. Refs #3872 * chore(#3872): backfill changeset PR number --------- Co-authored-by: sim <sim@local>
This commit is contained in:
@@ -1472,7 +1472,22 @@ describe('#1264: state.patch preserves curated progress frontmatter for non-prog
|
||||
assert.ok(patchResult.success, `state patch failed: ${patchResult.error}`);
|
||||
|
||||
const output = JSON.parse(patchResult.output);
|
||||
assert.deepEqual(output.updated, ['Total Plans in Phase']);
|
||||
// MOVED under ADR-3473 §8.7 (#3872): every `progress.*` leaf here
|
||||
// genuinely changed on disk (the curated 22/6/12/50 block is
|
||||
// disk-derived-resynced to match the 8 real plan dirs this fixture
|
||||
// creates) — this is exactly the #3743/#3818 direction §8.7 closes
|
||||
// (design doc row 4): a field the OLD `reconcileReportedFields`
|
||||
// suppressed via its `progress`-is-`preserve-always` classification
|
||||
// filter, regardless of whether the value actually changed, is now
|
||||
// reported at DOTTED-LEAF granularity because it actually did.
|
||||
assert.deepEqual(output.updated.slice().sort(), [
|
||||
'Total Plans in Phase',
|
||||
'progress.completed_phases',
|
||||
'progress.completed_plans',
|
||||
'progress.percent',
|
||||
'progress.total_phases',
|
||||
'progress.total_plans',
|
||||
].sort());
|
||||
|
||||
const progress = readPersistedProgress(statePath);
|
||||
assert.strictEqual(progress.total_plans, 8);
|
||||
|
||||
@@ -328,7 +328,16 @@ describe('state contract — call-site wiring (integration, real CLI)', () => {
|
||||
'| 1. A | 0/1 | Not started | - |',
|
||||
'',
|
||||
]);
|
||||
writeState(tmpDir, ['status: planning'], [
|
||||
// ADR-3473 §8.7 (#3872) / test-matrix row 17 (D15): `gsd_state_version`
|
||||
// is pre-seeded here so this fixture isolates the ONE thing it is meant
|
||||
// to prove (zero recognized Current Position labels is a genuine no-op)
|
||||
// from an UNRELATED, already-correct §8.7 behavior — a frontmatter block
|
||||
// synthesizing `gsd_state_version` for the first time on a document that
|
||||
// never had one IS a real, reportable addition (row 17/D15, pinned
|
||||
// separately by "state patch accepts JSON object input from workflows"
|
||||
// above). Omitting it here would make THIS no-op test fail for a reason
|
||||
// that has nothing to do with recognized labels.
|
||||
writeState(tmpDir, ['gsd_state_version: 1.0', 'status: planning'], [
|
||||
'# Project State', '',
|
||||
'(no recognized labels here)',
|
||||
]);
|
||||
@@ -358,12 +367,19 @@ describe('state contract — call-site wiring (integration, real CLI)', () => {
|
||||
// Additional no-op path found while auditing `state advance-plan`
|
||||
// (cmdStateAdvancePlan, src/state.cts): re-invoking advance-plan while
|
||||
// already parked at "last plan, ready for verification" reproduces
|
||||
// byte-identical STATE.md content on the SECOND call — `updated` still
|
||||
// reports `Status`/`Last Activity` (reconcileReportedFields matches
|
||||
// against the value ALREADY persisted from the first call), but nothing
|
||||
// is written on the second call, so publishing on `updated.length > 0`
|
||||
// alone would be wrong here; the fix gates on
|
||||
// `readModifyWriteStateMd`'s own write-happened return value instead.
|
||||
// byte-identical STATE.md content on the SECOND call. MOVED under
|
||||
// ADR-3473 §8.7 (#3872): before that change, `reconcileReportedFields`
|
||||
// compared the transform's OWN reported fields against the FINAL
|
||||
// persisted bytes, so `Status`/`Last Activity` (values the transform
|
||||
// always names, which trivially still matched the byte-identical file)
|
||||
// came back non-empty even though nothing was written. §8.7 replaced
|
||||
// that with a diff against the transaction's PRE-WRITE snapshot, so a
|
||||
// genuinely byte-identical second call now correctly reconciles to
|
||||
// `updated: []` — a true no-op is reported as a true no-op. Publishing
|
||||
// still does not fire on this call: `cmdStateAdvancePlan` gates on
|
||||
// `readModifyWriteStateMd`'s own write-happened return value, never on
|
||||
// `updated.length`, so this remains a no-op-does-not-publish regression
|
||||
// test — only the expected shape of the (now-correct) `updated` moved.
|
||||
test('advancePlanNoOpDoesNotPublish', (t) => {
|
||||
const tmpDir = createTempProject();
|
||||
t.after(() => cleanup(tmpDir));
|
||||
@@ -385,7 +401,7 @@ describe('state contract — call-site wiring (integration, real CLI)', () => {
|
||||
const second = runGsdTools(['state', 'advance-plan'], tmpDir);
|
||||
assert.ok(second.success, `second (no-op) advance-plan call must genuinely succeed: ${second.error}`);
|
||||
const output = JSON.parse(second.output);
|
||||
assert.ok(Array.isArray(output.updated) && output.updated.length > 0, 'reconciled updated[] is non-empty even though nothing was written this call');
|
||||
assert.deepStrictEqual(output.updated, [], 'ADR-3473 §8.7: a byte-identical second call is a genuine no-op — `updated` must reconcile to empty, not merely reflect fields the transform always names');
|
||||
assert.strictEqual(fs.existsSync(statePathOf(tmpDir)), false, 'the second, no-op advance-plan call must not publish state.json');
|
||||
});
|
||||
|
||||
|
||||
1205
tests/state.test.cjs
1205
tests/state.test.cjs
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user