You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug(tests): unit stage does not isolate HOME, so three unit tests read the developer's real Pi state and fail locally #3228
I searched open and closed issues and did not find a report of this problem.
I reviewed this report and removed credentials, tokens, private paths, hostnames, and other sensitive data.
Problem
The unit-tests stage of scripts/run-test-suite.mjs isolates GENTLE_PI_CONFIG_HOME, TMPDIR and Git config, but not HOME. Three unit tests still resolve state from the developer's real home (an existing Pi install under ~/.pi/agent), so pnpm test fails locally for any contributor who uses Pi, while CI (no Pi home) stays green.
Failing tests on a machine with a configured Pi:
tests/review-delivery-preflight.test.ts — #2997: a foreground or background delivery cannot precede an explicit committed-range assessment (expected true, actual false)
tests/review-relay-transport-agent.test.ts — capture forwards no selection when the lens has no configured model, leaving the missing-model refusal to the relay (the "no configured model" case receives the model configured in the developer's real Pi settings)
tests/session-profile-v1-compat.test.ts — gap (section 10): after a startup-none clear a pin appears; a reviewer without A1 follows it, the current one does not
All three pass when the same files run with an empty HOME, so the leak is host home state, not the code under test. This is the same class as #1717 (fixed per test); isolating HOME in the unit stage would close it for the whole suite.
Steps to reproduce
Use a machine with Pi installed and configured (a populated ~/.pi/agent, including a default model).
On main (b1af8a493), run pnpm test: the unit-tests stage fails with the three tests above.
Run only those files with the runner's isolation plus an empty home: HOME=$(mktemp -d) node --experimental-strip-types --test tests/review-delivery-preflight.test.ts tests/review-relay-transport-agent.test.ts tests/session-profile-v1-compat.test.ts
All three pass.
Expected and actual behavior
Expected: unit tests are hermetic; the runner gives the unit-tests stage a private HOME (as it already does for GENTLE_PI_CONFIG_HOME and TMPDIR), so results do not depend on the contributor's Pi install.
Actual: the stage inherits the real HOME, and three tests read the developer's Pi state and fail.
not ok - #2997: a foreground or background delivery cannot precede an explicit committed-range assessment
expected: true
actual: false
not ok - capture forwards no selection when the lens has no configured model, leaving the missing-model refusal to the relay
actual: '<model from the developer's real Pi settings>'
not ok - gap (section 10): after a startup-none clear a pin appears; a reviewer without A1 follows it, the current one does not
I can reproduce one of the three on Windows 11 (mainb1af8a493, Node 24.13), and isolating HOME alone wouldn't fix it there. There are two more leak paths.
The failing test is tests/review-relay-transport-agent.test.ts › capture forwards no selection when the lens has no configured model…. It receives the model from the frontmatter of agents/review-reliability.md in my agent home. That home is resolved by lib/agent-home.ts:10:
The unit stage strips GIT_*, GENTLE_PI_AGENTS_*, GENTLE_PI_CONFIG_HOME and GENTLE_SHELL_CONFIG_HOME, but not those two variables. I ran only that test through scripts/run-test-suite.mjs with different environments:
Environment
Result
From a Gentle Shell terminal (exports both GENTLE_PI_AGENT_HOME and PI_CODING_AGENT_DIR)
fails, even with HOME and USERPROFILE pointed at an empty dir
Either one of the two unset
fails
Both unset
passes
Both unset, HOME = fake home containing .pi/agent/agents/review-reliability.md
passes (ignored)
Both unset, USERPROFILE = that fake home
fails with the fake home's model
So os.homedir() follows USERPROFILE on Windows, and anyone running pnpm test from a Gentle Shell terminal leaks through the env vars before homedir() is even reached.
A fix covering all three would, in the unit stage, drop GENTLE_PI_AGENT_HOME and PI_CODING_AGENT_DIR and point both HOME and USERPROFILE at the stage's temp dir. The other two tests pass here only because I have no ~/.pi/agent config, so I couldn't check whether they leak through the same path.
Thanks, this is a better diagnosis than mine: isolating HOME alone is not enough.
I checked the Linux side to see which path each test takes. Both variables are unset in my environment, so my three failures all came through HOME:
Environment (Linux, GENTLE_PI_AGENT_HOME and PI_CODING_AGENT_DIR unset)
Result
real HOME
all 3 fail
empty HOME
all 3 pass
real HOME, PI_CODING_AGENT_DIR pointed at an empty dir
the capture test passes; #2997 and the session-profile pin test still fail
So the capture test leaks through the agent home you found in lib/agent-home.ts:10, while the other two read something else under the home directory. Your fix covers both: drop GENTLE_PI_AGENT_HOME and PI_CODING_AGENT_DIR in the unit stage, and point HOME and USERPROFILE at the stage's temp dir. That would close all three on Linux and Windows.
Activity
aiorellana502 commentedon Nov 13, 2026
I can reproduce one of the three on Windows 11 (
mainb1af8a493, Node 24.13), and isolatingHOMEalone wouldn't fix it there. There are two more leak paths.The failing test is
tests/review-relay-transport-agent.test.ts›capture forwards no selection when the lens has no configured model…. It receives the model from the frontmatter ofagents/review-reliability.mdin my agent home. That home is resolved bylib/agent-home.ts:10:The unit stage strips
GIT_*,GENTLE_PI_AGENTS_*,GENTLE_PI_CONFIG_HOMEandGENTLE_SHELL_CONFIG_HOME, but not those two variables. I ran only that test throughscripts/run-test-suite.mjswith different environments:GENTLE_PI_AGENT_HOMEandPI_CODING_AGENT_DIR)HOMEandUSERPROFILEpointed at an empty dirHOME= fake home containing.pi/agent/agents/review-reliability.mdUSERPROFILE= that fake homeSo
os.homedir()followsUSERPROFILEon Windows, and anyone runningpnpm testfrom a Gentle Shell terminal leaks through the env vars beforehomedir()is even reached.A fix covering all three would, in the unit stage, drop
GENTLE_PI_AGENT_HOMEandPI_CODING_AGENT_DIRand point bothHOMEandUSERPROFILEat the stage's temp dir. The other two tests pass here only because I have no~/.pi/agentconfig, so I couldn't check whether they leak through the same path.danielgap commentedon Nov 13, 2026
Thanks, this is a better diagnosis than mine: isolating
HOMEalone is not enough.I checked the Linux side to see which path each test takes. Both variables are unset in my environment, so my three failures all came through
HOME:GENTLE_PI_AGENT_HOMEandPI_CODING_AGENT_DIRunset)HOMEHOMEHOME,PI_CODING_AGENT_DIRpointed at an empty dir#2997and the session-profile pin test still failSo the capture test leaks through the agent home you found in
lib/agent-home.ts:10, while the other two read something else under the home directory. Your fix covers both: dropGENTLE_PI_AGENT_HOMEandPI_CODING_AGENT_DIRin the unit stage, and pointHOMEandUSERPROFILEat the stage's temp dir. That would close all three on Linux and Windows.