* test(#2850): add failing-first tests for workstream statusline state readGsdState only ever reads the flat .planning/STATE.md via a directory walk-up; it has no path for .planning/workstreams/<ws>/STATE.md and never consults GSD_WORKSTREAM or the stored active-workstream pointer, so the GSD-state segment silently disappears in workstream mode. These tests prove the RED before the fix lands. Uses shared saveSessionEnv/restoreSessionEnv/clearSessionEnv helpers now added to tests/helpers.cjs (single source of truth for the session-env-var save/clear/restore pattern also used by tests/active-workstream-store.unit.test.cjs, which is updated here to consume the same shared helpers instead of its own local, already-diverged copy). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(#2850): resolve active workstream in the statusline readGsdState only ever walked up looking for a flat .planning/STATE.md; it had no branch for .planning/workstreams/<ws>/STATE.md and never consulted GSD_WORKSTREAM or the stored active-workstream pointer, so the GSD-state segment silently vanished in workstream-mode projects with no root STATE.md (exit 0, no diagnostic). Reuses the existing CLI>env>store resolution seam (resolveActiveWorkstream, active-workstream-store.cts) and the existing mode-detection/path-building seam (listAvailableWorkstreams/planningPaths, planning-workspace.cts) rather than re-implementing either inline. When workstream mode is detected but nothing resolves, readGsdState now returns a {noActiveWorkstream:true} sentinel that formatGsdState/formatGsdStateCompact render as "no active workstream" -- observable, never silent emptiness. Flat-mode behavior and the case where a resolved workstream has no STATE.md yet are both unchanged. Adds active-workstream-store.cts's peekActiveWorkstream: a read-only sibling of getActiveWorkstream. resolveActiveWorkstream's default store lookup self-heals a stale/invalid pointer by deleting it (adapter.clear()) -- correct for a command, but not for a renderer invoked once per prompt, which must never mutate persistent, possibly cross-session state as a side effect of drawing a screen. The statusline now injects peekActiveWorkstream via resolveActiveWorkstream's own getStored override, keeping the env>store precedence itself fully reused while removing only the store tier's write side effect. This satisfies the issue's AC4 ("the fix is purely additive to what's displayed"). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * chore(#2850): backfill changeset PR number to 3012 --------- Co-authored-by: sim <sim@local> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -232,6 +232,31 @@ function getActiveWorkstream(cwd: string, opts: ActiveWorkstreamOpts = {}): stri
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read-only sibling of getActiveWorkstream (#2850): identical resolution —
|
||||
* adapter -> stored name -> validate format -> workstream dir exists — but
|
||||
* NEVER calls adapter.clear(). getActiveWorkstream's self-heal (deleting a
|
||||
* stale/invalid pointer) is correct for a command that is actively acting on
|
||||
* the active workstream; it is wrong for a read-only consumer invoked on
|
||||
* every render (e.g. the statusline hook), which must never mutate
|
||||
* persistent, possibly cross-session state as a side effect of drawing a
|
||||
* screen. A stale or invalid pointer simply resolves to null here — the
|
||||
* caller decides what "unresolvable" means for its own render, and the
|
||||
* pointer file is left exactly as it was for whatever created it to fix.
|
||||
*/
|
||||
function peekActiveWorkstream(cwd: string, opts: ActiveWorkstreamOpts = {}): string | null {
|
||||
const adapter = pickActiveWorkstreamAdapter(cwd, opts);
|
||||
if (!adapter) return null;
|
||||
|
||||
const name = adapter.read();
|
||||
if (!name || !validateWorkstreamName(name)) return null;
|
||||
|
||||
const wsDir = path.join(planningRoot(cwd), 'workstreams', name);
|
||||
if (!fs.existsSync(wsDir)) return null;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
function setActiveWorkstream(cwd: string, name: string | null | undefined, opts: ActiveWorkstreamOpts = {}): void {
|
||||
const adapter = pickActiveWorkstreamAdapter(cwd, opts);
|
||||
if (!adapter) return;
|
||||
@@ -348,6 +373,7 @@ export = {
|
||||
createMemoryPointerAdapter,
|
||||
pickActiveWorkstreamAdapter,
|
||||
getActiveWorkstream,
|
||||
peekActiveWorkstream,
|
||||
setActiveWorkstream,
|
||||
clearActiveWorkstream,
|
||||
parseCliWorkstream,
|
||||
|
||||
Reference in New Issue
Block a user