Plan: the merge train is the merge gate, and git push runs the static checks only

Closes: #960. Branches: chore/ci-merge-train-gate, then chore/ci-first-car. Status: Done (2026-11-28) — merge train is the merge gate (!1044 798ab5522)

Context

The operator’s ruling (2026-11-28, in conversation): make this repository’s CI/CD mirror craig’s and canopy’s, with minimal testing on the pre-push hook and the heavy tests in CI. Two forks, answered the same day: the hook runs the static checks only, no suite; consumer-sim’s live-model rows run once per release, locally, before the tag.

What the tree and GitLab say today:

  • .githooks/pre-push verifies signatures, guards main, and runs node tools/task.mjs prepush-validate: the whole validate, unless tools/lib/validate-stamp.mjs finds it already passed on the pushed tree.

  • validate in tools/task.mjs is lint, typecheck, spdx, planLint, the themes drift check, bundle, test and testAsRoot. testAsRoot (tools/lib/as-root.mjs) repeats the suites under unshare -r; when the caller is root already it skips, so CI, whose container is root, runs the suites as root only.

  • .gitlab-ci.yml runs validate on an MR’s pipeline, on main and on a release tag, and rehearse (consumer-sim --no-model) on tags only. A branch pushed before its MR exists gets a pipeline of its own, so one MR costs three pipelines.

  • The project’s settings (read through the API, 2026-11-28): merge_trains_enabled, merge_pipelines_enabled and only_allow_merge_if_pipeline_succeeds are false; the push rule’s reject_unsigned_commits is unset. Nothing server-side waits for a pipeline: an MR is merged seconds after its push, and its pipeline ends five to seven minutes later (pipelines 3127792786, 3127670764: the validate job 438 s and 313 s).

  • The last local validate (.pi/scratch/p952-validate.log) and the CI job of the same tree (pipeline 3127792786) disagree on what ran. Run as an ordinary user and skipped or not collected as root: 39 tests (pi-ssh 33, pi-agents 2, pi-modes 2, pi-remote 1, tools/lib 1). Run locally and skipped in CI: 35 (model-battery 33, pi-shellcheck 1, pi-vertex 1).

  • The workspace token is a Maintainer’s (permissions.project_access.access_level 40).

Design

1. One verb for the static checks

