Skip to content

ci-gate --affected: iteration runs test only what the change can reach (ci-kit test history, M4) - #101

Merged
SSFSKIM merged 2 commits into
masterfrom
unit-affected
Oct 21, 2026
Merged

SSFSKIM merged 2 commits into
masterfrom
unit-affected

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 21, 2026

Copy link
Copy Markdown
Owner

M4 of ci-kit's test-history spec (docs/doperpowers/specs/2026-10-21-test-history-design.md, "Selection (M4)"). The architect agreed the rule on 2026-10-21. About three of every four unit runs are iteration runs on trees that never land. scripts/ci-gate.sh --affected lets such a run test only what its change can reach.

A selected run is never landing evidence. That holds even when a fallback made it run the whole suite. A red selected run counts as red. A landing still needs a full class 1a run on the head's tree, without --affected.

What changed

  • scripts/ci-gate.sh --affected. It fetches origin/master and lists the change in the pushed commit: every line of git diff --name-status -M -z from the merge base to the tested commit. If the fetch fails, it goes ahead, since a stale origin/master only widens the set. The list is written as:

    • Affected-Count: <n>;
    • one Affected: <status>\t<path>[\t<new path>] line per path;
    • Selection: affected.

    The commit's subject is ci-gate: <short> affected, and that subject is the run's display title, so gh run list and gh run view show affected. Above 200 paths it lists none, and the plan runs the whole suite with the reason "too many paths". The list reaches the plan as one environment variable, which Linux caps at 128 KiB; the bound keeps even renames between the tree's longest paths near 60 KiB. 200 is the 93rd percentile of the files a landing changed over the last 200 landings. The header documents the flag and the landing rule.

  • .github/scripts/gate-affected.mjs (new) holds the decision as a pure function, affected(message). Its result is either { paths, related } (run vitest related over related) or { paths, reason } (run the whole suite). gate-plan.mjs reads the Selection: trailer on a push only, and refuses any value other than affected. It then writes selection=affected and related=<JSON | empty> to its outputs, plus one summary line:

    • Selection: affected — <n> paths, unit runs vitest related, or
    • Selection: affected — full suite: <reason> (<the path>).

    A run without the trailer writes neither. A test pins its outputs and summary byte for byte.

  • .github/workflows/gate.yml. The plan exports selection and related. When related is set, the unit and unit:darwin test steps run .github/scripts/unit-related.mjs (new); otherwise they run the commands they always ran. That script calls vitest 5's startVitest with related and passWithNoTests. It exists because vitest's CLI cannot intersect related mode with file filters: related takes no filters, and --related is not an option of run. unit:darwin needs that intersection to keep its own file set (scripts/darwin-unit-files.sh). The JUnit report, the upload and the step names are unchanged.

The fallbacks

The architect's list, unchanged. The first one that applies gives the reason:

  1. the lockfile or any package.json;
  2. any vitest or vite config (vitest.config.*, vite.config.*, electron.vite.config.*), or test support: a non-test file under a support/ directory of a test tree (test/support, test/live/support, apps/desk-hub/test/support), which holds the setup files, the global setup, the config's own helper and the scripts suites spawn;
  3. gate files (.github/, scripts/);
  4. any path outside src/, test/, apps/<app>/src/ and apps/<app>/test/;
  5. a deleted or renamed non-test file;
  6. what tests read through fs or a glob. The build found two cases (below).

What the graph cannot see. I found this by reading the suites for readFileSync, readdir, import.meta.glob, query imports and spawned or bundled code, in test files and test support. Then I checked it against vitest 5.0.2's own getRelevantTestSpecifications, run locally.

  • Query imports are invisible to vitest's related walk. It checks existsSync on the dependency's id with the query still attached, so ?raw, ?inline and ?asset imports are dropped. Measured: src/renderer/src/styles/tokens.css reaches no suite, although four DOM suites import it ?raw. A plain .css or .json import is followed. So any non-script file in the source and test trees runs the whole suite: fixtures, snapshots, the guides' .md, css read as text, and the design-system defaults. This covers more than the data part of the fs/glob item.

  • The named data directories (READ_AS_DATA) fall back for script files too:

    • test/fixtures/;
    • test/snapshots/;
    • apps/desk-web/test/fixtures/;
    • src/artifacts/types/design_system/defaults/;
    • src/artifacts/slides/fixtures/claude/;
    • src/renderer/src/terminal/__fixtures__/.

    Outside the trees, the suites also read the following, which fallback 4 already covers: spikes/protocol-probe/fixtures, spikes/browser-probe, e2e/fixtures, e2e/support, apps/desk-hub/{deploy,fake-machine,local}, apps/desk-hub/wrangler.jsonc, apps/desk-web/public, and docs/doperpowers/evidence (read by src/shared/plugins/cli.test.ts).

  • ⚠ Source readers (SOURCE_READERS) are not fallbacks; this departs from the literal rule. Some suites read whole source trees through fs, a lint, a build, or a bundle they build and run:

    • the tokens guard (all of src/renderer);
    • compiled-suites.test (src/renderer, src/main/artifacts);
    • the read-only guard (src/engine-host/fs);
    • one-schema (lints src/);
    • bundle-guard and the preload bundle.test (they read out/, which the job builds from src/);
    • bridge.test (walks src/preload and src/shared);
    • react-compiler.test (four named files);
    • sigkill and retention-crash (an esbuild-bundled writer);
    • the hub's Worker suites (they reach apps/desk-hub/src only through the global setup's bundle, the fake machine's bin.ts and local/run.ts);
    • sw-imports.test (apps/desk-web/src/sw).

    Making these trees fallback directories would send nearly every change to the whole suite. Instead, a change under a reader's tree adds that reader to the related list; for the hub, it adds its local.ts and hub.ts, which brings in all 23 suites that import them. No fallback is weakened. CI-opt agreed this and told the architect. One place, with a comment, names the rule: a suite that starts reading a source tree this way belongs in the list, and the landing's full class 1a catches one that is missing.

Proof runs

All three are unit-only, on the pool, on scratch commits off this branch. This branch changes .github/ and scripts/, so a change taken from master would always fall back ("a gate file"). The proofs therefore took the change from this PR's head, as a session's will once this lands: they ran from a scratch clone whose origin/master was pinned at the PR head, with no fetch refspec. The script itself was unmodified.

  1. A source-only change. A comment edit in src/renderer/src/sidebar/reveal.ts: run 39570557690, green.
    • Its title is ci-gate: ce6b943d affected, and the summary reads Selection: affected — 1 paths, unit runs vitest related.
    • The related list was the module plus the five readers of src/renderer and src/.
    • 136 files, 2,006 tests, against 1,615 files and 22,450 tests in a full run.
    • The JUnit report's 136 (project, file) pairs equal exactly the set that vitest's own related computation gives locally for the same paths.
    • Unit job 234 s (test step 177 s). Full runs on the same base took 499 s (445 s) in proof 3 and 471 s (421 s) in the class 1a run below. Today's six other full unit runs took 468–532 s for the job.
    • Of the 177 s, vitest's graph walk took about 34 s before the first file ran. The tail was the two App.test.tsx, which the sidebar reaches through the whole-app mount; the compiled one took 56 s.
  2. A planted failure in reveal.test.ts (related to the module): run 39571488563, red: 1 failed | 2006 passed, the planted assertion.
  3. A fallback. A new test/fixtures/m4-proof.txt: run 39573713454, green. Its title is ci-gate: ab7b289a affected. The summary reads Selection: affected — full suite: read through fs, a glob or a query import (test/fixtures/m4-proof.txt), and the whole suite ran: 1,615 files, 22,450 passed and 80 skipped.

unit:darwin with --affected on the mini is not run here. CI-opt schedules that one.

Landing evidence

Class 1a on the pool at the head ebe0d6af5, without --affected: run 39575096972, green. static, unit and probes all passed.

  • The run's title is ci-gate: ebe0d6af, with no affected.
  • The plan wrote no selection.
  • unit ran the whole suite: 1,615 files, 22,450 passed and 80 skipped, in a 471 s job.

Master has moved since this branch's base 909a1e5bd by one commit, a594a452e, which touches only docs; it shares no path with this branch.

Tests

  • .github/scripts/gate-plan.test.mjs covers:
    • every fallback, each naming its path;
    • a rename or delete of a test file (the selection holds; the renamed file is related, the deleted one is not) and of a non-test file (full);
    • the bound, and a list that does not add up;
    • a change of zero paths;
    • the source readers;
    • a run with no trailer, whose outputs and summary are byte-identical;
    • a refused Selection: value;
    • the workflow's wiring;
    • that every named reader, tree and data directory exists, so a moved reader fails here.
  • scripts/ci-gate.test.mjs runs the script whole, against a local origin with a master, and covers:
    • the subject and trailers of a change holding an M, an A, a D and an R;
    • that gate-plan.mjs reads those trailers;
    • the bound at 201 paths;
    • a zero-path change, which aborted under macOS's Bash 3.2 until review round 1 (doperpowers:reviewer-medium; its one finding was fixed in ebe0d6a).
  • node --test .github/scripts/*.test.mjs scripts/*.test.mjs: 73 pass.

What the data says about the rule as written

I replayed the plan's decision over the whole diffs of the last 200 landings. Only 10 would select. In 143, a path outside the trees sends the run to the whole suite, almost always docs/ (141 landings touch it). Gate files account for 29, too many paths for 11, data for 4 and test support for 3. Leaving out docs/ would give 45 selections; leaving out docs/ and e2e/ would give 63.

Iteration runs are earlier states of a branch, with fewer docs edits, so this is a floor. The store records each run's selection, which will show the real rate. docs/ cannot simply be exempted: a unit suite reads docs/doperpowers/evidence. This is the question the spec's Decision Log left for the store's data.

Sminos-Session: CI-opt#a45b97a3 (doperpowers on macbook)

…h (ci-kit test history, M4)

scripts/ci-gate.sh --affected lists the change's paths (git diff --name-status -M from the merge base with
origin/master) in the pushed commit, under `Selection: affected` and the subject `ci-gate: <short> affected`.
The plan (gate-affected.mjs) narrows unit and unit:darwin to vitest's related mode over them, or runs the
full suite with the reason in its summary where the module graph cannot see: the lockfile or a package.json,
a vitest or vite config, test support, gate files, a path outside the source and test trees, a deleted or
renamed non-test file, a file read through fs, a glob or a query import. Suites that read source trees
without importing them (guards, builds, bundles) join the related list when their tree changes. unit:darwin
takes only the related suites among its own files (unit-related.mjs, vitest's API). A run without the
trailer is unchanged. A selected run is never landing evidence.

Sminos-Session: CI-opt#a45b97a3 (doperpowers on macbook)
Skip the path-trailer loop for an empty affected array: Bash 3.2 treats its expansion as unbound under set -u. Preserve the affected subject and zero-count trailers, with a regression test on master's unchanged tree.

Sminos-Session: CI-opt#a45b97a3 (doperpowers on macbook)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T09:30:19.794418Z ebe0d6a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

SSFSKIM added a commit that referenced this pull request Oct 21, 2026
… --affected for iteration runs: the trailers, vitest related, the fallbacks, READ_AS_DATA and SOURCE_READERS in place of the fs/glob rule; never landing evidence; the docs/ follow-up); §3.5's --affected bullet

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
@SSFSKIM
SSFSKIM merged commit ee9ecac into master Oct 21, 2026
@SSFSKIM
SSFSKIM deleted the unit-affected branch October 21, 2026 09:29

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ebe0d6af5d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// a support module in the list brings every suite that imports it. A suite that starts reading a source tree that way
// belongs here. One that is missing goes unrun in a selected run while it should have run, and the landing's full
// class 1a is what catches it.
export const SOURCE_READERS = [

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add the browser-import logging guard to source readers

When an affected run changes a script under src/main/browser/import/ other than log.ts, Vitest's import graph does not select src/main/browser/import/log.test.ts: that test imports only ./log but recursively reads every TypeScript file in the directory to enforce the no-console invariant. Consequently, a unit-only --affected run can pass without executing this guard; add this directory/test pair to SOURCE_READERS.

Useful? React with 👍 / 👎.

Comment thread scripts/ci-gate.sh
Comment on lines +201 to +202
trailers+=$'\n'"Selection: affected"$'\n'"Affected-Count: ${#affected_lines[@]}"
if ((${#affected_lines[@]} > 0 && ${#affected_lines[@]} <= AFFECTED_BOUND)); then for line in "${affected_lines[@]}"; do trailers+=$'\n'"Affected: $line"; done; fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Bound affected trailers by encoded byte size

When a change contains at most 200 unusually long paths, this count-only bound still writes every path into the commit message. For example, a few dozen paths near Linux's approximately 4 KiB path limit can make github.event.head_commit.message exceed the per-environment-string limit when assigned to HEAD_MESSAGE, preventing the plan step from starting instead of falling back to the full suite. Apply a byte-size bound to the serialized trailers, not only a path-count bound.

Useful? React with 👍 / 👎.

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.

1 participant