Skip to content

CI: fetch private legs with a GitHub App installation token; the PAT becomes the fallback - #13

Merged
brettheap merged 3 commits into
mainfrom
feat/legs-app-token
Sep 4, 2026
Merged

brettheap merged 3 commits into
mainfrom
feat/legs-app-token

Conversation

@brettheap

@brettheap brettheap commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Lane: repo-shape

Brett Heap ruled: "we should move this over to a github app."

What changed

The assembly-root validate workflow's leg-fetch step now tries a GitHub App installation token first and falls back to the existing SHAPE_LEGS_TOKEN PAT — never the other way, never both, resolution order is fixed:

  1. steps.app-token.outputs.token (minted by actions/create-github-app-token, run when both App secrets are present)
  2. SHAPE_LEGS_TOKEN (the fine-grained PAT, unchanged fallback)
  3. none — same unauthenticated git submodule update as before, for public legs

Which source won is exposed as step output legs_credential: app|pat|none and printed. Degrade semantics are unchanged in shape (root checkout never carries a token; naming/manifest always run; pins only when legs are available; hard failure only when a credential was configured and the fetch still failed) — just credential-source-aware now.

Two new secrets

  • SHAPE_LEGS_APP_ID — the GitHub App's ID
  • SHAPE_LEGS_APP_PRIVATE_KEY — the App's private key PEM

