Skip to content

ci(merge-train): exact-SHA train proof with train-gate (merge-queue v2 step 1) - #4582

Merged
Daniel Meppiel (danielmeppiel) merged 12 commits into
mainfrom
p-mq1-merge-train
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 12 commits into
mainfrom
p-mq1-merge-train

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

This is merge-queue v2 step 1: the exact-SHA train proof. Pushing a speculative ref queue/t<id>/p<k>-full (or -guard, or the base probe queue/b<sha12>/p0-full) now produces ONE train-gate verdict on that exact SHA. That verdict covers the full merge-time gate, including hermetic integration, which today runs only on merge_group and on dispatch.

  • New .github/workflows/merge-train.yml:
    • Triggers: push on queue/t*/p* and queue/b*/p*, plus workflow_dispatch. There is no pull_request_target and no other push.
    • Jobs:
      • scope: parses -guard or -full. The base comes from the Queue-Base: trailer, or else merge-base with main.
      • guard: the shared lint chain, the test-architecture ratchet contracts, the one tests/quality module those leave out, and the NOTICE drift check (on the merge_group required list).
      • tier1: calls ci.yml.
      • tier2: calls ci-integration.yml, with secrets: inherit because only it needs secrets.
      • train-gate: always(). It passes only when every job is green, or when tier1 and tier2 are skipped for a -guard ref.
    • Concurrency is per ref and never cancelled.
  • ci.yml and ci-integration.yml gain a workflow_call trigger with an optional base_sha input. Base expressions append || inputs.base_sha. No pull_request or merge_group job behaviour changes.
  • The Lint steps move unchanged into the composite .github/actions/lint-chain. ci.yml's Lint job and the train guard both use it, so the chain has one owner.
  • tests/quality/test_ci_topology.py contracts, each with mutation-style negative cases:
    • triggers;
    • full scope covers every merge_group EXPECTED_CHECKS name, derived from the workflows rather than hardcoded;
    • secrets and permissions match what the callees need;
    • train-gate needs every job and runs with always();
    • no shared caches (ci(lifecycle): the dispatched-ref lifecycle workflow uses no shared cache #4531);
    • lint-chain single owner.
      Existing frozen-environment and symlink-lint contracts now also read the composite's steps; none were weakened.
  • Docs: cicd.instructions.md and contributing/integration-testing.md.

Deferred to step 3, where the runner first needs it: JUnit XML upload from every test job. No ruleset change, no --admin change.

Issue and approved scope

Issue: Fixes #4574

Human scope-approval comment: the apm-scope:v1 record is in the issue body. The merge-queue v2 design and plan were approved by the regent on Daniel's behalf on 2026-11-21, and the work is owned by Ops (DM v3).

Does this PR complete the issue, or what remains? It completes step 1. Acceptance runs on queue refs follow merge: (a) a ref at main's SHA is green; (b) a seeded lint-budget break fails guard; (c) a -guard ref runs only scope, guard and train-gate.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally (targeted, guarded, no xdist): the new and touched test_ci_topology.py cases, 44 passed. 13 other workflow and quality contract files, 266 passed. ruff 0.15.12 check and format clean. actionlint clean (one SC2086 already on main). The architecture-boundary, auth-signal, complexity-ratchet, taxonomy-allowance and taxonomy --changed checks are all clean.
  • All existing tests pass. Pending CI: 2 lifecycle collection tests in test_ci_topology.py failed locally only because the shared venv imported a stale src.
  • Added tests for new functionality

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • N/A -- this PR does not change OpenAPM-observable behaviour.

Add .github/workflows/merge-train.yml: a push to queue/t*/p* or
queue/b*/p* (or a manual dispatch) proves that exact SHA and reports one
train-gate check. The -guard/-full ref suffix sets the scope:

- scope parses the ref and resolves the train base (Queue-Base trailer,
  else the merge base with origin/main);
- guard runs the lint chain, the architecture ratchet contracts, the
  remaining tests/quality module and the NOTICE check, with caches off;
- tier1 and tier2 call ci.yml and ci-integration.yml through new
  workflow_call triggers (optional base_sha input); only tier2 inherits
  secrets, and each tier gets the union of its callee's permissions;
- train-gate (if: always()) passes only when every job is green, with the
  tiers skipped on guard scope, and writes a step summary.

Move the Lint steps into the .github/actions/lint-chain composite action,
used by ci.yml's Lint job and the train guard, so the chain has one owner.
pull_request and merge_group behaviour is unchanged.

tests/quality/test_ci_topology.py pins the triggers, full-scope coverage of
every merge_group EXPECTED_CHECKS name (derived from the workflows), the
gate, the cache contract and the lint-chain owner, with mutation cases.
Workflow uv and lint-step contracts now read local composite action steps.

Co-authored-by: Copilot App <[email protected]>
Comment thread .github/workflows/merge-train.yml Fixed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical gaps can certify the wrong SHA, bypass baseline checks, reuse shared caches, and mistake a guard-only pass for a full proof.

7 open issues
What changed in this PR

This PR adds step 1 of merge-queue v2 (#4574): running existing CI tiers against speculative queue commits and reporting their results through train-gate, before those commits land on main.

Changes:

  • Adds guard-only and full train runs, with base resolution and an aggregate gate.
  • Makes both CI tiers reusable and extracts the lint chain into a shared composite action.
  • Adds topology contracts and documents the train workflow.
File Description
tests/​workflow_contracts.py Adds helpers to inspect composite-action steps.
tests/​unit/​test_windows_native_symlink_workflow.py Follows the extracted action when checking lint coverage.
tests/​quality/​test_ci_topology.py Adds train topology and mutation contracts; adapts existing action checks.
scripts/​check_complexity_ratchet.py Updates a comment identifying the lint path-list owner.
docs/​src/​content/​docs/​contributing/​integration-testing.md Documents train refs, scopes, and proof lookup.
.github/​workflows/​merge-train.yml Adds scope resolution, guards, reusable tiers, and train-gate.
.github/​workflows/​ci.yml Adds reusable-workflow inputs and delegates linting to the composite action.
.github/​workflows/​ci-integration.yml Adds a reusable-workflow entry point and optional base input.
.github/​instructions/​cicd.instructions.md Documents train topology and operating constraints.
.github/​actions/​lint-chain/​action.yml Centralizes the lint chain shared by CI and train guards.

Review effort: Balanced

Comment thread .github/workflows/merge-train.yml Resolved
Comment thread .github/workflows/merge-train.yml Resolved
Comment thread .github/workflows/merge-train.yml Resolved
Comment thread .github/workflows/ci.yml Resolved
Comment thread .github/workflows/merge-train.yml Resolved
Comment thread .github/workflows/merge-train.yml Resolved
…tions from source (#4574)

CodeQL flagged cache poisoning: the workflow_dispatch `ref` input let the
guard check out an arbitrary SHA. Drop the input. Every job now checks out
the triggering commit, a manual probe dispatches the queue branch itself
(`gh workflow run merge-train.yml --ref queue/t<id>/p<k>-full`), and the
scope job fails on any ref that is not queue/t<id>/p<k>-guard|-full or
queue/b<sha12>/p0-full, whatever the event. The topology contracts pin a
dispatch without inputs and default-ref checkouts, with mutation cases.

APM Self-Check reported hash drift on the deployed cicd instructions. Put
the merge-train section in the .apm/instructions source, redeploy with the
tree's apm, and update the two lock hash lines; `apm audit --ci` is clean.

Co-authored-by: Copilot App <[email protected]>
…#4574)

Amendment A plus accepted #4582 review threads:

- Caches: merge-train's guard restores caches (main's included) but never
  saves (setup-uv enable-cache: true, save-cache: false). ci.yml and
  ci-integration.yml are unchanged: under the call they save only into the
  queue branch's scope. The train contract now forbids any cache save in
  merge-train.yml and the lint chain; lifecycle-journeys stays caches-off.
- cleanup deletes the train branch after train-gate (if: always(), the
  only job with contents: write, refs re-validated in the step, tolerates
  an already-deleted branch); train-gate never needs it.
- Every job skips the push a branch deletion fires (github.event.deleted),
  so no failing check lands on main's commit.
- Each run gets its own concurrency group, so a pending run is never
  replaced.
- A Queue-Base trailer must equal the merge base with main; an older
  ancestor would weaken the baseline-growth ratchets.
- CODEOWNERS gives .github/actions/** the workflow review bar.
- Docs: queue refs are branches, restore-only caches, cleanup, and a full
  proof is a successful run on the -full branch at the exact SHA. The cicd
  instructions are edited at source and redeployed with the tree apm.

Co-authored-by: Copilot App <[email protected]>
main's #4337 requires Spec conformance gate and Spec tests (1-3/3) in merge_group, so a full train must produce them. spec-conformance.yml gains a workflow_call trigger, merge-train.yml calls it as the spec tier, and train-gate reads its result.

Co-authored-by: Copilot App <[email protected]>
…train

# Conflicts:
#	.apm/instructions/cicd.instructions.md
#	.github/instructions/cicd.instructions.md
#	apm.lock.yaml
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.

Merge queue v2 step 1: exact-SHA train proof (merge-train.yml and train-gate)

3 participants