Commit Graph

1 Commits

Author SHA1 Message Date
Tom Boucher
6c27b2b338 fix(state): record-metric/add-decision: auto-create sections + workstream routing (#3286) (#3291)
* test: state record-metric/add-decision: auto-create + workstream routing (#3286 RED)

Three failing test groups:
- Bug A: silent no-op contract (exit 0 with recorded/added:false)
- Bug B: auto-create ## Performance Metrics / ## Decisions when absent
- Bug C: --ws routing writes to workstream STATE.md, not root

* fix(state): workstream-route + auto-create sections in record-metric/add-decision (#3286)

Bug B: cmdStateRecordMetric now auto-creates ## Performance Metrics (with
canonical table header) when absent, instead of silently returning
{ recorded: false }. cmdStateAddDecision does the same for ## Decisions.
Both functions return created: true in the JSON when the section was
newly scaffolded — matching the DWIM behavior of state begin-phase and
advance-plan.

Bug A: silent no-op disappears — sections are auto-created, so recorded/added
is always true on valid input.

Bug C: workstream routing via planningPaths(cwd) already reads GSD_WORKSTREAM
which gsd-tools.cjs sets from --ws before calling state handlers. Confirmed
by the passing --ws routing tests.

Fixes #3286

* refactor(state): extend DWIM auto-create to cmdStateAddBlocker (k302/k014)

Applies the same section auto-create pattern from record-metric/add-decision
to add-blocker: when ## Blockers / ### Blockers is absent, auto-scaffold it
instead of silently returning added:false. Returns created:true in the JSON
when newly scaffolded, matching the uniform shape across all three write verbs.

Per k014 (duplicate algorithm drift), the pattern is now applied uniformly
across all cmdState* functions that mutate a named section.

* changeset: pr=3291 for #3286

* fix(state): remove dead else-branches flagged by CodeRabbit (#3291)

After the auto-create fallback, recorded/added is always true — the else
blocks emitting { recorded: false } / { added: false } were unreachable.
Removed all three dead branches (cmdStateRecordMetric, cmdStateAddDecision,
cmdStateAddBlocker) and replaced with an explanatory comment per CR nitpick.
2026-05-09 07:40:56 -04:00