* fix(#4488): report state update as successful when the value is already correct `cmdStateUpdate` unconditionally overwrote `updateCore`'s own `updated:true` signal with `reconcileReportedFields`'s disk-diff result. That diff reports `[]` -- by design -- whenever `readModifyWriteStateMd`'s #948 no-op guard fires because the transform's output was byte-identical to the input, which happens precisely when the requested value already equals what's on disk. The field genuinely was found and matched; there was simply nothing left to change. Collapsing that into the same `false`/"not found" response as a genuine miss produced an actively wrong diagnostic message and a silent same-day no-op in gsd-ship + gsd-extract-learnings, which both write `Last Activity` to today's date. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * docs(#4488): backfill changeset pr number to 4581 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * fix(#4488): untrack tdd-red-evidence.cjs, completing its ADR-457 gitignore migration Bundled discovery from this PR's own CI run: tests/lint-compiled-artifact- sync.test.cjs's full tsc compile (which runs whenever ANY compiled artifact remains tracked) SIGTERM'd under shard contention. gsd-core/bin/lib/tdd-red- evidence.cjs (introduced by #3770/PR #4279) was the sole remaining tracked artifact -- a tenth, later, separate instance of the #2657/#2653 migration-gap defect class this test file's closed nine-item list doesn't cover. Untracked it and added the .gitignore entry, same fix shape as the original nine. This eliminates the slow tsc-compile path entirely (verified: 0.1s vs ~7s locally) rather than papering over a timeout. Added a generic regression test asserting the tracked set is fully empty. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --------- Co-authored-by: sim <sim@local> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -13797,6 +13797,155 @@ describe('#905: syncStateFrontmatter preserves scalars when body annotations are
|
||||
});
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Bug #4488: state update reports a same-value write as "field not found"
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('bug #4488: state update reports updated:true, not a false "not found", when the new value equals the current value', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = createTempProject();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('same-value update on a template-shaped STATE.md reports updated:true, not "not found"', () => {
|
||||
// Exact shape from the issue: frontmatter last_activity AND body
|
||||
// "Last activity:" line already hold the value being "written". The
|
||||
// transform's own stateReplaceField match succeeds and produces
|
||||
// byte-identical output, which trips readModifyWriteStateMd's #948
|
||||
// no-op guard before reconcileReportedFields' preWriteState snapshot is
|
||||
// ever populated -- reconciliation then (correctly, for the general
|
||||
// case) reports "[]", and cmdStateUpdate must not read that as "the
|
||||
// field could not be found".
|
||||
const statePath = path.join(tmpDir, '.planning', 'STATE.md');
|
||||
fs.writeFileSync(statePath, [
|
||||
'---',
|
||||
'gsd_state_version: "1.0"',
|
||||
'current_phase: 1',
|
||||
'current_phase_name: Test Phase',
|
||||
'status: planning',
|
||||
'last_activity: 2026-09-07',
|
||||
'---',
|
||||
'',
|
||||
'# Project State',
|
||||
'',
|
||||
'## Current Position',
|
||||
'',
|
||||
'Phase: 1 of 1 (Test Phase)',
|
||||
'Status: In progress',
|
||||
'Last activity: 2026-09-07',
|
||||
'',
|
||||
].join('\n'), 'utf-8');
|
||||
|
||||
const result = runGsdTools('state update "Last Activity" "2026-09-07"', tmpDir);
|
||||
assert.ok(result.success, `state update failed: ${result.error}`);
|
||||
|
||||
const json = JSON.parse(result.output);
|
||||
assert.strictEqual(
|
||||
json.updated,
|
||||
true,
|
||||
`same-value update must report updated:true, not a false negative (got: ${JSON.stringify(json)})`,
|
||||
);
|
||||
assert.ok(
|
||||
!('reason' in json),
|
||||
`same-value update must not carry a "field not found" reason (got: ${JSON.stringify(json)})`,
|
||||
);
|
||||
|
||||
// The file itself is untouched byte-for-byte (there was nothing to change).
|
||||
const after = fs.readFileSync(statePath, 'utf-8');
|
||||
assert.match(after, /^last_activity: 2026-09-07$/m);
|
||||
assert.match(after, /^Last activity: 2026-09-07$/m);
|
||||
});
|
||||
|
||||
test('changed-value update (control) still reports updated:true and actually rewrites the line', () => {
|
||||
// Same fixture, different target date -- the pre-existing, always-worked
|
||||
// path. Pins that the #4488 fix does not turn INTO a false positive for
|
||||
// a real change.
|
||||
const statePath = path.join(tmpDir, '.planning', 'STATE.md');
|
||||
fs.writeFileSync(statePath, [
|
||||
'---',
|
||||
'gsd_state_version: "1.0"',
|
||||
'last_activity: 2026-09-07',
|
||||
'---',
|
||||
'',
|
||||
'## Current Position',
|
||||
'',
|
||||
'Last activity: 2026-09-07',
|
||||
'',
|
||||
].join('\n'), 'utf-8');
|
||||
|
||||
const result = runGsdTools('state update "Last Activity" "2026-09-08"', tmpDir);
|
||||
assert.ok(result.success, `state update failed: ${result.error}`);
|
||||
const json = JSON.parse(result.output);
|
||||
assert.strictEqual(json.updated, true);
|
||||
|
||||
const after = fs.readFileSync(statePath, 'utf-8');
|
||||
assert.match(after, /^Last activity: 2026-09-08$/m);
|
||||
});
|
||||
|
||||
test('a genuinely absent field still reports updated:false with the case-D diagnostic', () => {
|
||||
// Control for the other direction: this must NOT become a blanket
|
||||
// "always true" -- a field with no body source line and no frontmatter
|
||||
// key at all is still a real failure.
|
||||
const statePath = path.join(tmpDir, '.planning', 'STATE.md');
|
||||
fs.writeFileSync(statePath, [
|
||||
'---',
|
||||
'gsd_state_version: "1.0"',
|
||||
'---',
|
||||
'',
|
||||
'## Current Position',
|
||||
'',
|
||||
'Status: In progress',
|
||||
'',
|
||||
].join('\n'), 'utf-8');
|
||||
|
||||
const result = runGsdTools('state update "Last Activity" "2026-09-08"', tmpDir);
|
||||
assert.ok(result.success, `state update failed: ${result.error}`);
|
||||
const json = JSON.parse(result.output);
|
||||
assert.strictEqual(json.updated, false);
|
||||
assert.match(json.reason, /not found in STATE\.md/);
|
||||
});
|
||||
|
||||
test('#3699 case-D repair with a same-value frontmatter target still reports updated:true', () => {
|
||||
// Case D fires when the CALLER addresses the FRONTMATTER key directly
|
||||
// (e.g. "last_activity", per explainUpdateFailure's own "update
|
||||
// \"last_activity\" directly to repair" instruction) on a document whose
|
||||
// body has no source line at all. That repair write can ALSO be
|
||||
// byte-identical to the original (the frontmatter already holds the
|
||||
// target value) and trip the same #948 no-op guard as the body-label
|
||||
// path above -- a second origin for the #4488 collapse, covered here so
|
||||
// it doesn't regress silently.
|
||||
const statePath = path.join(tmpDir, '.planning', 'STATE.md');
|
||||
fs.writeFileSync(statePath, [
|
||||
'---',
|
||||
'gsd_state_version: "1.0"',
|
||||
'current_phase: 1',
|
||||
'current_phase_name: Test Phase',
|
||||
'status: planning',
|
||||
'last_activity: 2026-09-07',
|
||||
'---',
|
||||
'',
|
||||
'## Current Position',
|
||||
'',
|
||||
'Status: In progress',
|
||||
'',
|
||||
].join('\n'), 'utf-8');
|
||||
|
||||
const result = runGsdTools('state update last_activity 2026-09-07', tmpDir);
|
||||
assert.ok(result.success, `state update failed: ${result.error}`);
|
||||
const json = JSON.parse(result.output);
|
||||
assert.strictEqual(
|
||||
json.updated,
|
||||
true,
|
||||
`same-value case-D repair must report updated:true (got: ${JSON.stringify(json)})`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Bug #1230 regression suite
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user