Repository navigation
CI: fetch private legs with a GitHub App installation token; the PAT becomes the fallback - #13
Conversation
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
Reviewer's GuideThe 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 resolutionsequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
There was a problem hiding this comment.
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
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
🟡 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 invalidate.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
legslist is empty or includes foreign-owned legs. Withowner:set, an emptyrepositories:value can mint an installation token scoped to all repositories for that owner, and foreign-owned legs will still forcegit submodule updateto 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.
| 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 |
| 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" |
| 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 |
Lane: repo-shape Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_015WekBEXf55Xv64psGe5t3T # Conflicts: # tests/test_repo_hygiene.py
…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]>



Lane: repo-shape
Brett Heap ruled: "we should move this over to a github app."
What changed
The assembly-root
validateworkflow's leg-fetch step now tries a GitHub App installation token first and falls back to the existingSHAPE_LEGS_TOKENPAT — never the other way, never both, resolution order is fixed:steps.app-token.outputs.token(minted byactions/create-github-app-token, run when both App secrets are present)SHAPE_LEGS_TOKEN(the fine-grained PAT, unchanged fallback)git submodule updateas before, for public legsWhich source won is exposed as step output
legs_credential: app|pat|noneand 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 IDSHAPE_LEGS_APP_PRIVATE_KEY— the App's private key PEMBoth org secrets on the assembly root; presence is checked via job-level
env: SHAPE_LEGS_APP_SET, neversecretsin a stepif:(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
.gitmodulesand scopes the mint'srepositories: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: falseplus 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
actionlint(v1.7.12, matching this repo's CI) plusshellcheck(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 exactrun: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_TOKENparagraph becomes "Reading private legs in CI" (App preferred, PAT fallback, exactgh secret setcommands 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:
Bug Fixes:
Enhancements:
CI:
Documentation:
Tests: