fix(#360): command handlers honour ctx.cwd, not process.cwd() - #361
Merged
Conversation
/work and /work-status both resolved the project root from process.cwd() while ignoring the ctx.cwd Pi hands the handler. ExtensionContext.cwd is first-class API and resolveRepoRoot() already took the parameter — the plumbing existed, it was just fed the wrong value. Wherever Pi's process cwd differs from the session cwd, /work silently retargeted its state file at the wrong repo. The visible symptom was test residue: because production ignored the context it was given, test-command-flow.ts could not isolate itself, so every run of the standard pre-push gate wrote 547/548/549/551/561/789 .json into the real .pi/work-state/ alongside genuine cycle records. Those sat at status "running" with an empty eventLog, so a real /work 547 would have collided with a fixture. Test changes beyond passing a temp cwd: - The temp dir is `git init`-ed. resolveRepoRoot falls back to the raw cwd outside a repo, which makes the driver throw early and emit a crash-report sendUserMessage, perturbing the message counts. - Count assertions now read a `promptMessages()` view that filters the driver's own "pi-ensemble:" status lines. The driver is fire-and-forget and shares the sendUserMessage transport with prompt bodies, so every hardcoded count was a latent race on how fast `gh issue view` failed. - A closing assertion compares the repo's state dir against a snapshot taken at startup. Verified it fails (exit 1) with the bug reintroduced. Fixes #360
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #360.
What
/work(commands.ts:191) and/work-status(work-status.ts:362) resolved the repo root fromprocess.cwd()instead of thectx.cwdPi hands the handler.ExtensionContext.cwdis first-class API andresolveRepoRoot(cwd)already took the parameter — the plumbing existed, it was just fed the wrong value.Why it mattered
Two ways:
Production: whenever Pi's process cwd differs from the session cwd,
/workwrites its state file into the wrong repo.Observable today: because production ignored the context it was given,
test-command-flow.tshad no seam to isolate through. Every run of the §1 pre-push gate wrote fixtures into the live state dir:These sat at
"status":"running"with an emptyeventLog, so a real/work 547would have collided with a fixture.561.jsoncarried"issues":[561,562,563]— the exact multi-issue shapework-driver-context.ts:139cites as the historical false-MERGED incident. (Correction to the issue text:.pi/work-state/is gitignored, so these were written-by-accident, never committed.)Test changes beyond passing a temp cwd
Passing a temp dir alone turned the suite red, for two reasons worth recording:
git init-ed.resolveRepoRootfalls back to the raw cwd outside a repo, which makes the driver throw early and emit its crash-reportsendUserMessage— perturbing the message counts asserted downstream.promptMessages()view that filters the driver's ownpi-ensemble:status lines. The driver is fire-and-forget and shares thesendUserMessagetransport with prompt bodies, so every hardcoded count in this file was a latent race on how fastgh issue viewfailed. Against a real repoghwas slow enough to hide it; against a local temp repo it fails instantly and the race surfaced.Verification
bun run build,tsc --noEmit,bun run check, 60/60 offline smoke tests.test-command-flow.tsrun 3× consecutively — stable, no residue.ctx.cwdreverted toprocess.cwd(), the closing assertion reports✗ /work cases honour ctx.cwd — repo .pi/work-state/ is unchanged by the suiteand the file exits 1. A gate nobody has watched fail is not a gate.bun run checkscopes tosrc/, which is clean).Out of scope
spawn.ts:162(spec.cwd ?? process.cwd()— correct fallback, no ctx), andpermission-*.ts/session-autosave.ts, which run outside command-handler context where the process cwd is genuinely right.