Skip to content

test: stop test runs from touching the real sessions directory, leaking Xvfb, and using live pids - #286

Merged
ElbertePlinio merged 8 commits into
mainfrom
fix/261-264-test-hygiene
Oct 7, 2026
Merged

ElbertePlinio merged 8 commits into
mainfrom
fix/261-264-test-hygiene

Conversation

@ElbertePlinio

@ElbertePlinio ElbertePlinio commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Fixes four test-hygiene bugs. No product code changed.

Requirement Verified by Scenario Result Evidence
#264: find the test that writes to the real home Attribution run Temporary setup giving each test file its own HOME for one full run Only x11-prebind.test.ts created entries Worker report
#264: isolate it and guard the real home Automated Real sessions directory overlaid by tmpfs in a private namespace: old test left desk-7829492d and the guard reported it; fixed test left nothing; guard unit tests (9) Pass Worker report; test/home-sessions-guard.test.ts
#264: do not delete existing entries Manual check Real ~/.pickforge/lab/sessions held 335 entries before and after a full coverage run Unchanged, nothing deleted Lead run
#261: pids above 4194304 accepted by the product path Automated isPidAlive gets ESRCH; record checks need only an integer Pass Changed tests
#262: destroy leftover sessions before the registry goes Forced experiment 1 s test timeout plus a 2 s sleep between two creates: old code left Xvfb :104 running with a live record; new code left nothing and refused the late create Pass Worker report
#263: temp root outside the repo Automated os.tmpdir() root Pass Changed test
#263: failure under concurrent load Repro and repeat runs 32 concurrent runs of the file: before, the kill case timed out in 32 of 32; after, 32 of 32 passed (3.8 to 4.5 s) Pass Worker report
Review fixes (Astra, Fable) Forced experiments and automated Cleanup captures its own directory and envs, keys calls by PICKFORGE_HOME, bounds the drain at 20 s and kills surviving CLI groups; old code deleted the next test's directory and removed a directory under a running CLI, new code did neither. Guard covers every depth and both legacy roots, detects added, removed and modified entries including replaced directories; PICKFORGE_TEST_ALLOW_REAL_HOME_CHANGES=1 downgrades it to a warning Pass; both reviewers report resolved, no new findings Worker reports; guard tests
No regressions Automated bun run lint, bun run typecheck, bun run build; GSK_RENDERER=cairo bun run test:coverage at 1fc4c24: 2910 passed, 6 skipped, thresholds held (87.91 / 82.85 / 88.32 / 88.86); PickCheck no new or worsened violations Pass Lead run

The guard has one local limit: a test run from a branch without the #264 fix, or real Pickforge sessions used on the same host during a run, change the watched directories and fail the run. Set PICKFORGE_TEST_ALLOW_REAL_HOME_CHANGES=1 to turn that into a warning. CI starts with an empty home and stays strict.

QA pass skipped: test-only changes with nothing to drive.

Follow-ups filed: #285 (pickforgeHome ignores the env object's HOME), #288 (cleanup cannot stop helpers the CLI starts in their own process groups).

Closes #261
Closes #262
Closes #263
Closes #264

Pids below pid_max can belong to live processes after the counter wraps.
Move the browser record inspection, partial startup and VNC rollback
fixtures above PID_MAX_LIMIT (4194304), as PR #255 did for the
pre-identity fixture. Closes #261.
The x11-prebind fallback test sets an empty PICKFORGE_HOME, so the state
root falls back to os.homedir(). That reads the process HOME, not the
env object, so each run left a desk-* permit directory and a takeover
identity file in the real ~/.pickforge/lab/sessions. Point HOME at the
test root for that case.

Add a global setup guard that fails the run when the real sessions
directory gains or loses entries. It only observes and never deletes.
Closes #264.
A test that exceeds its timeout keeps running after vitest moves on. Its
later session create then ran after afterEach had destroyed the sessions
and deleted the registry, and the new Xvfb outlived the run with a
recreated registry under the test temp dir. afterEach now closes the
test's envs to new CLI calls, waits for running ones, destroys every
session, and keeps the registry when a destroy fails. Closes #262.
The kill case waits on three fixed 1 s product budgets and took 4.5 s on
an idle host, so the 5 s vitest default timed it out under concurrent
suites. 32 parallel runs of the file timed it out every time before
this change and passed every time after. Also create the temp root under
the OS temp directory, so a killed worker no longer leaves
.viewer-state-test-* in the checkout. Closes #263.
The home sessions guard compared top-level names only, so a rewritten
session record or a new permit inside an existing session passed. It
also ignored the legacy ~/.pickforge/picklab and ~/.picklab session
roots that fallback resolution can write into.

Snapshot every entry at any depth with its type, inode, size and mtime,
and report added, removed and modified paths relative to the root.
Watch the legacy roots too. PICKFORGE_TEST_ALLOW_REAL_HOME_CHANGES=1
turns the failure into a warning on a shared host where real sessions
run during the tests.
afterEach removed the module-level tmpDir after an unbounded wait for
running CLI calls. If a call outlived the hook timeout, the next test
had already replaced tmpDir, and the resumed cleanup deleted the newer
registry. Calls were also keyed by env object, so an env copy, as in
the browser viewer watch test, was never closed or awaited.

Capture the test's directory and envs at the start of cleanup. Key
running and closed calls by PICKFORGE_HOME. Spawn each CLI in its own
process group and keep the child, wait at most 20 s, SIGKILL the group
of any survivor, then destroy all sessions and remove only this test's
directory.
@ElbertePlinio
ElbertePlinio merged commit c1300aa into main Oct 7, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/261-264-test-hygiene branch October 7, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant