mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 01:39:51 +01:00
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>
This commit is contained in:
6 files changed
+286
-267
No files matched your search
+1
-1
@@ -61,7 +61,7 @@
|
||||
"smoke:notion-generic-live": "node scripts/smoke/notion-generic-live.mjs",
|
||||
"smoke:posthog-live": "node scripts/smoke/posthog-live.mjs",
|
||||
"smoke:terminal-bench-loop-skill": "node scripts/smoke/terminal-bench-loop-skill-smoke.mjs",
|
||||
"test:release-registry": "node scripts/ci-profile/node-test.mjs scripts/macos-runner-runtime.test.mjs scripts/macos-runner-runtime-cache.test.mjs scripts/macos-runner-runtime-workflow.test.mjs scripts/ci-profile/reporters.test.mjs scripts/ci/retry-reporter.test.mjs scripts/ci/stalled-file-reporter.test.mjs scripts/__tests__/runner-vitest-package-lanes.test.mjs scripts/__tests__/canary-startup-playwright.test.mjs scripts/__tests__/cursor-public-install-sandbox.test.mjs scripts/__tests__/grok-public-install-sandbox.test.mjs scripts/__tests__/public-install-closure.test.mjs scripts/__tests__/public-install-registry.test.mjs scripts/__tests__/prefetch-child.test.mjs scripts/__tests__/stage-bundled-packages.test.mjs scripts/__tests__/pack-staged-packages.test.mjs scripts/__tests__/retain-runner-qualification-packages.test.mjs scripts/__tests__/runner-release-crate-cache.test.mjs scripts/__tests__/runner-debug-crate-cache.test.mjs scripts/__tests__/agent-build-cache.test.mjs scripts/__tests__/agent-preflight.test.mjs scripts/__tests__/vitest-worker-isolation.test.mjs scripts/verify-release-registry-state.test.mjs scripts/release-package-map.test.mjs scripts/check-release-package-bootstrap.test.mjs scripts/check-no-git-push.test.mjs scripts/release-lib.test.mjs scripts/draft-stable-notes.test.mjs scripts/release-registry-versions.test.mjs scripts/link-plugin-dev-sdk.test.js scripts/acpx-patch-packaging.test.mjs scripts/service-onboard-smoke.test.mjs scripts/docker-onboard-smoke.test.mjs scripts/preview-artifacts.test.mjs scripts/cloud-migrator-artifacts.test.mjs scripts/typecheck-test-programs.test.mjs scripts/__tests__/local-verify.test.mjs scripts/test-sandbox-providers.test.mjs scripts/__tests__/ci-typecheck-lane.test.mjs scripts/scale-ramp/scale-ramp.test.ts scripts/scale-ramp/scale-ramp-spend.test.ts",
|
||||
"test:release-registry": "node scripts/ci-profile/node-test.mjs scripts/macos-runner-runtime.test.mjs scripts/macos-runner-runtime-cache.test.mjs scripts/macos-runner-runtime-workflow.test.mjs scripts/ci-profile/reporters.test.mjs scripts/ci/retry-reporter.test.mjs scripts/ci/stalled-file-reporter.test.mjs scripts/__tests__/runner-vitest-package-lanes.test.mjs scripts/__tests__/canary-startup-playwright.test.mjs scripts/__tests__/cursor-public-install-sandbox.test.mjs scripts/__tests__/grok-public-install-sandbox.test.mjs scripts/__tests__/public-install-closure.test.mjs scripts/__tests__/public-install-registry.test.mjs scripts/__tests__/prefetch-child.test.mjs scripts/__tests__/stage-bundled-packages.test.mjs scripts/__tests__/pack-staged-packages.test.mjs scripts/__tests__/retain-runner-qualification-packages.test.mjs scripts/__tests__/runner-release-crate-cache.test.mjs scripts/__tests__/runner-debug-crate-cache.test.mjs scripts/__tests__/agent-build-cache.test.mjs scripts/__tests__/agent-preflight.test.mjs scripts/__tests__/vitest-worker-isolation.test.mjs scripts/verify-release-registry-state.test.mjs scripts/release-package-map.test.mjs scripts/check-release-package-bootstrap.test.mjs scripts/check-no-git-push.test.mjs scripts/release-lib.test.mjs scripts/draft-stable-notes.test.mjs scripts/release-registry-versions.test.mjs scripts/link-plugin-dev-sdk.test.js scripts/acpx-patch-packaging.test.mjs scripts/service-onboard-smoke.test.mjs scripts/docker-onboard-smoke.test.mjs scripts/preview-artifacts.test.mjs scripts/cloud-migrator-artifacts.test.mjs scripts/typecheck-test-programs.test.mjs scripts/__tests__/local-verify.test.mjs scripts/__tests__/local-verify-partitions.test.mjs scripts/__tests__/local-verify-reuse.test.mjs scripts/test-sandbox-providers.test.mjs scripts/__tests__/ci-typecheck-lane.test.mjs scripts/scale-ramp/scale-ramp.test.ts scripts/scale-ramp/scale-ramp-spend.test.ts",
|
||||
"storybook-visual:baseline": "node scripts/storybook-visual-baseline.mjs",
|
||||
"test:storybook-visual": "node scripts/storybook-visual-baseline.mjs download && node scripts/storybook-visual-baseline.mjs verify && pnpm build-storybook && npx playwright test --config tests/storybook-visual/playwright.config.ts",
|
||||
"test:storybook-visual:update": "node scripts/storybook-visual-baseline.mjs download && pnpm build-storybook && npx playwright test --config tests/storybook-visual/playwright.config.ts --update-snapshots && node scripts/storybook-visual-baseline.mjs pack",
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFileSync, spawnSync } from "node:child_process";
|
||||
import { cpSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { stripVTControlCharacters } from "node:util";
|
||||
import { localEnvironment } from "../local-verify/inputs.mjs";
|
||||
|
||||
export const repository = fileURLToPath(new URL("../../", import.meta.url));
|
||||
|
||||
export function fixture(t) {
|
||||
const root = realpathSync(mkdtempSync(path.join(tmpdir(), "local-verify-")));
|
||||
t.after(() => rmSync(root, { recursive: true, force: true }));
|
||||
const write = (file, text) => {
|
||||
mkdirSync(path.dirname(path.join(root, file)), { recursive: true });
|
||||
writeFileSync(path.join(root, file), text);
|
||||
};
|
||||
for (const directory of ["scripts/ci", "scripts/local-verify", ".github/scripts"]) {
|
||||
cpSync(path.join(repository, directory), path.join(root, directory), { recursive: true });
|
||||
}
|
||||
for (const file of ["scripts/local-verify.mjs", "scripts/run-vitest-stable.mjs", "scripts/general-server-shard.mjs",
|
||||
"scripts/test-line-shard.mjs", "scripts/ci-profile/record.mjs", "turbo.json", ".github/ci-task-matrix.json"]) {
|
||||
write(file, readFileSync(path.join(repository, file), "utf8"));
|
||||
}
|
||||
for (const directory of ["server/src/__tests__", "server/scripts"]) mkdirSync(path.join(root, directory), { recursive: true });
|
||||
mkdirSync(path.join(root, "node_modules/.pnpm"), { recursive: true });
|
||||
for (const name of ["vitest", "oxc-parser", ".bin"]) {
|
||||
symlinkSync(path.join(repository, "node_modules", name), path.join(root, "node_modules", name), "dir");
|
||||
}
|
||||
for (const file of ["node_modules/.modules.yaml", "node_modules/.pnpm/lock.yaml"]) {
|
||||
write(file, readFileSync(path.join(repository, file), "utf8"));
|
||||
}
|
||||
write(".gitignore", "node_modules\nnode_modules/\n.turbo/\n.env\n");
|
||||
write("package.json", JSON.stringify({ name: "local-verification-fixture", private: true, type: "module", packageManager: "pnpm@9.15.4",
|
||||
scripts: { verify: "node scripts/local-verify.mjs", "test:run": "vitest run" } }));
|
||||
write("vitest.config.mjs", 'export default {test:{projects:["ui","cli"]}};');
|
||||
for (const [directory, name] of [["ui", "@paperclipai/ui"], ["cli", "paperclipai"]]) {
|
||||
write(`${directory}/vitest.config.mjs`, `export default {test:{name:${JSON.stringify(name)},include:["src/**/*.test.ts"]}};`);
|
||||
}
|
||||
write("ui/src/leaf.ts", "export const value = 1;\n");
|
||||
write("ui/src/other.ts", "export const other = 1;\n");
|
||||
write("ui/src/consumer.test.ts", 'import {test,expect} from "vitest"; import {value} from "./leaf"; test("affected consumer",()=>{expect(value).toBeGreaterThan(0);expect(process.env.LOCAL_VERIFY_FLAVOR).not.toBe("fail");});');
|
||||
write("ui/src/unrelated.test.ts", 'import {test,expect} from "vitest"; import {other} from "./other"; test("unrelated full-suite control",()=>expect(other).toBe(123456));');
|
||||
write("cli/src/independent.test.ts", 'import {test,expect} from "vitest"; test("unchanged consumer project",()=>expect(1).toBe(1));');
|
||||
const git = (...args) => execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
||||
git("init", "-q"); git("add", ".");
|
||||
git("-c", "user.name=Test", "-c", "user.email=test@example.invalid", "commit", "-qm", "baseline");
|
||||
const base = git("rev-parse", "HEAD");
|
||||
write("ui/src/leaf.ts", "export const value = 2;\n");
|
||||
const env = localEnvironment({ ...process.env, FORCE_COLOR: "0" });
|
||||
delete env.NODE_TEST_CONTEXT;
|
||||
delete env.DATABASE_URL;
|
||||
delete env.PAPERCLIP_TEST_POSTGRES_ADMIN_URL;
|
||||
for (const name of Object.keys(env)) if (/^PAPERCLIP_.*_TEST_DATABASE_URL$/.test(name)) delete env[name];
|
||||
const run = (args = [], extra = {}) => {
|
||||
const result = spawnSync(process.execPath, [path.join(root, "scripts/local-verify.mjs"), "--base", base, ...args], {
|
||||
cwd: root, env: { ...env, ...extra }, encoding: "utf8", timeout: 120_000, maxBuffer: 8 * 1024 * 1024,
|
||||
});
|
||||
assert.equal(result.error, undefined);
|
||||
return { ...result, text: stripVTControlCharacters(result.stdout + result.stderr) };
|
||||
};
|
||||
return { root, write, git, base, env, run };
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
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]);
|
||||
});
|
||||
@@ -0,0 +1,126 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { chmodSync, readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import { stripVTControlCharacters } from "node:util";
|
||||
import { fixture, repository } from "./local-verify-fixture.mjs";
|
||||
|
||||
test("explicit full execution cannot reuse a passing subset; opaque checks stay fresh", { timeout: 180_000 }, async t => {
|
||||
const f = fixture(t);
|
||||
assert.equal(f.run().status, 0);
|
||||
const full = f.run(["--full"]);
|
||||
assert.equal(full.status, 1, full.text);
|
||||
assert.match(full.text, /unrelated full-suite control/);
|
||||
f.write("ui/src/consumer.test.ts", 'import {test,expect} from "vitest"; import {readFileSync} from "node:fs"; import {value} from "./leaf"; test("opaque fresh check",()=>expect(readFileSync(process.env.LOCAL_VERIFY_INPUT,"utf8")).toBe(String(value)));');
|
||||
f.git("add", "ui/src/consumer.test.ts");
|
||||
f.write(".turbo/external-input", "2");
|
||||
const input = { LOCAL_VERIFY_INPUT: path.join(f.root, ".turbo/external-input") };
|
||||
const opaque = f.run([], input);
|
||||
assert.equal(opaque.status, 0, opaque.text);
|
||||
assert.match(opaque.text, /Test Files\s+1 passed/);
|
||||
const fresh = f.run([], input);
|
||||
assert.equal(fresh.status, 0, fresh.text);
|
||||
assert.match(fresh.text, /Test Files\s+1 passed/);
|
||||
f.write(".turbo/external-input", "changed externally");
|
||||
const external = f.run([], input);
|
||||
assert.equal(external.status, 1, external.text);
|
||||
assert.match(external.text, /opaque fresh check/);
|
||||
});
|
||||
|
||||
test("source mutation and interruption do not publish reusable passes", { timeout: 120_000 }, async t => {
|
||||
const f = fixture(t);
|
||||
const runControlled = action => new Promise((resolve, reject) => {
|
||||
const child = spawn(process.execPath, [path.join(f.root, "scripts/local-verify.mjs"), "--base", f.base, "--no-cache"], {
|
||||
cwd: f.root, env: f.env, stdio: ["ignore", "pipe", "pipe"],
|
||||
});
|
||||
let text = "", acted = false;
|
||||
const timer = setTimeout(() => { child.kill("SIGTERM"); reject(new Error("Controlled verification did not finish")); }, 60_000);
|
||||
const collect = bytes => {
|
||||
text += bytes;
|
||||
if (!acted && text.includes("[verify] Running")) { acted = true; action(child); }
|
||||
};
|
||||
child.stdout.on("data", collect); child.stderr.on("data", collect);
|
||||
child.once("error", reject);
|
||||
child.once("close", (code, signal) => { clearTimeout(timer); resolve({ code, signal, text, acted }); });
|
||||
});
|
||||
const changed = await runControlled(() => f.write("ui/src/leaf.ts", "export const value = 4;\n"));
|
||||
assert.equal(changed.acted, true);
|
||||
assert.equal(changed.code, 1, changed.text);
|
||||
assert.match(changed.text, /Inputs changed during verification/);
|
||||
const beforeInterrupt = f.run();
|
||||
assert.equal(beforeInterrupt.status, 0, beforeInterrupt.text);
|
||||
const interrupted = await runControlled(child => child.kill("SIGTERM"));
|
||||
assert.equal(interrupted.acted, true);
|
||||
assert.equal(interrupted.code, 143, interrupted.text);
|
||||
const result = f.run();
|
||||
assert.equal(result.status, 0, result.text);
|
||||
assert.match(result.text, /Test Files\s+1 passed/);
|
||||
assert.doesNotMatch(result.text, /reusing a passing local result/);
|
||||
});
|
||||
|
||||
test("stale SDK public input pins stop verification before selection; fresh pins and unrelated changes continue", async t => {
|
||||
const f = fixture(t);
|
||||
const sdkInputs = "tests/runner-e2e/source-sdk-public-inputs.mjs", registry = "tests/runner-e2e/source-sdk-public-inputs.json";
|
||||
const blob = text => createHash("sha1").update(`blob ${Buffer.byteLength(text)}\0`).update(text).digest("hex");
|
||||
const outputSha256 = "a".repeat(64);
|
||||
f.write(sdkInputs, readFileSync(path.join(repository, sdkInputs), "utf8"));
|
||||
f.write("tests/runner-e2e/report-lock.json", `${JSON.stringify({ inputSha256: "b".repeat(64), outputSha256 })}\n`);
|
||||
f.write("packages/shared/src/schema.ts", "export const schema = 1;\n");
|
||||
const writeRegistry = schema => f.write(registry, `${JSON.stringify({ lockSha256: outputSha256, inputs: {
|
||||
"package.json": blob(readFileSync(path.join(f.root, "package.json"), "utf8")), "packages/shared/src/schema.ts": blob(schema) } }, null, 2)}\n`);
|
||||
writeRegistry("export const schema = 1;\n");
|
||||
f.git("add", "."); f.git("-c", "user.name=Test", "-c", "user.email=test@example.invalid", "commit", "-qm", "sdk pin baseline");
|
||||
const base = f.git("rev-parse", "HEAD");
|
||||
const run = args => {
|
||||
const result = spawnSync(process.execPath, [path.join(f.root, "scripts/local-verify.mjs"), "--base", base, ...args], {
|
||||
cwd: f.root, env: f.env, encoding: "utf8", timeout: 120_000, maxBuffer: 8 * 1024 * 1024 });
|
||||
assert.equal(result.error, undefined);
|
||||
return { ...result, text: stripVTControlCharacters(result.stdout + result.stderr) };
|
||||
};
|
||||
// Unrelated change: the pin check does not run, even with a stale registry in the tree.
|
||||
f.write("ui/src/leaf.ts", "export const value = 3;\n");
|
||||
f.write("packages/shared/src/schema.ts", "export const schema = 2;\n");
|
||||
f.git("add", "packages/shared/src/schema.ts"); f.git("-c", "user.name=Test", "-c", "user.email=test@example.invalid", "commit", "-qm", "untracked drift");
|
||||
const unrelatedBase = f.git("rev-parse", "HEAD");
|
||||
const unrelated = spawnSync(process.execPath, [path.join(f.root, "scripts/local-verify.mjs"), "--base", unrelatedBase, "--explain"], {
|
||||
cwd: f.root, env: f.env, encoding: "utf8", timeout: 120_000, maxBuffer: 8 * 1024 * 1024 });
|
||||
assert.doesNotMatch(unrelated.stdout + unrelated.stderr, /is stale/);
|
||||
// Pinned input changed without a registry refresh: exit 1, name the input and the command, write nothing.
|
||||
const before = readFileSync(path.join(f.root, registry));
|
||||
const stale = run(["--explain"]);
|
||||
assert.equal(stale.status, 1, stale.text);
|
||||
assert.match(stale.text, /source-sdk-public-inputs\.json is stale for 1 pinned input\(s\): packages\/shared\/src\/schema\.ts \(changed\)/);
|
||||
assert.match(stale.text, /source-sdk-public-inputs\.mjs \$\(git rev-parse HEAD\) --write/);
|
||||
assert.doesNotMatch(stale.text, /Vitest test files selected|Broader verification required/);
|
||||
assert.deepEqual(readFileSync(path.join(f.root, registry)), before);
|
||||
// Refreshed pins: verification continues to selection.
|
||||
writeRegistry("export const schema = 2;\n");
|
||||
const fresh = run(["--explain"]);
|
||||
assert.doesNotMatch(fresh.text, /is stale/);
|
||||
assert.match(fresh.text, /Vitest test files selected|Broader verification required/);
|
||||
assert.notEqual(fresh.status, 1, fresh.text);
|
||||
});
|
||||
|
||||
test("an edit between diff discovery and fingerprinting cannot certify a partial selection", { skip: process.platform === "win32" }, t => {
|
||||
const f = fixture(t);
|
||||
const executable = execFileSync("which", ["git"], { encoding: "utf8" }).trim();
|
||||
f.write(".turbo/bin/package.json", '{"type":"commonjs"}');
|
||||
f.write(".turbo/bin/git", `#!${process.execPath}
|
||||
const {execFileSync}=require('node:child_process');
|
||||
const fs=require('node:fs');
|
||||
const args=process.argv.slice(2);
|
||||
const result=execFileSync(${JSON.stringify(executable)},args,{stdio:['ignore','pipe','pipe']});
|
||||
if(args[0]==='diff'&&!args.includes('--cached')&&!fs.existsSync('.turbo/diff-edited')){
|
||||
fs.writeFileSync('ui/src/other.ts','export const other = 2;\\n');
|
||||
fs.writeFileSync('.turbo/diff-edited','done');
|
||||
}
|
||||
process.stdout.write(result);
|
||||
`);
|
||||
chmodSync(path.join(f.root, ".turbo/bin/git"), 0o755);
|
||||
const result = f.run([], { PATH: `${path.join(f.root, ".turbo/bin")}${path.delimiter}${f.env.PATH}` });
|
||||
assert.equal(result.status, 1, result.text);
|
||||
assert.match(result.text, /Inputs changed/);
|
||||
assert.doesNotMatch(result.text, /Local Vitest verification passed/);
|
||||
});
|
||||
@@ -1,70 +1,11 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { chmodSync, cpSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { lstatSync, mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { stripVTControlCharacters } from "node:util";
|
||||
import { comparison, localEnvironment, snapshot } from "../local-verify/inputs.mjs";
|
||||
import { comparison, snapshot } from "../local-verify/inputs.mjs";
|
||||
import { planVerification } from "../local-verify/plan.mjs";
|
||||
|
||||
const repository = fileURLToPath(new URL("../../", import.meta.url));
|
||||
|
||||
function fixture(t) {
|
||||
const root = realpathSync(mkdtempSync(path.join(tmpdir(), "local-verify-")));
|
||||
t.after(() => rmSync(root, { recursive: true, force: true }));
|
||||
const write = (file, text) => {
|
||||
mkdirSync(path.dirname(path.join(root, file)), { recursive: true });
|
||||
writeFileSync(path.join(root, file), text);
|
||||
};
|
||||
for (const directory of ["scripts/ci", "scripts/local-verify", ".github/scripts"]) {
|
||||
cpSync(path.join(repository, directory), path.join(root, directory), { recursive: true });
|
||||
}
|
||||
for (const file of ["scripts/local-verify.mjs", "scripts/run-vitest-stable.mjs", "scripts/general-server-shard.mjs",
|
||||
"scripts/test-line-shard.mjs", "scripts/ci-profile/record.mjs", "turbo.json", ".github/ci-task-matrix.json"]) {
|
||||
write(file, readFileSync(path.join(repository, file), "utf8"));
|
||||
}
|
||||
for (const directory of ["server/src/__tests__", "server/scripts"]) mkdirSync(path.join(root, directory), { recursive: true });
|
||||
mkdirSync(path.join(root, "node_modules/.pnpm"), { recursive: true });
|
||||
for (const name of ["vitest", "oxc-parser", ".bin"]) {
|
||||
symlinkSync(path.join(repository, "node_modules", name), path.join(root, "node_modules", name), "dir");
|
||||
}
|
||||
for (const file of ["node_modules/.modules.yaml", "node_modules/.pnpm/lock.yaml"]) {
|
||||
write(file, readFileSync(path.join(repository, file), "utf8"));
|
||||
}
|
||||
write(".gitignore", "node_modules\nnode_modules/\n.turbo/\n.env\n");
|
||||
write("package.json", JSON.stringify({ name: "local-verification-fixture", private: true, type: "module", packageManager: "pnpm@9.15.4",
|
||||
scripts: { verify: "node scripts/local-verify.mjs", "test:run": "vitest run" } }));
|
||||
write("vitest.config.mjs", 'export default {test:{projects:["ui","cli"]}};');
|
||||
for (const [directory, name] of [["ui", "@paperclipai/ui"], ["cli", "paperclipai"]]) {
|
||||
write(`${directory}/vitest.config.mjs`, `export default {test:{name:${JSON.stringify(name)},include:["src/**/*.test.ts"]}};`);
|
||||
}
|
||||
write("ui/src/leaf.ts", "export const value = 1;\n");
|
||||
write("ui/src/other.ts", "export const other = 1;\n");
|
||||
write("ui/src/consumer.test.ts", 'import {test,expect} from "vitest"; import {value} from "./leaf"; test("affected consumer",()=>{expect(value).toBeGreaterThan(0);expect(process.env.LOCAL_VERIFY_FLAVOR).not.toBe("fail");});');
|
||||
write("ui/src/unrelated.test.ts", 'import {test,expect} from "vitest"; import {other} from "./other"; test("unrelated full-suite control",()=>expect(other).toBe(123456));');
|
||||
write("cli/src/independent.test.ts", 'import {test,expect} from "vitest"; test("unchanged consumer project",()=>expect(1).toBe(1));');
|
||||
const git = (...args) => execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
||||
git("init", "-q"); git("add", ".");
|
||||
git("-c", "user.name=Test", "-c", "user.email=test@example.invalid", "commit", "-qm", "baseline");
|
||||
const base = git("rev-parse", "HEAD");
|
||||
write("ui/src/leaf.ts", "export const value = 2;\n");
|
||||
const env = localEnvironment({ ...process.env, FORCE_COLOR: "0" });
|
||||
delete env.NODE_TEST_CONTEXT;
|
||||
delete env.DATABASE_URL;
|
||||
delete env.PAPERCLIP_TEST_POSTGRES_ADMIN_URL;
|
||||
for (const name of Object.keys(env)) if (/^PAPERCLIP_.*_TEST_DATABASE_URL$/.test(name)) delete env[name];
|
||||
const run = (args = [], extra = {}) => {
|
||||
const result = spawnSync(process.execPath, [path.join(root, "scripts/local-verify.mjs"), "--base", base, ...args], {
|
||||
cwd: root, env: { ...env, ...extra }, encoding: "utf8", timeout: 120_000, maxBuffer: 8 * 1024 * 1024,
|
||||
});
|
||||
assert.equal(result.error, undefined);
|
||||
return { ...result, text: stripVTControlCharacters(result.stdout + result.stderr) };
|
||||
};
|
||||
return { root, write, git, base, env, run };
|
||||
}
|
||||
import { fixture, repository } from "./local-verify-fixture.mjs";
|
||||
|
||||
test("real selected execution reuses passes and invalidates source, environment, untracked tests and broad inputs", { timeout: 180_000 }, async t => {
|
||||
const f = fixture(t);
|
||||
@@ -122,28 +63,6 @@ test("real selected execution reuses passes and invalidates source, environment,
|
||||
assert.match(config.text, /vitest.config.mjs/);
|
||||
});
|
||||
|
||||
test("explicit full execution cannot reuse a passing subset; opaque checks stay fresh", { timeout: 180_000 }, async t => {
|
||||
const f = fixture(t);
|
||||
assert.equal(f.run().status, 0);
|
||||
const full = f.run(["--full"]);
|
||||
assert.equal(full.status, 1, full.text);
|
||||
assert.match(full.text, /unrelated full-suite control/);
|
||||
f.write("ui/src/consumer.test.ts", 'import {test,expect} from "vitest"; import {readFileSync} from "node:fs"; import {value} from "./leaf"; test("opaque fresh check",()=>expect(readFileSync(process.env.LOCAL_VERIFY_INPUT,"utf8")).toBe(String(value)));');
|
||||
f.git("add", "ui/src/consumer.test.ts");
|
||||
f.write(".turbo/external-input", "2");
|
||||
const input = { LOCAL_VERIFY_INPUT: path.join(f.root, ".turbo/external-input") };
|
||||
const opaque = f.run([], input);
|
||||
assert.equal(opaque.status, 0, opaque.text);
|
||||
assert.match(opaque.text, /Test Files\s+1 passed/);
|
||||
const fresh = f.run([], input);
|
||||
assert.equal(fresh.status, 0, fresh.text);
|
||||
assert.match(fresh.text, /Test Files\s+1 passed/);
|
||||
f.write(".turbo/external-input", "changed externally");
|
||||
const external = f.run([], input);
|
||||
assert.equal(external.status, 1, external.text);
|
||||
assert.match(external.text, /opaque fresh check/);
|
||||
});
|
||||
|
||||
test("working tree comparison includes commits, staging, deletion, rename and untracked files", t => {
|
||||
const f = fixture(t);
|
||||
f.git("add", "ui/src/leaf.ts");
|
||||
@@ -167,27 +86,6 @@ test("dependency installation, ignored dotenv and child environment enter the ca
|
||||
assert.equal(snapshot(f.root, { ...f.env, PAPERCLIP_TEST_POSTGRES_ADMIN_URL: "postgres://external.invalid/test" }).cacheable, false);
|
||||
});
|
||||
|
||||
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("repository skill directory links preserve reuse while target edits invalidate it", t => {
|
||||
const f = fixture(t);
|
||||
mkdirSync(path.join(f.root, ".claude/skills"), { recursive: true });
|
||||
@@ -221,43 +119,6 @@ test("local chat selection schedules affected split chat suites through general-
|
||||
]);
|
||||
});
|
||||
|
||||
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("fingerprints preserve file boundaries when content resembles another input record", t => {
|
||||
const f = fixture(t), a = "ui/src/hash-a.ts", b = "ui/src/hash-b.ts";
|
||||
f.write(a, ""); f.write(b, "tail");
|
||||
@@ -268,71 +129,6 @@ test("fingerprints preserve file boundaries when content resembles another input
|
||||
assert.notEqual(snapshot(f.root, f.env).hash, first);
|
||||
});
|
||||
|
||||
test("an edit between diff discovery and fingerprinting cannot certify a partial selection", { skip: process.platform === "win32" }, t => {
|
||||
const f = fixture(t);
|
||||
const executable = execFileSync("which", ["git"], { encoding: "utf8" }).trim();
|
||||
f.write(".turbo/bin/package.json", '{"type":"commonjs"}');
|
||||
f.write(".turbo/bin/git", `#!${process.execPath}
|
||||
const {execFileSync}=require('node:child_process');
|
||||
const fs=require('node:fs');
|
||||
const args=process.argv.slice(2);
|
||||
const result=execFileSync(${JSON.stringify(executable)},args,{stdio:['ignore','pipe','pipe']});
|
||||
if(args[0]==='diff'&&!args.includes('--cached')&&!fs.existsSync('.turbo/diff-edited')){
|
||||
fs.writeFileSync('ui/src/other.ts','export const other = 2;\\n');
|
||||
fs.writeFileSync('.turbo/diff-edited','done');
|
||||
}
|
||||
process.stdout.write(result);
|
||||
`);
|
||||
chmodSync(path.join(f.root, ".turbo/bin/git"), 0o755);
|
||||
const result = f.run([], { PATH: `${path.join(f.root, ".turbo/bin")}${path.delimiter}${f.env.PATH}` });
|
||||
assert.equal(result.status, 1, result.text);
|
||||
assert.match(result.text, /Inputs changed/);
|
||||
assert.doesNotMatch(result.text, /Local Vitest verification passed/);
|
||||
});
|
||||
|
||||
test("stale SDK public input pins stop verification before selection; fresh pins and unrelated changes continue", async t => {
|
||||
const f = fixture(t);
|
||||
const sdkInputs = "tests/runner-e2e/source-sdk-public-inputs.mjs", registry = "tests/runner-e2e/source-sdk-public-inputs.json";
|
||||
const blob = text => createHash("sha1").update(`blob ${Buffer.byteLength(text)}\0`).update(text).digest("hex");
|
||||
const outputSha256 = "a".repeat(64);
|
||||
f.write(sdkInputs, readFileSync(path.join(repository, sdkInputs), "utf8"));
|
||||
f.write("tests/runner-e2e/report-lock.json", `${JSON.stringify({ inputSha256: "b".repeat(64), outputSha256 })}\n`);
|
||||
f.write("packages/shared/src/schema.ts", "export const schema = 1;\n");
|
||||
const writeRegistry = schema => f.write(registry, `${JSON.stringify({ lockSha256: outputSha256, inputs: {
|
||||
"package.json": blob(readFileSync(path.join(f.root, "package.json"), "utf8")), "packages/shared/src/schema.ts": blob(schema) } }, null, 2)}\n`);
|
||||
writeRegistry("export const schema = 1;\n");
|
||||
f.git("add", "."); f.git("-c", "user.name=Test", "-c", "user.email=test@example.invalid", "commit", "-qm", "sdk pin baseline");
|
||||
const base = f.git("rev-parse", "HEAD");
|
||||
const run = args => {
|
||||
const result = spawnSync(process.execPath, [path.join(f.root, "scripts/local-verify.mjs"), "--base", base, ...args], {
|
||||
cwd: f.root, env: f.env, encoding: "utf8", timeout: 120_000, maxBuffer: 8 * 1024 * 1024 });
|
||||
assert.equal(result.error, undefined);
|
||||
return { ...result, text: stripVTControlCharacters(result.stdout + result.stderr) };
|
||||
};
|
||||
// Unrelated change: the pin check does not run, even with a stale registry in the tree.
|
||||
f.write("ui/src/leaf.ts", "export const value = 3;\n");
|
||||
f.write("packages/shared/src/schema.ts", "export const schema = 2;\n");
|
||||
f.git("add", "packages/shared/src/schema.ts"); f.git("-c", "user.name=Test", "-c", "user.email=test@example.invalid", "commit", "-qm", "untracked drift");
|
||||
const unrelatedBase = f.git("rev-parse", "HEAD");
|
||||
const unrelated = spawnSync(process.execPath, [path.join(f.root, "scripts/local-verify.mjs"), "--base", unrelatedBase, "--explain"], {
|
||||
cwd: f.root, env: f.env, encoding: "utf8", timeout: 120_000, maxBuffer: 8 * 1024 * 1024 });
|
||||
assert.doesNotMatch(unrelated.stdout + unrelated.stderr, /is stale/);
|
||||
// Pinned input changed without a registry refresh: exit 1, name the input and the command, write nothing.
|
||||
const before = readFileSync(path.join(f.root, registry));
|
||||
const stale = run(["--explain"]);
|
||||
assert.equal(stale.status, 1, stale.text);
|
||||
assert.match(stale.text, /source-sdk-public-inputs\.json is stale for 1 pinned input\(s\): packages\/shared\/src\/schema\.ts \(changed\)/);
|
||||
assert.match(stale.text, /source-sdk-public-inputs\.mjs \$\(git rev-parse HEAD\) --write/);
|
||||
assert.doesNotMatch(stale.text, /Vitest test files selected|Broader verification required/);
|
||||
assert.deepEqual(readFileSync(path.join(f.root, registry)), before);
|
||||
// Refreshed pins: verification continues to selection.
|
||||
writeRegistry("export const schema = 2;\n");
|
||||
const fresh = run(["--explain"]);
|
||||
assert.doesNotMatch(fresh.text, /is stale/);
|
||||
assert.match(fresh.text, /Vitest test files selected|Broader verification required/);
|
||||
assert.notEqual(fresh.status, 1, fresh.text);
|
||||
});
|
||||
|
||||
test("documentation-only changes and empty diffs do not start a full suite", async t => {
|
||||
const f = fixture(t);
|
||||
f.write("ui/src/leaf.ts", "export const value = 1;\n");
|
||||
@@ -345,60 +141,3 @@ test("documentation-only changes and empty diffs do not start a full suite", asy
|
||||
diff: { ...comparison(f.root, f.base), changed: [] } });
|
||||
assert.deepEqual(plan.jobs, []);
|
||||
});
|
||||
|
||||
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]);
|
||||
});
|
||||
|
||||
test("source mutation and interruption do not publish reusable passes", { timeout: 120_000 }, async t => {
|
||||
const f = fixture(t);
|
||||
const runControlled = action => new Promise((resolve, reject) => {
|
||||
const child = spawn(process.execPath, [path.join(f.root, "scripts/local-verify.mjs"), "--base", f.base, "--no-cache"], {
|
||||
cwd: f.root, env: f.env, stdio: ["ignore", "pipe", "pipe"],
|
||||
});
|
||||
let text = "", acted = false;
|
||||
const timer = setTimeout(() => { child.kill("SIGTERM"); reject(new Error("Controlled verification did not finish")); }, 60_000);
|
||||
const collect = bytes => {
|
||||
text += bytes;
|
||||
if (!acted && text.includes("[verify] Running")) { acted = true; action(child); }
|
||||
};
|
||||
child.stdout.on("data", collect); child.stderr.on("data", collect);
|
||||
child.once("error", reject);
|
||||
child.once("close", (code, signal) => { clearTimeout(timer); resolve({ code, signal, text, acted }); });
|
||||
});
|
||||
const changed = await runControlled(() => f.write("ui/src/leaf.ts", "export const value = 4;\n"));
|
||||
assert.equal(changed.acted, true);
|
||||
assert.equal(changed.code, 1, changed.text);
|
||||
assert.match(changed.text, /Inputs changed during verification/);
|
||||
const beforeInterrupt = f.run();
|
||||
assert.equal(beforeInterrupt.status, 0, beforeInterrupt.text);
|
||||
const interrupted = await runControlled(child => child.kill("SIGTERM"));
|
||||
assert.equal(interrupted.acted, true);
|
||||
assert.equal(interrupted.code, 143, interrupted.text);
|
||||
const result = f.run();
|
||||
assert.equal(result.status, 0, result.text);
|
||||
assert.match(result.text, /Test Files\s+1 passed/);
|
||||
assert.doesNotMatch(result.text, /reusing a passing local result/);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"inputs": {
|
||||
"package.json": "d9d6052ec03ec7bf20a875d9bcbe83ea96695097",
|
||||
"package.json": "bf14b05f6dd6276a8fbc9da8fa5b6ff031d60b8c",
|
||||
"packages/plugins/sdk/package.json": "b7a4936e2803fd0d3b32dd7f17fc1ea86609ead0",
|
||||
"packages/plugins/sdk/src/bundlers.ts": "883bf3d9f2bd42877cfc0c3707cd882a6f6248d0",
|
||||
"packages/plugins/sdk/src/define-plugin.ts": "a99e07ce77ef72fcf1df1347346aacb8ba12e284",
|
||||
|
||||
Reference in new issue
Block a user