From 6ed4c8ebca5d2370c9d3286b44bd1e05082416d4 Mon Sep 17 00:00:00 2001 From: gregoryfoster Date: Fri, 27 Nov 2026 19:33:03 +0000 Subject: [PATCH 1/5] #146 fix: worktrees get their own venv, not the main checkout's worktree-create.sh symlinked the main checkout's .venv into every worktree (.skills/worktree_venv defaulted to link), so a worktree's uv sync re-pointed the main checkout's editable install at the worktree; once removed, the operator scripts lost src. Set the knob to none, pinned by tests/ci/test_worktree_venv_knob.py (the file, and the vendored script run against it), and say so in AGENTS.md. Co-Authored-By: Claude Opus 5.5 --- .skills/worktree_venv | 1 + AGENTS.md | 2 + tests/ci/test_worktree_venv_knob.py | 87 +++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 .skills/worktree_venv create mode 100644 tests/ci/test_worktree_venv_knob.py diff --git a/.skills/worktree_venv b/.skills/worktree_venv new file mode 100644 index 0000000..621e94f --- /dev/null +++ b/.skills/worktree_venv @@ -0,0 +1 @@ +none diff --git a/AGENTS.md b/AGENTS.md index 128217e..b0c14ea 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -22,6 +22,8 @@ Python ≥3.12, uv, pytest, ruff, PostgreSQL 16, Alembic. `pre-commit` runs ruff only, never pytest. A clean commit hook says nothing about correctness — only CI does (`.github/workflows/ci.yml`: `lint`, `test`, `migrations`). CI pins CPython 3.12 and installs with `uv sync --locked`, because `core = "sysmon"` coverage needs both; `tests/ci/` asserts it. **Local-gate attestation** (#133): with `.skills/attest-local-gate` = `on`, shipping-work's `push.sh` runs the gate, pushes, and posts `gate/local`; `test` then skips its `Run tests` step on that human PR's head. `lint` and `migrations` never skip, nor does Dependabot's, a fork's, or `main`'s push run. Install the hook once per clone, from the main checkout; worktrees share its `.git/hooks`. Never `pre-commit install` from a worktree: it pins that worktree's venv, and once the worktree is removed every commit is refused (no `pre-commit` on PATH to fall back to) until reinstalled from the main checkout (#110). +**Worktrees get their own venv** (#146): `.skills/worktree_venv` = `none`, so `worktree-create.sh` links no `.venv`; run `uv sync` in a new worktree. A linked one is the main checkout's, and a worktree's `uv sync` re-pointed its editable install at the worktree: once that was removed, the operator scripts (`rotate_key.py`, `seed_tenant.py`) lost `src`. `tests/ci/test_worktree_venv_knob.py`. + ## Project Layout `src/api/` is transport (routes, schemas, auth deps); `src/core/` is domain. Core never imports api. diff --git a/tests/ci/test_worktree_venv_knob.py b/tests/ci/test_worktree_venv_knob.py new file mode 100644 index 0000000..58d8fb8 --- /dev/null +++ b/tests/ci/test_worktree_venv_knob.py @@ -0,0 +1,87 @@ +"""Tests for ``.skills/worktree_venv``: each worktree gets its own venv (#146). + +With the knob's default, ``link``, ``worktree-create.sh`` symlinks the main +checkout's ``.venv`` into every worktree. A worktree's ``uv sync`` or ``uv run`` +then reinstalls the editable project into that one venv, pointing the main +checkout's ``_editable_impl_co_status.pth`` at the worktree; once the worktree +is removed, ``src`` stops resolving for the operator scripts that run from the +main checkout (``rotate_key.py``, ``seed_tenant.py``, ``import_monitors.py``). + +The first test holds the file, read with the script's grammar (whole-line ``#`` +comments and blank lines dropped, the first line left, trimmed): CI checks out +no submodule, so it can't run the script. The second runs the vendored +``worktree-create.sh`` against a scratch repo carrying this knob, so a submodule +bump that renames the knob or its value fails a local run. +""" + +import shutil +import subprocess +from pathlib import Path + +import pytest + +from tests.ci.test_dependencies import REPO_ROOT + +KNOB = REPO_ROOT / ".skills" / "worktree_venv" +CREATE = REPO_ROOT / "skills" / "using-git-worktrees" / "scripts" / "worktree-create.sh" + + +def configured(text: str) -> str: + """The knob's value as ``worktree_venv_mode`` reads it.""" + lines = [line.strip() for line in text.splitlines()] + lines = [line for line in lines if line and not line.startswith("#")] + return lines[0] if lines else "" + + +@pytest.mark.parametrize( + ("text", "expected"), + [ + ("none\n", "none"), + ("# worktrees get their own venv\n\n none \n", "none"), + ("", ""), + ("# only a comment\n", ""), + ], +) +def test_configured_reads_as_the_script_does(text: str, expected: str): + """Comments and blank lines aren't values; whitespace around one is dropped.""" + assert configured(text) == expected + + +def test_knob_reads_none(): + """Tracked, so every clone's worktrees provision their own venv.""" + assert configured(KNOB.read_text()) == "none" + + +def git(cwd: Path, *args: str) -> None: + """Run git quietly in ``cwd``, failing the test on error.""" + subprocess.run(["git", *args], cwd=cwd, check=True, capture_output=True) + + +@pytest.mark.skipif(not CREATE.is_file(), reason="skills-vendor not checked out (CI)") +def test_worktree_create_links_no_venv_under_this_knob(tmp_path: Path): + """A primary with a venv and this knob yields a worktree with no ``.venv``, said on stderr.""" + primary = tmp_path / "primary" + (primary / ".skills").mkdir(parents=True) + shutil.copyfile(KNOB, primary / ".skills" / "worktree_venv") + (primary / ".venv" / "bin").mkdir(parents=True) + (primary / ".venv" / "bin" / "activate").touch() + (primary / ".gitignore").write_text(".worktrees/\n.venv\n.skills/\n") + git(primary, "init", "-q", "-b", "main") + git(primary, "add", ".gitignore") + git(primary, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "init") + + out = subprocess.run( + ["bash", str(CREATE), "--new", "probe"], + cwd=primary, + capture_output=True, + text=True, + check=False, + env={"PATH": "/usr/bin:/bin", "HOME": str(tmp_path)}, + ) + + assert out.returncode == 0, out.stderr + worktree = Path(out.stdout.strip().splitlines()[-1]) + assert worktree.is_dir(), out.stdout + assert not (worktree / ".venv").exists() + assert not (worktree / ".venv").is_symlink() + assert "worktree_venv=none" in out.stderr, out.stderr From debe6e0a950e93b072aa7310478aa6ba09a12bf5 Mon Sep 17 00:00:00 2001 From: gregoryfoster Date: Fri, 27 Nov 2026 20:00:00 +0000 Subject: [PATCH 2/5] =?UTF-8?q?#146=20docs:=20CR=202=20=E2=80=94=20AGENTS.?= =?UTF-8?q?md's=20worktree=20venv=20line=20to=20one=20sentence?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index b0c14ea..ec4d781 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -22,7 +22,7 @@ Python ≥3.12, uv, pytest, ruff, PostgreSQL 16, Alembic. `pre-commit` runs ruff only, never pytest. A clean commit hook says nothing about correctness — only CI does (`.github/workflows/ci.yml`: `lint`, `test`, `migrations`). CI pins CPython 3.12 and installs with `uv sync --locked`, because `core = "sysmon"` coverage needs both; `tests/ci/` asserts it. **Local-gate attestation** (#133): with `.skills/attest-local-gate` = `on`, shipping-work's `push.sh` runs the gate, pushes, and posts `gate/local`; `test` then skips its `Run tests` step on that human PR's head. `lint` and `migrations` never skip, nor does Dependabot's, a fork's, or `main`'s push run. Install the hook once per clone, from the main checkout; worktrees share its `.git/hooks`. Never `pre-commit install` from a worktree: it pins that worktree's venv, and once the worktree is removed every commit is refused (no `pre-commit` on PATH to fall back to) until reinstalled from the main checkout (#110). -**Worktrees get their own venv** (#146): `.skills/worktree_venv` = `none`, so `worktree-create.sh` links no `.venv`; run `uv sync` in a new worktree. A linked one is the main checkout's, and a worktree's `uv sync` re-pointed its editable install at the worktree: once that was removed, the operator scripts (`rotate_key.py`, `seed_tenant.py`) lost `src`. `tests/ci/test_worktree_venv_knob.py`. +**Worktrees get their own venv** (#146, `tests/ci/test_worktree_venv_knob.py`): `.skills/worktree_venv` = `none`, so `uv sync` in a new worktree; a linked main `.venv` lets a worktree's `uv sync` re-point the operator scripts' `src` at it. ## Project Layout From ef5e99e16f0b0ba9712c7c81d684e57c365f644c Mon Sep 17 00:00:00 2001 From: gregoryfoster Date: Fri, 27 Nov 2026 20:00:06 +0000 Subject: [PATCH 3/5] =?UTF-8?q?#146=20docs:=20CR=201=20=E2=80=94=20harness?= =?UTF-8?q?-made=20worktrees=20get=20their=20own=20venv=20too?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit using-git-worktrees tells an agent to ln -s the main .venv into a worktree the harness made; the knob never reaches that path. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index ec4d781..2f7e328 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -22,7 +22,7 @@ Python ≥3.12, uv, pytest, ruff, PostgreSQL 16, Alembic. `pre-commit` runs ruff only, never pytest. A clean commit hook says nothing about correctness — only CI does (`.github/workflows/ci.yml`: `lint`, `test`, `migrations`). CI pins CPython 3.12 and installs with `uv sync --locked`, because `core = "sysmon"` coverage needs both; `tests/ci/` asserts it. **Local-gate attestation** (#133): with `.skills/attest-local-gate` = `on`, shipping-work's `push.sh` runs the gate, pushes, and posts `gate/local`; `test` then skips its `Run tests` step on that human PR's head. `lint` and `migrations` never skip, nor does Dependabot's, a fork's, or `main`'s push run. Install the hook once per clone, from the main checkout; worktrees share its `.git/hooks`. Never `pre-commit install` from a worktree: it pins that worktree's venv, and once the worktree is removed every commit is refused (no `pre-commit` on PATH to fall back to) until reinstalled from the main checkout (#110). -**Worktrees get their own venv** (#146, `tests/ci/test_worktree_venv_knob.py`): `.skills/worktree_venv` = `none`, so `uv sync` in a new worktree; a linked main `.venv` lets a worktree's `uv sync` re-point the operator scripts' `src` at it. +**Worktrees get their own venv** (#146, `tests/ci/test_worktree_venv_knob.py`): `.skills/worktree_venv` = `none`; in any worktree, harness-made too, `uv sync`, never `using-git-worktrees`' `ln -s
/.venv`, since a worktree's `uv sync` re-points the linked main venv's `src` at that worktree, breaking the operator scripts once it is removed. ## Project Layout From ed9c2b1dccd0a2e2e34a4e77758ab8bf4f67b7b2 Mon Sep 17 00:00:00 2001 From: gregoryfoster Date: Fri, 27 Nov 2026 20:00:24 +0000 Subject: [PATCH 4/5] =?UTF-8?q?#146=20test:=20CR=203=20=E2=80=94=20the=20k?= =?UTF-8?q?nob=20test's=20scratch=20repo=20runs=20in=20an=20isolated=20env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- tests/ci/test_worktree_venv_knob.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/ci/test_worktree_venv_knob.py b/tests/ci/test_worktree_venv_knob.py index 58d8fb8..ff50038 100644 --- a/tests/ci/test_worktree_venv_knob.py +++ b/tests/ci/test_worktree_venv_knob.py @@ -14,6 +14,7 @@ bump that renames the knob or its value fails a local run. """ +import os import shutil import subprocess from pathlib import Path @@ -52,9 +53,18 @@ def test_knob_reads_none(): assert configured(KNOB.read_text()) == "none" -def git(cwd: Path, *args: str) -> None: +def isolated(home: Path) -> dict[str, str]: + """An env for the scratch repo: the caller's PATH, no ``GIT_*``, ``home`` as HOME. + + A ``GIT_DIR`` or ``GIT_INDEX_FILE`` from a hook would aim the scratch + commit at the real repo, and a global ``commit.gpgsign`` would refuse it. + """ + return {"PATH": os.environ["PATH"], "HOME": str(home)} + + +def git(cwd: Path, env: dict[str, str], *args: str) -> None: """Run git quietly in ``cwd``, failing the test on error.""" - subprocess.run(["git", *args], cwd=cwd, check=True, capture_output=True) + subprocess.run(["git", *args], cwd=cwd, env=env, check=True, capture_output=True) @pytest.mark.skipif(not CREATE.is_file(), reason="skills-vendor not checked out (CI)") @@ -66,9 +76,10 @@ def test_worktree_create_links_no_venv_under_this_knob(tmp_path: Path): (primary / ".venv" / "bin").mkdir(parents=True) (primary / ".venv" / "bin" / "activate").touch() (primary / ".gitignore").write_text(".worktrees/\n.venv\n.skills/\n") - git(primary, "init", "-q", "-b", "main") - git(primary, "add", ".gitignore") - git(primary, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "init") + env = isolated(tmp_path) + git(primary, env, "init", "-q", "-b", "main") + git(primary, env, "add", ".gitignore") + git(primary, env, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "init") out = subprocess.run( ["bash", str(CREATE), "--new", "probe"], @@ -76,7 +87,7 @@ def test_worktree_create_links_no_venv_under_this_knob(tmp_path: Path): capture_output=True, text=True, check=False, - env={"PATH": "/usr/bin:/bin", "HOME": str(tmp_path)}, + env=env, ) assert out.returncode == 0, out.stderr From da4b09e024eaf34bd333915cd4daa26f8d31cd0a Mon Sep 17 00:00:00 2001 From: gregoryfoster Date: Fri, 27 Nov 2026 20:00:49 +0000 Subject: [PATCH 5/5] =?UTF-8?q?#146=20test:=20CR=204=20=E2=80=94=20a=20lin?= =?UTF-8?q?k=20control=20in=20place=20of=20the=20stderr=20wording=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- tests/ci/test_worktree_venv_knob.py | 38 ++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/tests/ci/test_worktree_venv_knob.py b/tests/ci/test_worktree_venv_knob.py index ff50038..d61301e 100644 --- a/tests/ci/test_worktree_venv_knob.py +++ b/tests/ci/test_worktree_venv_knob.py @@ -9,13 +9,13 @@ The first test holds the file, read with the script's grammar (whole-line ``#`` comments and blank lines dropped, the first line left, trimmed): CI checks out -no submodule, so it can't run the script. The second runs the vendored -``worktree-create.sh`` against a scratch repo carrying this knob, so a submodule -bump that renames the knob or its value fails a local run. +no submodule, so it can't run the script. The others run the vendored +``worktree-create.sh`` against a scratch repo carrying this knob, and ``link`` as +the control, so a submodule bump that renames the knob or its value, or stops +the scratch repo reaching the linker, fails a local run. """ import os -import shutil import subprocess from pathlib import Path @@ -67,12 +67,11 @@ def git(cwd: Path, env: dict[str, str], *args: str) -> None: subprocess.run(["git", *args], cwd=cwd, env=env, check=True, capture_output=True) -@pytest.mark.skipif(not CREATE.is_file(), reason="skills-vendor not checked out (CI)") -def test_worktree_create_links_no_venv_under_this_knob(tmp_path: Path): - """A primary with a venv and this knob yields a worktree with no ``.venv``, said on stderr.""" +def created_worktree(tmp_path: Path, knob: str) -> Path: + """Run the vendored ``worktree-create.sh`` from a scratch primary with a venv and ``knob``.""" primary = tmp_path / "primary" (primary / ".skills").mkdir(parents=True) - shutil.copyfile(KNOB, primary / ".skills" / "worktree_venv") + (primary / ".skills" / "worktree_venv").write_text(knob) (primary / ".venv" / "bin").mkdir(parents=True) (primary / ".venv" / "bin" / "activate").touch() (primary / ".gitignore").write_text(".worktrees/\n.venv\n.skills/\n") @@ -93,6 +92,27 @@ def test_worktree_create_links_no_venv_under_this_knob(tmp_path: Path): assert out.returncode == 0, out.stderr worktree = Path(out.stdout.strip().splitlines()[-1]) assert worktree.is_dir(), out.stdout + return worktree + + +needs_vendor = pytest.mark.skipif(not CREATE.is_file(), reason="skills-vendor not checked out (CI)") + + +@needs_vendor +def test_worktree_create_links_no_venv_under_this_knob(tmp_path: Path): + """A primary with a venv and this knob yields a worktree with no ``.venv``.""" + worktree = created_worktree(tmp_path, KNOB.read_text()) assert not (worktree / ".venv").exists() assert not (worktree / ".venv").is_symlink() - assert "worktree_venv=none" in out.stderr, out.stderr + + +@needs_vendor +def test_worktree_create_links_the_venv_under_link(tmp_path: Path): + """The control: the same scratch primary under ``link`` gets the symlink. + + Without it, a change to the linker's guard would leave the test above + passing without ever reaching the knob. + """ + worktree = created_worktree(tmp_path, "link\n") + assert (worktree / ".venv").is_symlink() + assert (worktree / ".venv").resolve() == (tmp_path / "primary" / ".venv").resolve()