From 1e08b013de370171ffa4b5462a8cd0195cd503fb Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Mon, 5 Oct 2026 20:02:50 +0100 Subject: [PATCH] fix: cortex find_script walks ancestors without resolving symlinks (#471) find_script walked root.resolve().parents, so a tree reached through a symlinked PyAutoCortex (bundle worktrees link it to the canonical checkout) returned the script under the resolved path, not the path the caller named. Walk root.absolute().parents instead; load_cortex still keys its module on script.resolve(). Restores test_a_fixture_tree_finds_the_schema_its_checkout_ships (dropped in the d04e3a0 rewrite) verbatim, and adds a tmp_path symlink regression test; both were red before the fix. Co-Authored-By: Claude Opus 5.5 --- agents/conductors/cortex/_cortex.py | 2 +- tests/test_cortex_conductor.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/agents/conductors/cortex/_cortex.py b/agents/conductors/cortex/_cortex.py index 40c01e04..c4b0658e 100644 --- a/agents/conductors/cortex/_cortex.py +++ b/agents/conductors/cortex/_cortex.py @@ -118,7 +118,7 @@ def find_script(root: Path) -> Path | None: """The `scripts/cortex.py` that governs the tree at `root`: in the root, then its ancestors (a fixture tree lives inside its checkout), then the resolved checkout — the schema that reads a tree is the one beside it.""" - for candidate in (root, *root.resolve().parents): + for candidate in (root, *root.absolute().parents): script = candidate / "scripts" / "cortex.py" if script.is_file(): return script diff --git a/tests/test_cortex_conductor.py b/tests/test_cortex_conductor.py index 1cccbe73..0ed4d3a0 100644 --- a/tests/test_cortex_conductor.py +++ b/tests/test_cortex_conductor.py @@ -771,6 +771,28 @@ def test_root_resolution_order(tmp_path, monkeypatch): assert _cortex.resolve_root().name == "PyAutoCortex" +def test_a_fixture_tree_finds_the_schema_its_checkout_ships(skeleton): + """A data root need not be a checkout: the fixture has no `scripts/`, and + the script that governs it is the one shipped beside it.""" + assert (skeleton / "scripts").exists() is False + assert _cortex.find_script(skeleton) == cortex_root() / "scripts" / "cortex.py" + + +def test_find_script_walks_the_symlinked_path_not_the_resolved_one(tmp_path): + """A bundle worktree links `PyAutoCortex` to the canonical checkout: the + script found for a tree under the link is named under the link, so it + compares equal to the checkout the caller resolved (#471).""" + real = tmp_path / "real" + (real / "scripts").mkdir(parents=True) + (real / "scripts" / "cortex.py").write_text("", encoding="utf-8") + (real / "tests" / "fixtures" / "skeleton").mkdir(parents=True) + wt = tmp_path / "wt" + wt.mkdir() + (wt / "PyAutoCortex").symlink_to(real, target_is_directory=True) + tree = wt / "PyAutoCortex" / "tests" / "fixtures" / "skeleton" + assert _cortex.find_script(tree) == wt / "PyAutoCortex" / "scripts" / "cortex.py" + + def test_the_conductor_is_mind_free_and_names_no_instance_path(): src = CONDUCTOR.read_text(encoding="utf-8") assert not re.search(r"^(?:from|import) _(?:intake|sizing)\b", src, re.M)