mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-25 16:14:26 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Pull-request CI checks run on every commit before maintainers can merge code > - PR #22679 cut PR CI from 15–30+ minutes down toward 4.5–5.5 minutes on 4-core runners > - Remaining wall-clock bottlenecks sit in unsharded `workspaces-b`, serial typecheck preparation, E2E server/UI startup, fixed Vitest worker caps, and remaining soak and duplicated UI tests > - This pull request adds Phase 2 optimizations across server soak triage, typecheck DAG overlap, E2E fast boot and shard balance, dynamic CPU-aware workers, pure-Node workspace link preflight, UI pruning, and permanent test-budget enforcement > - The benefit is ordinary feature PRs finish in ~3.1–3.8 minutes on 4-core runners and scale automatically to ~2.0–3.0 minutes on 8-core runners while keeping core invariants and nightly coverage intact ## Linked Issues or Issue Description Refs #22679 **Problem Statement** After #22679 landed, several PR lanes still took 4.5–6 minutes on 4-core runners (`general-workspaces-b` ran unsharded, `Typecheck + Release Registry` waited on a serial server build before starting UI and test-program checks, E2E shards paid full `cli onboard` + minified UI build overhead, and Vitest worker counts did not scale with runner CPU count). **Proposed Solution** Split `general-workspaces-b` across two duration-balanced shards, overlap typecheck preparation tasks behind a shared runner-vendor node, replace E2E `onboard` with a direct template-PG boot + unminified inline UI build, scale Vitest/Playwright/Typecheck workers dynamically by CPU and RAM, replace `tsx` in workspace-link preflight with pure Node, prune redundant mocked UI tests and additional real-clock server soak suites (still run on `master`, `release-verify`, `cloud-readiness`, and `PAPERCLIP_CI_FULL=1`), and add a permanent test-budget policy check. **Expected Benefit** Brings ordinary PR CI wall-clock down to ~3.1–3.8 minutes on 4-core runners (and ~2.0–3.0 minutes on 8-core runners) with automated guardrails against future test-time regressions. ## What Changed - **Server soak triage & permanent test-budget guardrail (`scripts/ci/nightly-only-suites.json`, `rules/test-budget.mdc`, `.greptile/files.json`, `scripts/check-test-budget.mjs`, `scripts/check-test-budget.test.mjs`, `.github/workflows/pr-trusted.yml`):** Expanded the PR-excluded soak/heavy-integration manifest to 568 genuine heavy suites (preserving 100% of company isolation, authz, checkout, approval, budget, activity-log, security, telemetry, and serialized suites on every PR) and wired `node scripts/check-test-budget.mjs` into the `policy` job. - **Typecheck DAG overlap & CPU/RAM scaling (`scripts/ci-typecheck-lane.mjs`, `scripts/typecheck-test-programs.mjs`, `scripts/__tests__/ci-typecheck-lane.test.mjs`, `scripts/typecheck-test-programs.test.mjs`):** Moved `build server without type checks` and `check server runtime assets` out of serial `prepare` into parallel DAG nodes behind `prepare runner vendor`, added `computeResourceProfile` scaling across 2/4/8-core runners, and added missing UI/Runner consumer routing inputs (`packages/paperclip-runner/` for `@paperclipai/ui`, `packages/adapter-utils/` for Runner test programs). - **E2E fast boot, dynamic workers & 8-shard rebalance (`tests/e2e/start-e2e-server.ts`, `tests/e2e/playwright.config.ts`, `scripts/e2e-shard.mjs`, `scripts/e2e-shard-durations.json`, `.github/workflows/pr-trusted.yml`, `.github/workflows/release-verify.yml`):** Added direct throwaway template-PG boot (`fsync=off`), unminified inline Vite fallback build, dynamic parallel workers (`min(4, floor(cpus/2))`), empirical `1.5x` parallel speedup weighting across 8 shards, targeted trims to slowest E2E specs, and hashed workspace `package.json` manifests into the `e2e-ui-dist-v2` cache key. - **Dynamic Vitest workers, 2-shard `workspaces-b`, and pure-Node preflight (`scripts/ci/vitest-workers.mjs`, `scripts/ci/workspaces-b-shard.mjs`, `scripts/ensure-workspace-package-links.mjs`, `scripts/ci-dependency-cache.mjs`, `packages/db/src/test-embedded-postgres.ts`, `.github/ci-task-matrix.json`, `.github/actions/setup-ci-dependencies/action.yml`, `package.json`):** Scaled Vitest workers dynamically (`4→7` general, `3→5` serialized) with `max_connections=300` before PostgreSQL start, split `general-workspaces-b` into 2 duration-weighted shards (backward-compatible unsharded for release workflows), replaced `tsx` workspace-link preflight with pure Node (~29× faster), and parallelized `ci-dependency-cache.mjs` child queries. - **UI Vitest worker scaling, fake timers & E2E-duplicated suite pruning (`ui/vitest.config.ts`, 4 `maps/` files, and UI test suites):** Scaled UI `maxWorkers` dynamically, converted real-clock sleeps in kept suites to fake timers, removed 34 E2E-duplicated mocked jsdom suites, and updated corresponding `maps/` prose references. ## Verification - `node --test .github/scripts/tests/ci-plan.test.mjs .github/scripts/tests/ci-dependency-cache.test.mjs .github/scripts/tests/pr-dependency-cache.test.mjs scripts/__tests__/run-vitest-stable-shard.test.mjs scripts/__tests__/run-vitest-stable-pr-mode.test.mjs scripts/__tests__/ci-typecheck-lane.test.mjs scripts/typecheck-test-programs.test.mjs scripts/__tests__/e2e-shard.test.mjs scripts/check-test-budget.test.mjs scripts/ci/test-selection-pr-timings.test.mjs`: **160/160 PASS** - `node scripts/check-test-budget.mjs`: **PASS** (`568` nightly suites validated) - `node scripts/check-maps.mjs`: **PASS** (`35 areas, 192 capability IDs`) - `pnpm --filter @paperclipai/ui typecheck` & `pnpm --filter @paperclipai/db typecheck`: **PASS** - Live CI verification runs on the new `pr-trusted.yml@master` (from #22679) with `profile-ci` enabled to export the full job/step/file waterfall to Honeycomb `paperclip-ci`. ## Risks - Medium CI scope: touches workflow matrix partitioning, E2E startup, and test runners; does not change production app runtime behavior. - All PR-demoted soak suites continue to execute on `master`, `release-verify`, `cloud-readiness`, local `pnpm test:run`, and `PAPERCLIP_CI_FULL=1`. - All new `policy` and `setup-ci-dependencies` commands keep file-existence guards so reruns of older PR branches continue to work. ## Model Used - Google Gemini (Antigravity swarm orchestrating specialized worker agents with shell, file editing, and test execution tools) and Anthropic Claude Opus (verification and optimization sub-agents). ## 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
427 lines
17 KiB
JavaScript
427 lines
17 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import { test } from "node:test";
|
|
import { fileURLToPath } from "node:url";
|
|
import {
|
|
checkCoverage,
|
|
checkCoverageAsync,
|
|
defaultConcurrency,
|
|
findUncheckedTests,
|
|
LOCKED_PROVIDERS,
|
|
PROGRAMS,
|
|
prepareTestPrograms,
|
|
PROVIDER_WORKSPACE,
|
|
RESOLVE_ARGS,
|
|
SANDBOX_PROVIDER_PROGRAMS,
|
|
SANDBOX_PROVIDERS,
|
|
selectTestPrograms,
|
|
typecheckTestPrograms,
|
|
typecheckTestProgramsAsync,
|
|
} from "./typecheck-test-programs.mjs";
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
const tsc = path.join(root, "node_modules", "typescript", "bin", "tsc");
|
|
|
|
const harness = (overrides = {}) => {
|
|
const calls = { pnpm: [], tsc: [], linked: 0, errors: [] };
|
|
return {
|
|
calls,
|
|
options: {
|
|
root: "/repo",
|
|
programs: ["a/tsconfig.test.json", "b/tsconfig.test.json"],
|
|
pnpm: (args, { cwd }) => {
|
|
calls.pnpm.push({ args, cwd });
|
|
return 0;
|
|
},
|
|
linkPlugins: () => {
|
|
calls.linked += 1;
|
|
},
|
|
run: (args) => {
|
|
calls.tsc.push(args);
|
|
return { status: 0 };
|
|
},
|
|
checkFiles: () => [],
|
|
log: () => {},
|
|
logError: (message) => calls.errors.push(message),
|
|
...overrides,
|
|
},
|
|
};
|
|
};
|
|
|
|
test("findUncheckedTests reports only test files outside programs and other checks", () => {
|
|
assert.deepEqual(
|
|
findUncheckedTests({
|
|
trackedFiles: ["a/x.test.ts", "a/y.spec.tsx", "a/z.test.tsx", "a/helper.ts", "a/n.test.mjs", "server/src/s.test.ts"],
|
|
checkedFiles: ["a/x.test.ts", "a/y.spec.tsx"],
|
|
checkedElsewhere: ["server/src/"],
|
|
}),
|
|
["a/z.test.tsx"],
|
|
);
|
|
});
|
|
|
|
test("every program exists, and the provider list matches the tracked provider packages", () => {
|
|
for (const program of PROGRAMS) assert.ok(existsSync(path.join(root, program)), program);
|
|
assert.ok(existsSync(path.join(root, PROVIDER_WORKSPACE, "pnpm-lock.yaml")));
|
|
const tracked = execFileSync("git", ["ls-files", "packages/plugins/sandbox-providers"], { cwd: root, encoding: "utf8" });
|
|
const manifests = tracked.split("\n").filter((file) => file.endsWith("/package.json"));
|
|
assert.deepEqual(manifests.map((manifest) => path.dirname(manifest)).sort(), [...SANDBOX_PROVIDERS].sort());
|
|
});
|
|
|
|
test("the provider workspace lists every provider without its own lockfile by full path, so Dependabot sees them", () => {
|
|
const workspace = readFileSync(path.join(root, PROVIDER_WORKSPACE, "pnpm-workspace.yaml"), "utf8");
|
|
const listed = [...workspace.matchAll(/^\s+-\s+(\S+)\s*$/gm)].map((match) => match[1]);
|
|
assert.ok(listed.every((entry) => !entry.includes("*")), "Dependabot does not expand a glob that starts with ../");
|
|
const providers = listed.map((entry) => path.posix.normalize(path.posix.join(PROVIDER_WORKSPACE, entry)));
|
|
const unlocked = SANDBOX_PROVIDERS.filter((provider) => !LOCKED_PROVIDERS.includes(provider));
|
|
assert.deepEqual(providers.sort(), unlocked.sort());
|
|
});
|
|
|
|
test("each provider with its own lockfile is a provider and has that lockfile", () => {
|
|
for (const provider of LOCKED_PROVIDERS) {
|
|
assert.ok(SANDBOX_PROVIDERS.includes(provider), provider);
|
|
assert.ok(existsSync(path.join(root, provider, "pnpm-lock.yaml")), provider);
|
|
}
|
|
});
|
|
|
|
test("no provider commits a lockfile, except the one Daytona already has", () => {
|
|
const tracked = execFileSync("git", ["ls-files", "packages/plugins/sandbox-providers"], { cwd: root, encoding: "utf8" });
|
|
assert.deepEqual(
|
|
tracked.split("\n").filter((file) => file.endsWith("/pnpm-lock.yaml")),
|
|
["packages/plugins/sandbox-providers/daytona/pnpm-lock.yaml"],
|
|
);
|
|
});
|
|
|
|
test("a type error in one program still checks the rest and fails the run", () => {
|
|
const { options, calls } = harness({
|
|
run: (args) => {
|
|
calls.tsc.push(args);
|
|
return { status: args[1].startsWith("a/") ? 2 : 0 };
|
|
},
|
|
});
|
|
assert.equal(typecheckTestPrograms(options), 2);
|
|
assert.deepEqual(calls.tsc, [
|
|
["-p", "a/tsconfig.test.json"],
|
|
["-p", "b/tsconfig.test.json"],
|
|
]);
|
|
});
|
|
|
|
test("a killed compiler stops the run", () => {
|
|
const { options, calls } = harness({
|
|
run: (args) => {
|
|
calls.tsc.push(args);
|
|
return { status: null, signal: "SIGKILL" };
|
|
},
|
|
});
|
|
assert.equal(typecheckTestPrograms(options), 1);
|
|
assert.equal(calls.tsc.length, 1);
|
|
});
|
|
|
|
test("providers install frozen without scripts, then relink the SDK", () => {
|
|
const { options, calls } = harness();
|
|
assert.equal(typecheckTestPrograms(options), 0);
|
|
const install = calls.pnpm.find(({ cwd }) => cwd === path.join("/repo", PROVIDER_WORKSPACE));
|
|
assert.ok(install.args.includes("--frozen-lockfile"));
|
|
assert.ok(install.args.includes("--ignore-scripts"));
|
|
assert.equal(calls.linked, 1);
|
|
});
|
|
|
|
test("preparation runs on its own, and a run that skips it only checks", () => {
|
|
const prepared = harness();
|
|
assert.equal(prepareTestPrograms(prepared.options), 0);
|
|
assert.ok(prepared.calls.pnpm.some(({ cwd }) => cwd === path.join("/repo", PROVIDER_WORKSPACE)));
|
|
assert.equal(prepared.calls.linked, 1);
|
|
assert.deepEqual(prepared.calls.tsc, []);
|
|
|
|
const checked = harness();
|
|
assert.equal(typecheckTestPrograms({ ...checked.options, prepare: false }), 0);
|
|
assert.deepEqual(checked.calls.pnpm, []);
|
|
assert.equal(checked.calls.linked, 0);
|
|
assert.equal(checked.calls.tsc.length, 2);
|
|
});
|
|
|
|
test("a locked provider installs frozen from its own lockfile, outside any workspace", () => {
|
|
const { options, calls } = harness();
|
|
assert.equal(typecheckTestPrograms(options), 0);
|
|
for (const provider of LOCKED_PROVIDERS) {
|
|
const install = calls.pnpm.find(({ cwd }) => cwd === path.join("/repo", provider));
|
|
assert.ok(install.args.includes("--ignore-workspace"));
|
|
assert.ok(install.args.includes("--frozen-lockfile"));
|
|
assert.ok(install.args.includes("--ignore-scripts"));
|
|
}
|
|
});
|
|
|
|
// Each directory's first frozen install fails; resolution and the second frozen install pass.
|
|
const staleOnce = (directory, calls) => {
|
|
const cwd = path.join("/repo", directory);
|
|
let frozenAttempts = 0;
|
|
return (args, options) => {
|
|
calls.pnpm.push({ args, cwd: options.cwd });
|
|
if (options.cwd !== cwd || !args.includes("--frozen-lockfile")) return 0;
|
|
frozenAttempts += 1;
|
|
return frozenAttempts === 1 ? 1 : 0;
|
|
};
|
|
};
|
|
const installSteps = (calls, directory) =>
|
|
calls.pnpm
|
|
.filter(({ cwd }) => cwd === path.join("/repo", directory))
|
|
.map(({ args }) => (args.includes("--frozen-lockfile") ? "frozen" : args));
|
|
|
|
test("a stale provider lockfile is resolved in place, then installed frozen", () => {
|
|
const { options, calls } = harness();
|
|
options.pnpm = staleOnce(PROVIDER_WORKSPACE, calls);
|
|
assert.equal(typecheckTestPrograms(options), 0);
|
|
assert.deepEqual(installSteps(calls, PROVIDER_WORKSPACE), ["frozen", RESOLVE_ARGS, "frozen"]);
|
|
assert.ok(RESOLVE_ARGS.includes("--resolution-only") && RESOLVE_ARGS.includes("--ignore-scripts"));
|
|
assert.equal(calls.tsc.length, 2);
|
|
});
|
|
|
|
test("a stale locked-provider lockfile is resolved in place, outside any workspace", () => {
|
|
const [provider] = LOCKED_PROVIDERS;
|
|
const { options, calls } = harness();
|
|
options.pnpm = staleOnce(provider, calls);
|
|
assert.equal(typecheckTestPrograms(options), 0);
|
|
const [, resolve] = installSteps(calls, provider);
|
|
assert.deepEqual(installSteps(calls, provider), ["frozen", resolve, "frozen"]);
|
|
for (const flag of ["--ignore-workspace", "--resolution-only", "--ignore-scripts", "--no-frozen-lockfile"]) {
|
|
assert.ok(resolve.includes(flag), flag);
|
|
}
|
|
assert.equal(calls.tsc.length, 2);
|
|
});
|
|
|
|
test("a locked provider install that still fails stops before any program runs", () => {
|
|
const [provider] = LOCKED_PROVIDERS;
|
|
const { options, calls } = harness({
|
|
pnpm: (args, { cwd }) => (cwd === path.join("/repo", provider) ? 1 : 0),
|
|
});
|
|
assert.equal(typecheckTestPrograms(options), 1);
|
|
assert.equal(calls.tsc.length, 0);
|
|
assert.ok(calls.errors[0].includes(provider), calls.errors[0]);
|
|
});
|
|
|
|
test("a provider install that still fails stops before any program runs", () => {
|
|
const { options, calls } = harness({
|
|
pnpm: (args, { cwd }) => (cwd === path.join("/repo", PROVIDER_WORKSPACE) ? 1 : 0),
|
|
});
|
|
assert.equal(typecheckTestPrograms(options), 1);
|
|
assert.equal(calls.tsc.length, 0);
|
|
assert.match(calls.errors[0], /could not install the sandbox providers/);
|
|
});
|
|
|
|
test("an uncovered test file fails the run and is named", () => {
|
|
const { options, calls } = harness({ checkFiles: () => ["a/z.test.tsx"] });
|
|
assert.equal(typecheckTestPrograms(options), 1);
|
|
assert.match(calls.errors[0], /a\/z\.test\.tsx/);
|
|
});
|
|
|
|
test("the coverage check fails closed when a program cannot be listed", () => {
|
|
const { options } = harness({ checkFiles: () => null });
|
|
assert.equal(typecheckTestPrograms(options), 1);
|
|
});
|
|
|
|
test("naming programs skips the coverage check", () => {
|
|
let checked = false;
|
|
const { options } = harness({
|
|
coverage: false,
|
|
checkFiles: () => {
|
|
checked = true;
|
|
return [];
|
|
},
|
|
});
|
|
assert.equal(typecheckTestPrograms(options), 0);
|
|
assert.equal(checked, false);
|
|
});
|
|
|
|
test("checkCoverage uses the compiler's file list, so a dropped sibling is caught", () => {
|
|
const directory = mkdtempSync(path.join(root, "node_modules", ".typecheck-test-programs-"));
|
|
try {
|
|
const relative = path.relative(root, directory).split(path.sep).join("/");
|
|
writeFileSync(path.join(directory, "foo.test.ts"), "export {};\n");
|
|
writeFileSync(path.join(directory, "foo.test.tsx"), "export {};\n");
|
|
writeFileSync(path.join(directory, "tsconfig.json"), JSON.stringify({ compilerOptions: { noEmit: true, jsx: "preserve" }, include: ["*"] }));
|
|
const unchecked = checkCoverage({
|
|
root,
|
|
programs: [`${relative}/tsconfig.json`],
|
|
workspaceConfigs: () => [],
|
|
trackedFiles: () => [`${relative}/foo.test.ts`, `${relative}/foo.test.tsx`],
|
|
});
|
|
assert.deepEqual(unchecked, [`${relative}/foo.test.tsx`]);
|
|
} finally {
|
|
rmSync(directory, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("a real type error in a test-style program makes tsc exit non-zero", () => {
|
|
const directory = mkdtempSync(path.join(tmpdir(), "typecheck-test-programs-"));
|
|
try {
|
|
writeFileSync(path.join(directory, "bad.test.ts"), "export const value: number = 'text';\n");
|
|
writeFileSync(path.join(directory, "tsconfig.json"), JSON.stringify({ compilerOptions: { noEmit: true, types: [] }, include: ["*.ts"] }));
|
|
const { status, stdout } = spawnSync(process.execPath, [tsc, "-p", directory, "--pretty", "false"], { encoding: "utf8" });
|
|
assert.notEqual(status, 0);
|
|
assert.match(stdout, /bad\.test\.ts.*TS2322/);
|
|
} finally {
|
|
rmSync(directory, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("selectTestPrograms skips sandbox providers and examples unless their inputs or SDK/shared changed", () => {
|
|
const full = selectTestPrograms(null);
|
|
assert.deepEqual(full.programs, PROGRAMS);
|
|
assert.equal(full.includeProviders, true);
|
|
assert.equal(full.checkCoverage, true);
|
|
|
|
const serverOnly = selectTestPrograms(["server/src/services/issues.ts", "server/src/__tests__/issues.test.ts"]);
|
|
assert.deepEqual(serverOnly.programs, []);
|
|
assert.equal(serverOnly.includeProviders, false);
|
|
assert.equal(serverOnly.includeRunnerEval, false);
|
|
assert.equal(serverOnly.checkCoverage, false);
|
|
|
|
const daytonaOnly = selectTestPrograms(["packages/plugins/sandbox-providers/daytona/src/plugin.ts"]);
|
|
assert.deepEqual(daytonaOnly.programs, ["packages/plugins/sandbox-providers/daytona/tsconfig.test.json"]);
|
|
assert.equal(daytonaOnly.includeProviders, true);
|
|
assert.equal(daytonaOnly.includeRunnerEval, false);
|
|
|
|
const cloudflare = selectTestPrograms(["packages/plugins/sandbox-providers/cloudflare/src/plugin.ts"]);
|
|
assert.deepEqual(cloudflare.programs, [
|
|
"packages/plugins/sandbox-providers/cloudflare/tsconfig.test.json",
|
|
"packages/plugins/sandbox-providers/cloudflare/bridge-template/tsconfig.test.json",
|
|
]);
|
|
assert.equal(cloudflare.includeProviders, true);
|
|
|
|
const sdkChange = selectTestPrograms(["packages/plugins/sdk/src/index.ts"]);
|
|
assert.equal(sdkChange.includeProviders, true);
|
|
for (const providerProgram of SANDBOX_PROVIDER_PROGRAMS) {
|
|
assert.ok(sdkChange.programs.includes(providerProgram), providerProgram);
|
|
}
|
|
assert.ok(sdkChange.programs.includes("packages/kv-demo-mcp-server/tsconfig.test.json"));
|
|
assert.ok(sdkChange.programs.includes("packages/plugins/examples/plugin-orchestration-smoke-example/tsconfig.test.json"));
|
|
|
|
const uiWithTest = selectTestPrograms(["ui/src/components/Card.tsx", "ui/src/components/Card.test.tsx"]);
|
|
assert.deepEqual(uiWithTest.programs, ["tests/tsconfig.playwright.json"]);
|
|
assert.equal(uiWithTest.includeProviders, false);
|
|
assert.equal(uiWithTest.checkCoverage, true);
|
|
assert.deepEqual(uiWithTest.changedTestFiles, ["ui/src/components/Card.test.tsx"]);
|
|
|
|
const tsconfigEdit = selectTestPrograms(["ui/tsconfig.json"]);
|
|
assert.equal(tsconfigEdit.checkCoverage, true);
|
|
assert.equal(tsconfigEdit.changedTestFiles, null);
|
|
|
|
const adapterUtilsEdit = selectTestPrograms(["packages/adapter-utils/src/github-launcher.ts"]);
|
|
assert.ok(adapterUtilsEdit.programs.some((program) => program.startsWith("packages/paperclip-runner/")));
|
|
assert.equal(adapterUtilsEdit.includeRunnerEval, true);
|
|
});
|
|
|
|
test("prepareTestPrograms can skip sandbox provider installs, runner eval prep, and plugin SDK", () => {
|
|
const { options, calls } = harness();
|
|
assert.equal(
|
|
prepareTestPrograms({ ...options, includeProviders: false, includeRunnerEval: false, includePluginSdk: false }),
|
|
0,
|
|
);
|
|
assert.deepEqual(calls.pnpm, []);
|
|
assert.equal(calls.linked, 0);
|
|
|
|
const evalOnly = harness();
|
|
assert.equal(
|
|
prepareTestPrograms({ ...evalOnly.options, includeProviders: false, includeRunnerEval: true, includePluginSdk: false }),
|
|
0,
|
|
);
|
|
assert.equal(evalOnly.calls.pnpm.length, 1);
|
|
assert.ok(evalOnly.calls.pnpm[0].args.includes("ensure:eval-build-deps"));
|
|
assert.equal(evalOnly.calls.linked, 0);
|
|
});
|
|
|
|
test("typecheckTestProgramsAsync runs programs concurrently up to the limit and preserves failure/signal semantics", async () => {
|
|
let active = 0;
|
|
let peak = 0;
|
|
const started = [];
|
|
const status = await typecheckTestProgramsAsync({
|
|
root: "/repo",
|
|
programs: ["a/tsconfig.test.json", "b/tsconfig.test.json", "c/tsconfig.test.json", "d/tsconfig.test.json"],
|
|
prepare: false,
|
|
coverage: false,
|
|
concurrency: 2,
|
|
checkers: 1,
|
|
log: () => {},
|
|
logError: () => {},
|
|
runAsync: async (args) => {
|
|
started.push(args);
|
|
active += 1;
|
|
peak = Math.max(peak, active);
|
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
active -= 1;
|
|
return { status: args[1].startsWith("b/") ? 2 : 0, signal: null, output: "", durationMs: 10 };
|
|
},
|
|
});
|
|
assert.equal(status, 2);
|
|
assert.equal(peak, 2);
|
|
assert.equal(started.length, 4);
|
|
assert.deepEqual(started[0], ["-p", "a/tsconfig.test.json", "--checkers", "1"]);
|
|
|
|
// A killed compiler stops queuing further programs.
|
|
const killedStarts = [];
|
|
const killedStatus = await typecheckTestProgramsAsync({
|
|
root: "/repo",
|
|
programs: ["a/tsconfig.test.json", "b/tsconfig.test.json", "c/tsconfig.test.json"],
|
|
prepare: false,
|
|
coverage: false,
|
|
concurrency: 1,
|
|
log: () => {},
|
|
logError: () => {},
|
|
runAsync: async (args) => {
|
|
killedStarts.push(args[1]);
|
|
return { status: 1, signal: "SIGKILL", output: "", durationMs: 5 };
|
|
},
|
|
});
|
|
assert.equal(killedStatus, 1);
|
|
assert.deepEqual(killedStarts, ["a/tsconfig.test.json"]);
|
|
});
|
|
|
|
test("checkCoverageAsync checks targeted files with early exit and skips uninstalled providers", async () => {
|
|
const listed = [];
|
|
const covered = await checkCoverageAsync({
|
|
root: "/repo",
|
|
includeProviders: false,
|
|
onlyFiles: ["ui/src/Card.test.tsx"],
|
|
concurrency: 1,
|
|
workspaceConfigs: () => ["cli/tsconfig.json", "ui/tsconfig.json"],
|
|
trackedFiles: () => ["ui/src/Card.test.tsx", "packages/plugins/sandbox-providers/daytona/src/x.test.ts"],
|
|
listFilesAsync: async (config) => {
|
|
listed.push(config);
|
|
return {
|
|
status: 0,
|
|
output: "",
|
|
files: config === "ui/tsconfig.json" ? ["ui/src/Card.test.tsx"] : [],
|
|
};
|
|
},
|
|
logError: () => {},
|
|
});
|
|
assert.deepEqual(covered, []);
|
|
// Prioritized ui/tsconfig.json first and stopped immediately once covered.
|
|
assert.deepEqual(listed, ["ui/tsconfig.json"]);
|
|
|
|
const uncovered = await checkCoverageAsync({
|
|
root: "/repo",
|
|
includeProviders: false,
|
|
onlyFiles: ["ui/src/Orphan.test.tsx"],
|
|
concurrency: 2,
|
|
workspaceConfigs: () => ["ui/tsconfig.json"],
|
|
trackedFiles: () => ["ui/src/Orphan.test.tsx"],
|
|
listFilesAsync: async (config) => {
|
|
assert.ok(!SANDBOX_PROVIDER_PROGRAMS.includes(config), `should skip uninstalled provider ${config}`);
|
|
return { status: 0, output: "", files: [] };
|
|
},
|
|
logError: () => {},
|
|
});
|
|
assert.deepEqual(uncovered, ["ui/src/Orphan.test.tsx"]);
|
|
});
|
|
|
|
test("defaultConcurrency scales safely with CPU count and memory", () => {
|
|
const GiB = 1024 ** 3;
|
|
assert.equal(defaultConcurrency({ cpus: 2, totalMemoryBytes: 8 * GiB }), 1);
|
|
assert.equal(defaultConcurrency({ cpus: 4, totalMemoryBytes: 16 * GiB }), 2);
|
|
assert.equal(defaultConcurrency({ cpus: 8, totalMemoryBytes: 16 * GiB }), 3);
|
|
assert.equal(defaultConcurrency({ cpus: 8, totalMemoryBytes: 32 * GiB }), 4);
|
|
});
|