Skip to content

update-shape.py: check reports upstream-added; apply --add <path> takes a file the standard gained since the pin - #29

Merged
brettheap merged 1 commit into
mainfrom
feat/update-shape-add
Sep 4, 2026
Merged

brettheap merged 1 commit into
mainfrom
feat/update-shape-add

Conversation

@brettheap

@brettheap brettheap commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Lane: codex-intake-shape
Claim: #28 (comment)

What

Part of #28 (PR B of two). update-shape.py re-synced only the pin's own rows, so a file the standard ADDS after a project was cut never reached that project. Now:

  • check reports upstream-added for a destination the upstream's copy lists name at the target commit and the pin has no row for and the root has no file at. The lists are read out of the target commit's own scripts/shape_materialize.py with ast (no exec, no import), mapped source→destination the way _materialize does, project vs family lists chosen by the manifest the tool already distinguishes. An older upstream whose materializer lacks the names yields no additions and no error. check still exits 1 when there is anything to do.
  • apply --add <path> (repeatable) copies the named file, sets the executable bit per the materializer's list, appends the sha256 row, moves commit/digests.tree_sha256, mirrors into the manifest, runs the project's own validators and rolls back whole — including unlinking created files — on red. Without --add, apply writes none of them, says not added; pass --add <path>, and re-pins the rest.
  • Refusals: --add of an already-pinned path, of a path the target's lists do not name, and of a path the root already has a file at (update-add-would-overwrite). Absolute or .. destinations from an upstream list are rejected before any write.
  • Two defects the new tests exposed are fixed: git commit -- <path> refuses an untracked pathspec (added paths are now staged by name first), and the printed NEXT hint now includes git add -- <added> &&.

Deliberate choices

  • A path the root already has a file at is NOT reported as upstream-added — that is the in-place-adoption state (Makefile, .gitignore merged away, pin rows under shape/), which the existing test test_a_file_with_no_pin_row_is_not_a_shape_file protects. The overwrite refusal is still reachable by naming the path.
  • No omit/ignore list. A project that declines an addition sees it on every check until a file arrives at that path. Stated in the README rather than solved here.
  • The README paragraph names AGENTS-shape.md as the motivating addition; that file arrives in PR A (feat/agents-shape-file), in flight.

Evidence

  • python3 -m pytest tests -q: 387 passed. New module tests/test_update_shape_add.py (fixture: scaffold at C1, upstream C2 adds a verbatim file; check/apply/--add/refusals/family/older-commit).
  • README cap 513 → 532 for the 19 lines added; AGENTS.md fits under its existing cap.
  • templates/, scripts/shape_materialize.py copy lists and adopt-project.py untouched.

🤖 Generated with Claude Code

Summary by Sourcery

Support detecting and selectively adopting files added by the standard after a project was pinned.

New Features:

  • Report files newly added by the upstream standard and support explicitly adopting selected additions with repeatable apply --add <path> options.

Bug Fixes:

  • Ensure newly added files are staged before committing and include them in the generated follow-up command.
  • Reject unsafe upstream destinations and roll back newly created files when validation fails.

Enhancements:

  • Read target-commit copy lists safely and distinguish project and family additions while preserving existing adoption behavior.

Documentation:

  • Document upstream-added reporting, explicit file adoption, refusal cases, and the behavior of projects that defer additions.

Tests:

  • Add coverage for upstream additions, target-commit list handling, project and family roots, adoption refusals, executable files, commits, and transactional rollback.

…>` takes a file the standard gained since the pin

A pin can only record what existed the day it was written, and `update-shape.py`
re-synced ONLY the pin's own rows — right for a file a project merged away,
and blind to a file the standard adds later. Issue #28 adds `AGENTS-shape.md`
to both root templates; without this, it would reach none of MedxEHR,
MedxGlass, MedxScribe or the InkRouter members except by hand.

`check` now also reports `upstream-added`: a destination the UPSTREAM's copy
lists name AT THE TARGET COMMIT — read out of that commit's own
`scripts/shape_materialize.py` with `ast`, never this checkout's lists and
never `exec` — that the pin has no row for and the root has no file at (a
file already there is the in-place-adoption state, not an addition; the
Makefile/.gitignore merged-away case stays quiet, as the existing test
demands). It counts as something to do, so `check` still exits 1.

`apply` writes none of them unless `--add <path>` names one, per file: copy,
chmod per the executable list, append the sha256 row, move the pin, all in the
same transaction and rolled back whole — including unlinking created files —
if a validator goes red. `--add` refuses a path already pinned, one the
target's lists do not name, and one the root already has a file at
(`update-add-would-overwrite`): two files with one name is a merge.
Destinations that are absolute or contain `..` are rejected before any write.

Two defects found by the new tests and fixed: `git commit -- <path>` refuses an
untracked pathspec, so added paths are staged by name first, and the printed
NEXT hint now says `git add -- <added> &&`. A project that DECLINES an
addition has no way to say so yet and will see it on every `check`; that is
left open on purpose and said in the README.

README 513 -> 532; AGENTS.md § Updating gains point 5.

Part of #28.

Lane: codex-intake-shape
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 4, 2026 13:29
@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 2 days and 2 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@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.

@sourcery-ai

sourcery-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR extends update-shape.py to discover files added by the standard after a project was pinned, report them safely from target-commit materializer data, and adopt them only through explicit per-file consent with full metadata updates, validation, rollback, and commit support. It adds comprehensive project/family integration coverage and documents the resulting workflow and deliberate adoption semantics.

Sequence diagram for detecting and explicitly adopting upstream-added files

sequenceDiagram
    participant User
    participant UpdateShape as update-shape.py
    participant Git as Upstream git
    participant Root as Project or family root
    participant Validators

    User->>UpdateShape: check --at <commit>
    UpdateShape->>Git: blob(<commit>, scripts/shape_materialize.py)
    UpdateShape->>UpdateShape: ast.parse materializer lists
    UpdateShape->>Git: blob(<commit>, source path)
    UpdateShape-->>User: report upstream-added, exit 1
    User->>UpdateShape: apply --at <commit> --add <path> --yes
    UpdateShape->>UpdateShape: resolve_additions
    UpdateShape->>Root: copy file and set executable bit
    UpdateShape->>Root: append sha256 row and update commit/tree_sha256
    UpdateShape->>Root: update manifest
    UpdateShape->>Validators: run project or family validators
    alt validation fails
        UpdateShape->>Root: rollback metadata and remove created files
    else validation succeeds
        UpdateShape-->>User: re-sync completed
    end
Loading

Flow diagram for upstream-added adoption decisions

flowchart TD
    A[Read target commit materializer with ast] --> B[Map target copy lists to destinations]
    B --> C{Pin has a row?}
    C -->|Yes| D[Handle as existing pinned copy]
    C -->|No| E{Root already has a file?}
    E -->|Yes| F[Silently treat as in-place adoption]
    E -->|No| G[Report upstream-added]
    G --> H{apply includes --add <path>?}
    H -->|No| I[Do not write; print pass --add <path>]
    H -->|Yes| J{Path is valid and named by target lists?}
    J -->|No| K[Refuse]
    J -->|Yes| L[Copy file, append pin row, update manifest]
    L --> M[Run validators and commit or roll back]
Loading

File-Level Changes

Change Details Files
Detect upstream files added after the project’s pin by parsing the target commit’s materializer definitions without executing upstream code.
  • Parse copy-list literals and constants with ast, including project/family-specific mappings and executable flags.
  • Classify unpinned, absent-root paths as upstream-added while ignoring adopted paths already present in the root.
  • Reject unsafe absolute or parent-traversing destinations and treat older materializers as having no additions.
update-shape.py
Add explicit, transactional consent for bringing newly upstream files into a project or family root.
  • Add repeatable apply --add <path> handling with refusals for pinned, unlisted, and overwrite cases.
  • Copy bytes with materializer-consistent modes, append digest rows, update commit/tree metadata and manifests.
  • Roll back modified metadata and newly created files when validation fails.
  • Keep unselected additions untouched while re-pinning existing rows and explain the required --add flag.
update-shape.py
Cover upstream-addition detection, adoption behavior, family scoping, validation rollback, and branch commits with integration tests.
  • Build a two-commit upstream fixture and verify target-commit list reading, project/family separation, executable modes, and pin updates.
  • Test all add refusals, no---add behavior, rollback cleanup, and staging of newly created files.
  • Verify check exit status, report states, validator results, and actionable NEXT hints.
tests/test_update_shape_add.py
Document the new upstream-addition workflow and adjust repository hygiene limits for the expanded guidance.
  • Explain upstream-added, per-file consent, refusal semantics, and the lack of an omit mechanism.
  • Update operator guidance to distinguish re-syncing pinned rows from adopting later additions.
  • Raise the README line-count assertion to match the added documentation.
README.md
AGENTS.md
tests/test_repo_hygiene.py

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

@sonarqubecloud

sonarqubecloud Bot commented Sep 4, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There are a few concrete safety/robustness gaps in the new --add/filesystem-write paths (argument validation consistency and rollback coverage on OSError) that should be addressed before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds first-class support in update-shape.py for detecting files that were added upstream after a project/family was pinned, and for selectively adopting those files via an explicit apply --add <path> workflow.

Changes:

  • Extend check to report upstream-added entries derived from the target commit’s scripts/shape_materialize.py copy lists (parsed via ast).
  • Extend apply with repeatable --add <path> to copy newly-added files, set executable bits, append new pin rows, and include additions in commits/hints with rollback on validator failure.
  • Add a comprehensive new test module covering additions, refusals, family-vs-project list separation, and rollback behavior; update README/AGENTS docs and README line-cap.
File summaries
File Description
update-shape.py Implements upstream-added detection and apply --add adoption flow (AST list reading, refusals, transactional writes, commit/hint updates).
tests/test_update_shape_add.py New test coverage for upstream-added reporting, --add behavior, refusal cases, family handling, and rollback.
tests/test_repo_hygiene.py Updates README line-cap to reflect added documentation.
README.md Documents upstream-added reporting and explicit adoption via --add, including refusal cases and behavioral constraints.
AGENTS.md Updates the “Updating a project’s shape” procedure to include upstream-added / --add guidance.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread update-shape.py
Comment on lines 1135 to 1144
except Refusal:
for path, original in written.items():
path.write_bytes(original)
for path in reversed(created):
if path.is_dir():
if not any(path.iterdir()):
path.rmdir()
elif path.exists():
path.unlink()
raise
Comment thread update-shape.py
Comment on lines +552 to +563
def inside_a_root(rel: str) -> bool:
"""Is `rel` a path a root can actually hold?

An absolute path or one with a `..` segment would put a copy OUTSIDE the
root this command was pointed at. Nothing in openRepoShape's lists has ever
looked like that, and this is not a defence against the standard — it is
that these strings arrive from a file read out of a git history, and a
write that leaves the directory a human named is the one mistake that
cannot be rolled back by putting the tree as it was.
"""
parts = Path(rel).parts
return bool(parts) and not Path(rel).is_absolute() and ".." not in parts
Comment thread update-shape.py
Comment on lines +1014 to +1016
taking = resolve_additions(rows, additions,
[str(path) for path in (args.add or [])],
target)
brettheap added a commit that referenced this pull request Sep 5, 2026
…scribes (#51) (#58)

Git for Windows installs core.autocrlf=true by default; a colleague who did nothing but clone a scaffolded project got CRLF in the worktree and every pinned row went red for them alone. #53 covered the clone setup-project.py makes; this covers the next person. `* text=auto eol=lf` in both root templates, PINNED like every other copy (a file that says what the bytes are is worth nothing if it can be edited without the pin noticing); it joins COPIED_VERBATIM and FAMILY_COPIED_VERBATIM and nothing else in the materializer needed to change. Proof, as tests: a `git -c core.autocrlf=true clone` of a scaffolded project shows w/lf for every pinned file and its own validate-pins.py exits 0; the same clone with the file removed shows w/crlf and FINDING shape-copy-drift on every copy. Existing projects report `upstream-added: .gitattributes` on their next update-shape check and take it with `apply --add` (#29 machinery, tested). 583 tests.

Lane: xfactory-2 (xFactory-2)

Co-authored-by: Claude Fable 5.1 <[email protected]>
@brettheap
brettheap deleted the feat/update-shape-add branch September 11, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants