mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 09:39:53 +01:00
## 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
386 lines
20 KiB
TypeScript
386 lines
20 KiB
TypeScript
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import { computeBuildInputsDigest } from "../../../packages/paperclip-runner/scripts/build-inputs.mjs";
|
|
import { buildRunnerBuildPlan } from "../../../packages/paperclip-runner/scripts/run-build.mjs";
|
|
import {
|
|
RUNNER_IMAGE_CONTEXT_INPUTS,
|
|
RUNNER_IMAGE_INPUTS_SCHEMA,
|
|
computeContextTreeDigest,
|
|
computeRunnerImageIdentity,
|
|
} from "../../../scripts/runner-image-identity.mjs";
|
|
|
|
/**
|
|
* The Runner image is named after its identity. An identity that misses an
|
|
* input gives a changed Runner the name of an older one.
|
|
*/
|
|
|
|
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
|
const dockerfile = readFileSync(path.join(repoRoot, "Dockerfile"), "utf8");
|
|
|
|
const roots: string[] = [];
|
|
afterEach(() => {
|
|
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true });
|
|
});
|
|
|
|
function write(root: string, relative: string, content: string) {
|
|
const file = path.join(root, ...relative.split("/"));
|
|
mkdirSync(path.dirname(file), { recursive: true });
|
|
writeFileSync(file, content);
|
|
return file;
|
|
}
|
|
|
|
/** A repository with the real Dockerfile and one small file for every kind of input. */
|
|
function repository(): string {
|
|
const root = mkdtempSync(path.join(tmpdir(), "runner-image-identity-"));
|
|
roots.push(root);
|
|
write(root, "Dockerfile", dockerfile);
|
|
write(root, ".dockerignore", "node_modules\n");
|
|
for (const input of RUNNER_IMAGE_CONTEXT_INPUTS) {
|
|
if (!input.startsWith("packages/paperclip-") && input !== "patches") write(root, input, `input ${input}\n`);
|
|
}
|
|
write(root, "packages/paperclip-runner/package.json", "{}\n");
|
|
write(root, "packages/paperclip-runner/src/index.ts", "export const runner = 1;\n");
|
|
write(root, "packages/paperclip-runner/runner/crates/runner-core/src/lib.rs", "pub fn runner() {}\n");
|
|
write(root, "packages/paperclip-eval-kernel/src/index.ts", "export const kernel = 1;\n");
|
|
write(root, "patches/acpx@0.22.0.patch", "patch\n");
|
|
write(root, "ui/src/App.tsx", "export const app = 1;\n");
|
|
write(root, "server/src/index.ts", "export const server = 1;\n");
|
|
write(root, "packages/shared/src/index.ts", "export const shared = 1;\n");
|
|
return root;
|
|
}
|
|
|
|
const digestOf = (root: string) => computeRunnerImageIdentity(root).digest as string;
|
|
|
|
describe("Runner image identity", () => {
|
|
it("reports the tag, the context tree, the Dockerfile and the Runner build inputs", () => {
|
|
const identity = computeRunnerImageIdentity(repository());
|
|
expect(identity.schema).toBe(RUNNER_IMAGE_INPUTS_SCHEMA);
|
|
expect(identity.digest).toMatch(/^[0-9a-f]{64}$/);
|
|
expect(identity.tag).toBe(`inputs-${identity.digest}`);
|
|
expect(identity.image).toBe("ghcr.io/paperclipai/paperclip-runner");
|
|
expect(identity.platforms).toEqual(["linux/amd64", "linux/arm64"]);
|
|
expect(identity.context.inputs).toEqual(RUNNER_IMAGE_CONTEXT_INPUTS);
|
|
expect(identity.context.digest).toMatch(/^[0-9a-f]{64}$/);
|
|
expect(identity.dockerfile.sha256).toMatch(/^[0-9a-f]{64}$/);
|
|
expect(identity.buildInputs.schema).toBe("paperclip.runner-build-inputs.v2");
|
|
});
|
|
|
|
it("is the same for the same tree", () => {
|
|
const root = repository();
|
|
expect(digestOf(root)).toBe(digestOf(root));
|
|
expect(digestOf(repository())).toBe(digestOf(root));
|
|
});
|
|
|
|
it.each([
|
|
["a Runner TypeScript source file", "packages/paperclip-runner/src/index.ts"],
|
|
["a Runner Rust source file", "packages/paperclip-runner/runner/crates/runner-core/src/lib.rs"],
|
|
["the eval kernel the Runner builds first", "packages/paperclip-eval-kernel/src/index.ts"],
|
|
["a dependency patch", "patches/acpx@0.22.0.patch"],
|
|
["the lockfile", "pnpm-lock.yaml"],
|
|
["the root manifest", "package.json"],
|
|
["the pnpm configuration", ".npmrc"],
|
|
["the pack archive script", "scripts/create-provider-pack-archive.mjs"],
|
|
["the layout script", "scripts/runner-image-layout.mjs"],
|
|
["the contract copy that build:typescript checks", "packages/shared/src/provider-failure.generated.ts"],
|
|
["the Dockerfile, in a stage the Runner is not built from", "Dockerfile"],
|
|
])("changes when %s changes", (_label, file) => {
|
|
const root = repository();
|
|
const before = digestOf(root);
|
|
write(root, file, file === "Dockerfile" ? dockerfile.replace("FROM base AS production\n", "FROM base AS production\nRUN true\n") : "changed\n");
|
|
expect(digestOf(root)).not.toBe(before);
|
|
});
|
|
|
|
it.each([
|
|
["a UI source file", "ui/src/App.tsx"],
|
|
["a server source file", "server/src/index.ts"],
|
|
["another package's source file", "packages/shared/src/index.ts"],
|
|
["a new file outside the Runner's inputs", "server/src/services/new-service.ts"],
|
|
])("does not change when %s changes", (_label, file) => {
|
|
const root = repository();
|
|
const before = digestOf(root);
|
|
write(root, file, "changed\n");
|
|
expect(digestOf(root)).toBe(before);
|
|
});
|
|
|
|
it("refuses an input that is missing from the build context", () => {
|
|
const root = repository();
|
|
rmSync(path.join(root, "scripts/create-provider-pack-archive.mjs"));
|
|
expect(() => computeRunnerImageIdentity(root)).toThrow(/scripts\/create-provider-pack-archive\.mjs, which is missing/);
|
|
});
|
|
|
|
describe("context tree", () => {
|
|
// The Runner's build-input digest skips dot-directories and any directory
|
|
// named dist, and it does not read file modes. The image build copies
|
|
// those paths and modes all the same, so the identity must see them.
|
|
it.each([
|
|
["a file in a dot-directory", "packages/paperclip-runner/runner/.cargo/config.toml"],
|
|
["a file in a directory named dist", "packages/paperclip-runner/src/vendor/dist/bundle.js"],
|
|
])("changes for %s, which the Runner build-input digest does not read", (_label, file) => {
|
|
const root = repository();
|
|
const before = computeRunnerImageIdentity(root);
|
|
write(root, file, "[build]\n");
|
|
const after = computeRunnerImageIdentity(root);
|
|
expect(after.buildInputs.digest).toBe(before.buildInputs.digest);
|
|
expect(after.digest).not.toBe(before.digest);
|
|
});
|
|
|
|
it("changes when only the executable bit of a file changes", () => {
|
|
const root = repository();
|
|
const file = write(root, "packages/paperclip-runner/scripts/provision.sh", "#!/bin/sh\n");
|
|
chmodSync(file, 0o644);
|
|
const before = computeRunnerImageIdentity(root);
|
|
chmodSync(file, 0o755);
|
|
expect(computeBuildInputsDigest(root).digest).toBe(before.buildInputs.digest);
|
|
expect(digestOf(root)).not.toBe(before.digest);
|
|
});
|
|
|
|
it("records a symbolic link by its target and does not follow it", () => {
|
|
const root = repository();
|
|
const link = path.join(root, "packages/paperclip-runner/current");
|
|
symlinkSync("src", link);
|
|
const before = digestOf(root);
|
|
rmSync(link);
|
|
symlinkSync("../../server/src", link);
|
|
const after = digestOf(root);
|
|
expect(after).not.toBe(before);
|
|
write(root, "server/src/index.ts", "changed\n");
|
|
expect(digestOf(root)).toBe(after);
|
|
});
|
|
|
|
it("changes when a file is added or removed, and not with the order of a directory listing", () => {
|
|
const root = repository();
|
|
const before = digestOf(root);
|
|
write(root, "packages/paperclip-eval-kernel/src/extra.ts", "export {};\n");
|
|
expect(digestOf(root)).not.toBe(before);
|
|
rmSync(path.join(root, "packages/paperclip-eval-kernel/src/extra.ts"));
|
|
expect(digestOf(root)).toBe(before);
|
|
const other = repository();
|
|
for (const name of ["b.ts", "Z.ts", "a.ts", "_c.ts"]) write(root, `packages/paperclip-runner/src/${name}`, "x\n");
|
|
for (const name of ["_c.ts", "a.ts", "Z.ts", "b.ts"]) write(other, `packages/paperclip-runner/src/${name}`, "x\n");
|
|
expect(computeContextTreeDigest(root)).toEqual(computeContextTreeDigest(other));
|
|
});
|
|
});
|
|
|
|
describe(".dockerignore", () => {
|
|
// Its rules decide which files the build receives, and nothing else. The
|
|
// identity is computed inside the build, from the files it received.
|
|
it("does not change the identity when its text changes and the received files do not", () => {
|
|
const root = repository();
|
|
const before = digestOf(root);
|
|
write(root, ".dockerignore", "node_modules\nui/dist\nserver/tmp\n");
|
|
expect(digestOf(root)).toBe(before);
|
|
});
|
|
|
|
it("changes the identity when a rule removes a file from the Runner's context", () => {
|
|
const root = repository();
|
|
write(root, "packages/paperclip-runner/styles.css", "body {}\n");
|
|
const before = digestOf(root);
|
|
// What a new `packages/paperclip-runner/styles.css` rule does to the build context.
|
|
rmSync(path.join(root, "packages/paperclip-runner/styles.css"));
|
|
expect(digestOf(root)).not.toBe(before);
|
|
});
|
|
|
|
it("keeps out of the build context every directory a build script or a Vite configuration of a package among the identity's inputs writes its output into, so a tree with a local build and a clean checkout of one commit give the build the same files", () => {
|
|
const rules = readFileSync(path.join(repoRoot, ".dockerignore"), "utf8").split(/\r?\n/).filter((rule) => rule && !rule.startsWith("#"));
|
|
const lastRuleFor = (target: string) => rules.filter((rule) => target.split("/").some((_, index, segments) =>
|
|
path.matchesGlob(segments.slice(0, index + 1).join("/"), rule.replace(/^!/, "").replace(/^\//, "")))).at(-1);
|
|
const outputs = RUNNER_IMAGE_CONTEXT_INPUTS.filter((input) => existsSync(path.join(repoRoot, input, "package.json"))).flatMap((input) => {
|
|
const manifest = JSON.parse(readFileSync(path.join(repoRoot, input, "package.json"), "utf8"));
|
|
const scripts = Object.values(manifest.scripts as Record<string, string>).join("\n");
|
|
const emitted = [...scripts.matchAll(/\btsc -p (\S+)(?!\S| --noEmit)/g)].map((match) =>
|
|
JSON.parse(readFileSync(path.join(repoRoot, input, match[1]), "utf8")).compilerOptions.outDir as string);
|
|
const compiled = [...scripts.matchAll(/--manifest-path (\S+)\/Cargo\.toml/g)].map((match) => `${match[1]}/target`);
|
|
const bundled = readdirSync(path.join(repoRoot, input)).filter((name) => /^vite\..*config\.[cm]?[jt]s$/.test(name)).flatMap((name) =>
|
|
[...readFileSync(path.join(repoRoot, input, name), "utf8").matchAll(/\boutDir:\s*(?:resolve\(packageRoot,\s*)?"([^"]+)"/g)].map((match) => match[1]));
|
|
return [...emitted, ...compiled, ...bundled].map((output) => path.posix.join(input, output));
|
|
});
|
|
expect(outputs).toEqual(expect.arrayContaining([
|
|
"packages/paperclip-eval-kernel/dist",
|
|
"packages/paperclip-runner/dist",
|
|
"packages/paperclip-runner/dist-browser",
|
|
"packages/paperclip-runner/dist-issue-thread",
|
|
"packages/paperclip-runner/dist-scenarios",
|
|
"packages/paperclip-runner/dist-sdk",
|
|
"packages/paperclip-runner/dist-standalone",
|
|
"packages/paperclip-runner/runner/target",
|
|
]));
|
|
for (const output of new Set(outputs)) expect(lastRuleFor(output)?.startsWith("!"), output).toBe(false);
|
|
});
|
|
});
|
|
});
|
|
|
|
/**
|
|
* The identity hashes the whole Dockerfile and the context inputs. That is
|
|
* the whole of what the build reads only while these three rules hold.
|
|
*/
|
|
describe("Runner image stages", () => {
|
|
// BuildKit accepts an instruction in any case and with any indentation, and
|
|
// FROM with flags. A stage starts wherever BuildKit starts one; the first
|
|
// rule below then allows only the spelling the other rules can read.
|
|
const stagesOf = (text: string) => [...text.matchAll(/^[ \t]*from[ \t].*$/gim)].map((match, index, all) => ({
|
|
from: /^FROM (\S+)(?: AS \S+)?$/.exec(match[0])?.[1] ?? "",
|
|
// The name BuildKit gives the stage, however the line is spelt.
|
|
name: (/\sas\s+(\S+)\s*$/i.exec(match[0])?.[1] ?? "").toLowerCase(),
|
|
lines: text.slice(match.index, all[index + 1]?.index ?? text.length).split("\n").filter((line) => !/^\s*#/.test(line)),
|
|
}));
|
|
type Stage = ReturnType<typeof stagesOf>[number];
|
|
/** The lines of a stage that read something and are not in the one spelling these rules read. */
|
|
const misspelt = (stage: Stage) => stage.lines.filter((line, index) => (index === 0
|
|
// No lowercase keyword, no indentation, no flag on FROM.
|
|
? !/^FROM \S+ AS runner-artifacts[a-z-]*$/.test(line)
|
|
// No ADD or ONBUILD, no other flag, and no source on a continuation line.
|
|
: /^\s*(?:from|copy|add|onbuild)(?:\s|$)/i.test(line)
|
|
&& !/^COPY (?:--link )?(?:--from=runner-artifacts[a-z-]* )?[^-\s]\S*(?: [^\s\\]+)+$/.test(line)));
|
|
const stages = stagesOf(dockerfile);
|
|
const names = stages.map((stage) => stage.name);
|
|
const runner = stages.filter((stage) => stage.name.startsWith("runner-artifacts"));
|
|
const copies = (stage: Stage) => stage.lines.filter((line) => /^COPY\s/.test(line));
|
|
|
|
it("spell every FROM and COPY the one way these rules read, and use no ADD or ONBUILD", () => {
|
|
expect(runner.length).toBeGreaterThan(3);
|
|
for (const stage of runner) expect(misspelt(stage), stage.name).toEqual([]);
|
|
});
|
|
|
|
it.each([
|
|
["a lowercase stage keyword", "FROM scratch as runner-artifacts-extra\nCOPY secrets /\n"],
|
|
["a lowercase from", "from scratch AS runner-artifacts-extra\n"],
|
|
["a flag on FROM", "FROM --platform=linux/amd64 node:24 AS runner-artifacts-extra\n"],
|
|
["a lowercase copy", "FROM scratch AS runner-artifacts-extra\ncopy secrets /\n"],
|
|
["an indented COPY", "FROM scratch AS runner-artifacts-extra\n COPY secrets /\n"],
|
|
["an ADD in any case", "FROM scratch AS runner-artifacts-extra\n add secrets /\n"],
|
|
["a COPY continued on the next line", "FROM scratch AS runner-artifacts-extra\nCOPY package.json \\\n secrets /\n"],
|
|
["a COPY with another flag", "FROM scratch AS runner-artifacts-extra\nCOPY --parents secrets /\n"],
|
|
["an ONBUILD trigger", "FROM scratch AS runner-artifacts-extra\nONBUILD COPY secrets /\n"],
|
|
])("would catch %s in a stage BuildKit reads as one of the Runner's", (_label, text) => {
|
|
const added = stagesOf(text).filter((stage) => stage.name.startsWith("runner-artifacts"));
|
|
expect(added).toHaveLength(1);
|
|
expect(misspelt(added[0])).not.toEqual([]);
|
|
});
|
|
|
|
it("start only from each other, from scratch, or from an image pinned by digest", () => {
|
|
for (const stage of runner) {
|
|
if (stage.from === "scratch" || names.includes(stage.from)) {
|
|
expect(stage.from === "scratch" || stage.from.startsWith("runner-artifacts"), stage.name).toBe(true);
|
|
} else {
|
|
expect(stage.from, stage.name).toMatch(/@sha256:[0-9a-f]{64}$/);
|
|
}
|
|
for (const line of copies(stage)) {
|
|
const source = /--from=(\S+)/.exec(line)?.[1];
|
|
if (source) expect(source, line).toMatch(/^runner-artifacts/);
|
|
}
|
|
}
|
|
});
|
|
|
|
it("read the build context only through runner-artifacts-context", () => {
|
|
for (const stage of runner) {
|
|
const text = stage.lines.join("\n");
|
|
expect(text, stage.name).not.toMatch(/^ADD\s/m);
|
|
expect(text, stage.name).not.toMatch(/--mount=/);
|
|
expect(text, stage.name).not.toMatch(/<</);
|
|
if (stage.name === "runner-artifacts-context") continue;
|
|
const fromContext = copies(stage).filter((line) => !line.includes("--from="));
|
|
// The identity stage copies the Dockerfile itself, whose text the identity covers.
|
|
expect(fromContext, stage.name).toEqual(stage.name === "runner-artifacts-identity-compute" ? ["COPY Dockerfile ./"] : []);
|
|
}
|
|
});
|
|
|
|
it("copy into runner-artifacts-context exactly the paths the identity hashes", () => {
|
|
const context = runner.find((stage) => stage.name === "runner-artifacts-context")!;
|
|
const sources = copies(context).flatMap((line) => line.split(/\s+/).slice(1, -1));
|
|
expect(sources.filter((source) => source.startsWith("--"))).toEqual([]);
|
|
expect([...sources].sort()).toEqual([...RUNNER_IMAGE_CONTEXT_INPUTS].sort());
|
|
});
|
|
|
|
it("end in two file trees, the full one being the slim one plus the transport layers", () => {
|
|
// Each COPY --link is one layer that does not depend on the layers under
|
|
// it. The slim variant is the first two; the full variant starts from it,
|
|
// so it has the same two layers and then the transport archives.
|
|
const slim = runner.find((stage) => stage.name === "runner-artifacts-slim")!;
|
|
const full = runner.find((stage) => stage.name === "runner-artifacts")!;
|
|
const instructions = (stage: typeof slim) => stage.lines.filter((line) => /^[A-Z]+\s/.test(line)).slice(1);
|
|
expect(slim.from).toBe("scratch");
|
|
expect(instructions(slim)).toEqual([
|
|
"COPY --link --from=runner-artifacts-build /out-large/ /",
|
|
"COPY --link --from=runner-artifacts-build /out/ /",
|
|
]);
|
|
expect(full.from).toBe("runner-artifacts-slim");
|
|
expect(instructions(full)).toEqual([
|
|
"COPY --link --from=runner-artifacts-build /out-archives/ /",
|
|
"COPY --link --from=runner-artifacts-build /out-transport/ /",
|
|
]);
|
|
// `docker build .` builds the last stage.
|
|
expect(names.at(-1)).toBe("cloud");
|
|
const application = stages.filter((stage) => !stage.name.startsWith("runner-artifacts"));
|
|
for (const stage of application) {
|
|
expect(stage.from, stage.name).not.toMatch(/^runner-artifacts/);
|
|
const read = [...stage.lines.join("\n").matchAll(/from=(runner-artifacts[a-z-]*)/g)].map((match) => match[1]);
|
|
expect(read.filter((name) => name !== "runner-artifacts"), stage.name).toEqual([]);
|
|
}
|
|
expect(application.filter((stage) => /from=runner-artifacts/.test(stage.lines.join("\n"))).map((stage) => stage.name))
|
|
.toEqual(["build", "runner-provider-pack"]);
|
|
});
|
|
|
|
it("name the published image in the pack only for a publication build, which is off by default", () => {
|
|
const build = runner.find((stage) => stage.name === "runner-artifacts-build")!.lines.join("\n");
|
|
expect(build).toContain('ARG PAPERCLIP_RUNNER_IMAGE_PUBLICATION=""\n');
|
|
expect(build).toContain('publication="${PAPERCLIP_RUNNER_IMAGE_PUBLICATION}";');
|
|
// The pack builder reads the variable from the environment. It is set in
|
|
// one place, inside the branch that tests for a publication build.
|
|
expect(build.match(/PAPERCLIP_RUNNER_INPUTS_DIGEST=/g)).toHaveLength(1);
|
|
expect(build).toMatch(/if \[ -n "\$publication" \]; then \\\n\s+PAPERCLIP_RUNNER_INPUTS_DIGEST="\$\(node -p /);
|
|
expect(build).not.toMatch(/^ENV .*PAPERCLIP_RUNNER_INPUTS_DIGEST/m);
|
|
});
|
|
|
|
it("run every output step of the Runner's own build, and know every other step", () => {
|
|
// The image build runs the steps of the Runner's `build` script that write
|
|
// output, between the two that record the build stamp. This list is the
|
|
// whole script: a new step fails here until someone decides whether the
|
|
// image build must run it too.
|
|
const manifest = JSON.parse(readFileSync(path.join(repoRoot, "packages/paperclip-runner/package.json"), "utf8"));
|
|
expect(manifest.scripts.build).toBe("node scripts/run-build.mjs");
|
|
const phases = buildRunnerBuildPlan({ env: {} }) as Array<{
|
|
steps?: Array<{ label: string }>;
|
|
chains?: Array<{ steps: Array<{ label: string }> }>;
|
|
}>;
|
|
const plannedLabels = phases.flatMap((phase) =>
|
|
phase.steps
|
|
? phase.steps.map((step) => step.label)
|
|
: (phase.chains ?? []).flatMap((chain) => chain.steps.map((step) => step.label)),
|
|
);
|
|
expect(plannedLabels).toEqual([
|
|
"record-build-inputs:begin",
|
|
"build:eval-kernel",
|
|
"tsc:version",
|
|
"tsc:tsconfig",
|
|
"tsc:surfaces",
|
|
"cargo:release-runnerd",
|
|
"check:protocol-manifest",
|
|
"check:acpx-profiles",
|
|
"check:antigravity-models",
|
|
"check:protocol-schema-module",
|
|
"check:acpx-sidecar-contract",
|
|
"check:runtime-context-contract",
|
|
"check:provider-failure-contract",
|
|
"check:capability-contract",
|
|
"check:capability-inventory",
|
|
"build:verified-entrypoints",
|
|
"install:copilot-assets",
|
|
"build:runner-binary",
|
|
"check:protocol-coverage",
|
|
"check:semantic-contracts",
|
|
"check:replay-goldens",
|
|
"check:semantic-action-catalog",
|
|
"check:runner-workflow-traceability",
|
|
"record-build-inputs:finish",
|
|
]);
|
|
const build = runner.find((stage) => stage.name === "runner-artifacts-build")!.lines.join("\n");
|
|
for (const step of ["node scripts/record-build-inputs.mjs --begin;", "pnpm run build:typescript;", "pnpm run build:binary;",
|
|
"node scripts/record-build-inputs.mjs --finish;", "pnpm install --frozen-lockfile --filter '@paperclipai/paperclip-runner...'"]) {
|
|
expect(build).toContain(step);
|
|
}
|
|
});
|
|
});
|