Files
PaperClipAI/packages/paperclip-runner/scripts/run-check-runner.test.mjs
T
Dotta 1c36d24d0c perf(ci): parallelize Runner Rust checks, Runner build, and typecheck lane (#22957)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Live 8-core PR runs (`45667106472`, `45665466678`, `45668834558`)
showed two critical-path stragglers on Rust- and TypeScript-heavy PRs:
> 1. `Verify Paperclip Runner (rust)` (`206s` step): ran a redundant
`cargo check --workspace` (`8.1s`) before `cargo test --release`,
executed all 44 compiled Rust test binaries **sequentially** (`119.2s`
vs `~50s` parallel!), and then re-invoked `cargo test --release` twice
more for `check:conformance-parity` and `check:replay-parity` (`~8s`).
> 2. `Typecheck + Release Registry` (`100s–147s` step): ran `CLI
guidance safety` (`2.9s`) and `typecheck @paperclipai/paperclip-runner`
(`5.6s`) serially before `prepare:runner-vendor`, ran
`packages/paperclip-runner` `build` (`17.1s` hit / `51.0s` miss)
serially across 12 steps, and scheduled lighter `7–10s` test projects
ahead of the 4 `17–25s` server test layers.
> - This pull request parallelizes `check:runner`
(`run-check-runner.mjs`), `packages/paperclip-runner` `build`
(`run-build.mjs`), and `scripts/ci-typecheck-lane.mjs` cleanly across 8
cores with full process-group signal cleanup (`stopActiveChildren`),
exact `CARGO_BIN_EXE_*` / `CARGO_MANIFEST_DIR` fidelity, fail-closed
parity assertions, exact `record-build-inputs --begin/--finish`
bracketing, and 100% check parity.

## Linked Issues or Issue Description

Refs #22804

**What existing behavior does this improve?**
Execution wall-clock of `Verify Paperclip Runner (rust)`, `Typecheck +
Release Registry`, and `Build` on 8-core runners.

**Subsystem affected**
packages/paperclip-runner/ and scripts/ — Rust test orchestration,
Runner package build, and monorepo typecheck DAG

**Current behavior**
`check:runner` runs `cargo check`, 44 Rust test binaries sequentially,
and 2 redundant parity re-runs; `packages/paperclip-runner` `build`
executes 12 build/check steps serially; `ci-typecheck-lane.mjs` blocks
`prepare:runner-vendor` behind serial `prepare` steps and under-utilizes
8-core / 32 GiB runners.

**Proposed behavior**
Execute `check:runner` with overlapped `acpx-profiles` / `cargo fmt
--check` / `cargo test --release --no-run` followed by LPT-ordered
concurrent execution of all 44 test binaries + `--doc` + fail-closed
parity verification; parallelize `packages/paperclip-runner` `build`
into race-free pre-dist / build / staging / post-dist phases;
parallelize `CLI guidance safety` and `typecheck
@paperclipai/paperclip-runner` in `ci-typecheck-lane.mjs`, LPT-order
post-declaration tasks, and tune 8-core / >=24 GiB concurrency
(`laneConcurrency: 8`, `serverDeclCheckers: 6`).

## What Changed

- **`packages/paperclip-runner/scripts/run-check-runner.mjs` &
`run-check-runner.test.mjs`:**
- Overlaps `check:acpx-profiles` and `cargo fmt --all -- --check` with
`cargo test --release --locked --workspace --no-run
--message-format=json-render-diagnostics`.
- Parses all 44 compiled test binaries with exact `CARGO_BIN_EXE_*` and
per-crate `CARGO_MANIFEST_DIR`, executes them concurrently in LPT order
(`codex_provider` first, `acpx_sidecar_stopped_time` isolated in its own
detached process group with `--test-threads=1`, plus `cargo test
--release --workspace --doc`).
- Verifies both `runs_the_mock_core_path_with_stable_output` and
`replay_fixture_parity` passed in the workspace run (failing closed if
missing or ignored), eliminating 2 redundant `cargo test`
re-invocations.
- **`packages/paperclip-runner/scripts/run-build.mjs` &
`run-build.test.mjs`:**
- Preserves exact `record-build-inputs.mjs --begin` / `--finish`
bracketing from the same parent PID, overlaps `eval-kernel + tsc`,
`cargo build --release` (honoring
`PAPERCLIP_RELEASE_RUNNER_ARTIFACTS_DIR`), and all 9 pure source-only
pre-dist checks, stages disjoint `dist/` outputs in parallel, and runs
all 5 `dist/`-importing checks (`check:runner-workflow-traceability`,
`check:protocol-coverage`, `check:semantic-contracts`,
`check:replay-goldens`, `check:semantic-action-catalog`) in parallel
post-dist.
- **`scripts/ci-typecheck-lane.mjs`,
`scripts/__tests__/ci-typecheck-lane.test.mjs`, &
`.github/scripts/tests/ci-plan.test.mjs`:**
- Moved `CLI guidance safety` and `typecheck
@paperclipai/paperclip-runner` (`needs: [PREPARE_RUNNER_VENDOR]` when
`runServer`) out of serial `prepare` into `tasks`.
- Ordered post-declaration tasks LPT (`tests/runner-e2e` -> 4 `server
layer test-*` -> smaller projects) and tuned 8+ core / >=24 GiB runners
to `laneConcurrency: 8`, `serverDeclCheckers: 6`.
- **`packages/paperclip-runner/scripts/run-check-static.mjs`,
`run-prep-tests.mjs`, & `package.json`:**
- Shared `stopActiveChildren` / process-group runner helpers across
`run-check-static.mjs`, `run-check-runner.mjs`, and `run-build.mjs`;
wired `run-build.test.mjs` and `run-check-runner.test.mjs` into
`PREP_TEST_FILES`.

## Verification

- `node --test .github/scripts/tests/*.test.mjs
scripts/__tests__/ci-typecheck-lane.test.mjs
scripts/check-test-budget.test.mjs
scripts/__tests__/runner-release-crate-cache.test.mjs` — **855/855
PASS**
- `node --test scripts/run-check-runner.test.mjs
scripts/run-build.test.mjs scripts/run-check-static.test.mjs
scripts/build-inputs.test.mjs scripts/stage-runner-binary.test.mjs` (in
`packages/paperclip-runner`) — **32/32 PASS**
- `node scripts/check-test-budget.mjs --base origin/master` and `node
scripts/check-maps.mjs` — **PASS**
- Live Linux Cargo/Runner and monorepo Typecheck/Build execution
verified end-to-end by PR CI.

## Risks

- Low risk: all 9 pre-dist checks were verified pure source read-only
while all 5 `dist/`-importing checks run strictly after `tsc` and asset
staging; Rust parity checks fail closed if either test is absent or
ignored; process-group cancellation ensures zero orphaned test
processes.

## Model Used

- Gemini 4 Neon (High) via Antigravity agent swarm (`server-prune`,
`verifier`, `ci-pipeline`).

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-11-25 13:40:47 -06:00

129 lines
5.5 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import {
buildRunnerCheckPlan,
formatCargoCompilerDiagnostics,
orderTestBinariesLpt,
parseCargoTestArtifacts,
REQUIRED_PARITY_TESTS,
runWithConcurrency,
verifyRequiredParityTests,
} from "./run-check-runner.mjs";
test("buildRunnerCheckPlan overlaps acpx-profiles, cargo fmt, and cargo test --release --no-run", () => {
const plan = buildRunnerCheckPlan({ cpus: 8 });
assert.equal(plan.binaryConcurrency, 6);
assert.equal(plan.heavyTestThreads, 8);
assert.equal(plan.defaultTestThreads, 4);
const labels = plan.compilePhase.map((step) => step.label);
assert.deepEqual(labels, ["check:acpx-profiles", "cargo:fmt", "cargo:test-no-run"]);
const cargoStep = plan.compilePhase[2];
assert.ok(cargoStep.args.includes("--release"));
assert.ok(cargoStep.args.includes("--no-run"));
assert.ok(cargoStep.args.includes("--message-format=json-render-diagnostics"));
assert.ok(plan.docTestCommand.args.includes("--doc"));
assert.deepEqual(plan.requiredParityTests, REQUIRED_PARITY_TESTS);
});
test("parseCargoTestArtifacts extracts unique test executables, manifest dirs, and CARGO_BIN_EXE_* map", () => {
const jsonLines = [
"warning: plain non-json line",
JSON.stringify({
reason: "compiler-artifact",
manifest_path: "/repo/packages/paperclip-runner/runner/crates/runner-core/Cargo.toml",
target: { name: "paperclip-runnerd", kind: ["bin"] },
profile: { test: false },
executable: "/repo/target/release/paperclip-runnerd",
}),
JSON.stringify({
reason: "compiler-artifact",
manifest_path: "/repo/packages/paperclip-runner/runner/crates/runner-core/Cargo.toml",
target: { name: "paperclip_runner_core", kind: ["lib"] },
profile: { test: true },
executable: "/repo/target/release/deps/paperclip_runner_core-aaa",
}),
JSON.stringify({
reason: "compiler-artifact",
manifest_path: "/repo/packages/paperclip-runner/runner/crates/runner-core/Cargo.toml",
target: { name: "codex_provider", kind: ["test"] },
profile: { test: true },
executable: "/repo/target/release/deps/codex_provider-bbb",
}),
JSON.stringify({
reason: "compiler-artifact",
manifest_path: "/repo/packages/paperclip-runner/runner/crates/runner-core/Cargo.toml",
target: { name: "codex_provider", kind: ["test"] },
profile: { test: true },
executable: "/repo/target/release/deps/codex_provider-bbb",
}),
JSON.stringify({
reason: "compiler-artifact",
manifest_path: "/repo/packages/paperclip-runner/runner/crates/process-table/Cargo.toml",
target: { name: "paperclip_process_table", kind: ["lib"] },
profile: { test: true },
executable: "/repo/target/release/deps/paperclip_process_table-ccc",
}),
].join("\n");
const { testBinaries, binEnv } = parseCargoTestArtifacts(jsonLines);
assert.deepEqual(binEnv, {
"CARGO_BIN_EXE_paperclip-runnerd": "/repo/target/release/paperclip-runnerd",
});
assert.equal(testBinaries.length, 3);
assert.equal(testBinaries[0].label, "paperclip_runner_core (lib)");
assert.equal(testBinaries[0].manifestDir, "/repo/packages/paperclip-runner/runner/crates/runner-core");
assert.equal(testBinaries[2].manifestDir, "/repo/packages/paperclip-runner/runner/crates/process-table");
});
test("orderTestBinariesLpt puts slowest Rust test binaries first", () => {
const ordered = orderTestBinariesLpt([
{ name: "oom_score", label: "oom_score" },
{ name: "acpx_park_preparation", label: "acpx_park_preparation" },
{ name: "codex_provider", label: "codex_provider" },
{ name: "acpx_sidecar_stopped_time", label: "acpx_sidecar_stopped_time" },
]);
assert.deepEqual(
ordered.map((entry) => entry.name),
["codex_provider", "acpx_sidecar_stopped_time", "acpx_park_preparation", "oom_score"],
);
});
test("verifyRequiredParityTests matches exact and prefix-filtered passing tests and fails closed when missing", () => {
const passing = [
"test tests::runs_the_mock_core_path_with_stable_output ... ok",
"test replay::tests::replay_fixture_parity_happy_path ... ok",
"test replay::tests::replay_fixture_parity_failed_run ... ok",
].join("\n");
assert.deepEqual(verifyRequiredParityTests(passing), []);
const ignored = [
"test tests::runs_the_mock_core_path_with_stable_output ... ignored",
"test replay::tests::replay_fixture_parity_happy_path ... ok",
].join("\n");
assert.deepEqual(verifyRequiredParityTests(ignored), ["runs_the_mock_core_path_with_stable_output"]);
assert.deepEqual(verifyRequiredParityTests(""), REQUIRED_PARITY_TESTS);
});
test("runWithConcurrency bounds parallelism and preserves result ordering", async () => {
let active = 0;
let peak = 0;
const results = await runWithConcurrency([10, 20, 30, 40, 50], 2, async (item) => {
active += 1;
peak = Math.max(peak, active);
await new Promise((resolve) => setTimeout(resolve, 5));
active -= 1;
return item * 2;
});
assert.equal(peak, 2);
assert.deepEqual(results, [20, 40, 60, 80, 100]);
});
test("formatCargoCompilerDiagnostics extracts rendered compiler messages and falls back to raw stdout", () => {
const jsonLines = [
JSON.stringify({ reason: "compiler-artifact", target: { name: "x" } }),
JSON.stringify({ reason: "compiler-message", message: { rendered: "error[E0425]: cannot find value\n" } }),
].join("\n");
assert.equal(formatCargoCompilerDiagnostics(jsonLines), "error[E0425]: cannot find value\n");
assert.equal(formatCargoCompilerDiagnostics("plain cargo failure\n"), "plain cargo failure\n");
});