Files
PaperClipAI/scripts/__tests__/local-verify-partitions.test.mjs
T
021be2c56d perf(ci): split local-verify tests so release registry runs them in parallel (#22819)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Every pull request runs the "Typecheck + Release Registry" CI job.
> - In a recent PR run that ran all checks, this job was the longest
check (450s). In other recent PR runs it took 405s and 413s.
> - In those runs, the `release registry tests` task took 178–202s.
Almost all of that time was one file:
`scripts/__tests__/local-verify.test.mjs`. Its tests ran one after the
other for ~200s, because `node --test` runs the tests in one file in
sequence.
> - While that task runs, it holds one of the three slots of the
typecheck lane and adds CPU load. This makes server declarations and
test projects start later and run slower.
> - This pull request splits the file into three balanced files, so
`node --test` runs them in parallel processes.
> - The benefit is a shorter release registry task (local measurement:
179s → 65s for these tests) and a shorter Typecheck + Release Registry
job.

## Linked Issues or Issue Description

No existing GitHub issue covers this, so here is the issue, following
the enhancement template.

**What existing behavior does this improve?**
How long the CI job "Typecheck + Release Registry" takes on PRs that
select the release registry tests.

**Subsystem affected**
CI and repository scripts (`scripts/__tests__`,
`test:release-registry`).

**Current behavior**
In the PR runs that select it, the job is the longest check (405–450s).
Its `release registry tests` task takes ~200s. Almost all of that time
comes from `scripts/__tests__/local-verify.test.mjs`. `node --test` runs
the tests in one file in sequence.

**Proposed behavior**
Move the shared fixture into a helper module. Split the tests into three
files with similar run times, so `node --test` runs them in parallel
processes.

**Reason and benefit**
Faster CI feedback for many PRs. What the tests check does not change.

**Breaking changes**
None. Only test files and the `test:release-registry` file list change.

## What Changed

- Moved `fixture()` and `repository` from
`scripts/__tests__/local-verify.test.mjs` to a new helper module,
`scripts/__tests__/local-verify-fixture.mjs`. The code is the same.
- Split the tests into three files with similar run times (measured on
CI):
- `local-verify.test.mjs` (~70s): real selected execution, plus the fast
snapshot and plan tests.
- `local-verify-partitions.test.mjs` (~68s): the general-workspaces-b/c
partition tests, installed dependency invalidation, and local server
selection.
- `local-verify-reuse.test.mjs` (~61s): explicit full execution, source
mutation and interruption, stale SDK pins, and edit during
fingerprinting.
- Added the two new files to `test:release-registry` in `package.json`.
- Refreshed `tests/runner-e2e/source-sdk-public-inputs.json`, because
`package.json` is a pinned SDK public input.
- The test bodies are the same. Only the imports changed.

## Verification

- Original file alone: `node --test
scripts/__tests__/local-verify.test.mjs` → 179s wall time (4 vCPU).
- Three new files: `node --test
scripts/__tests__/local-verify*.test.mjs` → 65s wall time. Each run has
the same 15 tests.
- In this sandbox, one test ("an edit between diff discovery and
fingerprinting...") fails both before and after the change. The cause is
a local `git` launcher wrapper that refuses a recursive call. CI does
not have this wrapper. The CI `Typecheck + Release Registry` job on this
PR runs all of the tests.
- Expected CI effect: the `release registry tests` task goes from ~200s
to ~70–100s (the CI runner has more CPU load than the local test). The
task frees its lane slot ~100s earlier. For PRs that select release
registry tests, I expect the Typecheck + Release Registry job to save
~30–60s (from ~405–450s). PRs that do not select release registry tests
are not affected.

## Risks

- Low risk. This change affects only test files.
- The three files now run at the same time. Each test uses its own
temporary fixture directory, so the tests do not share state.
- More parallel processes add CPU load to the 4 vCPU typecheck runner
for a shorter time. The total CPU work is the same.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), run as a Claude Code agent with
tool use (shell, GitHub CLI).

## 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
- [ ] I have run tests locally and they pass (14/15 pass locally; the
one failure is the sandbox git wrapper and also fails on master)
- [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
- [ ] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: devinfoley <139239+devinfoley@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 17:13:10 -08:00

91 lines
6.1 KiB
JavaScript

import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { lstatSync, readFileSync, symlinkSync, utimesSync } from "node:fs";
import path from "node:path";
import test from "node:test";
import { fixture } from "./local-verify-fixture.mjs";
for (const [group, task, primary, directory] of [
["general-workspaces-b", "ci:workspaces-b", "@paperclipai/shared", "packages/shared"],
["general-workspaces-c", "ci:db", "@paperclipai/db", "packages/db"],
]) test(`${group} discovers and executes reusable and fresh selected partitions`, { timeout: 180_000 }, t => {
const f = fixture(t);
const inventory = JSON.parse(execFileSync(process.execPath, [path.join(f.root, "scripts/run-vitest-stable.mjs"),
"--mode", "general", "--group", group, "--dry-run"], { cwd: f.root, env: f.env, encoding: "utf8" }));
const projects = inventory.workspaceProjects.map((project, index) => {
const folder = project === primary ? directory : `packages/fixture-${index}`;
f.write(`${folder}/vitest.config.mjs`, `export default {test:{name:${JSON.stringify(project)},include:["src/**/*.test.ts"]}};`);
f.write(`${folder}/src/independent.test.ts`, 'import {test,expect} from "vitest"; test("independent workspace",()=>expect(1).toBe(1));');
return folder;
});
f.write("ui/src/leaf.ts", "export const value = 1;\n");
f.write("vitest.config.mjs", `export default {test:{projects:${JSON.stringify(projects)}}};`);
f.write(".github/ci-task-matrix.json", JSON.stringify({ general_tests: [{ task, group }] }));
f.write(`${directory}/src/leaf.ts`, "export const value = 1;\n");
f.write(`${directory}/src/reusable.test.ts`, 'import {test,expect} from "vitest"; import {value} from "./leaf"; test("workspace consumer",()=>expect(value).toBeGreaterThan(0));');
f.write(`${directory}/src/fresh.test.ts`, 'import {test,expect} from "vitest"; import {readFileSync} from "node:fs"; import {value} from "./leaf"; test("fresh workspace consumer",()=>expect(readFileSync(process.env.LOCAL_VERIFY_INPUT,"utf8")).toBe(String(value)));');
f.git("add", "."); f.git("-c", "user.name=Test", "-c", "user.email=test@example.invalid", "commit", "-qm", "workspace baseline");
const base = f.git("rev-parse", "HEAD");
f.write(`${directory}/src/leaf.ts`, "export const value = 2;\n");
f.write(".turbo/external-input", "2");
const env = { LOCAL_VERIFY_INPUT: path.join(f.root, ".turbo/external-input") };
const first = f.run(["--base", base], env);
assert.equal(first.status, 0, first.text);
assert.equal((first.text.match(/Test Files\s+1 passed/g) ?? []).length, 2, first.text);
const reused = f.run(["--base", base], env);
assert.equal(reused.status, 0, reused.text);
assert.ok(reused.text.includes(`Reusing passed ${group}-reusable`), reused.text);
assert.equal((reused.text.match(/Test Files\s+1 passed/g) ?? []).length, 1, reused.text);
f.write(".turbo/external-input", "changed externally");
const changed = f.run(["--base", base], env);
assert.equal(changed.status, 1, changed.text);
assert.match(changed.text, /fresh workspace consumer/);
});
test("installed dependency code changes invalidate a real passing result", { timeout: 120_000 }, t => {
const f = fixture(t);
const installed = "node_modules/.pnpm/clsx@1.0.0/node_modules/clsx";
f.write(`${installed}/package.json`, '{"name":"clsx","version":"1.0.0","type":"module","exports":"./index.mjs"}');
f.write(`${installed}/index.mjs`, "export default () => 2;\n");
symlinkSync(path.join(f.root, installed), path.join(f.root, "node_modules/clsx"), "dir");
f.write("ui/src/consumer.test.ts", 'import {test,expect} from "vitest"; import clsx from "clsx"; import {value} from "./leaf"; test("installed dependency",()=>expect(clsx()).toBe(value));');
const first = f.run();
assert.equal(first.status, 0, first.text);
const reused = f.run();
assert.equal(reused.status, 0, reused.text);
assert.match(reused.text, /reusing a passing local result/);
const moduleFile = path.join(f.root, installed, "index.mjs"), original = lstatSync(moduleFile);
f.write(`${installed}/index.mjs`, "export default () => 0;\n");
utimesSync(moduleFile, original.atime, original.mtime);
const changed = f.run();
assert.equal(changed.status, 1, changed.text);
assert.match(changed.text, /installed dependency/);
assert.doesNotMatch(changed.text, /reusing a passing local result/);
});
test("local server selection retains native suites and serialized ownership under a CI caller", { timeout: 120_000 }, t => {
const f = fixture(t);
f.write("ui/src/leaf.ts", "export const value = 1;\n");
f.write("vitest.config.mjs", 'export default {test:{projects:["server"]}};');
f.write("server/vitest.config.mjs", 'export default {test:{name:"@paperclipai/server",include:["src/**/*.test.ts"]}};');
f.write("server/src/leaf.ts", "export const value = 1;\n");
const native = "server/src/services/native-runtime/plugin-runner-probe.test.ts";
const serialized = "server/src/__tests__/authz-owner.test.ts";
for (const [file, imported] of [[native, "../../leaf"], [serialized, "../leaf"]]) {
f.write(file, `import {test,expect} from "vitest"; import {value} from ${JSON.stringify(imported)}; test("local owner",()=>expect(value).toBeGreaterThan(0));`);
}
f.write(".github/ci-task-matrix.json", JSON.stringify({
general_tests: [{ task: "ci:server", group: "general-server-without-chat" }],
verify_serialized_server: [{ task: "ci:serialized" }],
}));
f.git("add", "."); f.git("-c", "user.name=Test", "-c", "user.email=test@example.invalid", "commit", "-qm", "server baseline");
const base = f.git("rev-parse", "HEAD");
f.write("server/src/leaf.ts", "export const value = 2;\n");
const result = f.run(["--base", base], { GITHUB_WORKFLOW: "PR" });
assert.equal(result.status, 0, result.text);
assert.equal((result.text.match(/Test Files\s+1 passed/g) ?? []).length, 2);
const record = JSON.parse(readFileSync(path.join(f.root, ".turbo/local-verify/last-run.json"), "utf8"));
assert.deepEqual(record.plan.manifest.lanes["general-server-without-chat"].shards[0]["@paperclipai/server"], [native]);
assert.deepEqual(record.plan.manifest.lanes.serialized.shards[0]["@paperclipai/server"], [serialized]);
});