Stop workflow-controller tests from leaking into ~/.corbits/projects - #603
Conversation
|
Holding this out of the imminent 0.2.108 cut — one change needs rethinking first. The The problem is So as written the guard turns a green suite red based on what a sibling worktree happens to be doing. A gate that fails for reasons unrelated to the code under test trains everyone to ignore it, and it would have blocked the three PRs that landed in the last hour. Scope it so it can only fail on residue this process is responsible for — compare against a snapshot taken in the same process and attribute by pid/session marker, or have the guard assert only on directories whose names match the test-run's own session ids. If neither is practical, make it opt-in (env var, or a separate Separately, for the record: the ~5,157 pre-existing |
WorkflowController never threaded an override for the state-tree home, so persist()/resume() always fell back to the real user home even when a test passed a sandboxed one. tests/unit/workflow-controller.test.ts was the concrete leaker: every start()/resume() call it exercised wrote a real session directory (t-wf-controller-*) into ~/.corbits/projects. Add an optional `home` to WorkflowControllerArgs and thread it through persist() and resume(), then pass the test's mkdtemp'd home through the controller and the one direct saveWorkflowState() call that skipped it. Add scripts/guard-real-projects-dir.ts, wired into `bun run test`, which snapshots ~/.corbits/projects before and after the suite and fails the run if anything new appears — a backstop against this class of leak recurring in any test, not just this file.
Compare against the real ~/.corbits/projects only for entries this run's own project keys account for, instead of any new entry: a plain before/after snapshot also picks up sibling checkouts running their own bun run check concurrently, which is our normal multi-worktree workflow and not something this suite is responsible for. Point TMPDIR/TMP/TEMP at a per-invocation scratch dir carrying this run's id before spawning bun test. project-key.ts derives a project key from the realpath of a test's mkdtemp'd cwd/home, so a real leak's key inherits the run id as a substring; only those entries fail the guard.
fdb83a0 to
9069180
Compare
…603) * Stop workflow-controller tests from leaking into ~/.corbits/projects WorkflowController never threaded an override for the state-tree home, so persist()/resume() always fell back to the real user home even when a test passed a sandboxed one. tests/unit/workflow-controller.test.ts was the concrete leaker: every start()/resume() call it exercised wrote a real session directory (t-wf-controller-*) into ~/.corbits/projects. Add an optional `home` to WorkflowControllerArgs and thread it through persist() and resume(), then pass the test's mkdtemp'd home through the controller and the one direct saveWorkflowState() call that skipped it. Add scripts/guard-real-projects-dir.ts, wired into `bun run test`, which snapshots ~/.corbits/projects before and after the suite and fails the run if anything new appears — a backstop against this class of leak recurring in any test, not just this file. * Attribute guard-real-projects-dir leaks to this test run Compare against the real ~/.corbits/projects only for entries this run's own project keys account for, instead of any new entry: a plain before/after snapshot also picks up sibling checkouts running their own bun run check concurrently, which is our normal multi-worktree workflow and not something this suite is responsible for. Point TMPDIR/TMP/TEMP at a per-invocation scratch dir carrying this run's id before spawning bun test. project-key.ts derives a project key from the realpath of a test's mkdtemp'd cwd/home, so a real leak's key inherits the run id as a substring; only those entries fail the guard.
…603) * Stop workflow-controller tests from leaking into ~/.corbits/projects WorkflowController never threaded an override for the state-tree home, so persist()/resume() always fell back to the real user home even when a test passed a sandboxed one. tests/unit/workflow-controller.test.ts was the concrete leaker: every start()/resume() call it exercised wrote a real session directory (t-wf-controller-*) into ~/.corbits/projects. Add an optional `home` to WorkflowControllerArgs and thread it through persist() and resume(), then pass the test's mkdtemp'd home through the controller and the one direct saveWorkflowState() call that skipped it. Add scripts/guard-real-projects-dir.ts, wired into `bun run test`, which snapshots ~/.corbits/projects before and after the suite and fails the run if anything new appears — a backstop against this class of leak recurring in any test, not just this file. * Attribute guard-real-projects-dir leaks to this test run Compare against the real ~/.corbits/projects only for entries this run's own project keys account for, instead of any new entry: a plain before/after snapshot also picks up sibling checkouts running their own bun run check concurrently, which is our normal multi-worktree workflow and not something this suite is responsible for. Point TMPDIR/TMP/TEMP at a per-invocation scratch dir carrying this run's id before spawning bun test. project-key.ts derives a project key from the realpath of a test's mkdtemp'd cwd/home, so a real leak's key inherits the run id as a substring; only those entries fail the guard.
Closes CL-6777.
Problem
WorkflowControllernever accepted an override for the state-tree home, sopersist()andresume()always fell back to the real user home even when a test passed a sandboxed one.tests/unit/workflow-controller.test.tswas the concrete leaker: everystart()/resume()call it exercised wrote a real session directory into~/.corbits/projects.Fix
hometoWorkflowControllerArgs, threaded throughpersist()andresume().mkdtemp'dhomeinto the controller and into the one directsaveWorkflowState()call that had skipped it.Guard
Added
scripts/guard-real-projects-dir.ts, wired intobun run test. It snapshots~/.corbits/projectsbefore/after the suite and fails on anything new.Update: the original guard failed on any new entry, including ones from other checkouts on the same machine running their own
bun run checkconcurrently — a routine part of our multi-worktree workflow, not something this suite is responsible for. Fixed by attributing residue to this run specifically: the guard now pointsTMPDIR/TMP/TEMPat a scratch directory named with a per-invocation run id before spawningbun test.src/session/project-key.tsderives a project key from the realpath of a test'scwd/home, so a real leak's project key inherits the run id as a substring. Only entries carrying it fail the guard; anything else is logged as ignored and left untouched (no deletion).Verified both directions:
~/.corbits/projectsmid-run — guard exited 0 and logged the entry as ignored.WorkflowControllerfix, ran the guard — it failed, reporting the 5 leaked directories, each carrying this run's id.bun run checkis green (5365 pass, 0 fail).Verification
bun run checkis green end to end (lint, typecheck, build, test).This is test-only infrastructure; no user-facing behavior changes, so no CHANGELOG entry.