mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 15:52:36 +01:00
fix(build): record Runner build inputs before the build and every dist output after it
Three gaps in the stamp the server's prepare:runner-vendor step trusts, all found in review: - The root patches directory was not an input, although build:typescript hashes patches/acpx@0.13.1.patch and copies the pi-acp and brace-expansion patches into dist. Every file under patches/ is now in the digest. - Only four outputs were checked, so a dist tree that lost a helper such as dist/cli/acpx-runtime-sidecar.cjs still counted as current. The stamp now records the path and size of every file under dist, and reuse requires all of them intact (reason code outputs_changed). - The digest was hashed after the build, so a source edited while the build ran was recorded as compiled. The Runner's build now brackets itself: record-build-inputs.mjs --begin captures the digest (and drops the old stamp) before the first step, --finish recomputes it after the last check and writes the stamp only if nothing moved. The stamp schema is now paperclip.runner-build-inputs.v2, so an older stamp is rejected and rebuilt. Rebuild paths are unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
c23faab3f4
commit
2d57542597
8 files changed
+477
-94
No files matched your search
@@ -9,12 +9,14 @@
|
||||
// 12-16s on the CI Build job's critical path (six master runs, 2026-10-11)
|
||||
// and the same again in every other `pnpm build`.
|
||||
//
|
||||
// The Runner's `build` now records a digest of its inputs after it succeeds
|
||||
// (packages/paperclip-runner/scripts/build-inputs.mjs). This step recomputes
|
||||
// the digest and reuses the build when the stamp matches and every output a
|
||||
// consumer reads exists; anything else runs the full Runner build exactly as
|
||||
// before. The standalone guarantee therefore holds: a fresh checkout, a
|
||||
// changed input, or a deleted output always rebuilds. Set
|
||||
// The Runner's `build` now records a digest of its inputs, captured before its
|
||||
// first step and confirmed after its last, together with a manifest of every
|
||||
// file it left under dist (packages/paperclip-runner/scripts/build-inputs.mjs).
|
||||
// This step recomputes the digest and reuses the build when the stamp matches
|
||||
// and every recorded output is still there at its recorded size; anything else
|
||||
// runs the full Runner build exactly as before. The standalone guarantee
|
||||
// therefore holds: a fresh checkout, a changed input, a deleted or truncated
|
||||
// output, or an edit that landed while the build ran always rebuilds. Set
|
||||
// PAPERCLIP_RUNNER_VENDOR_REBUILD=1 to rebuild regardless of the stamp.
|
||||
//
|
||||
// Usage: node scripts/prepare-runner-vendor.mjs [--repo-root <dir>]
|
||||
@@ -103,8 +105,10 @@ export function prepareRunnerVendor({
|
||||
}
|
||||
|
||||
log(`prepare:runner-vendor: rebuilding the Runner (${decision.detail})`);
|
||||
// A build that stops partway must not leave a stamp that vouches for it; the
|
||||
// Runner's own build writes a fresh one as its final step.
|
||||
// A build that stops partway must not leave a stamp that vouches for it. The
|
||||
// Runner's own build removes the stamp in its first step and writes a fresh
|
||||
// one in its last; removing it here as well covers a build command that
|
||||
// fails before its first step runs.
|
||||
removeBuildInputsStamp(assessment.stampPath);
|
||||
const buildStart = now();
|
||||
const status = run(RUNNER_VENDOR_BUILD_COMMAND, { cwd: path.join(repoRoot, "server"), env });
|
||||
|
||||
@@ -9,6 +9,7 @@ import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
assessRunnerBuild,
|
||||
beginRunnerBuild,
|
||||
buildInputsStampPath,
|
||||
readBuildInputsStamp,
|
||||
recordRunnerBuild,
|
||||
@@ -48,12 +49,14 @@ function makeRepo() {
|
||||
"pnpm-lock.yaml": "lockfileVersion: 9\n",
|
||||
"pnpm-workspace.yaml": "packages:\n - packages/*\n - server\n",
|
||||
"tsconfig.base.json": "{}\n",
|
||||
"patches/acpx@0.13.1.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",
|
||||
});
|
||||
@@ -61,6 +64,12 @@ function makeRepo() {
|
||||
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 });
|
||||
});
|
||||
@@ -130,7 +139,7 @@ describe("prepareRunnerVendor", () => {
|
||||
|
||||
it("skips the rebuild when the recorded build is current and reports the check time", () => {
|
||||
const { repoRoot, packageRoot } = makeRepo();
|
||||
recordRunnerBuild({ repoRoot, packageRoot });
|
||||
recordCurrentBuild({ repoRoot, packageRoot });
|
||||
const runs = [];
|
||||
const lines = [];
|
||||
|
||||
@@ -155,7 +164,7 @@ describe("prepareRunnerVendor", () => {
|
||||
|
||||
it("rebuilds when the inputs changed, removing the stale stamp before the build starts", () => {
|
||||
const { repoRoot, packageRoot } = makeRepo();
|
||||
recordRunnerBuild({ repoRoot, packageRoot });
|
||||
recordCurrentBuild({ repoRoot, packageRoot });
|
||||
writeFileSync(path.join(packageRoot, "src", "index.ts"), "export const one = 2;\n");
|
||||
const stampPath = buildInputsStampPath(packageRoot);
|
||||
const observed = [];
|
||||
@@ -182,6 +191,31 @@ describe("prepareRunnerVendor", () => {
|
||||
);
|
||||
});
|
||||
|
||||
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 = [];
|
||||
@@ -201,7 +235,7 @@ describe("prepareRunnerVendor", () => {
|
||||
|
||||
it("rebuilds a current build when PAPERCLIP_RUNNER_VENDOR_REBUILD=1", () => {
|
||||
const { repoRoot, packageRoot } = makeRepo();
|
||||
recordRunnerBuild({ repoRoot, packageRoot });
|
||||
recordCurrentBuild({ repoRoot, packageRoot });
|
||||
let runs = 0;
|
||||
const lines = [];
|
||||
|
||||
@@ -221,12 +255,12 @@ describe("prepareRunnerVendor", () => {
|
||||
});
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"end to end: the first server build rebuilds the Runner, the second reuses it, a change rebuilds again",
|
||||
"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 records the build inputs the way the real build does
|
||||
// as its final step.
|
||||
// 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);
|
||||
@@ -237,7 +271,8 @@ describe("prepareRunnerVendor", () => {
|
||||
"#!/bin/sh",
|
||||
"set -e",
|
||||
`printf '%s\\n' "$*" >> "${argvLog}"`,
|
||||
`"${process.execPath}" "${recordScript}" --package-root "${packageRoot}" > /dev/null`,
|
||||
`"${process.execPath}" "${recordScript}" --begin --package-root "${packageRoot}" > /dev/null`,
|
||||
`"${process.execPath}" "${recordScript}" --finish --package-root "${packageRoot}" > /dev/null`,
|
||||
].join("\n")}\n`,
|
||||
);
|
||||
chmodSync(pnpm, 0o755);
|
||||
@@ -262,6 +297,16 @@ describe("prepareRunnerVendor", () => {
|
||||
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,/);
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user