Both org secrets on the assembly root; presence is checked via job-level env: SHAPE_LEGS_APP_SET, never secrets in a step if: (that's what made GitHub reject the whole workflow file on the first real projects).

App permissions required

Contents: Read-only + Metadata: Read, installed on each consuming org with access to the leg repositories. A small step reads .gitmodules and scopes the mint's repositories: input to only the legs this repository's own owner also owns (an installation token is per-owner, so a foreign-owned leg is excluded with a warning and stays PAT-only). A configured App that fails to mint fails the job outright — continue-on-error: false plus a dedicated step naming both secrets and the required installation, since that's a misconfiguration, not a degrade.

Pinned: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2.2.2 (the current v2 release, pinned by commit sha per this repo's own rule).

Tests

251 passed in 45.59s

actionlint (v1.7.12, matching this repo's CI) plus shellcheck (0.10.0) on the template: clean.

New coverage: the mint step's pin/permissions/guard, both job-env booleans, the fetch step's App-before-PAT reference order, and the .gitmodules -> leg-name extraction — exercised by running the exact run: body pulled out of the rendered workflow against a crafted .gitmodules (HTTPS, SSH, and a foreign-owned leg), rather than a separate Python reimplementation that could drift from it.

Docs

README.md and templates/assembly-root/README.md: the SHAPE_LEGS_TOKEN paragraph becomes "Reading private legs in CI" (App preferred, PAT fallback, exact gh secret set commands for both). scaffold-project.py/adopt-project.py's one-line NOTE on a private/internal leg now names both options, App first. AGENTS.md does not mention the token — no change needed there.

🤖 Generated with Claude Code

https://claude.ai/code/session_015WekBEXf55Xv64psGe5t3T

Summary by Sourcery

Use short-lived GitHub App tokens as the preferred credential for fetching private CI legs while retaining PAT fallback and unauthenticated degradation.

New Features:

  • Use a GitHub App installation token to fetch private or internal leg repositories in CI, with the existing PAT retained as a fallback.

Bug Fixes:

  • Prevent leg-only credentials from being applied to the root checkout while preserving graceful degradation when no credential is configured.
  • Fail clearly when a configured GitHub App cannot mint a usable installation token or when a configured credential cannot fetch the legs.

Enhancements:

  • Resolve leg credentials deterministically as App, PAT, or none and expose the selected source in workflow output.
  • Scope App tokens to same-owner leg repositories and warn about foreign-owned legs that require the PAT fallback.

CI:

  • Update the validation workflow to mint and securely scope GitHub App installation tokens for submodule access.

Documentation:

  • Document GitHub App setup, required permissions, secret configuration, PAT fallback, and credential resolution behavior.

Tests:

  • Add coverage for App token pinning and configuration guards, credential precedence, and extraction of HTTPS and SSH leg repositories while excluding foreign-owned legs.

brettheap and others added 3 commits September 3, 2026 20:57
The leg-fetch step in the assembly-root validate workflow now tries an
App-minted token first (actions/create-github-app-token, pinned by
commit sha) and falls back to the existing SHAPE_LEGS_TOKEN PAT.

- new job-level env booleans SHAPE_LEGS_APP_SET / SHAPE_LEGS_TOKEN_SET
  (never secrets in an if:)
- a small step reads .gitmodules and emits the comma-separated leg
  names this repository's owner also owns (a foreign-owned leg is
  excluded with a warning: an installation token is per-owner)
- the mint step is guarded by SHAPE_LEGS_APP_SET, continue-on-error:
  false, and a dedicated failure step names both secrets and the
  required installation when a configured App cannot mint
- the leg-fetch step resolves App token -> PAT -> none, exposes which
  source won as step output legs_credential, and the existing degrade
  semantics (naming/manifest always, pins only when legs available,
  fail only when a configured credential still could not fetch) are
  unchanged in shape, just credential-source-aware

Lane: repo-shape
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_015WekBEXf55Xv64psGe5t3T
- mint step is pinned by 40-hex commit sha, scoped to permission-
  contents: read, guarded without secrets in any if:
- job env carries both SHAPE_LEGS_APP_SET and SHAPE_LEGS_TOKEN_SET
- the leg-fetch step references steps.app-token.outputs.token before
  SHAPE_LEGS_TOKEN, and exposes legs_credential: app|pat|none
- a misconfigured App fails loudly, naming both secrets and the
  required installation
- the .gitmodules -> leg-name extraction is exercised as the real
  shell it is: the exact run: body of the 'leg repository names from
  .gitmodules' step is pulled out of the rendered template and run,
  unmodified, against a crafted .gitmodules covering HTTPS, SSH and a
  foreign-owned leg (excluded from the App token, warned about)
- README.md's line-cap governance test moves 331 -> 359 with a new
  dated paragraph, matching the doc it guards

Lane: repo-shape
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_015WekBEXf55Xv64psGe5t3T
Replaces the SHAPE_LEGS_TOKEN paragraph in README.md and
templates/assembly-root/README.md with a 'Reading private legs in CI'
section: preferred is a dedicated GitHub App (Contents: Read-only +
Metadata: Read, installed on each consuming org), registered as org
secrets SHAPE_LEGS_APP_ID and SHAPE_LEGS_APP_PRIVATE_KEY; fallback is
the existing fine-grained SHAPE_LEGS_TOKEN PAT. Includes the exact
gh secret set commands for both and the (unchanged) degrade
behaviour, now credential-source-aware.

scaffold-project.py and adopt-project.py's one-line NOTE printed when
a private/internal leg is created now names both options, App first.

Lane: repo-shape
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_015WekBEXf55Xv64psGe5t3T
Copilot AI lite review requested due to automatic review settings September 4, 2026 00:58
@sourcery-ai

sourcery-ai Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR changes assembly-root CI to mint a pinned, owner-scoped GitHub App installation token for private legs, fall back deterministically to SHAPE_LEGS_TOKEN, and retain unauthenticated degradation when neither is configured. Documentation, scaffolding reminders, and rendered-workflow tests are updated to cover setup, failure semantics, credential isolation, and leg discovery.

Sequence diagram for GitHub App leg credential resolution

sequenceDiagram
    participant Workflow
    participant GitHubApp as GitHub App
    participant PAT as SHAPE_LEGS_TOKEN
    participant Git as Git submodules

    Workflow->>Workflow: leg repository names from .gitmodules
    Workflow->>GitHubApp: mint installation token
    alt App token available
        Workflow->>Git: git submodule update --init --recursive with App token
    else App not configured
        Workflow->>PAT: read fallback PAT
        alt PAT available
            Workflow->>Git: git submodule update --init --recursive with PAT
        else No credential
            Workflow->>Git: git submodule update --init --recursive unauthenticated
        end
    end
    Workflow->>Workflow: record legs_credential as app, pat, or none
Loading

File-Level Changes

Change Details Files
Add GitHub App installation-token authentication for private leg submodules with PAT fallback and explicit credential-source handling.
  • Mint a pinned App token when both App secrets are configured, requesting read-only contents access and limiting repositories to same-owner legs.
  • Resolve credentials in App, then PAT, then unauthenticated order; expose and log the winning source while keeping credentials scoped to the fetch step.
  • Preserve degraded validation behavior for missing credentials and fail explicitly for configured credentials that cannot fetch legs or for App minting misconfiguration.
templates/assembly-root/.github/workflows/validate.yml
Document GitHub App setup, PAT fallback, permissions, secret commands, and private-leg behavior.
  • Replace PAT-only guidance with App-first instructions and exact organization secret commands.
  • Explain owner-scoped App repository selection, fallback and failure semantics, and root-checkout credential isolation.
README.md
templates/assembly-root/README.md
Update project-generation guidance to mention both supported private-leg credential options.
  • Tell scaffold and adoption users to configure the preferred App or fallback PAT for private/internal legs.
scaffold-project.py
adopt-project.py
Expand workflow and repository hygiene tests to validate authentication ordering, safety, and repository-name extraction.
  • Assert App action pinning, permissions, guards, job-level secret booleans, failure messaging, and App-before-PAT resolution.
  • Execute the rendered shell extraction against HTTPS, SSH, and foreign-owner .gitmodules entries.
  • Adjust README length and workflow assertions for the new guidance.
tests/test_scaffold_e2e.py
tests/test_repo_hygiene.py

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

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="templates/assembly-root/.github/workflows/validate.yml" line_range="146-162" />
<code_context>
+          if [ -n "$SHAPE_LEGS_APP_TOKEN" ]; then
</code_context>
<issue_to_address>
**issue (broader_impact):** When `.gitmodules` contains a private leg owned by a different account and both the App and PAT are configured, the workflow excludes that leg from the App token but still selects the App token for the single global submodule fetch. The PAT is never used for the foreign leg, so the fetch fails even though the documented PAT-only route is configured.

**Triggers:** When a project has both same-owner and foreign-owned private legs and both credentials are present.

**Suggested fix:** Fetch same-owner legs with the App and foreign-owned legs with the PAT, or select the PAT for the entire fetch whenever foreign-owned legs are present; the current single-token resolution cannot support the stated foreign-leg behavior.
</issue_to_address>

### Comment 2
<location path="templates/assembly-root/.github/workflows/validate.yml" line_range="78" />
<code_context>
+              repo="${repo%.git}"
+              owner="${repo%%/*}"
+              name="${repo#*/}"
+              if [ "$owner" = "$REPO_OWNER" ]; then
+                if [ -z "$legs" ]; then
+                  legs="$name"
</code_context>
<issue_to_address>
**issue (bug_risk):** The owner comparison is case-sensitive even though GitHub account and organization names are case-insensitive. A valid leg URL such as `https://github.com/acme/Leg-spec` is excluded when `github.repository_owner` is `Acme`, causing the App token to omit the leg and the App-first fetch to fail.

**Triggers:** When the owner casing in `.gitmodules` differs from GitHub's `github.repository_owner` casing.

**Suggested fix:** Normalize both owner values to the same case before comparing them.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and this changes how CI authenticates to private repositories by minting and using a GitHub App installation token, with a PAT fallback; incorrect repository scoping or workflow handling could expose private repository contents or fetch unintended repositories. Reverting stops the new access path for future runs, but it cannot undo data that was already fetched or exposed by a faulty run.

Blocking findings: templates/assembly-root/.github/workflows/validate.yml:162, templates/assembly-root/.github/workflows/validate.yml:78


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +146 to 162
if [ -n "$SHAPE_LEGS_APP_TOKEN" ]; then
legs_credential=app
LEG_TOKEN="$SHAPE_LEGS_APP_TOKEN"
elif [ -n "$SHAPE_LEGS_TOKEN" ]; then
legs_credential=pat
LEG_TOKEN="$SHAPE_LEGS_TOKEN"
else
legs_credential=none
LEG_TOKEN=""
fi
echo "legs_credential=$legs_credential" >> "$GITHUB_OUTPUT"
echo "leg credential source: $legs_credential"
if [ -n "$LEG_TOKEN" ]; then
git \
-c "url.https://x-access-token:${SHAPE_LEGS_TOKEN}@github.com/.insteadOf=https://github.com/" \
-c "url.https://x-access-token:${SHAPE_LEGS_TOKEN}@github.com/[email protected]:" \
-c "url.https://x-access-token:${LEG_TOKEN}@github.com/.insteadOf=https://github.com/" \
-c "url.https://x-access-token:${LEG_TOKEN}@github.com/[email protected]:" \
submodule update --init --recursive

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (broader_impact): When .gitmodules contains a private leg owned by a different account and both the App and PAT are configured, the workflow excludes that leg from the App token but still selects the App token for the single global submodule fetch. The PAT is never used for the foreign leg, so the fetch fails even though the documented PAT-only route is configured.

Triggers: When a project has both same-owner and foreign-owned private legs and both credentials are present.

Suggested fix: Fetch same-owner legs with the App and foreign-owned legs with the PAT, or select the PAT for the entire fetch whenever foreign-owned legs are present; the current single-token resolution cannot support the stated foreign-leg behavior.

repo="${repo%.git}"
owner="${repo%%/*}"
name="${repo#*/}"
if [ "$owner" = "$REPO_OWNER" ]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): The owner comparison is case-sensitive even though GitHub account and organization names are case-insensitive. A valid leg URL such as https://github.com/acme/Leg-spec is excluded when github.repository_owner is Acme, causing the App token to omit the leg and the App-first fetch to fail.

Triggers: When the owner casing in .gitmodules differs from GitHub's github.repository_owner casing.

Suggested fix: Normalize both owner values to the same case before comparing them.

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

The workflow currently can prefer an App token even when foreign-owned legs require the PAT (and can also over-broaden App token scope when repositories ends up empty), which can break the intended fallback/degrade semantics and raises a token-scoping concern.

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

Pull request overview

This PR updates the assembly-root validate workflow to prefer a short-lived GitHub App installation token for fetching private leg submodules, with the existing SHAPE_LEGS_TOKEN PAT retained as fallback, and refreshes documentation + tests to match the new credential-resolution behavior.

Changes:

  • Add GitHub App token minting + deterministic credential resolution (app|pat|none) for the leg submodule fetch in validate.yml.
  • Extend end-to-end scaffold tests to assert token pinning/guards and to exercise the .gitmodules → leg-name extraction shell logic.
  • Update README docs and scaffold/adopt reminders to describe the GitHub App secrets and PAT fallback.
File summaries
File Description
tests/test_scaffold_e2e.py Adds/updates assertions around App token minting, precedence, and .gitmodules leg-name extraction execution.
tests/test_repo_hygiene.py Updates README line-cap expectation to account for expanded CI credential docs.
templates/assembly-root/README.md Documents “App first, PAT fallback” setup and expected degrade/fail behavior.
templates/assembly-root/.github/workflows/validate.yml Implements App-token minting + submodule fetch credential resolution + operator-facing outputs/messages.
scaffold-project.py Updates the private/internal legs reminder to mention App secrets first, PAT fallback.
README.md Updates main documentation for App secrets + PAT fallback and behavior semantics.
adopt-project.py Updates the private/internal legs reminder to mention App secrets first, PAT fallback.
Review details

Suppressed comments (2)

templates/assembly-root/.github/workflows/validate.yml:103

  • The App token mint step currently runs whenever the App secrets are present, even if the extracted legs list is empty or includes foreign-owned legs. With owner: set, an empty repositories: value can mint an installation token scoped to all repositories for that owner, and foreign-owned legs will still force git submodule update to fail (preventing PAT fallback due to the fixed precedence). Gate the mint step so it only runs when there are same-owner legs and no foreign-owned legs were detected.
      - name: mint a leg-reader token from the GitHub App
        id: app-token
        if: env.SHAPE_LEGS_APP_SET == 'true'
        continue-on-error: false

templates/assembly-root/.github/workflows/validate.yml:218

  • The hard-fail condition is keyed off job-level env booleans (SHAPE_LEGS_*_SET), which can be true even when no credential was actually used (e.g., App secrets present but minting intentionally skipped due to foreign/empty legs). This can cause a hard failure even though the job effectively degraded (legs_credential=none) or should have used PAT. Base the failure on the fetch step’s resolved output instead (fail only when legs_credential != 'none' and legs are unavailable).
      - name: fail — a leg credential is configured but the legs still could not be fetched
        if: steps.submodules.outputs.legs_available != 'true' && (env.SHAPE_LEGS_TOKEN_SET == 'true' || env.SHAPE_LEGS_APP_SET == 'true')
        run: |
  • Files reviewed: 7/7 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 on lines +158 to 162
if [ -n "$LEG_TOKEN" ]; then
git \
-c "url.https://x-access-token:${SHAPE_LEGS_TOKEN}@github.com/.insteadOf=https://github.com/" \
-c "url.https://x-access-token:${SHAPE_LEGS_TOKEN}@github.com/[email protected]:" \
-c "url.https://x-access-token:${LEG_TOKEN}@github.com/.insteadOf=https://github.com/" \
-c "url.https://x-access-token:${LEG_TOKEN}@github.com/[email protected]:" \
submodule update --init --recursive
Comment on lines +66 to +89
legs=""
if [ -f .gitmodules ]; then
while IFS= read -r url; do
[ -n "$url" ] || continue
case "$url" in
https://github.com/*) repo="${url#https://github.com/}" ;;
[email protected]:*) repo="${url#[email protected]:}" ;;
*) continue ;;
esac
repo="${repo%.git}"
owner="${repo%%/*}"
name="${repo#*/}"
if [ "$owner" = "$REPO_OWNER" ]; then
if [ -z "$legs" ]; then
legs="$name"
else
legs="$legs,$name"
fi
else
echo "::warning::leg $owner/$name is owned by a different account ($owner) than this repository ($REPO_OWNER); a GitHub App installation token is per-owner, so it is excluded from the App-minted token here and can only be reached via SHAPE_LEGS_TOKEN."
fi
done < <(git config --file .gitmodules --get-regexp '\.url$' | cut -d' ' -f2- || true)
fi
echo "legs=$legs" >> "$GITHUB_OUTPUT"
Comment on lines 377 to +379
assert ("if: steps.submodules.outputs.legs_available != 'true' && "
"env.SHAPE_LEGS_TOKEN_SET == 'true'") in fail_step
"(env.SHAPE_LEGS_TOKEN_SET == 'true' || "
"env.SHAPE_LEGS_APP_SET == 'true')") in fail_step
@brettheap
brettheap merged commit 05cf772 into main Sep 4, 2026
4 checks passed
brettheap added a commit that referenced this pull request Sep 4, 2026
brettheap added a commit that referenced this pull request Sep 10, 2026
…file, as AGENTS.md promised, and --branch may name the branch you are on (#84) (#85)

* update-shape.py: --accept-local re-pins a `both` row from the merged file, as AGENTS.md promised, and --branch may name the branch you are on (#84)

`apply` refused every `both` row before it ever consulted `--accept-local`,
so the exit AGENTS.md already documented — merge by hand, commit, re-run
with `--accept-local <path>` on the file you merged — could never actually
be taken. Found running S4 of #77 on InkRouter/IRRS and IRSS (their #13s):
both adopted an in-place Makefile that appends a CONTRACTS_DIR block and
keeps its pin row, so `classify()`'s "not a verbatim copy at the pinned
commit" branch reads it as `both` the moment upstream touches the template,
forever, regardless of any further local edit.

`cmd_apply`'s conflict refusal now excludes a `both` row whose path
`--accept-local` names: upstream bytes are never copied over it, and
`classify()` precomputes its digest from the working file the same way it
already does for `locally-modified`, so the row is recomputed from whatever
is on disk — the person's word, not a check that a merge actually happened.
An unaccepted `both` row still refuses with the existing wording; `check`'s
per-row detail for `both` gains one sentence naming `--accept-local <path>`
as the exit (kept out of `row.detail` itself, so the refusal's own wording
does not change).

`commit_on_branch` no longer assumes `--branch <name>` names a branch that
does not exist yet: `<name>` naming the root's tracking branch is refused
outright, current or not; naming the CURRENT branch (so, by that rule, not
the tracking branch) commits onto it directly — exactly the checkout the
documented `both` exit leaves behind once the hand merge is committed; an
existing branch that is not current is refused by name
(`update-branch-exists`); anything else is created fresh, as before.

Tests in test_update_shape.py: the existing CHANGED-file `both` case now
also asserts `--accept-local` succeeds and re-pins from the local, unmerged
bytes (`test_accept_local_on_a_both_row_repins_from_the_local_bytes`). A new
`adopted_root` fixture mirrors an in-place adoption's Makefile append
(`ADOPT_MAKEFILE_BLOCK`, hand-patching the pin row's digest the way
`_materialize` itself computes it) in its own upstream clone, so its second
commit moving the Makefile TEMPLATE (and, alongside it,
scripts/validate-manifest.py) cannot move any other test's default target.
Four tests cover `check` naming the exit, the unaccepted refusal, the
hand-merge-then-`--branch`-onto-that-branch exit end to end (re-pin, the
other changed file copied, green validate-pins.py/validate-manifest.py),
and an unmerged `--accept-local` still succeeding. Three more cover
`--branch`'s postures: current non-tracking branch, existing non-current
branch, and the tracking-branch refusal (checked on `main`, which is both
this root's tracking AND current branch, so it proves the tracking check
runs first). AGENTS.md point 4 now says the refusal has this exception and
that the hand-merge commit goes on the branch `apply` is then pointed at
with `--branch`; its cap moves 342 -> 344 with a dated entry in
test_repo_hygiene.py's own style.

82 passed (test_update_shape.py, test_update_shape_add.py,
test_repo_hygiene.py); 738 passed, 1 skipped for the full suite. Re-ran the
fix against a scratch clone of InkRouter/IRRS on branch
shape/update-3abeb8a4a27e, where the hand-merged Makefile from #13 is
already committed: `apply --accept-local Makefile --branch
shape/update-3abeb8a4a27e` re-pinned from that merged file, copied
AGENTS-shape.md, committed onto the same branch, and `make validate` is
green.

Lane: xfactory-2 (xFactory-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* test_update_shape.py: the adopted-root fixture builds on the existing one (SonarCloud duplication gate on #85) (#84)

PR #85's quality gate failed on one metric: 4.4% duplication on new code
(required <= 3%), no issues raised. `adopted_upstream_and_project` had
retyped `upstream_and_project`'s clone-then-scaffold-then-recursive-clone
block verbatim, and three tests each closed with the same
"exit 2, refusal id in stderr, pin's commit: untouched" tail.

`scaffold_upstream_and_project(tmp_path_factory, subdir)` is the part both
fixtures share: a fresh clone of this repository, `PROJECT` scaffolded from
it, and a recursive clone of that. Returns the pieces rather than a
finished fixture dict on purpose — one shared return shape across two
fixtures is how the second one drifts from the first — so each fixture
still makes its own commit(s) on top and returns its own dict.
`commit_upstream_changes(upstream, message, {source: text})` folds the
append-write-then-commit-then-capture-the-hash steps `upstream_and_project`'s
commit B and `adopted_upstream_and_project`'s commit B' both took; the
appended comment the two share for `CHANGED_SOURCE` is now the one constant
`UPSTREAM_FIX_LINE` rather than two copies of the same string.
`assert_refused_and_unpinned(result, root, upstream_and_project, refusal_id,
*needles)` is the repeated tail, now used by both `--branch` refusal tests,
the `both`-row conflict test, and the adopted-Makefile conflict test.

Behaviour and assertions are unchanged — same fixtures returned, same
refusals, same messages checked — and every docstring survives. Two clones
stay two clones: `adopted_upstream_and_project` still gets its OWN clone
rather than a further commit on `upstream_and_project`'s, because that one
is shared by every bare `check()` call in this module and a further commit
on it would move their implicit target commit out from under them.

82 passed (test_update_shape.py, test_update_shape_add.py,
test_repo_hygiene.py); 738 passed, 1 skipped for the full suite.

Lane: xfactory-2 (xFactory-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
@brettheap
brettheap deleted the feat/legs-app-token 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