Skip to content

fix: Brain tests not hermetic against a task worktree's activate.sh #677

Closed

Description

@Jammy2211

Overview

Running the PyAutoBrain suite from a task worktree after source <wt>/activate.sh fails test_grouped_organ_consumers::test_hygiene_map_and_heart_board_find_grouped_checkouts: activate.sh exports the organ-path variables (PYAUTO_ROOT, PYAUTO_BRAIN, PYAUTO_MIND, PYAUTO_HEART, PYAUTO_HANDS, PYAUTO_TASK) and _hygiene_repos.candidate_map_paths() honours PYAUTO_MIND as a hard override, so the test resolves the worktree's Mind instead of its tmp tree. CI has none of these variables, so it is green there; the PyAutoBrain#676 ship had to run with env -u PYAUTO_MIND.

Plan

  • Add one autouse fixture to tests/conftest.py that clears the organ-path variables activate.sh exports, so every test starts from CI's environment.
  • Tests that need one of them keep setting it themselves (autouse runs first, so their setenv wins).
  • Prove it: the full suite passes with activate.sh sourced and without it, no deselects.
  • Tier + merge mode: effective level: supervised; merge mode: auto-merge on green (declared Consequence: notify).
Detailed implementation plan

Affected Repositories

  • PyAutoBrain (primary)

Branch Survey

Repository Current Branch Dirty?
./PyAutoBrain main clean

Suggested branch: feature/brain-tests-hermetic-worktree-env

Implementation Steps

  1. tests/conftest.py: new autouse fixture _no_task_worktree_paths(monkeypatch) deleting PYAUTO_TASK, PYAUTO_ROOT, PYAUTO_BRAIN, PYAUTO_MIND, PYAUTO_HEART, PYAUTO_HANDS (raising=False), with a docstring citing bin/worktree.sh and this issue.
  2. Run pytest tests/ with the task worktree's activate.sh sourced, and again in a clean env; both all-pass.
  3. Ship via /ship_library, auto-merge on green.

Key Files

  • tests/conftest.py — suite-wide isolation fixtures
  • bin/worktree.sh:70-75 — the exports (unchanged)
  • agents/conductors/hygiene/_hygiene_repos.py — candidate_map_paths (unchanged; its override is by design)

Original Prompt

Click to expand starting prompt

Brain test suite is not hermetic against a task worktree's activate.sh organ paths

Type: bug
Target: PyAutoBrain
Repos:

  • PyAutoBrain
    Difficulty: small
    Autonomy: safe
    Priority: normal
    Status: formalised
    Consequence: notify
    Witness: with a task worktree's activate.sh sourced (PYAUTO_ROOT, PYAUTO_BRAIN, PYAUTO_MIND, PYAUTO_HEART, PYAUTO_HANDS, PYAUTO_TASK exported), pytest tests/ in PyAutoBrain passes in full, including tests/test_grouped_organ_consumers.py::test_hygiene_map_and_heart_board_find_grouped_checkouts; CI stays green
    Review-minutes: 0
    Unattended: ready
    Lane: any

Bug

Running the PyAutoBrain suite from a task worktree after source <wt>/activate.sh
(as start_library / ship_library instruct) fails
tests/test_grouped_organ_consumers.py::test_hygiene_map_and_heart_board_find_grouped_checkouts:
_hygiene_repos.resolve_map() returns $PYAUTO_MIND/repos.yaml (the worktree's
Mind) instead of the test's tmp tree. candidate_map_paths() treats PYAUTO_MIND
as a hard override by design; the test only sets PYAUTO_ROOT. CI has none of
these variables, so it passes there; the gap shows only locally, and it forced
env -u PYAUTO_MIND during the PyAutoBrain#676 ship (2026-11-18). The same failure
reproduces on origin/main.

bin/worktree.sh writes activate.sh exporting PYAUTO_TASK, PYAUTO_ROOT,
PYAUTO_BRAIN, PYAUTO_MIND, PYAUTO_HEART and PYAUTO_HANDS.

Fix

  • tests/conftest.py gains one autouse fixture that monkeypatch.delenvs those
    organ-path variables (raising=False), matching CI. Tests that need one set it
    themselves (autouse runs first, so their setenv still wins). Keep it
    alongside the existing isolation fixtures, with a docstring saying why.
  • Run the full suite twice: plain, and with a task worktree's activate.sh
    sourced. Both must pass with no deselects.

Activity

  1. Jammy2211 commented on Nov 18, 2026

    @Jammy2211
    ContributorAuthor

    Shipped in #678 (merged). New autouse fixture _no_task_worktree_paths in tests/conftest.py clears the organ-path variables a task worktree's activate.sh exports. Full suite: 2370 passed, 1 skipped, both with activate.sh sourced and without.

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