Title: mcpx testing: format.yaml -- auto-format after a green run; PR head vs main · Issue #1997 · developing-today/code · GitHub
Open Graph Title: mcpx testing: format.yaml -- auto-format after a green run; PR head vs main · Issue #1997 · developing-today/code
X Title: mcpx testing: format.yaml -- auto-format after a green run; PR head vs main · Issue #1997 · developing-today/code
Description: Relocated from dezren39/darwin-nix#142 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references inside it are historical (dezren39/ni...
Open Graph Description: Relocated from dezren39/darwin-nix#142 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue referenc...
X Description: Relocated from dezren39/darwin-nix#142 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue refe...
Opengraph URL: https://github.com/developing-today/code/issues/1997
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mcpx testing: format.yaml -- auto-format after a green run; PR head vs main","articleBody":"Relocated from dezren39/nix#142 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references inside it are historical (dezren39/nix numbering).\n\nParent: #95\n\n## Summary\n\nThe notes ask for a separate `format.yaml` that auto-commits formatting to `main` after the formatters succeed and the test workflow is green. This issue works through what that actually requires (trigger, token, loop guard, branch protection, the race with newer commits) and finds a logical conflict with the check-mode formatters in the test matrix (#141). Plain conclusion: **auto-committing to `main` is worse than formatting the PR head**; the recommendation is a blocking format check on PRs plus an autofix push to the PR branch, and a `main`-side workflow that opens a PR rather than committing directly. If the direct-to-main version is still wanted, the safe way to build it is written out below.\n\n## Original notes\n\n> - testing\n> - separately, format.yaml which auto-commits to main when format has changes and successfully completes all formatters, receives a green test workflow\n\n## Current state\n\n- No formatting automation. The only bot push today is the vendorHash repair in `mcpx.yml` (`:67-95` at 05c78b2), which commits to `renovate/*` / `dependabot/*` PR branches with `GITHUB_TOKEN`. Its comment states the repository's policy on rewriting branches (`mcpx.yml:68-70`): \"A human changing dependencies should see the failure and fix it deliberately rather than have it rewritten under them.\" The step ran on a real Renovate PR for the first time in #184 (run 36693225089) but took the no-op path (\"builds as-is; nothing to repair\"), so the push-back itself has still never run.\n- `main` has **no branch protection and no rulesets** (`.../branches/main/protection` -> 404; `.../rulesets` -> `[]`), so a direct push from Actions would succeed today, and would start failing the day protection is turned on.\n- Token behaviour ([trigger docs](https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/trigger-a-workflow)): events caused by `GITHUB_TOKEN` do **not** start new workflow runs -- so a push to `main` with it is never tested. The exception is `pull_request` `opened`/`synchronize`/`reopened`, which now create runs in an **approval-required** state. A GitHub App installation token or PAT does trigger runs normally.\n- `workflow_run` ([events docs](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#workflow_run)): only fires for a workflow file on the default branch; types `completed`/`requested`/`in_progress`; exposes `workflow_run.conclusion`, `head_branch`, `head_sha`, `event`; chains at most three levels deep.\n\n## The conflict to resolve first\n\n#141 puts formatters in **check mode** in the test matrix. If an unformatted commit reaches main, the `fmt` leg fails, the test workflow is red, and a `format.yaml` gated on \"a green test workflow\" **never runs**. Conversely, whenever the test workflow *is* green, formatting is already clean and there is nothing to commit. As written, the two notes cancel out. Ways out:\n1. Make the `fmt` leg non-blocking on `main` pushes (`continue-on-error: ${{ github.event_name == 'push' }}`) and have `format.yaml` check the individual job results through the API (`workflow_run.conclusion` is for the whole run). Works, but main can then be \"green\" while unformatted.\n2. Make formatting blocking on PRs, so main is always formatted by construction, and use `format.yaml` only for drift that does not come through a PR: a formatter version bump in `flake.lock`, a direct push. That is the recommended framing below.\n\n## Approaches\n\n### A -- auto-commit to `main` after a green run (the notes' design), least recommended\n\nHow to build it safely if chosen:\n- `on: workflow_run: { workflows: [mcpx-test], types: [completed] }`; `if: conclusion == 'success' && event == 'push' && head_branch == 'main'` (ignore `cancelled`, PR runs, and dispatches).\n- Check out `workflow_run.head_sha`; run the same pinned formatters (#141: `nix fmt`); if `git diff --quiet`, exit.\n- Race: if `main` has moved past `head_sha`, **skip** (the newer commit's own run will trigger `format.yaml` again) rather than rebase -- rebasing a bot commit onto untested code is the worst of both.\n- Verify the diff is formatting-only before pushing: `go build ./...` and `go vet ./...`, `deno check`, `nix eval` of the package -- seconds, and it catches a formatter bug or a bad version bump.\n- Bound what the bot may write (from #170): stage the explicit list from `git diff --name-only`, never `git add -A` (the repair step already stages one named file, `mcpx.yml:93`); **abort on an unexpectedly large diff** (a formatter version bump can legitimately reformat the whole tree -- a threshold such as 500 lines or 50 files, or any file outside a configured set, hands it to a human PR instead); re-run the check after committing and fail if it is still dirty, which catches two formatters fighting over one file.\n- Add `workflow_dispatch` beside `workflow_run`: `workflow_run` only fires for the workflow file on the default branch, so without it the workflow cannot be exercised before it merges (from #170).\n- Loop guard: commit as `github-actions[bot]` with a marker (`[mcpx-format]`) and skip when the triggering head commit carries it; with `GITHUB_TOKEN` no run is triggered anyway. With an App token, the push triggers a test run, which triggers `format.yaml`, which finds no diff and stops -- \"no diff\" is the real guard, the marker is belt and braces.\n- Branch protection: when it is turned on, the pusher must be on the bypass list; that requires a GitHub App (PATs belong to a person and bypassing as a person is worse).\n\nWhy it is least recommended:\n- With `GITHUB_TOKEN`, the formatted commit on main is **never tested**. For gofmt that is nearly safe (it only rewrites layout); for `deno fmt`, `shfmt`, `nixfmt` after a version bump it is \"probably fine\", which is the wrong standard for main.\n- Every unformatted merge becomes two commits on main (the change, then \"format\"), permanently in history and in `git blame`.\n- It needs `contents: write` on the default branch in an automated job, and it fights branch protection.\n- It only ever fires if the conflict above is resolved by making main's format check non-blocking.\n\n### B -- open a formatting PR from `main` drift\n\nSame trigger as A; instead of pushing to main, `peter-evans/create-pull-request` (or `gh pr create`) opens or updates a single branch `bot/mcpx-format` with the diff. The PR runs the full test workflow (with an App token; with `GITHUB_TOKEN` it lands in the approval-required state), and a human or auto-merge merges it. Tested, reviewable, protection-compatible, one extra PR when drift happens. Good as the **main-side** fallback.\n\n### C -- blocking check on PRs, autofix pushed to the PR head, B as the main fallback (recommended)\n\n- The `fmt` leg in the test workflow is blocking on PRs (check mode, prints the diff and the one command to fix: `nix fmt`; the diff also goes into `$GITHUB_STEP_SUMMARY` as a `git apply`-able patch, from #170).\n- An `autofix` job (same workflow, after `fmt` fails, same-repo branches only -- forks cannot be pushed to) runs `nix fmt` and pushes a commit to the PR branch, exactly like the existing vendorHash repair. Merge it into one \"bot push-back\" job with the vendorHash repair so a bot PR gets one push, not two. **Scope it the way the repair is scoped** (changed in the 2026-09-30 pass, from #170): always on bot branches (`renovate/*`, `dependabot/*` -- where a formatter bump lands, open question 3), and on a human's branch only when the author opts in (e.g. an `autofix` label). The repository has already written down that a human's branch is not rewritten under them (`mcpx.yml:68-70`); an unconditional autofix contradicts that and rewrites a branch mid-review, invalidating review comments and forcing a pull before the next push. If the user wants autofix on every PR anyway, that is a policy change to make explicitly, together with the repair step's comment.\n- Token: a GitHub App token, so the push triggers a normal (not approval-gated) run of the full workflow; the superseded run is cancelled by the PR concurrency group (#135). Loop guard: no diff -> no push; and skip when the head commit author is the App.\n- `format.yaml` exists only for drift on main that did not come through a PR (formatter bump, direct push): approach B.\n- Result: every commit on main is formatted **and tested**; with squash merges the autofix commit leaves no trace on main.\n- Off-the-shelf alternative to a custom job: autofix.ci (a GitHub App, free for OSS) does the PR-head push with its own loop/fork handling; it requires trusting a third-party app with write access. Worth considering; decide with the App-token question.\n\nRecommended because it keeps the notes' intent (nobody hand-formats; formatting never blocks a human for long) without an untested commit on main, and without overriding the branch-rewriting policy the repository already has.\n\n## Open questions\n\n1. Is the user OK replacing \"auto-commit to main\" with \"autofix the PR head + a formatting PR for drift\"? If not, build A with the safeguards above.\n2. GitHub App (new, owned by the user) vs autofix.ci vs a fine-grained PAT for the push-back? The same token would fix the vendorHash repair's approval-required runs (#49).\n3. Should Renovate/Dependabot formatter bumps (a new nixfmt in `flake.lock`) reformat inside the bump PR via the same autofix job? That is the cleanest place for format drift to land.\n4. Does the user merge by squash? (If merge commits are used, autofix commits appear in main's history.)\n5. A pre-commit hook (and which framework), or is `nix fmt` / `just fmt` plus the blocking check enough? A hook makes the blocking check nearly unreachable and `format.yaml` almost dead code -- which is fine; it is a backstop (from #170).\n6. Bot identity: reuse `mcpx-hash-bot` (`mcpx.yml:91-92`) or a separate `mcpx-format-bot` so `git log` says which bot did what? Cosmetic; decide once (from #170).\n7. Should the same push-back machinery regenerate derived artefacts CI checks (man page, OpenAPI, settings table)? That is #96/#145's drift problem; build the mechanism once (from #170).\n\n## Ease · Impact · Related\n\n**Ease** M (needs a token decision) · **Impact** low-med (convenience; quality comes from the blocking check) · **Depends on / related**: #95, #141 (the formatters and their pinning), #135 (concurrency cancels superseded runs; the vendorHash push-back job this merges with), #49 (bot push-back for every package, token choice), #99 (agents run `nix fmt` before pushing; CI is the backstop).\n\nSecurity/auth deferred; see tracker.\n\n## Acceptance criteria\n\n- format.yaml auto-formats only after a green run, distinguishes PR-head vs main behaviour as specified, and its CI run is green.\n- The work described in the Summary/Scope above is delivered via a branch + PR (no direct push to main); verification runs in GitHub Actions CI, not on the sandbox.\n- Evidence (CI links, timings, or probe output as applicable) is recorded on this issue before it is closed.\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-28T23:02:12Z","url":"https://github.com/developing-today/code/issues/1997"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9002d785-7b5b-66e0-1151-04cf145ae0db |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9A8A:F286:7281CA:956370:6B06283E |
| html-safe-nonce | b12a52aea552e39dcd620a32f92a9b6b833c81e809a097ba87b0742e04cc17fc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QThBOkYyODY6NzI4MUNBOjk1NjM3MDo2QjA2MjgzRSIsInZpc2l0b3JfaWQiOiI3NjUyNjcwMDUzMzAwNDA4OTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 92ac34c3b679d866765fefa7c0ca618c830b2a74f3e584b190ebd4f5bc218c23 |
| hovercard-subject-tag | issue:6089097939 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/1997/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8cfc6ecfd8a68e85bc09c1a3a23b428f329b3770536710f35027a6d2b30ec8fd/developing-today/code/issues/1997 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8cfc6ecfd8a68e85bc09c1a3a23b428f329b3770536710f35027a6d2b30ec8fd/developing-today/code/issues/1997 |
| og:image:alt | Relocated from dezren39/darwin-nix#142 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue referenc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9e10bb0ecc0bd0f8692aa89586ee9b54e498d7ab9f244a44cdb5b93653a125ce |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 32e57d5cc2ce6ce92ec6dceb65858344750c27c2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width