Skip to content

shape-doctor.py's behind_pin_only reason text, update-shape.py's _rewrite_readme phase order, and its untested UnicodeDecodeError arm carry three Copilot findings that PR #152's round cap left untaken #158

Closed

Description

@brettheap

Lane: openreposhape-2 (openRepoShape-2)

PR #152 ("update-shape.py apply now moves the README's trailing Shape: <repo> @ <sha>. line in the same commit as the pin it names, so a holder's README stops drifting from contracts/shape-pin.yaml", merged as b83ba5c) went through seven Copilot rounds. The eighth round, on head 7f25e14, surfaced three more findings, but the lane's brief caps a PR at three review rounds on one head before it must report back rather than keep chaining. All four checks were green and every earlier thread was answered at 7f25e14, so on Brett Heap's word "land 152 when it reports, then re-pin" the PR landed with these three recorded here rather than held open for a further round. None of the three was taken; this issue is the record of them and the place to take them.

What is wrong

  1. shape-doctor.py:1030-1033 — the behind_pin_only finding's reason text is self-contradicting in the one case it exists for. When no copied file differs but the pin names an older commit, the row says "no copied file differs, but the pin names an older commit, so \apply` would move the pin alone; {summary} ({where}){note}". The trailing {note}(fromreadme_shape_note) is appended unconditionally, and when the README carries its own trailing Shape:line that note saysapplywill *also* rewrite the README — so the row claims in one clause thatapplymoves the pin "alone" and in the next that it moves the README too.update-shape.py checkhad exactly this defect and baa77d0 fixed it (making the "alone" clause conditional on whether the note fires); the doctor's copy of the same wording was missed and still reads the old way on main. It matters because the doctor'sNEXTguidance is what an operator reads before runningcheck/apply`, and a self-contradicting reason line undercuts the very feature A scaffolded README's trailing Shape: … @ <sha> line is never rewritten by update-shape.py, so it drifts silently from contracts/shape-pin.yaml — InkRouter's holder reads 6fe09a4 four re-pins after the fact #148/update-shape.py apply now moves the README's trailing Shape: <repo> @ <sha>. line in the same commit as the pin it names, so a holder's README stops drifting from contracts/shape-pin.yaml (#148) #152 added.

  2. update-shape.py:1884-1886 (cmd_apply) — _rewrite_readme (line 1886) runs after _write_copies (line 1884), and .gitattributes is one of the digest-pinned copies _write_copies writes. _rewrite_readme calls readme_is_committed() (update-shape.py:1123 inside ReadmeShapeLine.state, using the helper defined at update-shape.py:960), which asks git status/git hash-object questions that are answered against attributes read from the working tree. So an upstream change to .gitattributes — e.g. a text=auto rule changing — is already on disk by the time the README's commit-state question is asked, even though nothing about the README itself changed. A README that would have read uncommitted-clean under the old attributes can read uncommitted-dirty under the new ones (or vice versa) purely because of copy ordering, and apply then silently leaves that root's stale Shape: line alone or rewrites it, for a reason that has nothing to do with the README. The classification _rewrite_readme needs (root, repository, target) is known before the first byte is copied, so reading the README's state before _write_copies runs looks like the right fix in principle — but it moves a phase inside a command whose rollback (Rollback ledger) is ordered around "copies, then pin, then README", and no existing fixture exercises an upstream .gitattributes change landing in the same apply as a README rewrite, so the fix needs a new test built first rather than a blind reorder.

  3. update-shape.py:1102-1104 (ReadmeShapeLine.state) — the UnicodeDecodeError arm (self.text = self.path.read_bytes().decode("utf-8") at 1102, except UnicodeDecodeError: return README_UNREADABLE at 1103-1104) has no deterministic test. tests/test_update_shape.py::test_a_readme_the_os_will_not_read_is_a_reading_rather_than_a_traceback (around line 1465) covers the sibling except OSError arm right below it, using the denied() helper (tests/test_update_shape.py:1418-1432) to chmod the README unreadable — but that helper explicitly pytest.skip()s when the current user isn't stopped by the permission bits (root, or a filesystem mounted without them, or Windows), so that test is non-deterministic by design. A README written as invalid UTF-8 bytes needs no privilege and skips nowhere on any platform, so it is a cheap way to get deterministic coverage of the README_UNREADABLE path that the OSError test cannot always provide.

What would fix it

  1. Make the behind_pin_only reason's "would move the pin alone" clause conditional on whether note is empty, the same shape as baa77d0's fix to update-shape.py check: when readme_shape_note returns a non-empty note (the README has its own trailing Shape: line that would also move), drop or rephrase the "alone" wording so the row does not claim two things at once; when note is empty, the existing wording still holds. A small, self-contained diff around shape-doctor.py:1030-1033, with a test asserting the row's text agrees with the note in both cases (mirroring whatever test protects update-shape.py check's baa77d0 fix).

  2. Build a fixture where an apply copies an upstream change to .gitattributes (e.g. a text=auto/eol= change) in the same run that would also rewrite a target root's README Shape: line, and use it to pin down current behavior before changing anything. Then move the README's commit-state read (the readme_is_committed() call inside ReadmeShapeLine.state) to before _write_copies runs in cmd_apply — snapshotting the classification (root, repository, target are all known up front) rather than reading it after the copies land — while keeping the actual README rewrite itself in its current place in the Rollback ledger ordering (after the pin move, before the validators), so rollback semantics are unchanged. Land the fixture and the reorder together so the ordering hazard has a regression test.

  3. Add a test that writes README.md as invalid UTF-8 bytes (a rendered Shape: line's bytes with one byte corrupted, or any non-UTF-8 byte sequence) and asserts the same three things the other left-alone READMEs are already asserted for: apply reports unreadable (or the doctor's equivalent wording) rather than raising, the file's bytes are untouched, and the file is absent from the commit. Place it beside test_a_readme_the_os_will_not_read_is_a_reading_rather_than_a_traceback in tests/test_update_shape.py, without a denied()-style skip since no privilege is needed to write invalid UTF-8.

Activity

  1. brettheap commented on Sep 13, 2026

    @brettheap
    ContributorAuthor

    (lane openreposhape-2 (openRepoShape-2), 2026-09-13T02:45Z) CLAIMED — session b92f33f0, on Brett Heap's word 'pick up 157 and 158, fan out'. Branch fix/readme-shape-line-followups, worktree ~/projects/openRepoShape--i158-readme-followups on Eagle, from origin/main b83ba5c. Scope: all three findings — the doctor's behind_pin_only reason wording, the README classification snapshot before _write_copies with the .gitattributes fixture that proves the ordering hazard, and a deterministic invalid-UTF-8 test for the README_UNREADABLE arm.

  2. brettheap commented on Sep 13, 2026

    @brettheap
    ContributorAuthor

    (lane openreposhape-2 (openRepoShape-2), 2026-09-13T03:2xZ) PULL REQUEST OPEN: #159 (head 3f4bade).

  3. brettheap commented on Sep 13, 2026

    @brettheap
    ContributorAuthor

    (lane openreposhape-2 (openRepoShape-2), 2026-09-13T04:0xZ) READY FOR REVIEW: #159, head 9eae223 (origin/main 511e9c2 merged in after #154 landed; never rebased). All four checks green on that head — tests (ubuntu) 3m19s, tests-macos 7m15s, tests-windows 15m32s, SonarCloud pass. PR-scoped Sonar quality gate OK on every condition, 0 new issues, 0 security hotspots, 0.0% duplication. Copilot round 1 on 3f4bade: "Approval recommended", 0 comments, 0 inline threads — nothing to reply to and nothing declined; Codex: "Didn't find any major issues" on 3f4bade; Sourcery: over its 7-day budget, but its guide marks all three of this issue's objectives addressed. Suite from the worktree: 1189 passed / 1 skipped (1185/1 on main plus the three tests added here). No digest-pinned file is touched, so no estate re-pin is owed by this PR. One deliberate departure from finding 1's "what would fix it", argued in the PR body and the commit: the "alone" clause is settled against the TARGET (the question update-shape.py check asks, and the one baa77d0 answered there) rather than against whether the note is empty — the note weighs the line against the PIN, so the commonest holder re-pin of all (a README naming its own pin, both behind) draws no note and is rewritten anyway, and a note-conditional fix would have left the false promise standing in exactly that case. Not merged: the orchestrator lands it.

  4. brettheap commented on Sep 13, 2026

    @brettheap
    ContributorAuthor

    (lane openreposhape-2 (openRepoShape-2), 2026-09-13T03:50:42Z) MERGED — #159 → ba14e1d (squash), on Brett Heap's word 'land 157 and 158 when they report, then re-pin'. the three findings PR #152's round cap left untaken (#158): the doctor's behind_pin_only row derives its 'would move the pin alone / and the README' clause from what a re-pin would actually move against the TARGET, so the row and the README note can no longer contradict; apply classifies the README BEFORE _write_copies lands a pinned .gitattributes change, so an upstream attributes change can no longer decide a README's fate mid-run (fixture first, rollback order unchanged); a deterministic not-valid-UTF-8 README test no platform can skip; Copilot approved, Codex clean; 1189 passed / 1 skipped; no pinned file. Object complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions