Skip to content

adopt-project.py: a plan that sends a source's .gitmodules to one leg and a submodule it registers to another, or keeps either in the root, is now a check finding and an execute refusal, and plan asks the one-leg question on .gitmodules itself (#166) - #194

Merged
brettheap merged 11 commits into
mainfrom
fix/adopt-split-submodule-plan
Oct 10, 2026

Conversation

@brettheap

@brettheap brettheap commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Lane: openreposhape-1 (openRepoShape-1)
Claim: #166 (comment)

What

adopt-project.py now holds an adoption plan to one rule about a source's own submodules: a gitlink and the .gitmodules that registers it are one fact, so they go to ONE leg, never the assembly root. The rule is applied in three places:

  1. plan asks. contracts/path-classification.yaml gains ambiguous-gitmodules, which asks the question on the top-level .gitmodules. plan then asks the same question on every entry that holds a gitlink, whatever rule matched that entry. The question names the submodules the entry holds and the rule it is no longer classified by. So plan never proposes an answer that check refuses.
  2. check finds. It prints one FINDING line per problem, each counting toward exit 1. There are four ids: plan-submodule-root, plan-gitmodules-unreadable, plan-submodule-unregistered and plan-submodule-split. When any of them is found, check prints the remediation once, after its findings.
  3. execute refuses. adopt-project.py execute refuses only plan-unresolved and plan-stale, so a plan check rejects as uncovered or with a bad leg creates and pushes both legs before it fails verification #168's _refuse_what_check_finds raises REFUSED <id> (exit 2) with every finding check prints, adopt-project.py execute refuses only plan-unresolved and plan-stale, so a plan check rejects as uncovered or with a bad leg creates and pushes both legs before it fails verification #168's remedy and then the submodule remediation. It runs before _create_leg_remotes, so nothing exists yet: no --local-remote-dir, an empty --work-dir, and the source's HEAD, refs and status unchanged.

check and execute read ONE list of findings, _entry_findings: coverage, each entry's leg: (#169's leg paths among them), then submodule_plan_problems(entries, tree, registered). So execute refuses every problem check finds, in check's words, all at once. The helper's callers read registered through Source.registered_submodules(tree), so it is a function of its arguments alone. registered_submodules reads the source's .gitmodules the way git's own submodule reader will read it inside the leg (below).

Why

On main, a plan answering .gitmodules -> code, upstream/ -> spec runs execute to exit 0 and prints adoption verified: every source path is in exactly one place. The assembly is then unclonable:

main execute exit=0
adoption verified: every source path is in exactly one place
fatal: No url found for submodule path 'spec/upstream/dependency' in .gitmodules
fatal: Failed to recurse into submodule path 'spec'
clone exit=128

The same happens to a gitlink that no .gitmodules registers, once it is kept in a leg. Take a source with upstream/orphan (as git add of an embedded clone leaves one), no .gitmodules, and the plan upstream/ -> code:

  • on main: check 0, execute 0 "adoption verified";
  • the source's own git clone --recurse-submodules exits 0;
  • the assembly's exits 128 with No url found for submodule path 'code/upstream/orphan'.

At the top level, git skips a gitlink with no URL. Inside a leg, the clone recurses with --init and dies on it. So for such a gitlink a leg is worse than the source, not "no worse".

With this branch, both plans are a check finding (exit 1) and an execute refusal (exit 2):

FINDING plan-submodule-split: the submodule upstream/dependency (entry upstream/) has leg: spec but the source's .gitmodules has leg: code, so the leg that holds the gitlink holds no URL for it and the assembly's recursive clone fails there
REFUSED plan-submodule-unregistered: 1 finding(s) in adoption-plan.yaml, as `check` prints them:
  FINDING plan-submodule-unregistered: the submodule upstream/orphan (entry upstream/) has leg: code but no .gitmodules entry in the source registers its path with a url, so the leg that holds the gitlink holds no URL for it and the assembly's recursive clone fails there

The rule as implemented

A path's leg is the leg: of the single plan entry _covering finds for it, a file entry or an ancestor directory. Gitlinks are the 160000 entries of Source.tree(). The problems are listed in this order, and execute's refusal is named by the first:

  • Root is refused. root is refused for .gitmodules and for every gitlink, one plan-submodule-root per path. The assembly root has exactly two mounts, and its .gitmodules is reserved for them. templates/assembly-root/.github/workflows/validate.yml reads every URL in that file as a leg.
  • Unreadable is refused where git fails on it, and says where. A .gitmodules that git cannot read for its submodules is never read as registering nothing; the finding says what git said, on one line (git cannot read the source's .gitmodules for its submodules (fatal: bad config line 2 in .gitmodules), ...), and where git fails on it, measured end to end on git 2.43:
    • beside a submodule, a FILE git cannot read fails git filter-repo: its git fast-export reads the checked-out .gitmodules for each gitlink in the history, so the extraction of either leg fails, wherever the plan sends the two, after both leg remotes exist. Refused for every plan that extracts a leg, both dropped included ("and the source holds a submodule, so git filter-repo fails on that file when execute extracts a leg, wherever the plan sends the two");
    • otherwise, in a leg that keeps the file or a gitlink, the assembly's recursive clone fails: on a line git cannot parse even with no gitlink in the leg, and on a .gitmodules that is itself a gitlink ("... where the assembly's recursive clone fails on it");
    • a key with no value (path or url with nothing after it) is fatal to git's submodule reader alone, which git runs only for a gitlink. Beside no submodule it is read as registering nothing, as main adopts and clones it when the tip holds no submodule (a gitlink only in history is a follow-up, same on main).
  • Unregistered is refused. Each gitlink kept in spec or code must be registered; otherwise it is one plan-submodule-unregistered, naming the gitlink and its leg. Registered means: the path belongs, by git's own rules, to a <name> whose url is non-empty.
    • Read as the leg will read it. The blob is piped into git config -z --no-includes --file - --list. Not --blob, which git's submodule code never uses: it reads bytes through a char (signed on x86), so a 0xFF byte reads as the end of the file, and it follows [include]. Not --file - alone either: probed on git 2.43, stdin config FOLLOWS includes by default, unlike --file <path>.
    • git's filters, mirrored (Registrations, after submodule-config.c's parse_config): a name that is empty or has a .. component at / or \ is ignored; a path or url starting with - is ignored and the value before it stands; a path belongs to the LAST name given it, and a name moved to another path removes its old path's entry whoever holds it (git's cache_remove_path); a path or url with no value at all, which --list prints but git's reader dies on, makes the file unreadable beside a submodule, except under a name git already ignores.
    • Why, when an entry names it. Registrations keeps how a named path came to register nothing, and the finding says it instead of "no .gitmodules entry ... registers its path with a url": the entry holding it has no url git reads (none, empty, or starting with -; or a later url-less name took the path), git ignores its suspicious name, its path starts with -, or another entry's move dropped it.
    • --list, not --get-regexp: the second exits 1 both for "no key matched" and for "bad config line"; --list exits 0 or 128.
    • A key with no <name> is ignored, as git ignores it. With no .gitmodules, nothing is registered. A .gitmodules that is no blob (a gitlink) is unreadable, with git cat-file's words.
    • An unregistered gitlink is reported as unregistered only, never also as split: no leg holds a URL for it.
  • Split is refused. A registered gitlink goes where .gitmodules goes, one plan-submodule-split per gitlink kept elsewhere. So .gitmodules cannot be dropped while one is kept.
  • Drop is tolerated. A gitlink sent to drop is fine, registered or not, and any one submodule may be dropped on its own. A registered one leaves its registration behind in the leg, inert: git walks the gitlinks in the index and looks each one up in .gitmodules, never the other way round. Dropping .gitmodules and every gitlink together is allowed. Pinned end to end (below): .gitmodules -> code, upstream/ -> drop verifies, the recursive clone exits 0, and bootstrap prints bootstrap ok.
  • plan asks on every entry that holds a gitlink. walk sees paths, not modes, so before this a submodule vendored at .specify/vendored, .cursor or .agents came out leg: root with no question, and one at docs/theme came out spec. check then refused the first and could find the second split.
    • Now ask_about_submodules, run right after walk, replaces each entry that covers a gitlink. The replacement carries the .gitmodules verdict: leg: null, review_required: true, rule ambiguous-gitmodules, its reason, and its question.
    • The question gains: "This entry holds the submodule(s) <paths>: it is asked this question, not classified by its rule <rule>."
    • Every path the question names is spelled, between backticks: a byte that is not UTF-8 as \xe9, a newline as \n, any other character that is not printable by a backslash, and a backslash or a backtick escaped. Written raw, a non-UTF-8 name raised mid-write and left --out empty, and a newline read back as a space. The spelled newline between double quotes is the YAML entry that covers the file.
    • What the rules imply is read before the question. The collision prediction, the follow-ups and the seeding record come from walk's entries, so a submodule under src/ or contracts/ keeps main's harness follow-up and CONTRACTS_DIR line, and no false SEEDED warning or seeded_from_template: true.
    • An entry holding more than one path names the entries that replace it, each submodule an entry of its own, descending only into a directory that holds one: "Split the entry if its paths do not all belong in one leg: replace it with an entry for each of src/app/, src/vendored, each with its own leg:. An entry added beside this one for a path it covers is plan-covered-twice." That holds for an entry of submodules only, too, so one can be dropped on its own. Past eight entries the question says how to make them and counts them instead of naming each: "replace it with an entry for each path directly in src/, 402 in all, ...", or "in one of docs/, docs/theme/, other than those directories" when nested. Adding src/vendored: drop BESIDE src/ is plan-covered-twice (and execute refuses it); the named split checks plan ok, and end to end it verifies, the recursive clone exits 0 and bootstrap prints bootstrap ok.
    • walk's folding is unchanged. Only the covering entry is replaced.
    • The 2026-09-02 ruling is unchanged for files. .specify/ and the assistant directories still stay in the root. Only a vendored SUBMODULE there is asked rather than rooted, because the root keeps no submodule of the source's. The policy comment above ambiguous-gitmodules records this.
    • Checked end to end: .specify/ split into .specify/vendored -> code and .specify/memory/ -> root, with .cursor (a submodule) and .gitmodules sent to code. execute verifies, the recursive clone exits 0 and bootstrap prints bootstrap ok. The constitution stays in the root.
  • Entries check already rejects are skipped. An entry that is unresolved, uncovered, covered twice or has a misspelled leg already produces its own check finding, and is not reported again as a submodule problem.
  • The order is the order to fix them in. A .gitmodules in the root makes every registered kept gitlink a split. An unreadable one hides which gitlinks are registered. An unregistered gitlink may need a commit in the source and a fresh plan, which would discard any answers already given. execute's refusal is named by the first of check's findings and lists up to REFUSED_FINDINGS_SHOWN (8) of them, then "and N more".
  • The common case does not change. A source with no gitlink and no .gitmodules returns nothing from the helper at once, and gets its plan entries back untouched. Re-checked at this head against main:
    • on the suite's no-submodule source, the plan file, plan's output, and check's output (unresolved and resolved) are byte-identical;
    • the two leg heads and leg trees from execute are identical;
    • the assembly differs only in the three files that carry the shape commit, and in the leg URLs, which name each run's own --local-remote-dir.

The remediation, printed by check after its findings and by execute with its refusal, gives the ways out:

  • send .gitmodules and its submodules to one leg, or drop them together;
  • drop any one submodule on its own, leaving its registration inert;
  • drop an unregistered gitlink, or register it in the source (an entry with its path and a url, committed) and re-run plan;
  • repair an unreadable .gitmodules the same way (in a source with no submodule, dropping it is enough);
  • to answer a submodule apart from the directory entry that holds it, REPLACE that entry with an entry for each of its children, as that entry's question lists them; an entry added beside it is plan-covered-twice;
  • never keep any of them in the root.

The question is true wherever it is printed

shape-doctor.py --placement-plan prints the same reason: and question: for an already-split project. A kind: placement-plan file never reaches check or execute, so the question names the tool that refuses (adopt-project.py), not those two subcommands. The reason: claims nothing that an empty .gitmodules would contradict (".gitmodules is where a repository registers its submodules"). The issue's sentence is kept verbatim but framed, "When a repository is adopted, a source's own .gitmodules goes to the SAME leg as every submodule it registers; execute writes the assembly root a fresh one for its two mounts.", so that it is also true of a leg already split.

Re-checked at ca5fb3d on an assembly adopted with .gitmodules and upstream/dependency both in code (round 4 changes neither the policy file nor the doctor):

  • the doctor's placement row is the same with 794828c's doctor and ca5fb3d's: note, "nothing is in the wrong leg";
  • ca5fb3d's doctor exits 0 (794828c's exits 3 only because its checkout cannot resolve the shape commit the assembly pins);
  • in the placement plan, code/.gitmodules' question: is the only line that differs from 794828c's.

Known and not changed here. The doctor's placement audit classifies leg paths by glob, as walk did, and cannot see a gitlink. On an assembly adopted as #166 requires, with a submodule at .cursor or .specify/vendored sent to the code leg, it reports FINDING placement ... code/.cursor: root by rule root-assistant-instructions; code/.specify/: root by rule root-spec-kit. main's doctor reports the same row. That is a shape-doctor.py follow-up: a leg entry holding a gitlink should be asked, never "root by rule".

Five reviews, seven commits

Merge order

#168, #167 and #169 are on main (f25d805) and merged into this branch (794828c, 5bef216, a037228). #168 makes execute refuse a plan with any check finding, so an entry with a misspelled leg, or a path no entry covers, can no longer keep .gitmodules or a gitlink in the root and reach the split. That also settles the hazard review 2 inferred (not executed) for #165, which changes _verify to skip only the two leg mounts: with #168 in, no such plan reaches _verify.

git merge-tree of this head with each open sibling is clean: #173 (05fa0e0, #165), #184 (f416e13, #171), fix/adopt-mount-past-gitignore (#174), fix/doctor-gitlink-placement (#176, PR #186) and fix/scaffold-force-add-shape-files (#175).