tools/task.mjs gains check: lint(), typecheck(), spdx(), planLint() and node tools/generate-themes.mjs --check, in that order, the lines validate opens with today. validate becomes check(); bundle(); test(); testAsRoot(); and its closing === validate: OK === line. It writes no stamp. prepush-validate, prepushValidate and the import from ./lib/validate-stamp.mjs are removed; tools/lib/validate-stamp.mjs and tools/lib/test/validate-stamp.test.mjs are deleted with them. The stamp existed to skip a long hook, and its second job (#409: the pushed commit is the tree validate read) passes to CI, which checks out the commit. The file’s header comment lists check, drops prepush-validate and stops calling validate the pre-push battery.

2. The hook

.githooks/pre-push keeps its core.hooksPath warning, the branch-deletion exit and the direct-to-main guard as they are. The signature loop and the validate block are removed. Its last step is:

echo "=== pre-push: task check ===" >&2
node tools/task.mjs check
echo "=== pre-push: OK ===" >&2

Its header says what it is: the static checks before a push; the merge train’s pipeline runs the battery and decides the merge; the push rule refuses an unsigned commit.

3. The pipeline

Job MR’s own pipeline Merge-train car main vX.Y.Z tag

lint (task check)

runs

-

-

-

validate (root)

by hand

runs, blocks

-

runs

validate-unprivileged (new)

by hand

runs, blocks

-

runs

rehearse

by hand

runs, blocks

-

runs

publish, published

-

-

-

as today

pages, GitLab’s scans

-

-

as today

-

signature-check is deleted. The three car jobs share one stage, so they run side by side. The changed parts of .gitlab-ci.yml:

stages:
  - security  # lint, and GitLab's scans
  - test      # the car: validate, validate-unprivileged, rehearse
  - release
  - published
  - pages

workflow:
  auto_cancel:
    on_new_commit: interruptible
  rules:
    # MR, merged-results and merge-train pipelines all arrive as this source; a failed job cancels the rest.
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      auto_cancel:
        on_new_commit: interruptible
        on_job_failure: all
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - if: $CI_COMMIT_TAG

# The car: automatic and blocking on a merge train and on a release tag; by hand on an MR's own pipeline.
.car-rules:
  rules:
    - if: $CI_MERGE_REQUEST_EVENT_TYPE == "merge_train"
    - if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+/
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      when: manual
      allow_failure: true

lint:
  extends: .node-pnpm
  stage: security
  interruptible: true
  tags:
    - $RUNNER_2XLARGE
  script:
    - node tools/task.mjs check
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_EVENT_TYPE != "merge_train"

validate:
  extends: [.node-pnpm, .car-rules]
  stage: test
  interruptible: true
  tags:
    - $RUNNER_2XLARGE
  script:
    - node tools/ci-search-tools.mjs /usr/local/bin
    - node tools/task.mjs validate

validate-unprivileged:
  extends: [.node-pnpm, .car-rules]
  stage: test
  interruptible: true
  tags:
    - $RUNNER_2XLARGE
  script:
    - node tools/ci-search-tools.mjs /usr/local/bin
    - node tools/task.mjs bundle
    - chown -R node:node "$CI_PROJECT_DIR"
    - setpriv --reuid=node --regid=node --init-groups env HOME=/home/node node tools/task.mjs test

rehearse:
  extends: .node-pnpm
  stage: test
  interruptible: true
  tags:
    - $RUNNER_2XLARGE
  script:
    - !reference [.pi-host, script]
    - node tools/task.mjs consumer-sim --no-model
  rules:
    - !reference [.car-rules, rules]
    - if: $CI_COMMIT_TAG =~ /^test-publish-/

validate keeps its two comment lines about ci-search-tools. validate-unprivileged is the pass a developer’s task validate makes first: task test as a user who is not root, so the 39 tests that need a permission to bite run before a merge. bundle runs first because the distribution’s tests read packages/pi/dist/; node is the node image’s own user. The comment block above validate ("DIVERGENCE FROM THE UPSTREAM STANDARD") is replaced by one that says the car is the gate and why two jobs run the suites. .publish-base, publish, publish-dry-run, published, pages, .pi-host, .node-pnpm and the scan overrides stay as they are.

4. Signatures: the push rule

reject_unsigned_commits on the project’s push rule refuses an unsigned commit at the push, which is where the hook’s loop and the signature-check job looked. It is set before the MR that removes those two merges (Order, step 5).

5. The project’s settings

P=projects/gadhs%2Fstandard%2Fpackage%2Fpi
glab api $P/push_rule -X PUT -F reject_unsigned_commits=true                      # step 5
glab api $P -X PUT -F merge_pipelines_enabled=true -F merge_trains_enabled=true \
  -F only_allow_merge_if_pipeline_succeeds=true -F allow_merge_on_skipped_pipeline=false \
  -F merge_trains_skip_train_allowed=false                                         # step 7
# undo, the operator's call when the runners are down:
glab api $P -X PUT -F merge_trains_enabled=false -F merge_pipelines_enabled=false \
  -F only_allow_merge_if_pipeline_succeeds=false

Each call is read back with a GET before the next step. A call the API refuses stops the work there and goes to the operator.

6. Landing an MR

AGENTS.md, "Agent session constraints (operator-set)": the bullet "Merge your own MR once the pre-push validate passes" is replaced by this text, which the operator approves with the plan:

The merge train is the merge gate (#960). git push -u origin <branch> (the hook runs the static checks, task check, and nothing else), glab mr create with Closes #N, then add the MR to the train: glab api -X PUT projects/gadhs%2Fstandard%2Fpackage%2Fpi/merge_requests/<iid>/merge -F auto_merge=true -F squash=false -F sha=<HEAD>. No approval is needed. The train’s pipeline runs the battery on the merged result and merges on green; the same call without auto_merge answers 405 by design. Wait for the merge in a job or a monitor that ends when the MR is merged or has left the train. A dropped car is a finding: fix it and add it again. Then note the merge SHA on the issue. task validate and consumer-sim in full are the release rehearsal, run here before a tag.

7. The release rehearsal

A release keeps its local run, once: on the release commit, before release tag, node tools/task.mjs validate and node tools/consumer-sim.mjs in full on a box with ADC. It is the one place consumer-sim’s 12 model rows run, and the tests the car’s image has no tool for. The release MR lands through the train like any other; the tag pipeline is unchanged in what it runs.

Scope

File Change

tools/task.mjs

Design 1

tools/lib/validate-stamp.mjs, tools/lib/test/validate-stamp.test.mjs

deleted (Design 1)

.githooks/pre-push

Design 2

.gitlab-ci.yml

Design 3

tools/lib/test/ci-gate.test.mjs

new: Tests, T1 to T6

AGENTS.md

Design 6

docs/modules/ROOT/pages/local-dev.adoc

§ The task runner: a check row, validate no longer "the pre-push battery", the prepush-validate row removed. § Hooks: pre-push as Design 2, the stamp paragraph removed. § Publishing: a new subsection "CI is the merge gate" (the table of Design 3, the calls of Design 5 with the undo, landing as Design 6, the skipped-in-the-car table’s follow-up issue); § Rehearsals: Design 7 in place of "Run consumer-sim in full, with a model, before a tag anyway"; the runner-class paragraph names lint and the three car jobs and drops the signature check

README.adoc

§ Contributing: task check runs on push; the NOTE says the train’s pipeline is the merge gate and a red pipeline blocks the merge

CONTRIBUTING.adoc

the "must be green before push" step and the Development block name check for a push and validate as the full local run

docs/modules/ROOT/pages/project-conventions.adoc

the CI images row: lint and validate-unprivileged beside validate; alpine:3 for signature-check removed

docs/modules/ROOT/pages/plans/ci-merge-train-gate.adoc, docs/modules/ROOT/nav.adoc

this plan, under Active

CHANGELOG.adoc

== Unreleased, one "Repo only" entry

packages/pi/test/distribution.test.ts reads .gitlab-ci.yml for the publisher line and the single pi pin; both stay, and the file is not edited.

Not in scope, each an issue or dropped: an Antora build on an MR’s pipeline; GitLab’s scans on MR pipelines (they stay on main, where the templates put them once bare-branch pipelines are gone); a switch that turns a skip the car should not have into a failure; Vertex credentials in CI; a Windows runner; `main’s push access.

Order of work

  1. Release 0.185.0 finishes as releases have so far: its branch chore/release-0.185.0 is cut and unpushed, and it is not part of this plan.

  2. File the issue. Branch chore/ci-merge-train-gate from main; commit this plan and its nav line; Status In progress.

  3. Design 1 to 3 and 6, the tests, the docs and the CHANGELOG entry, in commits on that branch. One full local task validate, and each mutant of Tests planted and seen to fail its test.

  4. Push (V2), open the MR. On its pipeline lint runs by itself; start validate, validate-unprivileged and rehearse by hand (V1). A red job is fixed on the branch until the three are green.

  5. Set the push rule (Design 5, first call) and read it back; V6.

  6. Merge the MR with the direct call, the last one made.

  7. Flip the settings (Design 5, second call) and read them back.

  8. Branch chore/ci-first-car: this plan’s Status to Done (date) — …, with an Erratum line for any deviation. Push, MR, V3, then add it to the train (V4).

  9. V5, the red car.

  10. Note the merge SHAs on the issue; file the follow-up issue V1’s table calls for, if it has rows, and the one that asks whether GitLab’s scans join the car; post the new flow to pi-win on the bus.

Tests

Contract, tools/lib/test/ci-gate.test.mjs. Each reads the files as text; a job’s block is the lines from its name at column 0 to the next line that starts at column 0.

Test Asserts Mutant it fails on

T1

workflow:’s rules are the MR event, `$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH and $CI_COMMIT_TAG, and no rule is a bare $CI_COMMIT_BRANCH

the bare-branch rule put back

T2

.car-rules holds three rules in this order: merge train with no when and no allow_failure; the v tag; the MR event with when: manual and allow_failure: true

allow_failure: true on the train rule; the last two swapped

T3

validate, validate-unprivileged and rehearse each take .car-rules; none has an allow_failure or a $CI_DEFAULT_BRANCH of its own

a main rule on validate

T4

validate-unprivileged’s script is, in order, `task.mjs bundle, chown -R node:node, and a setpriv --reuid=node --regid=node line that runs task.mjs test; validate’s runs `task.mjs validate

the setpriv prefix removed

T5

the hook and the lint job each run node tools/task.mjs check; the hook’s text holds no validate, no vitest and no task.mjs test; lint’s one rule excludes `merge_train

the hook’s line changed to task.mjs validate

T6

node tools/task.mjs prepush-validate exits 2 with the usage line, which lists check; in tools/task.mjs the body of validate opens with check();

check(); removed from validate

tools/lib/test/validate-stamp.test.mjs is deleted because the code it tests is; no other test is removed or changed.

Observed, recorded on the MRs:

  • V1 (step 4). The three car jobs green on the first MR’s pipeline. A table per package: tests run locally as user and as root (.pi/scratch/p952-validate.log), run by validate-unprivileged, run by validate; every test in a difference is named with what it needs.

  • V2 (step 4). The push runs task check and no suite; its wall time is recorded. A type error planted in the worktree refuses a push; it is removed.

  • V3 (step 8). PUT …/merge without auto_merge answers 405.

  • V4 (step 8). The first car: its train pipeline ran validate, validate-unprivileged and rehearse without a hand, the MR merged, and main’s pipeline ran `pages and the scans only.

  • V5 (step 9). A branch whose one change is a failing assertion in tools/judge-field (it passes task check), its MR added to the train: the car is dropped and main does not move. The MR is closed; deleting its branch is the human’s step.

  • V6 (step 5). A commit made unsigned with git commit-tree and pushed to refs/heads/scratch/unsigned-probe is refused by GitLab.

Risks

Risk Kind Mitigation

The runner fleet is down or queued: no car runs and nothing merges

fail-closed

the undo call of Design 5, the operator’s decision, documented in local-dev.adoc

A test that needs a tool the car’s image lacks skips there and no longer runs before a merge (35 today)

silent

V1’s table names each; the release rehearsal (Design 7) runs them before every tag; a follow-up issue for the rest

The unprivileged pass cannot run in the container (no node user, no setpriv, a path it cannot write)

fail-closed

the job is red at V1, before any setting changes

Consumer-sim’s model rows no longer run for each MR: a break in model-facing wiring reaches main

silent until the release rehearsal, fail-closed there

Design 7; the same run by hand for a change to a judge, review or helper prompt

The hook reads the worktree, so a dirty tree can pass for a broken commit

fail-closed

CI checks out the commit: lint on the MR, validate on the car

The hook is skipped (--no-verify, core.hooksPath unset)

fail-closed

lint runs the same verb on the MR’s pipeline (T5); the car runs validate

A pipeline is skipped or has no job, and the MR merges untested

fail-closed

allow_merge_on_skipped_pipeline=false (step 7’s read-back); every MR pipeline has lint (T5)

A Maintainer pushes to main directly, past the car

silent

the hook’s main guard, unchanged; pi’s commit guard refuses a commit on main; the next car tests main with that push in it

The push rule is not in force when the local and CI signature checks are removed

fail-open

step 5 sets it and V6 proves it before step 6 merges their removal

A tag is cut on a tree no car tested

fail-closed

the tag pipeline runs the car’s jobs before publish (T2’s tag rule)

A car is dropped and nobody looks

silent

Design 6: the wait is a job or monitor that ends on merged or dropped and wakes the session

A Windows-only break

silent, as today

unchanged: pi-win’s seat runs `validate by hand; no gate covered it before

GitLab’s scans (SAST, secret detection) ran on a branch’s own pipeline before its MR merged; with that pipeline gone they first run on main, after the merge

silent

they blocked no merge before either (the MR merged while they ran); an issue filed in step 10 asks whether they join the car

Delivery

The canonical page is docs/modules/ROOT/pages/local-dev.adoc; the release note is the "Repo only" entry in CHANGELOG.adoc == Unreleased (nothing ships: no package changes). The first MR carries Relates to #960, the first car Closes #960. After the car merges: the merge SHAs on the issue, the follow-up issues of step 10, and the bus post to pi-win.

Edit this page · latest