Skip to content

bug(tests): unit stage does not isolate HOME, so three unit tests read the developer's real Pi state and fail locally #3228

Open

Description

@danielgap

Before submitting

  • 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

  1. Use a machine with Pi installed and configured (a populated ~/.pi/agent, including a default model).
  2. On main (b1af8a493), run pnpm test: the unit-tests stage fails with the three tests above.
  3. 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
  4. 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.

gentle-pi version

main @ b1af8a4

Pi version

1.5.2

Operating system

Linux

Relevant logs or error output (optional)

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

Activity

  1. aiorellana502 commented on Nov 13, 2026

    @aiorellana502
    Contributor

    I can reproduce one of the three on Windows 11 (main b1af8a493, 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:

    env.GENTLE_PI_AGENT_HOME || env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent")

    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.

  2. danielgap commented on Nov 13, 2026

    @danielgap
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions