Skip to content

TR-1164: tests that exec or spawn a watch run on a scratch home - #585

Merged
sudopower merged 3 commits into
mainfrom
factory/TR-1164
Nov 11, 2026
Merged

sudopower merged 3 commits into
mainfrom
factory/TR-1164

Conversation

@sudopower

Copy link
Copy Markdown
Member

Ticket: TR-1164

What changed

Tests that exec or spawn a watch could attach to the real ~/factory when a patch missed (the TR-1069 incident: a real watch started and live stations moved onto it).

  • F6: every test that can restart or start a watch, run crew up, crew restart or a revive now runs on a scratch HOME, USERPROFILE, FACTORY_HOME and FACTORY_CREW_HOME. test_crew_kit.py env_ (line 744) is the first.
  • Guard: new tests/_crew_guard.py wraps os.exec* and subprocess.Popen. A start whose environment reaches the real home (HOME/USERPROFILE, FACTORY_CREW_HOME/FACTORY_HOME on ~/factory, or a crew process with no home) raises RealHomeReached, is recorded, and an exit hook ends the run non-zero, so a broad except Exception cannot hide it. Tests' own exec/spawn stand-ins call check_exec.
  • tests/test_crew_scratch_home.py (new, in ci_list.txt, 26 checks): the guard's rules, the guard on the real restart_self and watch.start with the old kit environment, and a scan that fails any test file that can start a crew process without the guard.
  • F5: test_crew_watch_process.py checks that watch() calls follow_engine every round, between the pid file claim and the steps (and not with once=True).
  • No change under tares/ or claude-plugin/; bash engine untouched.

Checks (scratch HOME, TARES_FACTORY_URL unset, PYTHON_KEYRING_BACKEND=keyring.backends.fail.Keyring)

  • All test_crew_* and test_factory_* in ci_list pass; test_factory_mcp and test_factory_desk only fail with the station's own TARES_PROJECT set, and pass without it (not related).
  • Break test F6: old env_ in test_crew_kit.py -> guard fails the run (exit 1, "no HOME or USERPROFILE ... no FACTORY_CREW_HOME"); restored, 121 passed.
  • Break test F5: follow_engine call removed from watch() -> the new check fails (87 passed, 1 failed); restored, 88 passed.
  • check_ledger ok; check_port_drift origin/main HEAD ok.

Assumptions

None.

@sudopower

Copy link
Copy Markdown
Member Author

factory/review: changes at b530668

The guard is the right shape: it wraps os.exec* and Popen.__init__, so a recorder that misses still can't exec onto the real home, and the atexit exit stops a broad except from hiding a refusal. But it also refuses harmless probes in four existing suites, so six CI test shards are red on this head.

Verified (worktree at b530668, TARES*/FACTORY*/CLAUDE* stripped, fail keyring)

  • Pass: test_crew_scratch_home 26/0, test_crew_kit 121/0, test_crew_watch_process 88/0, watch_revive 53/0, cc_update 221/0, idle_wake 96/0, lifecycle 97/0, pace 107/0, regrant 30/0, ci_list 55/0, dispatch 140/0, startup_time 5/0, unicode_home 8/0, views 138/0, fake_claude 47/0, ci_windows 39/0.
  • Fail (rc=1, "FAIL a test reached the real home"): test_crew_contract, test_crew_person, test_crew_session, test_crew_setup_contract.
  • Guard probe (with /usr/bin/true as the program, so a miss starts nothing):
    • tonight's incident shape is refused: -m tares.crew crew watch --interval 7 with an env of only PATH and TARES_FACTORY_ENGINE;
    • a bin/factory start with FACTORY_CREW_HOME=~/factory is refused;
    • a tares factory start with a scratch HOME and crew home is allowed.
  • ~/factory/stations.json was unchanged across my runs.
  • Scope: tests only, 13 files, +374/-8. No hooks.json, min_tares.txt, version or engine change.

F1 (P2, blocking): the guard fails four suites, and CI is red on six shards

  • fake_crew_env() now calls install(), so the guard covers every test that builds a fake crew. These four never pin HOME in os.environ. Each one then starts a non-crew python -c probe with the inherited env, and the guard refuses it with "HOME is the real home":
    • tests/test_crew_contract.py:323: Popen([python, "-c", "import time; time.sleep(120)", "crew", "watch"]).
    • tests/test_crew_person.py:207 and tests/test_crew_session.py:254: the dispatch import probe.
    • tests/test_crew_setup_contract.py:394: the d.find(['crew','up']) probe.
  • CI shows the same thing. test (mit|duckdb|postgres 3/5) fail on the contract probe, and 5/5 fails on the setup_contract probe. Job 130441243325 has _crew_guard.RealHomeReached: ... -c import time; time.sleep(120) crew watch: HOME is the real home.
  • Recommended fix: pin a scratch HOME and USERPROFILE (and FACTORY_CREW_HOME) in those four tests before install(), as the other wired tests already do. That keeps the strict check, where any process with the real HOME counts.
  • The other option is to apply the HOME check to crew-like argv only. That is weaker: a crew start the guard doesn't recognise would get through.
  • Either way, run each of those four suites and the CI shards before the next round.

F2 (P3, non-blocking, tests/_crew_guard.py crew_like): what counts as a crew start is narrow and textual

  • A watch started as python <path>/tares/crew/__main__.py ... is not recognised.
  • Any argument whose basename is factory (for example git -C ~/factory) counts as a crew start.
  • Neither is reachable today: tares/crew starts processes only through os.execve, os.execvpe and Popen. Worth a line in the docstring.

F3 (P3, non-blocking, tests/_crew_guard.py:26-30): on Windows the real home is read from expanduser("~")

  • That reads USERPROFILE. A runner or parent test that has already pointed USERPROFILE at a scratch folder makes the guard blind to the real home.
  • A Windows API for the profile folder would avoid this. Otherwise, say so in the docstring.

Not verified

  • windows-crew on this head: still pending at review time. Compare it with main's run in round 2.
  • windows-crew is advisory, but it is the only job that runs every parity scenario.

Also run: python tests/test_parity.py gave 95 passed, 0 failed. A Sonnet challenger confirmed F1 and found F2 and F3. Its claim that setup_contract pins HOME before install() is wrong: that file fails both locally and in CI shard 5/5.

Next round: a full re-pass, including the four suites above, CI 3/5 and 5/5, and windows-crew compared with main.

@sudopower

Copy link
Copy Markdown
Member Author

factory/review: pass at 71f2ea6 (round 2)

F1 is fixed: the four suites that probed with the real HOME now call _crew_guard.scratch_home() before anything spawns. The strict rule, that no process may carry the real home, stays as it was. F2 and F3 are written down in the guard's docstring, which is what I asked for.

Verified (worktree at 71f2ea6, TARES*/FACTORY*/CLAUDE* stripped, fail keyring)

  • Delta from b530668: 2 commits, no rebase, 7 test files, +49/-3. I judged 71f2ea6 only, as asked.
  • The four round 1 failures now pass: test_crew_contract 276/0, test_crew_person 32/0, test_crew_session 45/0, test_crew_setup_contract 85/0.
  • Also 0 failed: scratch_home 28, kit 121, watch_process 88, watch_revive 53, cc_update 221, idle_wake 96, lifecycle 97, pace 107, regrant 30, ci_list 55, dispatch 140, startup_time 5, unicode_home 8, views 138, fake_claude 47, ci_windows 39.
  • python tests/test_parity.py: 95 passed, 0 failed.
  • Break: I took the scratch_home() call out of test_crew_person. It fails again with "a test reached the real home", rc=1. Restored, it is 32/0.
  • scratch_home() is called once, and its folder is removed at exit; the new check covers both. The guard's exit hook is registered after it, so on a refusal the hook exits non-zero first.
  • Scope: tests only. No hooks.json, min_tares.txt, version or engine change.
  • CI on this head: all 29 required checks pass, including test (mit|duckdb|postgres 3/5) and 5/5, which failed in round 1.
  • windows-crew (run 42999718241, advisory): 164 passed, 3 failed, 43 skipped. These are the same three that fail on main's run 42991888647: test_crew_dispatch, launch_settings_crew and crew_g1_adopt_second_repo. PR 584 fixes them. This PR adds no Windows failure.

Resolved: F1 fixed. F2 and F3 fixed, by documenting them in the docstring.

Not run

  • Challenger skipped: a small delta (+49/-3, tests only), and the F1 fix and its break are verified.

@sudopower
sudopower merged commit 27d37be into main Nov 11, 2026
30 of 31 checks passed
@sudopower
sudopower deleted the factory/TR-1164 branch November 11, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant