mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-16 11:59:26 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The Runner is the part that executes agent work: a daemon (`paperclip-runnerd`) and a provider pack of agent tools > - `master` now publishes the Runner alone as the image `ghcr.io/paperclipai/paperclip-runner`, one time for each set of Runner inputs (#21204, #21229, #21230) > - The application image still compiles its own Runner on every build. The next steps make it copy the published Runner instead > - Before a build can do that, it must answer one question the same way as every other build: "does a published Runner exist for exactly this tree?" It must also fail clearly when the Runner it was given does not match the tree > - This pull request adds the script that answers the question, and a mode of the Runner vendor step that fails instead of rebuilding > - The benefit is that the later change to the image build is small, and that a wrong or unreachable answer can only mean "build the Runner yourself" ## Linked Issues or Issue Description Refs #21204, #21229 and #21230 (the Runner image). No issue exists for this change. **Problem or motivation** Three builders make images that contain the Runner: `docker.yml`, the merge-queue build and the release preview build. Each one would have to repeat three steps to find the published Runner of its tree: check the lockfile, compute the inputs digest in the build, and look up `inputs-<digest>`. Three copies can decide differently. A build that copies a Runner built elsewhere also has no Rust toolchain. If the copied Runner does not match the tree, `prepare-runner-vendor.mjs` starts a rebuild, and the build fails late at `cargo` with a message that hides the cause. **Proposed solution** Add `scripts/runner-image-resolve.mjs`, the one place that decides. Add `PAPERCLIP_RUNNER_VENDOR_REQUIRE_CURRENT=1` to `prepare-runner-vendor.mjs`. Nothing calls the resolver and nothing sets the variable in this pull request, so no workflow job changes. **Alternatives considered** - One command that builds and looks up. Two commands keep a registry credential, when a caller has one, out of the step that builds. - A wait for the publication of the commit. The decision whether the application build waits is open, so the resolver has no wait mode. It reports `absent` and stops. - A build argument that names the expected inputs. No `Dockerfile` declares one yet. The change that makes the application image copy the Runner will add both ends together. **Roadmap alignment** This is build infrastructure. It adds no product feature and does not overlap an item in `ROADMAP.md`. This is part 1 of 4 of a stack ([stack #21309](https://github.com/paperclipai/paperclip/stack/21309)). Merge the parts in order: 1. #21306: the resolver and the no-rebuild mode (this pull request) 2. #21307: the report-only job in `docker.yml` and the pull-request check of the application image's Runner path 3. #21308: reading a retained provider pack from its Runner image 4. #21310: a registry build cache for the Runner image build ## What Changed - `scripts/runner-image-resolve.mjs` (new, 185 lines), with two commands that share a directory: - `inputs --dir <dir>` exports the `runner-artifacts-context` target, runs the lockfile check on that export, and builds the `runner-artifacts-identity` target when the lockfile is current. It reads no credential. A lockfile that is behind stops there: no image is published for such a tree. - `resolve --dir <dir>` looks up `inputs-<digest>` and prints `mode`, `reason`, `inputs_digest`, `image`, `slim_image`, `build_contexts` and `labels`. It also writes them to `$GITHUB_OUTPUT` and a short report to `$GITHUB_STEP_SUMMARY`. - `mode` is `published` only for a complete publication whose full index names these inputs and both platforms. Both images are pinned by index digest. The slim digest is the one the full index names in `io.paperclip.runner.slim-digest`; the slim tag is never read on its own. - Every other answer is `inline`, with the last four values empty: | `reason` | Meaning | | --- | --- | | `lock-behind` | `pnpm-lock.yaml` is behind the Runner's manifests | | `absent` | no tag exists | | `incomplete`, `broken` | a publication stopped, or its two tags do not belong together | | `mismatch` | the full index names other inputs, or lacks a platform | | `unknown` | the registry refused, failed or could not be reached, or the lookup threw | - The resolver reuses `runnerLockState`, `readRunnerImageManifest`, `runnerPublicationState` and `runnerImageTags` from `scripts/runner-image-publish.mjs`. That file now exports `environmentCredentials`; it has no other change. - `server/scripts/prepare-runner-vendor.mjs`: with `PAPERCLIP_RUNNER_VENDOR_REQUIRE_CURRENT=1`, the step reuses a current build as before. When the build is not current, it prints the reason, starts no rebuild, leaves the stamp in place and exits with status 1. It also fails when `PAPERCLIP_RUNNER_VENDOR_REBUILD=1` is set at the same time. Without the variable the step is the same as before. - `doc/runner-image-contract.md` has a new section, "Choosing the Runner for an image build". `doc/DEVELOPING.md` describes the new variable. - The resolver is not an input of the Runner image, so the inputs digest does not change. ## Verification macOS (Node 26.12.0), in `server/`: - `node node_modules/vitest/vitest.mjs run scripts/prepare-runner-vendor.test.mjs src/__tests__/runner-image-resolve.test.ts src/__tests__/runner-image-publish.test.ts src/__tests__/runner-image-identity.test.ts src/__tests__/runner-image-workflow.test.ts src/__tests__/server-package-build-script.test.ts`: 179 tests pass in 6 files. 27 of them are new resolver tests and 3 are new tests of the vendor step, whose end-to-end test also has a new case. - `tsc` on the new test file, with the settings of `server/src/__tests__/tsconfig.json`: no error. Linux (`node:24.22.3-bookworm`, GNU tar 1.34, the worktree mounted read-only): the same files, 179 tests pass. Real runs, on clean exports of the tree (`git archive`), with no credential, on a `linux/arm64` Docker host: - On `master` at `62d673cc3f`: `inputs` gave `lock=current` and `inputs_digest=0e6662ad9c8c6451556c76bf326723645d4afaab2decc73cd5e0025f7dd8d1ca`. `resolve` gave `mode=published`, `image=ghcr.io/paperclipai/paperclip-runner@sha256:84f2c051aa4ed16c5cc138c08e3533fa417e92177f7d15af5f2aa3e0ba467162` and `slim_image=ghcr.io/paperclipai/paperclip-runner@sha256:f63ea43666ed708f1b0e5d2ade8bdc002885bf04252b9ed6cee21f7920e54f3c`. These are the two indexes that `master` published for those inputs. - The same tree with one line added to a Runner source file: another digest, `mode=inline`, `reason=absent`. - On `master` at `bc71c23e0a`, which changed the Runner's inputs, before its image was published: digest `88fe2929321b4706c77f11a098572ce990fec4449d505544c62ef3a84c28308a`, `mode=inline`, `reason=absent`. - Four deliberate faults in the resolver each make a test fail: no index check, only `absent` is inline, the identity is built for a lockfile that is behind, and the slim image is taken by tag. Never run: - A lookup with a registry credential. The package is public, so no caller needs one now. - Any workflow. No workflow calls the resolver in this pull request. - `linux/amd64`. - The full test suite, the full typecheck and `pnpm build`. `pnpm verify --explain` reports exit 2, "broader verification required", so CI must supply them. ## Risks - Low for existing behaviour: nothing calls the resolver, and the vendor step is the same unless the new variable is set. - The resolver does not verify the attestation of the image. The workflow that consumes the image must do that from the digest the resolver reports. - The resolver reports both build contexts, `runner-artifacts` and `runner-artifacts-slim`. A build that reads only one stage gets one context it does not use. - A `broken` publication is `inline`, not a failure. The Runner image workflow fails for that state. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - Claude Fable 5.2 (`claude-fable-5-2`), Anthropic, used through Claude Code with tool use (shell, file edits, local Docker builds). ## 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 - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
382 lines
15 KiB
JavaScript
382 lines
15 KiB
JavaScript
import { execFile } from "node:child_process";
|
|
import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import { promisify } from "node:util";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
assessRunnerBuild,
|
|
beginRunnerBuild,
|
|
buildInputsStampPath,
|
|
readBuildInputsStamp,
|
|
recordRunnerBuild,
|
|
} from "../../packages/paperclip-runner/scripts/build-inputs.mjs";
|
|
import {
|
|
FORCE_REBUILD_VARIABLE,
|
|
REQUIRE_CURRENT_VARIABLE,
|
|
RUNNER_VENDOR_BUILD_COMMAND,
|
|
TIMING_SCHEMA,
|
|
decideRunnerVendorAction,
|
|
prepareRunnerVendor,
|
|
resolvePnpmInvocation,
|
|
} from "./prepare-runner-vendor.mjs";
|
|
|
|
const execFileAsync = promisify(execFile);
|
|
const prepareScript = fileURLToPath(new URL("./prepare-runner-vendor.mjs", import.meta.url));
|
|
const recordScript = fileURLToPath(
|
|
new URL("../../packages/paperclip-runner/scripts/record-build-inputs.mjs", import.meta.url),
|
|
);
|
|
const executable = process.platform === "win32" ? "paperclip-runnerd.exe" : "paperclip-runnerd";
|
|
|
|
const roots = [];
|
|
|
|
function writeTree(root, files) {
|
|
for (const [relative, content] of Object.entries(files)) {
|
|
const absolute = path.join(root, ...relative.split("/"));
|
|
mkdirSync(path.dirname(absolute), { recursive: true });
|
|
writeFileSync(absolute, content);
|
|
}
|
|
}
|
|
|
|
/** A throwaway workspace whose Runner is already built, with no stamp yet. */
|
|
function makeRepo() {
|
|
const repoRoot = mkdtempSync(path.join(tmpdir(), "prepare-runner-vendor-"));
|
|
roots.push(repoRoot);
|
|
writeTree(repoRoot, {
|
|
"package.json": "{}\n",
|
|
"pnpm-lock.yaml": "lockfileVersion: 9\n",
|
|
"pnpm-workspace.yaml": "packages:\n - packages/*\n - server\n",
|
|
"tsconfig.base.json": "{}\n",
|
|
"patches/acpx@0.22.0.patch": "--- a\n+++ b\n",
|
|
"server/package.json": '{"name":"@paperclipai/server"}\n',
|
|
"packages/paperclip-runner/package.json": '{"name":"@paperclipai/paperclip-runner"}\n',
|
|
"packages/paperclip-runner/src/index.ts": "export const one = 1;\n",
|
|
"packages/paperclip-runner/dist/index.js": "export const one = 1;\n",
|
|
"packages/paperclip-runner/dist/live/index.js": "export {};\n",
|
|
"packages/paperclip-runner/dist/testing.js": "export {};\n",
|
|
"packages/paperclip-runner/dist/cli/acpx-runtime-sidecar.cjs": "module.exports = {};\n",
|
|
[`packages/paperclip-runner/dist/bin/${executable}`]: "binary\n",
|
|
"packages/paperclip-eval-kernel/src/index.ts": "export const kernel = 1;\n",
|
|
});
|
|
const packageRoot = path.join(repoRoot, "packages", "paperclip-runner");
|
|
return { repoRoot, packageRoot };
|
|
}
|
|
|
|
/** What the Runner's build does around its steps when nothing changes meanwhile. */
|
|
function recordCurrentBuild({ repoRoot, packageRoot }) {
|
|
beginRunnerBuild({ repoRoot, packageRoot });
|
|
return recordRunnerBuild({ repoRoot, packageRoot });
|
|
}
|
|
|
|
afterEach(() => {
|
|
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true });
|
|
});
|
|
|
|
describe("decideRunnerVendorAction", () => {
|
|
const current = { current: true, code: "inputs_unchanged", detail: "unchanged" };
|
|
const stale = { current: false, code: "inputs_changed", detail: "changed" };
|
|
|
|
it("reuses a current build and rebuilds a stale one, carrying the assessment's reason", () => {
|
|
expect(decideRunnerVendorAction({ env: {}, assessment: current })).toEqual({
|
|
action: "reuse",
|
|
code: "inputs_unchanged",
|
|
detail: "unchanged",
|
|
});
|
|
expect(decideRunnerVendorAction({ env: {}, assessment: stale })).toEqual({
|
|
action: "rebuild",
|
|
code: "inputs_changed",
|
|
detail: "changed",
|
|
});
|
|
});
|
|
|
|
it("rebuilds a current build when the operator forces it", () => {
|
|
expect(decideRunnerVendorAction({ env: { [FORCE_REBUILD_VARIABLE]: "1" }, assessment: current })).toEqual({
|
|
action: "rebuild",
|
|
code: "forced",
|
|
detail: `${FORCE_REBUILD_VARIABLE}=1`,
|
|
});
|
|
// Only the documented value forces; an unrelated value does not.
|
|
expect(decideRunnerVendorAction({ env: { [FORCE_REBUILD_VARIABLE]: "0" }, assessment: current }).action).toBe(
|
|
"reuse",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("decideRunnerVendorAction when the build must be current", () => {
|
|
const current = { current: true, code: "inputs_unchanged", detail: "unchanged" };
|
|
const stale = { current: false, code: "inputs_changed", detail: "changed" };
|
|
const required = { [REQUIRE_CURRENT_VARIABLE]: "1" };
|
|
|
|
it("reuses a current build and fails on a stale one instead of rebuilding", () => {
|
|
expect(decideRunnerVendorAction({ env: required, assessment: current }).action).toBe("reuse");
|
|
expect(decideRunnerVendorAction({ env: required, assessment: stale })).toEqual({
|
|
action: "fail",
|
|
code: "inputs_changed",
|
|
detail: "changed",
|
|
});
|
|
expect(decideRunnerVendorAction({ env: { [REQUIRE_CURRENT_VARIABLE]: "0" }, assessment: stale }).action).toBe("rebuild");
|
|
});
|
|
|
|
it("fails when a rebuild is forced as well: the two cannot both hold", () => {
|
|
expect(decideRunnerVendorAction({ env: { ...required, [FORCE_REBUILD_VARIABLE]: "1" }, assessment: current })).toMatchObject({
|
|
action: "fail",
|
|
code: "conflict",
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("resolvePnpmInvocation", () => {
|
|
it("runs the pnpm that is running the script, through Node for a JavaScript entry", () => {
|
|
expect(resolvePnpmInvocation({ npm_execpath: "/corepack/pnpm/9.15.4/bin/pnpm.cjs" }, "/usr/bin/node")).toEqual({
|
|
command: "/usr/bin/node",
|
|
argsPrefix: ["/corepack/pnpm/9.15.4/bin/pnpm.cjs"],
|
|
});
|
|
expect(resolvePnpmInvocation({ npm_execpath: "/opt/pnpm/pnpm" }, "/usr/bin/node")).toEqual({
|
|
command: "/opt/pnpm/pnpm",
|
|
argsPrefix: [],
|
|
});
|
|
expect(resolvePnpmInvocation({ npm_execpath: "C:\\pnpm\\pnpm.exe" }, "node.exe")).toEqual({
|
|
command: "C:\\pnpm\\pnpm.exe",
|
|
argsPrefix: [],
|
|
});
|
|
});
|
|
|
|
it("falls back to pnpm on PATH outside a pnpm script or under another package manager", () => {
|
|
expect(resolvePnpmInvocation({}, "/usr/bin/node")).toEqual({ command: "pnpm", argsPrefix: [] });
|
|
expect(resolvePnpmInvocation({ npm_execpath: "" }, "/usr/bin/node")).toEqual({ command: "pnpm", argsPrefix: [] });
|
|
expect(resolvePnpmInvocation({ npm_execpath: "/usr/lib/node_modules/npm/bin/npm-cli.js" }, "/usr/bin/node")).toEqual({
|
|
command: "pnpm",
|
|
argsPrefix: [],
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("prepareRunnerVendor", () => {
|
|
it("still runs the Runner build the server build has always run", () => {
|
|
// The Dockerfile's standalone `pnpm --filter @paperclipai/server build`
|
|
// depends on this exact command producing a current vendored Runner.
|
|
expect(RUNNER_VENDOR_BUILD_COMMAND).toBe("pnpm --filter @paperclipai/paperclip-runner build");
|
|
});
|
|
|
|
it("skips the rebuild when the recorded build is current and reports the check time", () => {
|
|
const { repoRoot, packageRoot } = makeRepo();
|
|
recordCurrentBuild({ repoRoot, packageRoot });
|
|
const runs = [];
|
|
const lines = [];
|
|
|
|
const status = prepareRunnerVendor({
|
|
repoRoot,
|
|
env: {},
|
|
run: (...args) => {
|
|
runs.push(args);
|
|
return 0;
|
|
},
|
|
log: (line) => lines.push(line),
|
|
});
|
|
|
|
expect(status).toBe(0);
|
|
expect(runs).toEqual([]);
|
|
expect(lines[0]).toMatch(/^prepare:runner-vendor: reusing the current Runner build \(inputs unchanged/);
|
|
expect(lines[1]).toMatch(
|
|
new RegExp(`^${TIMING_SCHEMA},action:reuse,reason:inputs_unchanged,check_ms:\\d+,build_ms:0$`),
|
|
);
|
|
expect(readBuildInputsStamp(buildInputsStampPath(packageRoot))).not.toBeNull();
|
|
});
|
|
|
|
it("rebuilds when the inputs changed, removing the stale stamp before the build starts", () => {
|
|
const { repoRoot, packageRoot } = makeRepo();
|
|
recordCurrentBuild({ repoRoot, packageRoot });
|
|
writeFileSync(path.join(packageRoot, "src", "index.ts"), "export const one = 2;\n");
|
|
const stampPath = buildInputsStampPath(packageRoot);
|
|
const observed = [];
|
|
const lines = [];
|
|
const env = { npm_execpath: "/corepack/pnpm.cjs" };
|
|
|
|
const status = prepareRunnerVendor({
|
|
repoRoot,
|
|
env,
|
|
run: (command, options) => {
|
|
observed.push({ command, ...options, stampPresent: readBuildInputsStamp(stampPath) !== null });
|
|
return 0;
|
|
},
|
|
log: (line) => lines.push(line),
|
|
});
|
|
|
|
expect(status).toBe(0);
|
|
expect(observed).toEqual([
|
|
{ command: RUNNER_VENDOR_BUILD_COMMAND, cwd: path.join(repoRoot, "server"), env, stampPresent: false },
|
|
]);
|
|
expect(lines[0]).toMatch(/^prepare:runner-vendor: rebuilding the Runner \(inputs changed/);
|
|
expect(lines[1]).toMatch(
|
|
new RegExp(`^${TIMING_SCHEMA},action:rebuild,reason:inputs_changed,check_ms:\\d+,build_ms:\\d+,status:0$`),
|
|
);
|
|
});
|
|
|
|
it("rebuilds when a file the build left under dist is gone, even one no consumer imports", () => {
|
|
const { repoRoot, packageRoot } = makeRepo();
|
|
recordCurrentBuild({ repoRoot, packageRoot });
|
|
rmSync(path.join(packageRoot, "dist", "cli", "acpx-runtime-sidecar.cjs"));
|
|
let runs = 0;
|
|
const lines = [];
|
|
|
|
const status = prepareRunnerVendor({
|
|
repoRoot,
|
|
env: {},
|
|
run: () => {
|
|
runs += 1;
|
|
return 0;
|
|
},
|
|
log: (line) => lines.push(line),
|
|
});
|
|
|
|
expect(status).toBe(0);
|
|
expect(runs).toBe(1);
|
|
expect(lines[0]).toMatch(
|
|
/^prepare:runner-vendor: rebuilding the Runner \(build output dist\/cli\/acpx-runtime-sidecar\.cjs is missing since /,
|
|
);
|
|
expect(lines[1]).toMatch(/,action:rebuild,reason:outputs_changed,/);
|
|
});
|
|
|
|
it("returns the build's failure status and leaves no stamp behind", () => {
|
|
const { repoRoot, packageRoot } = makeRepo();
|
|
const lines = [];
|
|
|
|
const status = prepareRunnerVendor({
|
|
repoRoot,
|
|
env: {},
|
|
run: () => 3,
|
|
log: (line) => lines.push(line),
|
|
});
|
|
|
|
expect(status).toBe(3);
|
|
expect(lines[0]).toMatch(/^prepare:runner-vendor: rebuilding the Runner \(no build stamp/);
|
|
expect(lines[1]).toMatch(/,action:rebuild,reason:no_stamp,.*,status:3$/);
|
|
expect(readBuildInputsStamp(buildInputsStampPath(packageRoot))).toBeNull();
|
|
});
|
|
|
|
it("rebuilds a current build when PAPERCLIP_RUNNER_VENDOR_REBUILD=1", () => {
|
|
const { repoRoot, packageRoot } = makeRepo();
|
|
recordCurrentBuild({ repoRoot, packageRoot });
|
|
let runs = 0;
|
|
const lines = [];
|
|
|
|
const status = prepareRunnerVendor({
|
|
repoRoot,
|
|
env: { [FORCE_REBUILD_VARIABLE]: "1" },
|
|
run: () => {
|
|
runs += 1;
|
|
return 0;
|
|
},
|
|
log: (line) => lines.push(line),
|
|
});
|
|
|
|
expect(status).toBe(0);
|
|
expect(runs).toBe(1);
|
|
expect(lines[1]).toMatch(/,action:rebuild,reason:forced,/);
|
|
});
|
|
|
|
it("with PAPERCLIP_RUNNER_VENDOR_REQUIRE_CURRENT=1, reuses a current build and never starts a rebuild", () => {
|
|
const { repoRoot, packageRoot } = makeRepo();
|
|
recordCurrentBuild({ repoRoot, packageRoot });
|
|
const stampPath = buildInputsStampPath(packageRoot);
|
|
const env = { [REQUIRE_CURRENT_VARIABLE]: "1" };
|
|
let runs = 0;
|
|
const prepare = (lines) =>
|
|
prepareRunnerVendor({
|
|
repoRoot,
|
|
env,
|
|
run: () => {
|
|
runs += 1;
|
|
return 0;
|
|
},
|
|
log: (line) => lines.push(line),
|
|
});
|
|
|
|
const reused = [];
|
|
expect(prepare(reused)).toBe(0);
|
|
expect(reused[1]).toMatch(/,action:reuse,reason:inputs_unchanged,/);
|
|
|
|
writeFileSync(path.join(packageRoot, "src", "index.ts"), "export const one = 2;\n");
|
|
const failed = [];
|
|
expect(prepare(failed)).toBe(1);
|
|
expect(runs).toBe(0);
|
|
expect(failed[0]).toMatch(
|
|
new RegExp(`^prepare:runner-vendor: ${REQUIRE_CURRENT_VARIABLE}=1 forbids the Runner rebuild this step needs \\(inputs changed`),
|
|
);
|
|
expect(failed[1]).toMatch(
|
|
new RegExp(`^${TIMING_SCHEMA},action:fail,reason:inputs_changed,check_ms:\\d+,build_ms:0,status:1$`),
|
|
);
|
|
// The stamp still describes the build it was written for; only a rebuild removes it.
|
|
expect(readBuildInputsStamp(stampPath)).not.toBeNull();
|
|
});
|
|
|
|
it.skipIf(process.platform === "win32")(
|
|
"end to end: the first server build rebuilds the Runner, the second reuses it, a change or a lost output rebuilds again",
|
|
async () => {
|
|
const { repoRoot, packageRoot } = makeRepo();
|
|
// A stand-in pnpm that behaves like the Runner build: it records how it
|
|
// was called, then brackets its (empty) step list with the same two
|
|
// record-build-inputs.mjs calls the real build makes.
|
|
const binDir = path.join(repoRoot, "bin");
|
|
const argvLog = path.join(repoRoot, "pnpm-argv.log");
|
|
mkdirSync(binDir);
|
|
const pnpm = path.join(binDir, "pnpm");
|
|
writeFileSync(
|
|
pnpm,
|
|
`${[
|
|
"#!/bin/sh",
|
|
"set -e",
|
|
`printf '%s\\n' "$*" >> "${argvLog}"`,
|
|
`"${process.execPath}" "${recordScript}" --begin --package-root "${packageRoot}" > /dev/null`,
|
|
`"${process.execPath}" "${recordScript}" --finish --package-root "${packageRoot}" > /dev/null`,
|
|
].join("\n")}\n`,
|
|
);
|
|
chmodSync(pnpm, 0o755);
|
|
const env = { ...process.env, PATH: `${binDir}${path.delimiter}${process.env.PATH ?? ""}` };
|
|
delete env[FORCE_REBUILD_VARIABLE];
|
|
delete env[REQUIRE_CURRENT_VARIABLE];
|
|
// The suite itself may run under pnpm; the script must then take the
|
|
// PATH fallback so the stand-in, not the real pnpm, receives the build.
|
|
delete env.npm_execpath;
|
|
const run = () => execFileAsync(process.execPath, [prepareScript, "--repo-root", repoRoot], { env });
|
|
const calls = () => readFileSync(argvLog, "utf8").split("\n").filter(Boolean);
|
|
|
|
const first = await run();
|
|
expect(calls()).toEqual(["--filter @paperclipai/paperclip-runner build"]);
|
|
expect(first.stdout).toMatch(/action:rebuild,reason:no_stamp,/);
|
|
expect(assessRunnerBuild({ repoRoot, packageRoot }).current).toBe(true);
|
|
|
|
const second = await run();
|
|
expect(calls()).toHaveLength(1);
|
|
expect(second.stdout).toMatch(/action:reuse,reason:inputs_unchanged,/);
|
|
|
|
writeFileSync(path.join(packageRoot, "src", "index.ts"), "export const one = 2;\n");
|
|
const third = await run();
|
|
expect(calls()).toHaveLength(2);
|
|
expect(third.stdout).toMatch(/action:rebuild,reason:inputs_changed,/);
|
|
|
|
rmSync(path.join(packageRoot, "dist", "cli", "acpx-runtime-sidecar.cjs"));
|
|
const fourth = await run();
|
|
expect(calls()).toHaveLength(3);
|
|
expect(fourth.stdout).toMatch(/action:rebuild,reason:outputs_changed,/);
|
|
// The stand-in build does not recreate the helper, so the new stamp's
|
|
// manifest no longer lists it and the next run reuses the build.
|
|
const fifth = await run();
|
|
expect(calls()).toHaveLength(3);
|
|
expect(fifth.stdout).toMatch(/action:reuse,reason:inputs_unchanged,/);
|
|
|
|
// Required to be current: a stale build fails the step and pnpm is not called.
|
|
writeFileSync(path.join(packageRoot, "src", "index.ts"), "export const one = 3;\n");
|
|
const required = { ...env, [REQUIRE_CURRENT_VARIABLE]: "1" };
|
|
await expect(execFileAsync(process.execPath, [prepareScript, "--repo-root", repoRoot], { env: required })).rejects.toMatchObject({
|
|
code: 1,
|
|
stdout: expect.stringMatching(/action:fail,reason:inputs_changed,/),
|
|
});
|
|
expect(calls()).toHaveLength(3);
|
|
},
|
|
);
|
|
});
|