Repository navigation
recorded_gitlink() reads the index before HEAD, so a staged leg bump validates - #25
Conversation
…validates THE VALIDATOR ANSWERED ABOUT THE COMMIT BEING REPLACED. `recorded_gitlink()` read `git ls-tree HEAD` first and fell back to the index only when HEAD recorded no gitlink at that path — so at the one moment the answer matters, it was the wrong one. An operator bumps a leg (`git add legs/<Leg>` moves the gitlink in the INDEX), edits `contracts/<role>-pin.yaml` to match, and runs `make validate` before committing, which is the whole point of running it. HEAD still records the old gitlink, so `validate-pins.py` reported a FALSE `pin-gitlink-mismatch` on a correct bump; `validate-family.py` did the same with `member-gitlink-mismatch`. The only way to clear the finding was to commit the thing the validator had just called wrong. It failed in the other direction too, and that half is worse: with the gitlink staged at a new commit and the pin left behind, reading HEAD compared the pin against the commit it agrees with and printed `pins ok`. A green check over drift, one commit before the drift lands. The docstring already said the index fallback exists for "precisely the moment the lockstep rule is about to be broken" — the order was simply inverted against its own stated reason. Index first, HEAD second. In a clean tree the two agree and the order is invisible; in CI, which checks out a commit, nothing changes at all. It decides the answer only when they disagree, and then the index is what the next commit will record. HEAD stays as the fallback, for a path the commit records and the index does not. THE FALLBACK COULD NEVER HAVE WORKED ANYWAY. Both listings were parsed at column 2, but they do not agree on that column: `ls-tree` emits `<mode> SP <type> SP <oid> TAB <path>` and `ls-files -s` emits `<mode> SP <oid> SP <stage> TAB <path>`. Reading the index therefore returned the STAGE — the literal string `0` — rather than a commit. That never surfaced because HEAD answered first in every tree anyone ran this in. The oid column now travels beside each argv in `GITLINK_LISTINGS` rather than being assumed to be the same for both. Three tests, each failing before this change: a staged-but-uncommitted spec leg bump whose pin moved with it now PASSES (it reported `pin-gitlink-mismatch`); the same bump with the pin left behind is still a finding (it printed `pins ok`); and the family's half of the same reading, a staged member bump with the `members[].pin.commit` row moved to match. Each uses an EMPTY commit for the leg, so the tree is unchanged, the pinned `tree_sha256` still recomputes, and the gitlink is the only fact that moved. 352 pass, from 349. A project picks this up the way it picks up any change to a copied shape file: `python3 update-shape.py`, which re-copies `scripts/repo_shape.py` and re-pins `contracts/shape-pin.yaml`. Lane: repo-shape Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_015WekBEXf55Xv64psGe5t3T
Reviewer's GuideUpdates gitlink resolution to use the index first, ensuring validators evaluate the commit a staged change would create rather than the superseded HEAD commit, fixes command-specific OID parsing, and adds regression tests for both passing and failing staged bumps. Sequence diagram for staged gitlink validationsequenceDiagram
participant Operator
participant Validator
participant recorded_gitlink
participant Index
participant HEAD
Operator->>Validator: validate-pins.py or validate-family.py
Validator->>recorded_gitlink: recorded_gitlink(repo, path)
recorded_gitlink->>Index: git ls-files -s -- path
Index-->>recorded_gitlink: staged gitlink OID
recorded_gitlink-->>Validator: index OID
Validator->>Validator: compare pin commit with index OID
Validator-->>Operator: pass or mismatch finding
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
🟡 Changes recommended
recorded_gitlink() can mis-read git ls-files -s entries in an unmerged index (stages 1/2/3), and the new family test uses an unconstrained replace that could rewrite multiple rows and become flaky.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes gitlink/pin validation to compare pins against the staged index state (what the next commit will record) before falling back to HEAD, aligning behavior with how operators actually run make validate during a leg/member bump and correcting an index-parsing defect.
Changes:
- Update
recorded_gitlink()to read the index beforeHEADand correctly extract the oid column from bothls-files -sandls-tree. - Add tests covering staged-but-uncommitted leg bumps (both matching-pin and stale-pin cases).
- Add a test covering staged-but-uncommitted family member bumps where the manifest row moves with the staged gitlink.
File summaries
| File | Description |
|---|---|
| scripts/repo_shape.py | Make gitlink reading index-first (with corrected oid parsing) so validators reflect staged bumps. |
| tests/test_pin_validator.py | Add coverage for staged leg bump validation (pass when pin matches staged gitlink; fail when it doesn’t). |
| tests/test_family.py | Add coverage for staged family member bump validation when the manifest pin moves with the staged gitlink. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| for line in out.splitlines(): | ||
| fields = line.replace("\t", " ").split() | ||
| if len(fields) >= 3 and fields[0] == "160000": | ||
| return fields[2].lower() | ||
| if len(fields) > oid_at and fields[0] == "160000": | ||
| return fields[oid_at].lower() |
| manifest_path = holder / "family.yaml" | ||
| manifest_path.write_text(manifest_path.read_text().replace(before, after)) |
Copilot's review of #25, both points taken. A CONFLICTED MERGE HOLDS THE SAME PATH THREE TIMES. `git ls-files -s` emits stages 1, 2 and 3 — base, ours and theirs — and no stage 0, and it lists them in that order, so reading the first `160000` row answered with the MERGE BASE. None of the three is a commit anybody is about to make, so an unmerged path now falls through to HEAD, which is what the fallback is for. `stage_at` travels beside the oid column in `GITLINK_LISTINGS`; `ls-tree` has no stage column and carries `None`. `test_an_unmerged_index_falls_back_to_head` writes the three stages straight into a scaffolded project's index with `update-index --index-info` — what a conflicted `git merge` leaves behind, without needing two branches that disagree about a submodule — and asserts the validator still passes. Without the stage filter it reports `pin-gitlink-mismatch` against the base commit. The family test's manifest edit is also pinned to ONE occurrence and asserts the pin it is moving is unique, so a fixture where two members happened to share a commit could not rewrite both rows. 353 pass, from 352. Lane: repo-shape Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_015WekBEXf55Xv64psGe5t3T
|
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, aligns behavior with the documented intent, and is backed by targeted regression tests that fail on main and pass with this patch.
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
…dex-first) into fix/reference-by-election-date One conflict, in adopt-project.py _template_values: main derives project_id via plan.project_id (#24); this branch reads elected_on once beside it. Both kept. Lane: codex-intake-shape Co-Authored-By: Claude Fable 5.1 <[email protected]>



Lane: repo-shape
Claim: #20 (comment)
Closes #20.
What was wrong
scripts/repo_shape.py::recorded_gitlink()readgit ls-tree HEAD -- <path>FIRST and fell back to the index (
git ls-files -s) only when HEAD recordedno gitlink there. Its own docstring said the index fallback exists for
"precisely the moment the lockstep rule is about to be broken" — the order was
inverted against its stated reason.
The moment it bites
An operator bumps a leg —
git add legs/<Leg>moves the gitlink in the INDEX— edits
contracts/<role>-pin.yamlto match, and runsmake validatebeforecommitting, which is the whole point of running it. HEAD still records the old
gitlink, so
templates/assembly-root/scripts/validate-pins.pyreported a FALSEpin-gitlink-mismatchon a correct bump, andtemplates/family-root/scripts/validate-family.pyreportedmember-gitlink-mismatchthe same way. The only way to clear the finding wasto commit the thing the validator had just called wrong.
It failed in the other direction too, and that half is worse: with the gitlink
staged at a new commit and the pin left behind, reading HEAD compared the pin
against the commit it agrees with and printed
pins ok— a green check overdrift, one commit before the drift lands.
What changed
Index first, HEAD second. In a clean tree the two agree and the order is
invisible; in CI, which validates a checkout of a commit, behaviour is
unchanged. The order decides the answer only when the two disagree, and then
the index is what the next commit will record. HEAD stays as the fallback, for
a path the commit records and the index does not. The docstring now says index
first, HEAD second, and why.
A second defect, found on the way: the fallback could never have worked
anyway. Both listings were parsed at column 2, but they do not agree on that
column —
ls-treeemits<mode> SP <type> SP <oid> TAB <path>whilels-files -semits<mode> SP <oid> SP <stage> TAB <path>. Reading the indextherefore returned the STAGE, the literal string
0, rather than a commit.It never surfaced because HEAD answered first in every tree anyone ran this
in. The oid column now travels beside each argv in
GITLINK_LISTINGSratherthan being assumed the same for both.
No copy of
repo_shape.pylives undertemplates/:scripts/shape_materialize.pycopies
scripts/repo_shape.pyout of this repository's own tree into ascaffolded assembly root (
COPIED_FROM_SHAPE) and family root(
FAMILY_COPIED_FROM_SHAPE), so there is one source file and nothing to keepin lockstep here.
What the tests prove
Three tests, each of which FAILS on
mainand passes here:test_a_staged_bump_with_the_pin_moved_to_match_passes— astaged-but-uncommitted spec leg bump whose pin moved with it now validates
(before:
pin-gitlink-mismatch, exit 1).test_a_staged_bump_the_pin_did_not_follow_is_still_a_finding— the samestaged bump with the pin left behind is still a finding, so the index
winning is not "whichever answer passes" (before:
pins ok, exit 0).test_validate_accepts_a_member_bump_that_is_staged_but_not_committed— thefamily's half of the same reading, a staged member bump with the
members[].pin.commitrow moved to match.Each uses an EMPTY commit for the leg, so the tree is unchanged, the pinned
tree_sha256still recomputes, and the gitlink is the only fact that moved.Full suite, run as CI runs it (
python3 -m pytest tests -q): 349 passedbefore, 353 passed after, no existing test changed.
Follow-up commit: stage 0 or nothing
Taken from Copilot's review. A conflicted merge leaves the index holding the
same path at stages 1, 2 and 3 — base, ours and theirs — and no stage 0, and
ls-files -slists them in that order, so reading the first160000rowwould have answered with the MERGE BASE. None of the three is a commit
anybody is about to make, so an unmerged path now falls through to HEAD,
which is what the fallback is for.
test_an_unmerged_index_falls_back_to_headwrites those stages straight into a scaffolded project's index with
update-index --index-infoand asserts the validator still passes; withoutthe stage filter it reports
pin-gitlink-mismatchagainst the base commit.The family test's manifest edit is also pinned to one occurrence.
How a project picks this up
The same way it picks up any change to a copied shape file:
python3 update-shape.py, which re-copiesscripts/repo_shape.pyand re-pinscontracts/shape-pin.yaml.🤖 Generated with Claude Code
https://claude.ai/code/session_015WekBEXf55Xv64psGe5t3T