_verify is untouched here. _mount_the_legs changes by one token (its git config subcommand is now the shared GIT_CONFIG constant) and one comment; _SplitTree and _pinned_shape_paths (#167) by one constant each.

Tests

In tests/test_adopt_submodules.py (28 cases at aaa9099, 52 at 09d7889, 77 at 326fb25, 101 at ca5fb3d, 128 now), every #166 test except the needs_filter_repo end-to-end ones runs without git-filter-repo, so the Windows job runs it:

  • the .gitmodules entry: review_required: true, rule ambiguous-gitmodules, the issue's sentence as framed, the unregistered clause, the drop-on-its-own clause, the tool-named root clause, and the reason:;
  • plan asks on the entry holding a gitlink at .specify/vendored, .cursor, .agents, docs/theme, upstream/dependency, src/vendored and docs/theme/sub, and on one entry holding two gitlinks:
    • each row equals the .gitmodules row, apart from its path and size;
    • its question names the gitlinks, between backticks, and the rule that matched (root-spec-kit, root-assistant-instructions, ambiguous-assistant-project-memory, spec-governance, default, code-source-and-tests), and, exactly where the entry holds more than one path, the entries that replace it (docs/theme/sub opens docs/theme/ and nothing else);
    • check on the untouched plan reports only plan-unresolved, never plan-submodule-root;
  • the split that question names is the edit that works: for an orphan src/vendored under src/, adding src/vendored: drop beside src/ is plan-covered-twice, and the named split, read back out of the question, checks plan ok;
  • past eight entries the question describes the split instead of listing it ("each path directly in src/, 14 in all"; nested, "one of docs/, docs/theme/, other than those directories, 10 in all"), and the entries made by that rule check plan ok;
  • what the rules imply survives the question: for src/vendor/dep and contracts/vendor/x, the follow-ups and the seeding record equal those of the same source without the submodule, the harness and CONTRACTS_DIR lines among them, and there is no SEEDED warning;
  • four names no plan line can hold, built through git update-index --index-info and skipped where git refuses one (Windows and a newline): a non-UTF-8 submodule, a non-UTF-8 file beside one, a newline file beside one, and a submodule with a backtick and a backslash. plan writes over the --out file that was there, and the question spells each; the spelled newline, typed between double quotes, is the entry that covers the file;
  • a check matrix of eleven .gitmodules/upstream/ answers. It now also asserts that the remediation is printed exactly once, after the findings and before the count, when there is a submodule finding, and not otherwise;
  • a gitlink under tools/: answered code, as its rule would have, beside .gitmodules -> spec, it is found split;
  • an orphan gitlink with no .gitmodules: refused when kept in code or spec, allowed dropped, refused in the root;
  • an unregistered gitlink beside a registered one: refused in code and in spec (as unregistered only), allowed dropped;
  • why an unregistered submodule's entry registers nothing, eight ways: no url, a - url, shadowed by a later url-less name, a suspicious name, moved off its path (by its own name and under a later one), a - path, and no entry at all (the old words);
  • what counts as a registration, each case what git's own reader does in a leg (probed on git 2.43): url-less, empty-url, name-less, another path and an empty file are refused; upper-case keys count; a 0xFF comment before a registration counts, and a 0xFF byte does not hide a later override; names ../escape, a\\..\\b and "" are ignored, a..b is not; url = -oops is ignored, and a path = -... after a good path leaves the good one; the last name given a path wins, url or none; a name moved off a path takes the path's registration with it; a no-value key under an ignored name is ignored;
  • [include]: a registration beside a relative include counts, and one only in an absolute include (a file on this machine) does not;
  • an unreadable .gitmodules beside a submodule: refused wherever the two go, both dropped included, and named as the extraction's failure; root is refused as well; the finding carries git's words, "in .gitmodules" and not "in standard input", for a bad config line, a path or url with no value, and a .gitmodules that is a gitlink, which is named as the clone's;
  • where git fails, six shapes: a path or url with no value beside no submodule passes; a bad line beside none is the clone's when kept and passes when dropped; a key with no value beside a dropped submodule is the extraction's; and a plan that extracts no leg passes;
  • a .gitmodules with no gitlink beside it: code, spec and drop pass; root is refused;
  • two registered submodules beside .gitmodules -> code: each one kept away from it is its own split, and only those;
  • a top-level gitlink, its own entry: its findings name it with no (entry ...);
  • uncovered, doubly covered and bad-leg entries, for the gitlink and for .gitmodules: check reports exactly its own finding and no remediation, and the helper returns nothing for the plan;
  • _refuse_what_check_finds through importlib on eleven plans. The refusal must list check's findings, code and lines, for all four ids, and end with the submodule remediation, including the replace-the-entry sentence; for four legal plans it must not be raised;
  • a mixed plan of eleven or ten problems: the refusal takes the first problem's code (root, else unregistered), and lists REFUSED_FINDINGS_SHOWN of check's findings plus "and N more";
  • through cmd_execute, a plan check rejects as uncovered and split is refused once, as plan-uncovered, listing both findings, with adopt-project.py execute refuses only plan-unresolved and plan-stale, so a plan check rejects as uncovered or with a bad leg creates and pushes both legs before it fails verification #168's remedy and the submodule one, before the remotes directory exists;
  • under needs_filter_repo:
    • execute on the split plan, on the orphan plan, and on an unreadable .gitmodules dropped with its submodule, exits 2 with its REFUSED line and check's finding. Afterwards the --local-remote-dir does not exist, the --work-dir is empty, and the source's HEAD, refs and status are unchanged;
    • a key with no value beside no submodule, kept in code: check passes, execute verifies and the assembly's recursive clone exits 0;
    • execute on accepted plans (both in code, both in spec, the submodule dropped on its own, and, hand-written, upper-case keys, a 0xFF comment, a relative include) verifies. The assembly's git clone --recurse-submodules and its scripts/bootstrap.py both exit 0. The leg's .gitmodules still registers the submodule; kept, it is checked out; dropped, it is absent.

tests/test_adopt_plan.py adds .gitmodules to the ambiguous-path test, which now pins each case's rule id. It also adds docs/theme/.gitmodules -> spec to the classification test, so that only the top-level file matches the new rule.

Every case of every new or changed test fails under at least one of the 24 named mutations in 326fb25's revert table. ca5fb3d's table has 31 rows: round 3 reverted whole; N1, N2, N3 and P3.3 each reverted by part; over-strict variants; and round 2's mutations re-run for the cases round 3 re-parametrised or whose helper it renamed. Every case of every new or changed test (61 cases in 11 functions) fails under at least one. One row fails nothing, by design: the name regex put back to .+, since the empty-name filter then catches nothing the regex lets through.

Round 4's table has 34 rows, each a fresh clone of ce5e52d with the final test file and one mutation, tests/test_adopt_submodules.py run with only #162's two slow end-to-end tests deselected: the baseline (126 passed, none failed); round 4's code reverted whole (51 failed); 24 single reversions and over-strict variants (NEW-1's two reads, the spelling's four parts, the cap and the opened directories, S3's relief both ways, the extraction rule, its leg and file conditions, the clone rule both ways, "standard input", each of N2's reasons and a reason for every path, the submodule refusal apart again, execute without the submodule findings, without their remedy); and round 3's reader rules re-run through the new Registrations, plus a dropped gitlink held to the rules and the split comparison inverted. Every case of every new or changed test (66 cases in 16 functions) fails under at least one, except #162's mount test, whose only edit is a named literal; its moved case fails when _mount_the_legs' -f is dropped.

Eleven test files (test_adopt_submodules, test_adopt_plan, test_adopt_e2e, test_adopt_spec_only, test_adopt_execute_refusals, test_adopt_ignored_shape_files, test_adopt_leg_paths, test_shape_doctor, test_windows_paths, test_cli_reference, test_repo_hygiene), run at this head:

  • with git-filter-repo: 890 passed, 1 skipped (the SHAPE_MEDXEHR_CLONE test);
  • without it: 832 passed, 59 skipped: 58 filter-repo-gated, and the SHAPE_MEDXEHR_CLONE test.

tests/test_adopt_execute_refusals.py (#168) and tests/test_adopt_leg_paths.py (#169) are unchanged from main and pass.

The full suite was last run at the first commit, aaa9099: 1262 passed, 1 skipped. It was not rerun for 326fb25, ca5fb3d or this head.

The 13 tests tests-windows failed at 6aaedc5 were two test-helper faults, not the tool: conftest.resolve wrote the plan CRLF on Windows (so edited() found no LF line), and raw_source kept a name git left out of the tree (update-index --index-info exits 0). resolve now writes LF and raw_source skips a case whose name is not in the committed tree, asked of git; two new tests hold both on Linux, and I reproduced all 13 failures on Linux (a simulated Windows text mode and a git that ignores a backslash and a newline) with no Windows machine.

README.md, AGENTS.md and docs/cli.md are unchanged. The rule is stated in the policy's own question:, which is what the person resolving the plan reads. render-cli-reference.py --check passes.

Closes #166

🤖 Generated with Claude Code

Summary by Sourcery

Enforce that source submodules and their .gitmodules registration are kept together in one leg or dropped safely throughout planning, checking, and execution.

New Features:

  • Add submodule-aware adoption planning that asks how .gitmodules and every source gitlink should be assigned.

Bug Fixes:

  • Prevent adoption plans from producing assemblies whose recursive clones fail because submodule registrations are rooted, split across legs, unreadable, or missing.
  • Ensure execution refuses every submodule-related plan finding before creating remotes or modifying the source.

Enhancements:

  • Model Git's submodule registration behavior when validating paths, URLs, includes, malformed configuration, and unusual path names.
  • Share one entry-finding pipeline between check and execute, including consolidated remediation guidance.
  • Preserve classification-derived follow-ups and seeding information while replacing submodule-holding entries with targeted questions.
  • Safely spell non-UTF-8, newline, backtick, and backslash paths in generated plan questions.

Documentation:

  • Document the one-leg submodule policy and remediation in the path-classification contract and adoption tool guidance.

Tests:

  • Add comprehensive unit and end-to-end coverage for submodule planning, validation, refusal behavior, Git configuration edge cases, path spelling, and successful recursive cloning.
  • Fix Windows test-plan editing to preserve LF line endings and skip git paths that the platform does not record.

brettheap and others added 9 commits October 7, 2026 11:29
…eg and a submodule it registers to another, or keeps either in the root, is now a `check` finding and an `execute` refusal, and `plan` asks the one-leg question on `.gitmodules` itself (#166)

A plan answering `.gitmodules -> code, upstream/ -> spec` (or `.gitmodules -> drop, upstream/ -> code`) used to pass `check`, run `execute` to "adoption verified", and leave an assembly whose `git clone --recurse-submodules` exits 128 on `No url found for submodule path 'spec/upstream/dependency'`. Reproduced on main before this change; refused before either leg exists after it.

ONE helper, `submodule_plan_problems(entries, tree)`, read by both `cmd_check` (as findings) and `_refuse_an_unrunnable_plan` (as a refusal), so the plan `check` passes is the plan `execute` runs. The leg of a path is the `leg:` of the single entry `_covering` it:
- `.gitmodules` and every gitlink (mode 160000): `root` is refused, one `plan-submodule-root` per path. The assembly root has exactly two mounts, `execute` writes it a fresh `.gitmodules` for them, and `validate.yml` reads every URL there as a leg.
- When the source has a `.gitmodules`, every gitlink kept in spec or code must share its leg, one `plan-submodule-split` per gitlink; so `.gitmodules` cannot be dropped while one is kept. A gitlink dropped beside a `.gitmodules` that went to a leg is allowed: its registration stays behind inert (verified: recursive clone exit 0, `bootstrap ok`). All dropped together is allowed.
- No `.gitmodules`: only the root rule, so an orphan gitlink adopted into a leg still adopts.
- An unresolved, invalid, uncovered or doubly covered entry is skipped: it is already its own finding.
A source with neither (the common case) returns nothing at once; its plan file and `check` output are byte-identical to main's.

`contracts/path-classification.yaml` gains `ambiguous-gitmodules`, asked first with the other named ambiguities, whose question states the constraint: "A source's own `.gitmodules` goes to the SAME leg as every submodule it registers; `execute` writes the assembly root a fresh one for its two mounts", and that `root` is not an answer. Only the top-level file matches.

With `root` refused, the root-kept submodule path #165 documents in `_verify` is no longer reachable from `execute`; `_verify` and `_mount_the_legs` are untouched and #165 stays open.

Tests: the plan question; the `check` matrix of eleven answers, a gitlink a rule classified silently (`tools/dep`), an orphan gitlink; the refusal through importlib, all without git-filter-repo; and one end-to-end refusal under `needs_filter_repo` asserting no leg repository was made. The two policy tests take `.gitmodules` (its rule id) and a nested `docs/theme/.gitmodules` (spec).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tered in the source's `.gitmodules` with a url, because the assembly's recursive clone dies on one that is not even where the source's own clone skips it, and a `.gitmodules` that `git config` cannot read is refused instead of being read as registering nothing (#166)

aaa9099 allowed a gitlink with no registration into a leg on the premise that it "was already unclonable in the source and is no worse in a leg". That premise is false. At the top level, `git clone --recurse-submodules` skips a gitlink that has no URL; once it is inside a leg, the clone recurses with `--init` and dies on it. The adversarial review's reproduction (`upstream/orphan`, no `.gitmodules`, `upstream/ -> code`) gave `check` 0, `execute` 0 "adoption verified", source clone rc 0, and assembly clone rc 128 `No url found for submodule path 'code/upstream/orphan'`. The same happens beside a `.gitmodules` that registers other paths. The sentence is withdrawn from the docstring; this message withdraws it from aaa9099's ("No `.gitmodules`: only the root rule, so an orphan gitlink adopted into a leg still adopts").

The rule, still in ONE helper, so `check` and `execute` cannot disagree. The helper is `submodule_plan_problems(entries, tree, registered)`, and it is now a pure function of the registrations its callers read:
- `Source.registered_submodules(tree)` returns the paths that have a `submodule.<name>.path` and a non-empty `submodule.<name>.url`. It reads them with `git config -z --blob <commit>:.gitmodules --list`. It uses `--list` and not `--get-regexp`, because the second exits 1 both for "no key matched" and for "bad config line" (probed on git 2.43); `--list` exits 0 or 128. A key with no `<name>` is ignored, as git ignores it. With no `.gitmodules`, nothing is registered.
- A gitlink kept in spec or code that is not registered is `plan-submodule-unregistered`, naming the gitlink and its leg. It is that and never also a split: no leg holds a URL for it. Dropped, it is fine.
- A `.gitmodules` that `git config` cannot read is `plan-gitmodules-unreadable` when the plan keeps it, or any gitlink, in a leg. It is never read as registering nothing.
- Unchanged: `root` refused for `.gitmodules` and every gitlink; a registered gitlink kept away from `.gitmodules` is `plan-submodule-split`; a dropped gitlink beside a leg's `.gitmodules` is inert.
- Problems are listed root, unreadable, unregistered, split: the order to fix them in. `execute`'s refusal takes the first problem's code and names eight details, then "and N more".
- The remediation says how to fix an unregistered gitlink: drop it, or register it in the source (an entry with path and url, committed) and re-run `plan`.

Text that was untrue where it is printed:
- The `ambiguous-gitmodules` question keeps the issue's sentence verbatim and "`root` is not an answer". Its "`check` finds it and `execute` refuses it" becomes "`adopt-project.py` refuses a plan that gives it". `shape-doctor.py --placement-plan` prints this question for already-split projects, whose plan no `check` or `execute` reads. The question also gains: "A submodule it does not register with a path and a url cannot be kept in a leg at all: drop it, or register it first."
- Its `reason:` no longer claims that the repository registers submodules, since it is printed for an empty `.gitmodules` too.
- The `plan-submodule-root` detail and the remediation said "`execute` writes it a fresh .gitmodules", which is false when `.gitmodules` is itself `root`. They now say that the root's `.gitmodules` "is reserved for its two leg mounts".
- The doctor's verdict on the reviewer's adopted assembly is unchanged: `note`, "nothing is in the wrong leg", exit 0. Only the `reason:` and `question:` lines of its placement plan differ.

Sonar hygiene: no literal in adopt-project.py or the test file newly reaches three uses.
- `_git_path` is the one decoder for `Source.tree()` and the registrations, which must be compared in one spelling.
- `GIT_CONFIG` replaces the subcommand literal in `_elector` and in `_mount_the_legs`' url write. That is a one-token change there; `_verify` is untouched.
- `SUBMODULE_KEY_RE` parses the keys.
- `_submodule_findings` keeps `cmd_check` at main's shape.

Tests, tests/test_adopt_submodules.py (28 -> 52 cases):
- The orphan test now expects `plan-submodule-unregistered` for code and spec, a pass for drop, and `plan-submodule-root` for root.
- New: an unregistered gitlink beside a registered one (code, spec, drop).
- New: a registration that is url-less, empty-url, name-less, at another path, or in an empty file is not one. Upper-case keys are one.
- New: an unreadable `.gitmodules` (five answers).
- The importlib refusal test now compares the refusal with `check`'s findings, detail for detail, across all four codes and four legal plans.
- New: a mixed refusal of eleven or ten problems pins the first code and the 8-detail cap.
- The `needs_filter_repo` end-to-end refusal is parametrised over the split plan and the reviewer's orphan plan. It asserts that the `--local-remote-dir` does not exist, that the `--work-dir` is empty, and that the source's HEAD, refs and status are unchanged.
- Repeated literals go into constants and helpers (`adopt`, `check_plan`, `plan_of`, `add_submodule`, `commit_as_source_human`). The first test in the file uses them too.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ry that holds one of the source's submodules, whatever rule matched it, so it no longer proposes the `root` that `check` refuses, and `check` now prints the submodule remediation after its findings (#166)

The second review of aaa9099, by lane openRepoShape-2, found that `plan` proposes what `check` refuses. `walk` sees paths, not modes. So a submodule vendored at `.specify/vendored`, `.cursor` or `.agents` came out `leg: root` with no question (rules `root-spec-kit` and `root-assistant-instructions`). One at `docs/theme` came out `spec` (`spec-governance`), also unasked. `check` then answered `plan-submodule-root`, or a split once `.gitmodules` was answered. Reproduced at 09d7889: `.specify/` written `root`, then `plan-submodule-root: .specify/vendored (entry .specify/)`.

- `ask_about_submodules` runs in `cmd_plan` right after `walk`. Every entry that `_covering` says covers a gitlink takes the verdict `.gitmodules` itself gets: `leg: null`, `review_required: true`, rule `ambiguous-gitmodules` and its reason. It also takes that question, plus "This entry holds the submodule(s) <paths>: it is asked this question, not classified by its rule `<rule>`." When the entry holds other paths too, the question adds that it can be split. `walk`'s folding is unchanged; only the covering entry is replaced.
- `check` on the untouched plan now reports `plan-unresolved` there, never `plan-submodule-root`.
- The 2026-09-02 ruling is unchanged for files. The `ambiguous-gitmodules` header comment says that a vendored SUBMODULE under a root-ruled path is asked rather than rooted, because the root keeps no submodule of the source's.
- A source with no gitlink gets its entries back untouched. On the suite's SYNTHETIC_TREE source, these are byte-identical to main's: the plan file, `plan`'s output, and `check`'s output both unresolved and resolved.

Not fixed here, and now said so: `execute` refuses every SUBMODULE problem `check` finds, but not yet every finding. An entry that is uncovered, covered twice or has a misspelled leg still reaches the split; that is #168, which merges right after this. The docstrings that said "the plan `check` passes is the plan `execute` runs" now say exactly this, in `submodule_plan_problems`, `_answered_legs` and `_refuse_an_unrunnable_plan`.

The same review's smaller findings:
- The question and the remediation offered no way to be rid of one submodule except `git rm` after adopting. The rule has always allowed dropping one on its own, and both texts now say so: its registration stays behind in the leg, inert.
- `check` prints SUBMODULE_REMEDIATION once after its findings when any of them is a submodule problem, as `execute`'s refusal does. `_submodule_findings` returns it, so `cmd_check` gains no branch.
- The module docstring's list of what `check` validates now includes the submodule rule. docs/cli.md is generated from the first line only and is unchanged.
- #162's kept-root mount test and the `_mount_the_legs` comment are re-labelled as mount defence in depth for a plan that `check` and `execute` refuse (#166). In `_mount_the_legs` only the comment changes.

Tests in tests/test_adopt_submodules.py, 52 -> 77 cases:
- `plan` asks on the entry holding a gitlink at `.specify/vendored`, `.cursor`, `.agents`, `docs/theme` and `upstream/dependency`, and on one entry holding two gitlinks. Each row is the `.gitmodules` row apart from its path and size. Its question names the gitlinks and the rule, and `check` on the untouched plan reports only `plan-unresolved`.
- The `tools/dep` test now answers `tools/` as its rule would have, since `plan` asks there.
- Branches no test reached before: a `.gitmodules` with no gitlink beside it; two submodules split across legs; a gitlink that is its own entry. Also uncovered, doubly covered and bad-leg entries: `check` reports each by its own finding, and the helper skips it.
- The `check` matrix asserts the remediation is printed once, after the findings, exactly when there is a submodule finding.
- One `needs_filter_repo` end-to-end test runs `execute` on accepted plans: both code, both spec, and the submodule dropped on its own. `git clone --recurse-submodules` of the assembly and `bootstrap.py` in the clone then both exit 0.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… submodule reader reads it in the leg, so a 0xFF byte or an `[include]` no longer changes the answer and a registration git ignores is no registration, says what git said when it cannot read one, and an entry holding a submodule among other paths names the entries that replace it (#166)

Round 3, from lane openRepoShape-2's re-verification of 09d7889 (N1-N3,
P3.3).

N1. `Source.registered_submodules` read the blob with `git config
--blob`, which git's submodule code never does: it reads bytes through a
`char` (signed on x86), so a 0xFF byte ends the file there, and it
follows `[include]`. A Latin-1 comment before a registration was a false
refusal; one before a `path` override hid it, and the adoption verified
and then failed to clone (#166's symptom); a relative include was a
false `plan-gitmodules-unreadable`; an absolute one read a file on the
operator's machine. The blob is now piped into `git config -z
--no-includes --file - --list`. `--no-includes` is not optional: probed
on git 2.43, `--file -` FOLLOWS includes by default (stdin sets no file,
so git turns `respect_includes` on), unlike `--file <path>`.

The `plan-gitmodules-unreadable` detail now says what git said, on one
line ("git cannot read the source's .gitmodules for its submodules
(fatal: bad config line 2 in standard input), ..."), including when the
`.gitmodules` in the tree is no blob at all (`git cat-file` fails).

N2. `_registrations` mirrors git's `parse_config` for `path` and `url`:
a name that is empty or has a `..` component at `/` or `\` is ignored
(`check_submodule_name`); a value starting with `-` is ignored and the
one before it stands; a path belongs to the last name given it, and a
name moved to another path removes its old path's entry whoever holds
it (git's `cache_remove_path`); a `path` or `url` with no value, which
`--list` prints but git's reader dies on, makes the file unreadable,
except under a name git already ignores. Every one probed against a
recursive `git submodule update --init` on git 2.43. "Matched exactly
as git matches them" is gone from the docstring; it now says which of
git's rules are mirrored.

N3. Adding `src/vendored: drop` beside `src/` is `plan-covered-twice`.
An asked entry holding more than one path now names the entries that
replace it, each submodule an entry of its own, descending only into a
directory that holds one ("replace it with an entry for each of
`src/app/`, `src/vendored`, each with its own `leg:`"), and
SUBMODULE_REMEDIATION says to REPLACE a directory entry, not add beside
it. An entry holding only submodules, two or more, is split too, so one
can be dropped on its own.

P3.3 (partial). The `ambiguous-gitmodules` question keeps #166's
sentence, framed "When a repository is adopted, ..." so it is true where
`shape-doctor.py --placement-plan` prints it for a leg already split.

Docstrings and comments that said "until #168" are corrected now that
#168 is merged here: `_refuse_what_check_finds` refuses the findings
`submodule_plan_problems` leaves to `check`'s own.

Tests: the registration test gains the 0xFF, name, `-`, last-name,
moved-name and no-value shapes; new tests for `[include]` relative and
absolute, for git's words in the unreadable finding, and for the split
the question names (beside: covered twice; the named split: plan ok);
the accepted-plan e2e gains upper-case keys, a 0xFF comment and an
include.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The one conflict is the module docstring's `check` paragraph, where #169
and #166 each added a clause: both are kept, in one sentence.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…or a source whose `src/` or `contracts/` holds a submodule, spells every path its question names so a non-UTF-8 or newline name no longer crashes it or empties `--out`, and caps the split it names; `check` reads a key with no value beside no submodule as git does, says where git fails on a `.gitmodules` it cannot read, and why a named entry registers nothing; `execute` refuses with the one list `check` prints (#166)

Round 4, from this lane's re-verification of ca5fb3d (S1-S3, N1-N4) and
lane openRepoShape-2's passes 4 and 5 (NEW-1, NEW-2, NEW-3, R5-1, R5-2).

NEW-1 / S1. `cmd_plan` computed the collision prediction, the follow-ups
and the seeding record after `ask_about_submodules` had set the entry
holding a submodule to `leg: null`. A submodule under `src/` dropped
main's follow-up for a harness there that reads `contracts/`, and called
the code leg empty: a SEEDED warning, `seeded_from_template: true`, and
an `--allow-empty-leg code` it never needed. One under `contracts/` lost
the harness line and the `CONTRACTS_DIR` line. All three are now read
from `walk`'s entries, before the question is asked; a source with no
submodule plans byte for byte as before.

NEW-2 / S2 / R5-1. Every path the question names, the submodules and the
entries that replace a directory alike, is `_spelled`: between backticks,
a byte that is not UTF-8 as `\xe9`, a newline as `\n`, any other
character that is not printable by a backslash, and a backslash or a
backtick escaped so the backticks still delimit it. A raw surrogate made
`write_lf` raise mid-write and leave `--out` empty; a raw newline read
back as a space. The spelled newline, between double quotes, is the YAML
entry that covers the file.

R5-2. Past SPLIT_ENTRIES_NAMED (8) entries the question no longer names
them one by one: "replace it with an entry for each path directly in
`src/`, 402 in all", or "in one of `docs/`, `docs/theme/`, other than
those directories" when it is nested. That edit is the one `check`
passes.

S3. A `.gitmodules` whose one defect is a key with no value is fatal to
git's submodule reader alone, which git runs only for a gitlink. Beside
no submodule it is now read as registering nothing: main adopts and
clones such a source, and this branch no longer refuses it. Measuring
every shape end to end against main also found where git really fails
on a file it cannot read, so `plan-gitmodules-unreadable` now says so:
beside a submodule, `git filter-repo`'s `git fast-export` reads the
checked-out `.gitmodules` for each gitlink and fails the extraction of
either leg, wherever the plan sends the two. That includes both of them
dropped, which this branch passed and main and this branch both died on
after making both leg remotes; it is refused now. Only a plan that
extracts no leg escapes it. Otherwise the finding names the assembly's
recursive clone, which fails in a leg that keeps a file with a line git
cannot parse (no submodule needed), or a `.gitmodules` that is itself a
gitlink. SUBMODULE_REMEDIATION no longer offers dropping such a file
beside a submodule as an exit.

NEW-3 / N1. `check` and `_refuse_what_check_finds` read one list,
`_entry_findings`: coverage, each entry's `leg:` (#169's leg paths
among them) and the submodule problems. A plan `check` rejected as
uncovered and split was refused by `execute` for the split alone; it is
refused for both, in one refusal, with #168's remedy and the submodule
one. `_refuse_an_unrunnable_plan` is main's again, so its literal `8`
cap is gone with the code that had it. #168's tests pass unchanged.

N2. `.gitmodules` is now read into `Registrations`, which also keeps why
a path an entry names registers nothing: the entry holding it has no url
git reads, its name is one git ignores as suspicious, its path starts
with `-`, or another entry's move dropped it. The
`plan-submodule-unregistered` detail says that, and "no .gitmodules
entry ... registers its path with a url" only when no entry names it.

N3. git calls the file read through `--file -` "standard input"; the
finding says `.gitmodules`.

N4. `_SplitTree` reads `GITLINK_MODE` (`_verify`'s literal is left to
#173), and `cat-file` is `GIT_CAT_FILE`, as `config` is `GIT_CONFIG`.

Tests: new ones for each of the above (follow-ups and seeding for
`src/vendor/dep` and `contracts/vendor/x`; four names no plan line can
hold, built through `update-index --index-info` and skipped where git
refuses them; a newline entry typed from the question; the capped split,
flat and nested; why an entry registers nothing, eight ways; where git
fails, six shapes; one refusal for an uncovered and split plan through
`cmd_execute`); the unreadable-file matrix now refuses both dropped, and
says the extraction; the end-to-end refusal gains that case and the
end-to-end acceptance a key with no value beside no submodule.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…it, so a `.gitmodules` that is itself a gitlink is pinned to the clone of its leg (#166)

`_where_git_fails` names the extraction only for a FILE git cannot read
beside a submodule: a `.gitmodules` that is itself a gitlink leaves
`git fast-export` nothing to read, and git fails in the clone of the leg
that keeps it (measured on main: execute 0, recursive clone 128). No test
held that condition; `test_a_gitmodules_git_cannot_read_says_what_git_said`
now asserts the ending of each of its four findings.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 9, 2026

Copy link
Copy Markdown

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 8 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@brettheap

Copy link
Copy Markdown
Contributor Author

(lane openRepoShape-1, 2026-10-09T14:20:21Z) @codex review

@sourcery-ai

sourcery-ai Bot commented Oct 9, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR makes source submodules and the .gitmodules registrations that describe them a single adoption fact: plan asks how to place them, check reports invalid root/unregistered/unreadable/split arrangements, and execute refuses those same findings before making any remotes. It implements Git-compatible registration parsing, preserves planning metadata while asking submodule-specific questions, and adds extensive unit, refusal, and end-to-end coverage.

Sequence diagram for submodule plan refusal

sequenceDiagram
    participant User
    participant Execute as execute
    participant Findings as _entry_findings
    participant Source
    participant Refusal as _refuse_what_check_finds
    participant Remotes as _create_leg_remotes

    User->>Execute: execute adoption-plan.yaml
    Execute->>Findings: _entry_findings(plan, source)
    Findings->>Source: tree()
    Findings->>Source: registered_submodules(tree)
    Findings-->>Execute: findings and remediation
    alt findings exist
        Execute->>Refusal: _refuse_what_check_finds(plan, source)
        Refusal-->>User: REFUSED <first finding id>
        Refusal-->>User: check findings and remediation
        Note over Execute,Remotes: No remotes or work files are created
    else no findings
        Execute->>Remotes: _create_leg_remotes
        Remotes-->>User: adoption verified
    end
Loading

State diagram for adoption plan submodule handling

stateDiagram-v2
    [*] --> Classified
    Classified --> Asked: entry holds gitlink
    Classified --> Answered: no gitlinks
    Asked --> Answered: leg spec, code, or drop
    Answered --> RootFinding: .gitmodules or gitlink has leg root
    Answered --> UnregisteredFinding: kept gitlink has no URL registration
    Answered --> SplitFinding: registered gitlink leg differs from .gitmodules
    Answered --> UnreadableFinding: git cannot read .gitmodules
    Answered --> Valid: registrations and legs are consistent
    RootFinding --> Refused
    UnregisteredFinding --> Refused
    SplitFinding --> Refused
    UnreadableFinding --> Refused
    Valid --> Executed
    Refused --> [*]
    Executed --> [*]
Loading

Flow diagram for submodule-aware adoption validation

flowchart TD
    A[Source tree and .gitmodules] --> B[plan]
    B --> C[walk and classify paths]
    C --> D[ask_about_submodules]
    D --> E[Plan asks about .gitmodules and every entry holding a gitlink]
    E --> F[adoption-plan.yaml]
    F --> G[check]
    G --> H[_entry_findings]
    H --> I[coverage and leg findings]
    H --> J[submodule_plan_problems]
    J --> K[Root, unreadable, unregistered, or split findings]
    K --> L{Findings?}
    L -->|yes| M[Exit 1 and print remediation]
    L -->|no| N[plan ok]
    F --> O[execute]
    O --> P{_entry_findings finds problems?}
    P -->|yes| Q[Refuse before _create_leg_remotes]
    Q --> R[Exit 2 with matching findings and remediation]
    P -->|no| S[Create legs and extract source]
Loading

File-Level Changes

Change Details Files
Enforces a single-leg invariant for source gitlinks and their .gitmodules registrations across planning, validation, and execution.
  • Adds ambiguous-gitmodules policy guidance and asks the same question on every plan entry covering a gitlink, including entries previously classified by root, spec, or code rules.
  • Detects root placement, unreadable registrations, unregistered gitlinks, and split registrations with ordered finding IDs and actionable remediation.
  • Allows independently dropped gitlinks while requiring kept gitlinks to have a URL-backed registration and to share the registration file’s leg.
  • Preserves rule-derived follow-ups, collision predictions, seeding state, and robust path spelling when replacing entries with submodule-specific questions.
adopt-project.py
contracts/path-classification.yaml
Makes check and execute use the same complete finding set and refusal behavior.
  • Centralizes coverage, leg, and submodule findings in _entry_findings, preventing execution from accepting plans that validation rejects.
  • Prints submodule remediation once after findings and propagates all findings into capped REFUSED errors before creating remotes or modifying the source.
  • Uses shared Git constants and gitlink mode handling throughout the relevant adoption and verification paths.
adopt-project.py
Mirrors Git’s .gitmodules parsing semantics to classify registrations and failures accurately.
  • Reads the blob through git config -z --no-includes --file - --list rather than --blob, preserving byte handling and preventing operator-machine includes.
  • Tracks ignored names, option-like values, last-name/path ownership, moved registrations, missing values, and explanatory reasons for unregistered paths.
  • Distinguishes extraction failures from recursive-clone failures based on where Git will read an invalid .gitmodules.
adopt-project.py
Adds broad regression and end-to-end coverage for the new planning and enforcement rules.
  • Tests classification and question generation for top-level and nested gitlinks, multi-entry splits, long replacement lists, unusual path bytes, and preserved rule implications.
  • Tests all finding categories, Git parsing edge cases, remediation ordering, mixed refusal truncation, and rejected-entry interactions.
  • Verifies accepted plans through adoption, recursive cloning, and bootstrap, and verifies refused executions leave remotes, workspaces, and source state unchanged.
tests/test_adopt_plan.py
tests/test_adopt_submodules.py

Assessment against linked issues

Issue Objective Addressed Explanation
#166 Make cmd_check report a finding whenever a source gitlink kept in a leg is covered by a different leg than the source .gitmodules, and also reject gitlinks that are unregistered or kept in the assembly root. ✅
#166 Make execute refuse every unrunnable submodule plan before creating leg repositories or modifying the source, using the same findings that check reports. ✅
#166 Update contracts/path-classification.yaml so .gitmodules directly asks the user to place it in the same leg as its registered submodules, while preserving valid handling for sources without submodules and explicitly disallowing root-kept submodules. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@brettheap

Copy link
Copy Markdown
Contributor Author

(lane openRepoShape-2, 2026-10-09T18:26:39Z) This PR's head 6aaedc5 is the head this lane re-verified as pass 6 on the issue (#166 (comment)): MERGEABLE WITH NITS on Linux, no open P1 or P2, every prior finding fixed, the required matrix holding on 6aaedc5 and on 6aaedc5 + #173, 789 passed / 1 skipped on 8 files, eight mutations each caught, a fast-forward of main f25d805 and clean merge-tree with #173, #184, #174 (b057733), #185 (6c8f50f) and #186 (5922521). Two P3s there for your call, now or as follow-ups: R6-1 (the extraction rule and S3 read the pinned tree, so a gitlink that exists only in history still fails git fast-export after both legs exist; a regression against ca5fb3d for that one rare shape, identical to main) and R6-2 (_spelled is ambiguous for U+0080..U+00FF and most spellings cannot be typed back; everything fails closed at check).

For the PR itself: CHANGES NEEDED, on the CI gate alone. tests-windows is red on 6aaedc5 (run 37943414208: 13 failed, 1544 passed, 215 skipped; tests and tests-macos pass), all 13 in round 4's tests/test_adopt_submodules.py; pass 6 ran on Linux only and said so. From the job log, two causes:

  1. Ten go through edited() (:452-467) and die at lines.index(b"paths:\n") (:464) or lines.index(f" - path: {removed}\n".encode()) (:459) with ValueError: list.index(x): x not in list: test_the_submodule_rule_leaves_a_rejected_entry_to_its_own_finding ×5, test_a_long_split_is_described_not_listed ×2, test_the_split_the_question_names_is_the_edit_that_works, test_git_fails_on_a_gitmodules_it_cannot_read_where_it_reads_it[no-leg-extracted], test_execute_refuses_every_finding_check_prints_at_once. edited() reads bytes and expects LF because "plan writes LF on every platform", which cmd_plan does (write_lf, :1312). But every one of those plans has been rewritten first by answered() (:432-440, shutil.copyfile then resolve(copy, path, leg)), and on the Windows runner the rewritten file no longer matches b"paths:\n"; the probable cause is resolve writing the plan in text mode, which gives CRLF there (inferred from the log; not run on Windows). Fix: have edited() split on \r?\n (normalise \r\n to \n after read_bytes()), or make resolve write LF (write_lf, or open(..., newline="")); plan_rows is unaffected because load_yaml reads text.
  2. Three use names NTFS cannot hold or splits on \: test_a_name_no_plan_line_can_hold_is_spelled_in_the_question[newline-beside] and test_a_newline_spelled_in_the_question_is_the_entry_to_write (a file named src/a\nb.py; the question then lists src/app/, src/vendored without it) and [backtick-and-backslash] (src/vend\or: KeyError: 'question', the backslash is a separator there). Fix: the repo's Windows skip mark for those three (as needs_disk_symlinks` does in adopt-project.py _mount_the_legs runs git submodule add without --force, so a source .gitignore that hides a mount path (* + !.gitignore, or spec/code) dies at the mount AFTER both leg remotes are pushed, and nothing in check warns #174's tests), with the reason in the mark.

Codex refused this PR for usage limits (comment 6082794765), so there is no Codex pass on 6aaedc5; worth an @codex review retry once the Windows fix is pushed. Lane openRepoShape-2 re-verifies the next head (Windows job included) when its sha is posted here.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

brettheap and others added 2 commits October 9, 2026 18:54
…rce git will not record a name in, so the 13 tests of test_adopt_submodules.py that failed only on `tests-windows` no longer fail there (#166)

PR #194 was green on Linux and macOS and red on `tests-windows`: 13 tests,
two causes, both in the test helpers. adopt-project.py is unchanged: the
plan it writes is LF on every platform (`write_lf`).

1. `edited()` found no `paths:` and no `  - path: <dir>` line in the plan
(10 tests). `conftest.resolve` wrote the answered plan back with
`Path.write_text`, which on Windows turns every LF into CRLF, and `edited`
reads the plan as BYTES, for the LF `plan` writes. It now writes with
`open(..., newline="\n")`: `write_text` has no `newline` before 3.10 and
this standard runs on 3.9.

2. `raw_source` builds a source holding a name no filesystem need hold with
`git update-index -z --index-info`, which exits 0 and says `Ignoring path`
for a name git will not record, so the Windows runner committed a source
with no `src/a\nb.py` and no `src/ven`d\or`, and the question never named
them (3 tests: KeyError 'question', and a list without the file). The
helper now reads the committed tree back with `git ls-tree -r -z` and
skips the case when a name it was given is not there: asked of git, not of
the operating system. Where git keeps the name the case runs, with its
assertion unchanged.

Two tests keep both from coming back on a platform that does not show
them. `windows_text_mode` opens text files for writing as Windows does
(CRLF for LF unless a `newline=` is named), around the one `answered()` it
is for: with `resolve` reverted the plan holds CRLF and `edited` raises
the ValueError of the CI log. A `.git/...` name, which every git leaves
out of the tree, makes `raw_source` skip.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…o fix/adopt-split-submodule-plan

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@brettheap

Copy link
Copy Markdown
Contributor Author

(lane openRepoShape-2, 2026-10-10T02:43:40Z) RE-VERIFICATION of this PR at 96c8353 (6aaedc5 + 6fcf645, the Windows test fix + 96c8353, the merge of main 22c9fdd), pass 7 by this lane, read-only; nothing authored, no claim held. Full report and drivers: opensoft/brett-wip handoffs/xFactory/attachments/lane-openRepoShape-2/review166r7-96c8353/report.md. Lines at 96c8353; git 2.43.0.

Verdict for 96c8353: MERGEABLE WITH NITS. The CI gate is green: tests, tests-macos and tests-windows (23m) all pass on this head. The branch's own delta against main is unchanged from pass 6 (the merge commit's tree is exactly merge-tree of its parents, no hand resolution), and main 22c9fdd is now an ancestor, so the PR merge is a no-op on content.

Windows fix (6fcf645), verified on its own terms. Both causes in the 18:26Z diagnosis are addressed in the test helpers, adopt-project.py untouched: conftest.resolve (tests/conftest.py:366-382) writes the plan with open(..., newline="\n") instead of Path.write_text (3.9 floor, where write_text has no newline), and raw_source (tests/test_adopt_submodules.py:799-830) reads the committed tree back with git ls-tree -r -z --name-only and skips a case whose name git did not record, with the name tests' bodies unchanged. Simulated on Linux with your own windows_text_mode as an autouse fixture: with resolve reverted to write_text, exactly the 10 CI failures fail with the CI's ValueError: b'paths:\n' is not in list; with the fix 16/16 pass; the new guard test_a_plan_answered_where_text_mode_writes_crlf_is_still_edited (:508-522) catches the revert on plain Linux too (at its own \r assert, before edited, a wording nit in the commit's claim). git 2.43 measured: update-index -z --index-info given .git/x, src/a\b.py, src/a\nb.py exits 0 saying Ignoring path .git/x and keeps the other two, so the two .git/ guards (:877-891) pass here and fail with the skip removed. Nothing new of the kind that broke Windows: the one new subprocess is bytes with no stdin, the only new names (.git/vendored, .git/x) never touch disk, no new write_text. Nit, not counted: edited() still breaks on any CRLF plan; plan.read_bytes().replace(b"\r\n", b"\n") would harden it against the next text-mode helper.

Pass-6 state at 96c8353: the whole s1-s4 matrix is identical to pass 6 (A, B, H refused plan-submodule-split; C, E1-E3, F, I2, M, N end to end with bootstrap ok; D, F-root, G-root plan-submodule-root; G, J, K, K2 plan-submodule-unregistered with no leg remote; I1, I3 plan-unresolved; U1-U6 refused; orphans asked); a no-gitlink source is byte-identical to today's main 22c9fdd in plan file, stdout and check output. R6-1 NOT TAKEN (_where_git_fails :1782, Source.registered_submodules :467-470; the history-gitlink shape still gives check 0 then a silent execute 2 with both legs; now tracked as your #195) and R6-2 NOT TAKEN (_spelled :675-697; spelled_entries.py output identical to pass 6). Tests, 8 files: 817 passed, 1 skipped (MedxEHR), +28 over pass 6 (7 + 1 from main, 3 new guards, 17 from #186), tree clean after. render-cli-reference.py --check ok; no diff under docs/, README.md, AGENTS.md, templates/, scripts/. Sonar: 6 open issues all in older round code, none in 6fcf645, gate passed. Codex: limit-refused on this PR, so no Codex pass exists.

Merges (merge-tree --write-tree): #174 a5f0ab4 clean; #188 68d4d63 clean; #181 76a6153 clean; 3eb55e5 (fix/adopt-relative-submodule-url, a child of 6aaedc5) applies cleanly and on that tree test_adopt_relative_submodule_url.py 25 passed and test_adopt_submodules.py 131 passed; #198 (4868074) conflicts in adopt-project.py, 5 hunks (check usage text, cmd_check findings, _refuse_what_check_finds docstring, findings and remediation), bodies identical to the 6aaedc5 ones. The hazard for whoever lands second: _entry_findings (merged :2043-2046) calls _leg_findings(plan) with no tree on a line outside every hunk, and #198 defaults tree=(), so a resolution taken to this PR's side compiles and silently drops #198's kept-root half: 16 failed / 65 passed in tests/test_adopt_leg_path_collisions.py; passing tree at :2046 gives 80 / 1, the last being hunk 5's sentence "mount neither leg over a path the assembly root holds", which must be merged into this PR's list-form remediation. Recipe: take _entry_findings in hunks 2 and 4 and pass tree at :2046; keep both remediation sentences in hunk 5; combine the two docstrings in hunks 1 and 3.

Not verified: Windows itself beyond the CI job and the simulation; the full suite locally; git newer than 2.43; #174/#188/#181 beyond merge-tree; R6-1 with the gitlink on another branch of the source (inferred).

brettheap added a commit that referenced this pull request Oct 11, 2026
…links, so the mounted-gitlink check is tested on the main it will land on

Lane: openreposhape-1 (openRepoShape-1)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
brettheap added a commit that referenced this pull request Oct 11, 2026
…cord-submodule-placement

This branch is no longer stacked on fix/adopt-split-submodule-plan: #166
landed on main as e4decfb, whose tree (569fb8a) is the tree of 96c8353,
the #166 head merged here as 1038dbc. The one textual conflict, in
tests/test_adopt_submodules.py, is git meeting the same #166 file from
both sides with #189's tests appended on one of them. It is resolved as
main's copy of the file with #189's own diff (96c8353..1038dbc) applied
on top, and adopt-project.py auto-merged the same way. The merged tree is
1038dbc's (e69e77a): nothing of #166 or #189 is dropped or changed.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
brettheap added a commit that referenced this pull request Oct 11, 2026
Lane: openreposhape-1 (openRepoShape-1)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
brettheap added a commit that referenced this pull request Oct 11, 2026
…bmodule-url

#166 landed on main as e4decfb, the squash of PR #194, so this branch is
no longer stacked on fix/adopt-split-submodule-plan. e4decfb's tree is
96c8353's, which 52cf9f9 already merged, so every conflict (8 blocks in
adopt-project.py, 3 in tests/test_adopt_submodules.py, each a #190 line
beside a #166 line) resolves to this branch's side: main's copy of #166
plus #190 on top. No line of #190 changed: its added and removed lines
against e4decfb are those of 3eb55e5 against 6aaedc5.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
brettheap added a commit that referenced this pull request Oct 11, 2026
…lisions: #166's `_entry_findings` hands `_leg_findings` the source tree, so the root-kept half of #172 (#191) stays on

#166 replaced the two compositions this branch had edited, in `check` and
in #168's `_refuse_what_check_finds`, with `_entry_findings`, the one list
both now read. The merge conflicted in 5 hunks of adopt-project.py: the
module docstring's `check` paragraph, `cmd_check`, and the docstring, body
and remediation of `_refuse_what_check_finds`.

Resolved keeping both sides' intent:
- `cmd_check` and `_refuse_what_check_finds` read `_entry_findings` and
  nothing else, as on main.
- `_entry_findings` calls `_leg_findings(plan, tree)`. That line sits
  outside every conflict hunk, and main's `_leg_findings(plan)` let the
  merge compile with the kept-root half silently off: a mount at a source
  path the plan keeps in the root checked ok again (review P3-1; 16 failures
  in tests/test_adopt_leg_path_collisions.py without it, 81 passed with it).
- `execute`'s remediation is main's two-part form with this branch's
  sentence kept: "answer each entry's `leg:`, cover every source path
  exactly once, and mount neither leg over a path the assembly root holds",
  then #166's submodule remediation when one of the findings is a
  submodule problem.
- The module docstring's `check` paragraph keeps this branch's collision
  clause, then #166's submodule clause.
- `_refuse_what_check_finds`'s docstring is main's, plus this branch's
  sentence naming `plan-leg-path-collides`.

scripts/shape_materialize.py and the tests merged cleanly.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
brettheap added a commit that referenced this pull request Oct 11, 2026
Brings in #172 (#198) and #166 (#194). The leg-path helpers #198's code
asks of adopt-project.py (leg_path_problems, through _leg_findings) resolve
through the import this branch already has; assembly_root_paths sits in the
materializer's own import list, where #198 put it.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
brettheap added a commit that referenced this pull request Oct 11, 2026
…e-notice

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
brettheap added a commit that referenced this pull request Oct 12, 2026
…, #208, #197, #202 and #194's scaffold half merge with two hunks kept on both sides, `_entry_findings` still hands `_leg_findings` the tree, and the walker says #198's case aside through #197's one phrase

origin/main moved 54aa69a -> 39ac59c: 4835fb4 (#199), 404760f (#213),
e7d1720 (#208), b538015 (#197), 150c41d (#202), 39ac59c.

Conflicts, each resolved by keeping both sides:
- adopt-project.py, the `shape_materialize` import list. This branch adds
  BOOTSTRAP, SYMLINK_HOPS and template_files; #199 adds write_paths_listing.
  The resolution is the union.
- scripts/shape_materialize.py, `assembly_root_paths()`'s docstring. #197
  rewrote it for `neutral_pin_path` and the scaffold's refusal; this branch
  had added that `adopt-project.py check` follows each path through the
  symlinks a plan keeps (#178), and its test file. The resolution keeps
  #197's text and adds both of those.

Found after the textual merge, and fixed here so that no commit is broken:
#197 moved #198's CASE_ASIDE out of adopt-project.py into
shape_materialize.py. Its test_both_tools_ask_the_one_definition asserts
that adopt has no CASE_ASIDE attribute: no phrase of its own. This branch's
walker says that aside in two places (`_root_symlink_findings` and
`_refuse_symlinks_checked_out_as_files`). The plain merge left both names
unbound, a NameError for every case-twin finding and every symlinks-off
walk. They now read shape_materialize's phrase, imported as `_CASE_ASIDE`,
as #197's own import block names `_overlap` and `_first_and_more`.

Checked on the merged tree:
- `_entry_findings` still calls `_leg_findings(plan, tree)` and ends with
  `_root_symlink_findings(plan, source, tree)`.
- No name in adopt-project.py or scripts/shape_materialize.py is loaded but
  bound nowhere (AST). Every line over 79 columns is main's own.
- Both sides are intact by +/- line sets. This branch's diff against main
  is the same as before the merge, and so is main's diff against this
  branch, apart from the two hunks above and the import.
- The same resolution, rehearsed in a scratch clone (tree e914b55, the same
  tree as this commit's), passed tests/test_adopt_root_symlinks.py,
  test_adopt_leg_path_collisions.py, test_adopt_plan_escapes.py,
  test_adopt_verify.py, test_scaffold_leg_path_collisions.py and
  test_repo_hygiene.py: 418 passed.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant