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
+26
-19
@@ -565,28 +565,35 @@ the suite on the fresh path.
|
|||||||
The server build vendors `packages/paperclip-runner/dist`, so its
|
The server build vendors `packages/paperclip-runner/dist`, so its
|
||||||
`prepare:runner-vendor` step has to make sure that directory is a current
|
`prepare:runner-vendor` step has to make sure that directory is a current
|
||||||
build. It used to run the Runner's full `build` every time. Now the Runner's
|
build. It used to run the Runner's full `build` every time. Now the Runner's
|
||||||
`build` ends by recording a digest of its inputs (every file under
|
`build` brackets itself with `scripts/record-build-inputs.mjs`: `--begin`, its
|
||||||
`packages/paperclip-runner` except `dist`, `dist-browser`, `runner/target`,
|
first step, forgets the previous stamp and records a digest of the build's
|
||||||
`node_modules` and dot-directories; every file under
|
inputs (every file under `packages/paperclip-runner` except `dist`,
|
||||||
`packages/paperclip-eval-kernel` except `dist` and `node_modules`; and the root
|
`dist-browser`, `runner/target`, `node_modules` and dot-directories; every
|
||||||
|
file under `packages/paperclip-eval-kernel` except `dist` and `node_modules`;
|
||||||
|
every file under the root `patches` directory, which the acpx profile check
|
||||||
|
hashes and the provider entrypoint bundler copies into `dist`; and the root
|
||||||
`package.json`, `pnpm-lock.yaml`, `pnpm-workspace.yaml` and
|
`package.json`, `pnpm-lock.yaml`, `pnpm-workspace.yaml` and
|
||||||
`tsconfig.base.json`) in
|
`tsconfig.base.json`). `--finish`, its last step, recomputes the digest and
|
||||||
`packages/paperclip-runner/node_modules/.cache/paperclip-runner-build-inputs.json`.
|
writes the stamp
|
||||||
`node server/scripts/prepare-runner-vendor.mjs` recomputes that digest and
|
`packages/paperclip-runner/node_modules/.cache/paperclip-runner-build-inputs.json`
|
||||||
reuses the build when it matches the stamp and `dist/index.js`,
|
only if the inputs are still the ones the build began with, together with the
|
||||||
`dist/live/index.js`, `dist/testing.js` and `dist/bin/paperclip-runnerd` all
|
path and size of every file under `dist`. An edit that lands while the build
|
||||||
exist. Anything else (no stamp, a changed input, a missing output, a stamp from
|
runs leaves no stamp, so the next consumer rebuilds.
|
||||||
another platform) runs `pnpm --filter @paperclipai/paperclip-runner build`
|
`node server/scripts/prepare-runner-vendor.mjs` reuses the build when the
|
||||||
exactly as before, so a standalone `pnpm --filter @paperclipai/server build`
|
stamp is for this platform, every recorded output is still there at its
|
||||||
on a fresh checkout still builds the Runner itself. Inside `pnpm build` the
|
recorded size, and the current digest matches. Anything else (no stamp, a
|
||||||
Runner has just been built by the same command, and the step skips a 12-16s
|
changed input, a deleted or truncated output, a stamp from another platform)
|
||||||
rebuild. The step prints one `paperclip.runner-vendor.timing.v1` line saying
|
runs `pnpm --filter @paperclipai/paperclip-runner build` exactly as before, so
|
||||||
which it did.
|
a standalone `pnpm --filter @paperclipai/server build` on a fresh checkout
|
||||||
|
still builds the Runner itself. Inside `pnpm build` the Runner has just been
|
||||||
|
built by the same command, and the step skips a 12-16s rebuild. The step
|
||||||
|
prints one `paperclip.runner-vendor.timing.v1` line saying which it did.
|
||||||
|
|
||||||
Set `PAPERCLIP_RUNNER_VENDOR_REBUILD=1` to rebuild regardless of the stamp. A
|
Set `PAPERCLIP_RUNNER_VENDOR_REBUILD=1` to rebuild regardless of the stamp. A
|
||||||
stamp is only written after a Runner build that passed every step, and the
|
stamp is only written after a Runner build that passed every step, and both
|
||||||
prepare step removes any existing stamp before it starts a rebuild, so a build
|
the Runner's first build step and the prepare step remove any existing stamp
|
||||||
that stops partway never leaves a stamp that vouches for it.
|
before a rebuild starts, so a build that stops partway never leaves a stamp
|
||||||
|
that vouches for it.
|
||||||
|
|
||||||
### Task search evaluation
|
### Task search evaluation
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@
|
|||||||
},
|
},
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "pnpm run check:protocol-manifest && pnpm run build:typescript && pnpm run check:capability-contract && pnpm run check:capability-inventory && pnpm run check:protocol-coverage && node scripts/generate-semantic-contracts.mjs --check && node scripts/check-runner-workflow-traceability.mjs && pnpm run build:binary && node scripts/generate-replay-goldens.mjs --check && node scripts/generate-semantic-action-catalog.mjs --check && node scripts/record-build-inputs.mjs",
|
"build": "node scripts/record-build-inputs.mjs --begin && pnpm run check:protocol-manifest && pnpm run build:typescript && pnpm run check:capability-contract && pnpm run check:capability-inventory && pnpm run check:protocol-coverage && node scripts/generate-semantic-contracts.mjs --check && node scripts/check-runner-workflow-traceability.mjs && pnpm run build:binary && node scripts/generate-replay-goldens.mjs --check && node scripts/generate-semantic-action-catalog.mjs --check && node scripts/record-build-inputs.mjs --finish",
|
||||||
"build:typescript": "pnpm run check:acpx-profiles && pnpm run ensure:eval-build-deps && pnpm run check:protocol-types && node ./node_modules/typescript/bin/tsc --version && node ./node_modules/typescript/bin/tsc -p tsconfig.json && node ./node_modules/typescript/bin/tsc -p tsconfig.surfaces.json && node scripts/build-verified-provider-entrypoints.mjs",
|
"build:typescript": "pnpm run check:acpx-profiles && pnpm run ensure:eval-build-deps && pnpm run check:protocol-types && node ./node_modules/typescript/bin/tsc --version && node ./node_modules/typescript/bin/tsc -p tsconfig.json && node ./node_modules/typescript/bin/tsc -p tsconfig.surfaces.json && node scripts/build-verified-provider-entrypoints.mjs",
|
||||||
"build:rust": "cargo build --manifest-path runner/Cargo.toml --locked --workspace --bins",
|
"build:rust": "cargo build --manifest-path runner/Cargo.toml --locked --workspace --bins",
|
||||||
"build:binary": "cargo build --release --manifest-path runner/Cargo.toml --locked -p paperclip-runner-core --bin paperclip-runnerd && node scripts/stage-runner-binary.mjs",
|
"build:binary": "cargo build --release --manifest-path runner/Cargo.toml --locked -p paperclip-runner-core --bin paperclip-runnerd && node scripts/stage-runner-binary.mjs",
|
||||||
|
|||||||
@@ -9,21 +9,35 @@
|
|||||||
// rebuild cost 12-16s on the CI Build job's critical path (six master runs,
|
// rebuild cost 12-16s on the CI Build job's critical path (six master runs,
|
||||||
// 2026-10-11), the same again in every other `pnpm build`.
|
// 2026-10-11), the same again in every other `pnpm build`.
|
||||||
//
|
//
|
||||||
// The Runner's `build` ends by recording a digest of every build input into a
|
// The Runner's `build` brackets itself with scripts/record-build-inputs.mjs:
|
||||||
// stamp under node_modules/.cache (scripts/record-build-inputs.mjs). The
|
// `--begin` removes any previous stamp and writes a pending record of the
|
||||||
// server's prepare step (server/scripts/prepare-runner-vendor.mjs) recomputes
|
// input digest before the first step reads anything; `--finish` recomputes
|
||||||
// the digest and reuses the build only when the stamp matches and the outputs
|
// the digest after the last check and writes the stamp under
|
||||||
// exist. Every other state rebuilds: a missing stamp, a changed input, a
|
// node_modules/.cache only if the inputs are still the ones the build started
|
||||||
// deleted output, a different platform. The slow direction is always the safe
|
// from, together with a manifest of every file the build left under dist. The
|
||||||
// one, and a stamp is only ever written after a build that passed every check.
|
// server's prepare step (server/scripts/prepare-runner-vendor.mjs) reuses the
|
||||||
|
// build only when the stamp matches, every recorded output is still there at
|
||||||
|
// its recorded size, and the current input digest matches. Every other state
|
||||||
|
// rebuilds: a missing stamp, a changed input, a deleted or truncated output, a
|
||||||
|
// different platform, an edit that landed while the build was running. The
|
||||||
|
// slow direction is always the safe one.
|
||||||
//
|
//
|
||||||
// Inputs: every file under packages/paperclip-runner except its build outputs
|
// Inputs: every file under packages/paperclip-runner except its build outputs
|
||||||
// (dist, dist-browser, runner/target), node_modules and dot-directories (tool
|
// (dist, dist-browser, runner/target), node_modules and dot-directories (tool
|
||||||
// caches); every file under packages/paperclip-eval-kernel except dist and
|
// caches); every file under packages/paperclip-eval-kernel except dist and
|
||||||
// node_modules, because build:typescript builds that package first; and the
|
// node_modules, because build:typescript builds that package first; every
|
||||||
// root files the Runner's tsconfig and dependency graph read. The toolchain
|
// file under the root patches directory, because check:acpx-profiles hashes
|
||||||
// pins live inside the package (rust-toolchain.toml, runner/Cargo.lock), and
|
// the acpx patch and build-verified-provider-entrypoints.mjs copies the pi-acp
|
||||||
// the TypeScript version comes from pnpm-lock.yaml, so both are covered.
|
// and brace-expansion patches into dist; and the root files the Runner's
|
||||||
|
// tsconfig and dependency graph read. The toolchain pins live inside the
|
||||||
|
// package (rust-toolchain.toml, runner/Cargo.lock), and the TypeScript version
|
||||||
|
// comes from pnpm-lock.yaml, so both are covered.
|
||||||
|
//
|
||||||
|
// Outputs: the server build vendors packages/paperclip-runner/dist wholesale
|
||||||
|
// (`cp -Rf ../packages/paperclip-runner/dist/. dist/vendor/paperclip-runner/`),
|
||||||
|
// so the stamp lists every file under dist with its size and reuse needs all
|
||||||
|
// of them present; a helper such as dist/cli/acpx-runtime-sidecar.cjs is
|
||||||
|
// opened by path at runtime, so a tree that lost it must not count as current.
|
||||||
|
|
||||||
import { createHash } from "node:crypto";
|
import { createHash } from "node:crypto";
|
||||||
import {
|
import {
|
||||||
@@ -40,16 +54,18 @@ import {
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
export const BUILD_INPUTS_SCHEMA = "paperclip.runner-build-inputs.v1";
|
export const BUILD_INPUTS_SCHEMA = "paperclip.runner-build-inputs.v2";
|
||||||
|
|
||||||
const RUNNER_PACKAGE_RELATIVE = "packages/paperclip-runner";
|
const RUNNER_PACKAGE_RELATIVE = "packages/paperclip-runner";
|
||||||
const EVAL_KERNEL_PACKAGE_RELATIVE = "packages/paperclip-eval-kernel";
|
const EVAL_KERNEL_PACKAGE_RELATIVE = "packages/paperclip-eval-kernel";
|
||||||
|
const ROOT_INPUT_DIRECTORIES = ["patches"];
|
||||||
const ROOT_INPUT_FILES = [
|
const ROOT_INPUT_FILES = [
|
||||||
"package.json",
|
"package.json",
|
||||||
"pnpm-lock.yaml",
|
"pnpm-lock.yaml",
|
||||||
"pnpm-workspace.yaml",
|
"pnpm-workspace.yaml",
|
||||||
"tsconfig.base.json",
|
"tsconfig.base.json",
|
||||||
];
|
];
|
||||||
|
const OUTPUT_DIRECTORY_RELATIVE = "dist";
|
||||||
const SKIPPED_DIRECTORY_NAMES = new Set(["node_modules", "dist", "dist-browser"]);
|
const SKIPPED_DIRECTORY_NAMES = new Set(["node_modules", "dist", "dist-browser"]);
|
||||||
const RUNNER_SKIPPED_DIRECTORIES = new Set([`${RUNNER_PACKAGE_RELATIVE}/runner/target`]);
|
const RUNNER_SKIPPED_DIRECTORIES = new Set([`${RUNNER_PACKAGE_RELATIVE}/runner/target`]);
|
||||||
|
|
||||||
@@ -65,25 +81,34 @@ export function buildInputsStampPath(packageRoot) {
|
|||||||
return path.join(packageRoot, "node_modules", ".cache", "paperclip-runner-build-inputs.json");
|
return path.join(packageRoot, "node_modules", ".cache", "paperclip-runner-build-inputs.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The outputs a consumer of the vendored Runner reads; all must exist for a build to count as current. */
|
/** Written by `--begin`, consumed by `--finish`; its presence means a build is (or was) in progress. */
|
||||||
|
export function buildInputsPendingPath(packageRoot) {
|
||||||
|
return path.join(packageRoot, "node_modules", ".cache", "paperclip-runner-build-inputs.pending.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The outputs every consumer of the vendored Runner reads; a build that did
|
||||||
|
* not produce them is not recorded, and a tree missing any of them is not
|
||||||
|
* current whatever the stamp says.
|
||||||
|
*/
|
||||||
export function expectedBuildOutputs(packageRoot, platform = process.platform) {
|
export function expectedBuildOutputs(packageRoot, platform = process.platform) {
|
||||||
const executable = platform === "win32" ? "paperclip-runnerd.exe" : "paperclip-runnerd";
|
const executable = platform === "win32" ? "paperclip-runnerd.exe" : "paperclip-runnerd";
|
||||||
return ["dist/index.js", "dist/live/index.js", "dist/testing.js", `dist/bin/${executable}`]
|
return ["dist/index.js", "dist/live/index.js", "dist/testing.js", `dist/bin/${executable}`]
|
||||||
.map((relative) => path.join(packageRoot, ...relative.split("/")));
|
.map((relative) => path.join(packageRoot, ...relative.split("/")));
|
||||||
}
|
}
|
||||||
|
|
||||||
function walk(repoRoot, relativeDirectory, skippedDirectories, out) {
|
function walk(root, relativeDirectory, { skipNames, skippedDirectories, skipDotDirectories }, out) {
|
||||||
const absolute = path.join(repoRoot, ...relativeDirectory.split("/"));
|
const absolute = path.join(root, ...relativeDirectory.split("/"));
|
||||||
if (!existsSync(absolute)) return;
|
if (!existsSync(absolute)) return;
|
||||||
const entries = readdirSync(absolute, { withFileTypes: true })
|
const entries = readdirSync(absolute, { withFileTypes: true })
|
||||||
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
const relative = `${relativeDirectory}/${entry.name}`;
|
const relative = `${relativeDirectory}/${entry.name}`;
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
if (entry.name.startsWith(".")) continue;
|
if (skipDotDirectories && entry.name.startsWith(".")) continue;
|
||||||
if (SKIPPED_DIRECTORY_NAMES.has(entry.name)) continue;
|
if (skipNames.has(entry.name)) continue;
|
||||||
if (skippedDirectories.has(relative)) continue;
|
if (skippedDirectories.has(relative)) continue;
|
||||||
walk(repoRoot, relative, skippedDirectories, out);
|
walk(root, relative, { skipNames, skippedDirectories, skipDotDirectories }, out);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Files and symlinks; a symlinked directory is hashed as its link target
|
// Files and symlinks; a symlinked directory is hashed as its link target
|
||||||
@@ -93,11 +118,18 @@ function walk(repoRoot, relativeDirectory, skippedDirectories, out) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const INPUT_WALK = {
|
||||||
|
skipNames: SKIPPED_DIRECTORY_NAMES,
|
||||||
|
skippedDirectories: new Set(),
|
||||||
|
skipDotDirectories: true,
|
||||||
|
};
|
||||||
|
|
||||||
/** Repo-relative POSIX paths of every build input, sorted. */
|
/** Repo-relative POSIX paths of every build input, sorted. */
|
||||||
export function collectBuildInputFiles(repoRoot) {
|
export function collectBuildInputFiles(repoRoot) {
|
||||||
const files = [];
|
const files = [];
|
||||||
walk(repoRoot, RUNNER_PACKAGE_RELATIVE, RUNNER_SKIPPED_DIRECTORIES, files);
|
walk(repoRoot, RUNNER_PACKAGE_RELATIVE, { ...INPUT_WALK, skippedDirectories: RUNNER_SKIPPED_DIRECTORIES }, files);
|
||||||
walk(repoRoot, EVAL_KERNEL_PACKAGE_RELATIVE, new Set(), files);
|
walk(repoRoot, EVAL_KERNEL_PACKAGE_RELATIVE, INPUT_WALK, files);
|
||||||
|
for (const directory of ROOT_INPUT_DIRECTORIES) walk(repoRoot, directory, INPUT_WALK, files);
|
||||||
for (const name of ROOT_INPUT_FILES) {
|
for (const name of ROOT_INPUT_FILES) {
|
||||||
if (existsSync(path.join(repoRoot, name))) files.push(name);
|
if (existsSync(path.join(repoRoot, name))) files.push(name);
|
||||||
}
|
}
|
||||||
@@ -131,6 +163,35 @@ export function computeBuildInputsDigest(repoRoot) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every file the build left under dist (the tree the server vendors), as
|
||||||
|
* package-relative POSIX paths with the size lstat reports, sorted. Nothing
|
||||||
|
* under dist is skipped: the server copies all of it.
|
||||||
|
*/
|
||||||
|
export function collectBuildOutputFiles(packageRoot) {
|
||||||
|
const files = [];
|
||||||
|
walk(packageRoot, OUTPUT_DIRECTORY_RELATIVE, { skipNames: new Set(), skippedDirectories: new Set(), skipDotDirectories: false }, files);
|
||||||
|
return files.sort().map((relative) => ({
|
||||||
|
path: relative,
|
||||||
|
size: lstatSync(path.join(packageRoot, ...relative.split("/"))).size,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The first recorded output that is gone or has changed size, or null when all are intact. */
|
||||||
|
export function findChangedBuildOutput(packageRoot, outputs) {
|
||||||
|
for (const output of outputs) {
|
||||||
|
const absolute = path.join(packageRoot, ...output.path.split("/"));
|
||||||
|
let stat;
|
||||||
|
try {
|
||||||
|
stat = lstatSync(absolute);
|
||||||
|
} catch {
|
||||||
|
return { ...output, state: "missing" };
|
||||||
|
}
|
||||||
|
if (stat.size !== output.size) return { ...output, state: "changed size", size: stat.size, recordedSize: output.size };
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export function readBuildInputsStamp(stampPath) {
|
export function readBuildInputsStamp(stampPath) {
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(readFileSync(stampPath, "utf8"));
|
const parsed = JSON.parse(readFileSync(stampPath, "utf8"));
|
||||||
@@ -152,8 +213,33 @@ export function removeBuildInputsStamp(stampPath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records the current inputs as the ones that produced the current outputs.
|
* First step of the Runner's build: forgets the previous build (a build in
|
||||||
* Call this only after a build that completed every step and check.
|
* progress can no longer vouch for its outputs) and records the inputs the
|
||||||
|
* build is about to read, so that `recordRunnerBuild` can tell whether they
|
||||||
|
* changed while it ran.
|
||||||
|
*/
|
||||||
|
export function beginRunnerBuild({
|
||||||
|
repoRoot,
|
||||||
|
packageRoot,
|
||||||
|
platform = process.platform,
|
||||||
|
arch = process.arch,
|
||||||
|
now = () => new Date(),
|
||||||
|
}) {
|
||||||
|
removeBuildInputsStamp(buildInputsStampPath(packageRoot));
|
||||||
|
const inputs = computeBuildInputsDigest(repoRoot);
|
||||||
|
const pending = { ...inputs, platform, arch, startedAt: now().toISOString() };
|
||||||
|
const pendingPath = buildInputsPendingPath(packageRoot);
|
||||||
|
writeBuildInputsStamp(pendingPath, pending);
|
||||||
|
return { ...pending, pendingPath };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Last step of the Runner's build, after every step and check has passed:
|
||||||
|
* records the inputs captured by `beginRunnerBuild` as the ones that produced
|
||||||
|
* the outputs now under dist. An edit that landed while the build ran means
|
||||||
|
* the outputs may not reflect the current inputs, so nothing is recorded and
|
||||||
|
* the next consumer rebuilds. A build that did not begin with
|
||||||
|
* `beginRunnerBuild`, or that left a required output missing, is an error.
|
||||||
*/
|
*/
|
||||||
export function recordRunnerBuild({
|
export function recordRunnerBuild({
|
||||||
repoRoot,
|
repoRoot,
|
||||||
@@ -162,11 +248,50 @@ export function recordRunnerBuild({
|
|||||||
arch = process.arch,
|
arch = process.arch,
|
||||||
now = () => new Date(),
|
now = () => new Date(),
|
||||||
}) {
|
}) {
|
||||||
const inputs = computeBuildInputsDigest(repoRoot);
|
|
||||||
const record = { ...inputs, platform, arch, recordedAt: now().toISOString() };
|
|
||||||
const stampPath = buildInputsStampPath(packageRoot);
|
const stampPath = buildInputsStampPath(packageRoot);
|
||||||
|
const pendingPath = buildInputsPendingPath(packageRoot);
|
||||||
|
const pending = readBuildInputsStamp(pendingPath);
|
||||||
|
if (!pending || pending.schema !== BUILD_INPUTS_SCHEMA || typeof pending.digest !== "string") {
|
||||||
|
removeBuildInputsStamp(stampPath);
|
||||||
|
throw new Error(
|
||||||
|
`no pending build inputs at ${pendingPath}: the Runner build must start with ` +
|
||||||
|
"`node scripts/record-build-inputs.mjs --begin` before it can record its result",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
rmSync(pendingPath, { force: true });
|
||||||
|
|
||||||
|
const missing = expectedBuildOutputs(packageRoot, platform).filter((file) => !existsSync(file));
|
||||||
|
if (missing.length > 0) {
|
||||||
|
removeBuildInputsStamp(stampPath);
|
||||||
|
throw new Error(`the Runner build finished without producing ${path.relative(packageRoot, missing[0])}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputs = computeBuildInputsDigest(repoRoot);
|
||||||
|
if (inputs.digest !== pending.digest) {
|
||||||
|
removeBuildInputsStamp(stampPath);
|
||||||
|
return {
|
||||||
|
recorded: false,
|
||||||
|
code: "inputs_changed_during_build",
|
||||||
|
detail:
|
||||||
|
`inputs changed while the build ran (digest ${pending.digest.slice(0, 12)} at start, ` +
|
||||||
|
`${inputs.digest.slice(0, 12)} now); the next consumer rebuilds`,
|
||||||
|
startedAt: pending.startedAt,
|
||||||
|
stampPath,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const outputs = collectBuildOutputFiles(packageRoot);
|
||||||
|
const record = {
|
||||||
|
...inputs,
|
||||||
|
platform,
|
||||||
|
arch,
|
||||||
|
startedAt: pending.startedAt,
|
||||||
|
recordedAt: now().toISOString(),
|
||||||
|
outputCount: outputs.length,
|
||||||
|
outputs,
|
||||||
|
};
|
||||||
writeBuildInputsStamp(stampPath, record);
|
writeBuildInputsStamp(stampPath, record);
|
||||||
return { ...record, stampPath };
|
return { recorded: true, code: "recorded", ...record, stampPath };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,7 +309,7 @@ export function assessRunnerBuild({
|
|||||||
if (!stamp) {
|
if (!stamp) {
|
||||||
return { current: false, code: "no_stamp", detail: `no build stamp at ${stampPath}`, stampPath };
|
return { current: false, code: "no_stamp", detail: `no build stamp at ${stampPath}`, stampPath };
|
||||||
}
|
}
|
||||||
if (stamp.schema !== BUILD_INPUTS_SCHEMA) {
|
if (stamp.schema !== BUILD_INPUTS_SCHEMA || !Array.isArray(stamp.outputs)) {
|
||||||
return {
|
return {
|
||||||
current: false,
|
current: false,
|
||||||
code: "schema_mismatch",
|
code: "schema_mismatch",
|
||||||
@@ -209,6 +334,17 @@ export function assessRunnerBuild({
|
|||||||
stampPath,
|
stampPath,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
const changedOutput = findChangedBuildOutput(packageRoot, stamp.outputs);
|
||||||
|
if (changedOutput) {
|
||||||
|
return {
|
||||||
|
current: false,
|
||||||
|
code: "outputs_changed",
|
||||||
|
detail:
|
||||||
|
`build output ${changedOutput.path} is ${changedOutput.state} since the build recorded at ` +
|
||||||
|
`${stamp.recordedAt}; ${stamp.outputs.length} outputs checked`,
|
||||||
|
stampPath,
|
||||||
|
};
|
||||||
|
}
|
||||||
const inputs = computeBuildInputsDigest(repoRoot);
|
const inputs = computeBuildInputsDigest(repoRoot);
|
||||||
if (inputs.digest !== stamp.digest) {
|
if (inputs.digest !== stamp.digest) {
|
||||||
return {
|
return {
|
||||||
@@ -222,7 +358,9 @@ export function assessRunnerBuild({
|
|||||||
return {
|
return {
|
||||||
current: true,
|
current: true,
|
||||||
code: "inputs_unchanged",
|
code: "inputs_unchanged",
|
||||||
detail: `inputs unchanged since the build recorded at ${stamp.recordedAt}; ${inputs.fileCount} files checked`,
|
detail:
|
||||||
|
`inputs unchanged since the build recorded at ${stamp.recordedAt}; ${inputs.fileCount} files ` +
|
||||||
|
`and ${stamp.outputs.length} outputs checked`,
|
||||||
stampPath,
|
stampPath,
|
||||||
inputs,
|
inputs,
|
||||||
stamp,
|
stamp,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import { execFile } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
import { mkdtemp, mkdir, readFile, rm, symlink, writeFile } from "node:fs/promises";
|
import { mkdtemp, mkdir, readFile, rm, stat, symlink, truncate, writeFile } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { test } from "node:test";
|
import { test } from "node:test";
|
||||||
@@ -9,8 +9,11 @@ import { fileURLToPath } from "node:url";
|
|||||||
import {
|
import {
|
||||||
BUILD_INPUTS_SCHEMA,
|
BUILD_INPUTS_SCHEMA,
|
||||||
assessRunnerBuild,
|
assessRunnerBuild,
|
||||||
|
beginRunnerBuild,
|
||||||
|
buildInputsPendingPath,
|
||||||
buildInputsStampPath,
|
buildInputsStampPath,
|
||||||
collectBuildInputFiles,
|
collectBuildInputFiles,
|
||||||
|
collectBuildOutputFiles,
|
||||||
computeBuildInputsDigest,
|
computeBuildInputsDigest,
|
||||||
expectedBuildOutputs,
|
expectedBuildOutputs,
|
||||||
readBuildInputsStamp,
|
readBuildInputsStamp,
|
||||||
@@ -28,7 +31,11 @@ async function writeTree(root, files) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A throwaway repo with one Runner source file, one Rust source, built outputs, and the usual noise. */
|
/**
|
||||||
|
* A throwaway repo with one Runner source file, one Rust source, two root
|
||||||
|
* patches, built outputs (the four every consumer reads plus one helper that
|
||||||
|
* is only opened by path), and the usual noise.
|
||||||
|
*/
|
||||||
async function makeRepo() {
|
async function makeRepo() {
|
||||||
const repoRoot = await mkdtemp(path.join(tmpdir(), "runner-build-inputs-"));
|
const repoRoot = await mkdtemp(path.join(tmpdir(), "runner-build-inputs-"));
|
||||||
await writeTree(repoRoot, {
|
await writeTree(repoRoot, {
|
||||||
@@ -36,6 +43,8 @@ async function makeRepo() {
|
|||||||
"pnpm-lock.yaml": "lockfileVersion: 9\n",
|
"pnpm-lock.yaml": "lockfileVersion: 9\n",
|
||||||
"pnpm-workspace.yaml": "packages:\n - packages/*\n",
|
"pnpm-workspace.yaml": "packages:\n - packages/*\n",
|
||||||
"tsconfig.base.json": "{}\n",
|
"tsconfig.base.json": "{}\n",
|
||||||
|
"patches/acpx@0.13.1.patch": "--- a\n+++ b\n",
|
||||||
|
"patches/pi-acp@0.0.33.patch": "--- c\n+++ d\n",
|
||||||
"packages/paperclip-runner/package.json": '{"name":"@paperclipai/paperclip-runner"}\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/src/index.ts": "export const one = 1;\n",
|
||||||
"packages/paperclip-runner/runner/src/main.rs": "fn main() {}\n",
|
"packages/paperclip-runner/runner/src/main.rs": "fn main() {}\n",
|
||||||
@@ -44,6 +53,7 @@ async function makeRepo() {
|
|||||||
"packages/paperclip-runner/dist/live/index.js": "export {};\n",
|
"packages/paperclip-runner/dist/live/index.js": "export {};\n",
|
||||||
"packages/paperclip-runner/dist/testing.js": "export {};\n",
|
"packages/paperclip-runner/dist/testing.js": "export {};\n",
|
||||||
"packages/paperclip-runner/dist/bin/paperclip-runnerd": "binary\n",
|
"packages/paperclip-runner/dist/bin/paperclip-runnerd": "binary\n",
|
||||||
|
"packages/paperclip-runner/dist/cli/acpx-runtime-sidecar.cjs": "module.exports = {};\n",
|
||||||
"packages/paperclip-runner/dist-browser/index.js": "browser\n",
|
"packages/paperclip-runner/dist-browser/index.js": "browser\n",
|
||||||
"packages/paperclip-runner/node_modules/dep/index.js": "dep\n",
|
"packages/paperclip-runner/node_modules/dep/index.js": "dep\n",
|
||||||
"packages/paperclip-runner/.vite/cache.json": "{}\n",
|
"packages/paperclip-runner/.vite/cache.json": "{}\n",
|
||||||
@@ -54,6 +64,9 @@ async function makeRepo() {
|
|||||||
return { repoRoot, packageRoot };
|
return { repoRoot, packageRoot };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const INPUT_FILE_COUNT = 10;
|
||||||
|
const OUTPUT_FILE_COUNT = 5;
|
||||||
|
|
||||||
async function withRepo(action) {
|
async function withRepo(action) {
|
||||||
const repo = await makeRepo();
|
const repo = await makeRepo();
|
||||||
try {
|
try {
|
||||||
@@ -63,7 +76,13 @@ async function withRepo(action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test("the input set covers sources, the eval kernel and root config, and skips outputs and caches", async () => {
|
/** A complete, undisturbed build: begin, (nothing changes), finish. */
|
||||||
|
function recordCurrentBuild({ repoRoot, packageRoot, platform, arch, now }) {
|
||||||
|
beginRunnerBuild({ repoRoot, packageRoot, platform, arch, now });
|
||||||
|
return recordRunnerBuild({ repoRoot, packageRoot, platform, arch, now });
|
||||||
|
}
|
||||||
|
|
||||||
|
test("the input set covers sources, the eval kernel, root patches and root config, and skips outputs and caches", async () => {
|
||||||
await withRepo(async ({ repoRoot }) => {
|
await withRepo(async ({ repoRoot }) => {
|
||||||
const files = collectBuildInputFiles(repoRoot);
|
const files = collectBuildInputFiles(repoRoot);
|
||||||
assert.deepEqual(files, [
|
assert.deepEqual(files, [
|
||||||
@@ -72,10 +91,27 @@ test("the input set covers sources, the eval kernel and root config, and skips o
|
|||||||
"packages/paperclip-runner/package.json",
|
"packages/paperclip-runner/package.json",
|
||||||
"packages/paperclip-runner/runner/src/main.rs",
|
"packages/paperclip-runner/runner/src/main.rs",
|
||||||
"packages/paperclip-runner/src/index.ts",
|
"packages/paperclip-runner/src/index.ts",
|
||||||
|
"patches/acpx@0.13.1.patch",
|
||||||
|
"patches/pi-acp@0.0.33.patch",
|
||||||
"pnpm-lock.yaml",
|
"pnpm-lock.yaml",
|
||||||
"pnpm-workspace.yaml",
|
"pnpm-workspace.yaml",
|
||||||
"tsconfig.base.json",
|
"tsconfig.base.json",
|
||||||
]);
|
]);
|
||||||
|
assert.equal(files.length, INPUT_FILE_COUNT);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the output manifest lists every file under dist with its size, and nothing outside it", async () => {
|
||||||
|
await withRepo(async ({ packageRoot }) => {
|
||||||
|
const outputs = collectBuildOutputFiles(packageRoot);
|
||||||
|
assert.deepEqual(outputs, [
|
||||||
|
{ path: "dist/bin/paperclip-runnerd", size: 7 },
|
||||||
|
{ path: "dist/cli/acpx-runtime-sidecar.cjs", size: 21 },
|
||||||
|
{ path: "dist/index.js", size: 22 },
|
||||||
|
{ path: "dist/live/index.js", size: 11 },
|
||||||
|
{ path: "dist/testing.js", size: 11 },
|
||||||
|
]);
|
||||||
|
assert.equal(outputs.length, OUTPUT_FILE_COUNT);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -83,12 +119,13 @@ test("the digest is stable, ignores outputs and caches, and tracks every kind of
|
|||||||
await withRepo(async ({ repoRoot }) => {
|
await withRepo(async ({ repoRoot }) => {
|
||||||
const before = computeBuildInputsDigest(repoRoot);
|
const before = computeBuildInputsDigest(repoRoot);
|
||||||
assert.equal(before.schema, BUILD_INPUTS_SCHEMA);
|
assert.equal(before.schema, BUILD_INPUTS_SCHEMA);
|
||||||
assert.equal(before.fileCount, 8);
|
assert.equal(before.fileCount, INPUT_FILE_COUNT);
|
||||||
assert.equal(computeBuildInputsDigest(repoRoot).digest, before.digest, "two reads disagree");
|
assert.equal(computeBuildInputsDigest(repoRoot).digest, before.digest, "two reads disagree");
|
||||||
|
|
||||||
// Outputs, dependencies, caches and the Rust target directory may change freely.
|
// Outputs, dependencies, caches and the Rust target directory may change freely.
|
||||||
await writeTree(repoRoot, {
|
await writeTree(repoRoot, {
|
||||||
"packages/paperclip-runner/dist/index.js": "export const one = 2;\n",
|
"packages/paperclip-runner/dist/index.js": "export const one = 2;\n",
|
||||||
|
"packages/paperclip-runner/dist/cli/acpx-runtime-sidecar.cjs": "changed\n",
|
||||||
"packages/paperclip-runner/dist-browser/index.js": "changed\n",
|
"packages/paperclip-runner/dist-browser/index.js": "changed\n",
|
||||||
"packages/paperclip-runner/node_modules/dep/index.js": "changed\n",
|
"packages/paperclip-runner/node_modules/dep/index.js": "changed\n",
|
||||||
"packages/paperclip-runner/.vite/cache.json": '{"changed":true}\n',
|
"packages/paperclip-runner/.vite/cache.json": '{"changed":true}\n',
|
||||||
@@ -97,7 +134,8 @@ test("the digest is stable, ignores outputs and caches, and tracks every kind of
|
|||||||
});
|
});
|
||||||
assert.equal(computeBuildInputsDigest(repoRoot).digest, before.digest, "an output changed the digest");
|
assert.equal(computeBuildInputsDigest(repoRoot).digest, before.digest, "an output changed the digest");
|
||||||
|
|
||||||
// Every input kind changes it: TypeScript, Rust, the eval kernel, root config, a new file, a rename.
|
// Every input kind changes it: TypeScript, Rust, the eval kernel, a root
|
||||||
|
// patch, root config, a new file, a rename.
|
||||||
const seen = new Set([before.digest]);
|
const seen = new Set([before.digest]);
|
||||||
const expectChange = async (label, files) => {
|
const expectChange = async (label, files) => {
|
||||||
await writeTree(repoRoot, files);
|
await writeTree(repoRoot, files);
|
||||||
@@ -108,6 +146,9 @@ test("the digest is stable, ignores outputs and caches, and tracks every kind of
|
|||||||
await expectChange("a Runner source", { "packages/paperclip-runner/src/index.ts": "export const one = 2;\n" });
|
await expectChange("a Runner source", { "packages/paperclip-runner/src/index.ts": "export const one = 2;\n" });
|
||||||
await expectChange("a Rust source", { "packages/paperclip-runner/runner/src/main.rs": "fn main() { }\n" });
|
await expectChange("a Rust source", { "packages/paperclip-runner/runner/src/main.rs": "fn main() { }\n" });
|
||||||
await expectChange("an eval-kernel source", { "packages/paperclip-eval-kernel/src/index.ts": "export const kernel = 2;\n" });
|
await expectChange("an eval-kernel source", { "packages/paperclip-eval-kernel/src/index.ts": "export const kernel = 2;\n" });
|
||||||
|
await expectChange("the pi-acp patch the build copies into dist", { "patches/pi-acp@0.0.33.patch": "--- c\n+++ d\n+e\n" });
|
||||||
|
await expectChange("the acpx patch the profile check hashes", { "patches/acpx@0.13.1.patch": "--- a\n+++ b\n+c\n" });
|
||||||
|
await expectChange("a new patch", { "patches/brace-expansion@5.0.9.patch": "--- x\n+++ y\n" });
|
||||||
await expectChange("the lockfile", { "pnpm-lock.yaml": "lockfileVersion: 9\nchanged: true\n" });
|
await expectChange("the lockfile", { "pnpm-lock.yaml": "lockfileVersion: 9\nchanged: true\n" });
|
||||||
await expectChange("the base tsconfig", { "tsconfig.base.json": '{"compilerOptions":{}}\n' });
|
await expectChange("the base tsconfig", { "tsconfig.base.json": '{"compilerOptions":{}}\n' });
|
||||||
await expectChange("a new file", { "packages/paperclip-runner/protocol/new.json": "{}\n" });
|
await expectChange("a new file", { "packages/paperclip-runner/protocol/new.json": "{}\n" });
|
||||||
@@ -128,7 +169,7 @@ test("a symlink is hashed as its target path, not followed", async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("a build is current only with a matching stamp and every consumer-facing output present", async () => {
|
test("a build is current only with a matching stamp and every recorded output intact", async () => {
|
||||||
await withRepo(async ({ repoRoot, packageRoot }) => {
|
await withRepo(async ({ repoRoot, packageRoot }) => {
|
||||||
const platform = "linux";
|
const platform = "linux";
|
||||||
const arch = "x64";
|
const arch = "x64";
|
||||||
@@ -137,24 +178,29 @@ test("a build is current only with a matching stamp and every consumer-facing ou
|
|||||||
assert.equal(assess().current, false);
|
assert.equal(assess().current, false);
|
||||||
assert.equal(assess().code, "no_stamp");
|
assert.equal(assess().code, "no_stamp");
|
||||||
|
|
||||||
const record = recordRunnerBuild({ repoRoot, packageRoot, platform, arch, now: () => new Date(0) });
|
const record = recordCurrentBuild({ repoRoot, packageRoot, platform, arch, now: () => new Date(0) });
|
||||||
|
assert.equal(record.recorded, true);
|
||||||
assert.equal(record.stampPath, buildInputsStampPath(packageRoot));
|
assert.equal(record.stampPath, buildInputsStampPath(packageRoot));
|
||||||
assert.deepEqual(readBuildInputsStamp(record.stampPath), {
|
const stamp = readBuildInputsStamp(record.stampPath);
|
||||||
schema: BUILD_INPUTS_SCHEMA,
|
assert.equal(stamp.schema, BUILD_INPUTS_SCHEMA);
|
||||||
digest: record.digest,
|
assert.equal(stamp.digest, record.digest);
|
||||||
fileCount: 8,
|
assert.equal(stamp.fileCount, INPUT_FILE_COUNT);
|
||||||
byteCount: record.byteCount,
|
assert.equal(stamp.byteCount, record.byteCount);
|
||||||
platform,
|
assert.equal(stamp.platform, platform);
|
||||||
arch,
|
assert.equal(stamp.arch, arch);
|
||||||
recordedAt: "1970-01-01T00:00:00.000Z",
|
assert.equal(stamp.startedAt, "1970-01-01T00:00:00.000Z");
|
||||||
});
|
assert.equal(stamp.recordedAt, "1970-01-01T00:00:00.000Z");
|
||||||
|
assert.equal(stamp.outputCount, OUTPUT_FILE_COUNT);
|
||||||
|
assert.deepEqual(stamp.outputs, collectBuildOutputFiles(packageRoot));
|
||||||
const current = assess();
|
const current = assess();
|
||||||
assert.equal(current.current, true, current.detail);
|
assert.equal(current.current, true, current.detail);
|
||||||
assert.equal(current.code, "inputs_unchanged");
|
assert.equal(current.code, "inputs_unchanged");
|
||||||
|
assert.match(current.detail, /10 files and 5 outputs checked/);
|
||||||
|
|
||||||
assert.equal(assessRunnerBuild({ repoRoot, packageRoot, platform: "win32", arch }).code, "platform_mismatch");
|
assert.equal(assessRunnerBuild({ repoRoot, packageRoot, platform: "win32", arch }).code, "platform_mismatch");
|
||||||
assert.equal(assessRunnerBuild({ repoRoot, packageRoot, platform, arch: "arm64" }).code, "platform_mismatch");
|
assert.equal(assessRunnerBuild({ repoRoot, packageRoot, platform, arch: "arm64" }).code, "platform_mismatch");
|
||||||
|
|
||||||
|
// The four outputs every consumer reads are checked by name.
|
||||||
for (const output of expectedBuildOutputs(packageRoot, platform)) {
|
for (const output of expectedBuildOutputs(packageRoot, platform)) {
|
||||||
const content = await readFile(output);
|
const content = await readFile(output);
|
||||||
await rm(output);
|
await rm(output);
|
||||||
@@ -166,6 +212,30 @@ test("a build is current only with a matching stamp and every consumer-facing ou
|
|||||||
}
|
}
|
||||||
assert.equal(assess().current, true);
|
assert.equal(assess().current, true);
|
||||||
|
|
||||||
|
// So is every other file the build left under dist: a helper that is only
|
||||||
|
// opened by path must be there, at the size the build wrote.
|
||||||
|
const helper = path.join(packageRoot, "dist", "cli", "acpx-runtime-sidecar.cjs");
|
||||||
|
const helperContent = await readFile(helper);
|
||||||
|
await rm(helper);
|
||||||
|
const gone = assess();
|
||||||
|
assert.equal(gone.current, false, "a missing helper still counted as current");
|
||||||
|
assert.equal(gone.code, "outputs_changed");
|
||||||
|
assert.match(gone.detail, /^build output dist\/cli\/acpx-runtime-sidecar\.cjs is missing since the build recorded at /);
|
||||||
|
await writeFile(helper, helperContent);
|
||||||
|
assert.equal(assess().current, true);
|
||||||
|
|
||||||
|
await truncate(helper, 3);
|
||||||
|
const truncated = assess();
|
||||||
|
assert.equal(truncated.current, false, "a truncated helper still counted as current");
|
||||||
|
assert.equal(truncated.code, "outputs_changed");
|
||||||
|
assert.match(truncated.detail, /^build output dist\/cli\/acpx-runtime-sidecar\.cjs is changed size since /);
|
||||||
|
await writeFile(helper, helperContent);
|
||||||
|
assert.equal(assess().current, true);
|
||||||
|
|
||||||
|
// A file the build did not produce may appear without invalidating it.
|
||||||
|
await writeFile(path.join(packageRoot, "dist", "extra.txt"), "later\n");
|
||||||
|
assert.equal(assess().current, true);
|
||||||
|
|
||||||
await writeFile(path.join(packageRoot, "src", "index.ts"), "export const one = 3;\n");
|
await writeFile(path.join(packageRoot, "src", "index.ts"), "export const one = 3;\n");
|
||||||
const changed = assess();
|
const changed = assess();
|
||||||
assert.equal(changed.current, false);
|
assert.equal(changed.current, false);
|
||||||
@@ -173,24 +243,109 @@ test("a build is current only with a matching stamp and every consumer-facing ou
|
|||||||
|
|
||||||
await writeFile(record.stampPath, JSON.stringify({ ...readBuildInputsStamp(record.stampPath), schema: "other" }));
|
await writeFile(record.stampPath, JSON.stringify({ ...readBuildInputsStamp(record.stampPath), schema: "other" }));
|
||||||
assert.equal(assess().code, "schema_mismatch");
|
assert.equal(assess().code, "schema_mismatch");
|
||||||
|
await writeFile(record.stampPath, JSON.stringify({ ...readBuildInputsStamp(record.stampPath), schema: BUILD_INPUTS_SCHEMA, outputs: undefined }));
|
||||||
|
assert.equal(assess().code, "schema_mismatch", "a stamp without an output manifest was trusted");
|
||||||
await writeFile(record.stampPath, "not json");
|
await writeFile(record.stampPath, "not json");
|
||||||
assert.equal(assess().code, "no_stamp");
|
assert.equal(assess().code, "no_stamp");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("record-build-inputs.mjs writes the stamp for the package it is pointed at", async () => {
|
test("an input edited while the build runs leaves no stamp, so the next consumer rebuilds", async () => {
|
||||||
await withRepo(async ({ repoRoot, packageRoot }) => {
|
await withRepo(async ({ repoRoot, packageRoot }) => {
|
||||||
const { stdout } = await execFileAsync(process.execPath, [recordScript, "--package-root", packageRoot]);
|
const stampPath = buildInputsStampPath(packageRoot);
|
||||||
|
const pendingPath = buildInputsPendingPath(packageRoot);
|
||||||
|
const assess = () => assessRunnerBuild({ repoRoot, packageRoot });
|
||||||
|
|
||||||
|
// A previous good build, then a new build begins: the old stamp is gone at
|
||||||
|
// once, because the outputs are about to be replaced.
|
||||||
|
recordCurrentBuild({ repoRoot, packageRoot });
|
||||||
|
assert.equal(assess().current, true);
|
||||||
|
const pending = beginRunnerBuild({ repoRoot, packageRoot, now: () => new Date(1000) });
|
||||||
|
assert.equal(pending.pendingPath, pendingPath);
|
||||||
|
assert.equal(readBuildInputsStamp(stampPath), null, "the old stamp survived the start of a new build");
|
||||||
|
assert.equal(readBuildInputsStamp(pendingPath).digest, pending.digest);
|
||||||
|
assert.equal(assess().code, "no_stamp");
|
||||||
|
|
||||||
|
// The build "compiles" the old source, then an edit lands before it ends.
|
||||||
|
await writeFile(path.join(packageRoot, "src", "index.ts"), "export const one = 2;\n");
|
||||||
|
const result = recordRunnerBuild({ repoRoot, packageRoot });
|
||||||
|
assert.equal(result.recorded, false);
|
||||||
|
assert.equal(result.code, "inputs_changed_during_build");
|
||||||
|
assert.match(result.detail, /^inputs changed while the build ran \(digest [0-9a-f]{12} at start, [0-9a-f]{12} now\); the next consumer rebuilds$/);
|
||||||
|
assert.equal(result.startedAt, "1970-01-01T00:00:01.000Z");
|
||||||
|
assert.equal(readBuildInputsStamp(stampPath), null, "a stamp was written for a build whose inputs moved");
|
||||||
|
assert.equal(readBuildInputsStamp(pendingPath), null, "the pending record was left behind");
|
||||||
|
assert.equal(assess().code, "no_stamp");
|
||||||
|
|
||||||
|
// An undisturbed build records normally, and only the pending record's
|
||||||
|
// start time is kept.
|
||||||
|
const record = recordCurrentBuild({ repoRoot, packageRoot });
|
||||||
|
assert.equal(record.recorded, true);
|
||||||
|
assert.equal(readBuildInputsStamp(pendingPath), null);
|
||||||
|
assert.equal(assess().current, true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a build that did not begin, or that left a required output missing, cannot be recorded", async () => {
|
||||||
|
await withRepo(async ({ repoRoot, packageRoot }) => {
|
||||||
|
const stampPath = buildInputsStampPath(packageRoot);
|
||||||
|
|
||||||
|
recordCurrentBuild({ repoRoot, packageRoot });
|
||||||
|
assert.throws(
|
||||||
|
() => recordRunnerBuild({ repoRoot, packageRoot }),
|
||||||
|
/no pending build inputs at .*paperclip-runner-build-inputs\.pending\.json: the Runner build must start with `node scripts\/record-build-inputs\.mjs --begin`/,
|
||||||
|
);
|
||||||
|
assert.equal(readBuildInputsStamp(stampPath), null, "the previous stamp outlived a build that did not begin");
|
||||||
|
|
||||||
|
beginRunnerBuild({ repoRoot, packageRoot });
|
||||||
|
await rm(path.join(packageRoot, "dist", "testing.js"));
|
||||||
|
assert.throws(
|
||||||
|
() => recordRunnerBuild({ repoRoot, packageRoot }),
|
||||||
|
/the Runner build finished without producing dist\/testing\.js/,
|
||||||
|
);
|
||||||
|
assert.equal(readBuildInputsStamp(stampPath), null);
|
||||||
|
assert.equal(assessRunnerBuild({ repoRoot, packageRoot }).code, "no_stamp");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("record-build-inputs.mjs brackets the build for the package it is pointed at", async () => {
|
||||||
|
await withRepo(async ({ repoRoot, packageRoot }) => {
|
||||||
|
const run = (...args) => execFileAsync(process.execPath, [recordScript, ...args, "--package-root", packageRoot]);
|
||||||
const expected = computeBuildInputsDigest(repoRoot);
|
const expected = computeBuildInputsDigest(repoRoot);
|
||||||
assert.match(stdout, new RegExp(`^${BUILD_INPUTS_SCHEMA} recorded: digest=${expected.digest.slice(0, 12)} files=8 `));
|
const short = expected.digest.slice(0, 12);
|
||||||
|
|
||||||
|
// --finish before any --begin is a wiring error, not a silent stamp.
|
||||||
|
await assert.rejects(run("--finish"), /no pending build inputs/);
|
||||||
|
assert.equal(readBuildInputsStamp(buildInputsStampPath(packageRoot)), null);
|
||||||
|
|
||||||
|
const begin = await run("--begin");
|
||||||
|
assert.match(begin.stdout, new RegExp(`^${BUILD_INPUTS_SCHEMA} begin: digest=${short} files=${INPUT_FILE_COUNT} bytes=\\d+\n$`));
|
||||||
|
assert.equal(readBuildInputsStamp(buildInputsPendingPath(packageRoot)).digest, expected.digest);
|
||||||
|
|
||||||
|
const finish = await run("--finish");
|
||||||
|
assert.match(
|
||||||
|
finish.stdout,
|
||||||
|
new RegExp(`^${BUILD_INPUTS_SCHEMA} recorded: digest=${short} files=${INPUT_FILE_COUNT} bytes=\\d+ outputs=${OUTPUT_FILE_COUNT} stamp=node_modules/.cache/paperclip-runner-build-inputs.json\n$`),
|
||||||
|
);
|
||||||
const stamp = readBuildInputsStamp(buildInputsStampPath(packageRoot));
|
const stamp = readBuildInputsStamp(buildInputsStampPath(packageRoot));
|
||||||
assert.equal(stamp.digest, expected.digest);
|
assert.equal(stamp.digest, expected.digest);
|
||||||
assert.equal(stamp.platform, process.platform);
|
assert.equal(stamp.platform, process.platform);
|
||||||
assert.equal(stamp.arch, process.arch);
|
assert.equal(stamp.arch, process.arch);
|
||||||
|
assert.equal(stamp.outputCount, OUTPUT_FILE_COUNT);
|
||||||
assert.equal(assessRunnerBuild({ repoRoot, packageRoot }).current, true);
|
assert.equal(assessRunnerBuild({ repoRoot, packageRoot }).current, true);
|
||||||
|
assert.equal((await stat(buildInputsStampPath(packageRoot))).isFile(), true);
|
||||||
|
|
||||||
|
// An edit between the two phases is reported and leaves nothing behind.
|
||||||
|
await run("--begin");
|
||||||
|
await writeFile(path.join(packageRoot, "src", "index.ts"), "export const one = 2;\n");
|
||||||
|
const moved = await run("--finish");
|
||||||
|
assert.match(moved.stdout, /^paperclip\.runner-build-inputs not recorded: inputs changed while the build ran /);
|
||||||
|
assert.equal(readBuildInputsStamp(buildInputsStampPath(packageRoot)), null);
|
||||||
|
|
||||||
|
await assert.rejects(run(), /one of --begin or --finish is required/);
|
||||||
|
await assert.rejects(run("--begin", "--finish"), /--finish cannot be combined with --begin/);
|
||||||
await assert.rejects(
|
await assert.rejects(
|
||||||
execFileAsync(process.execPath, [recordScript, "--bogus"]),
|
execFileAsync(process.execPath, [recordScript, "--begin", "--bogus"]),
|
||||||
/unknown argument --bogus/,
|
/unknown argument --bogus/,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
// Final step of the Runner package's `build`: records the digest of every
|
// Brackets the Runner package's `build` so server's prepare:runner-vendor can
|
||||||
// build input next to the outputs it produced, so server's
|
// reuse this build instead of repeating it when nothing has changed. See
|
||||||
// prepare:runner-vendor can reuse this build instead of repeating it when
|
// build-inputs.mjs for what counts as an input and an output.
|
||||||
// nothing has changed. See build-inputs.mjs for what counts as an input.
|
|
||||||
//
|
//
|
||||||
// Usage: node scripts/record-build-inputs.mjs [--package-root <dir>]
|
// --begin first step of the build: forgets the previous stamp and records
|
||||||
|
// the inputs the build is about to read
|
||||||
|
// --finish last step of the build, after every check: writes the stamp if
|
||||||
|
// the inputs are still the ones the build began with, with a
|
||||||
|
// manifest of every file under dist; otherwise writes nothing, so
|
||||||
|
// the next consumer rebuilds
|
||||||
|
//
|
||||||
|
// Usage: node scripts/record-build-inputs.mjs (--begin | --finish) [--package-root <dir>]
|
||||||
// The package root defaults to this package; the flag exists for tests that
|
// The package root defaults to this package; the flag exists for tests that
|
||||||
// build a throwaway package layout.
|
// build a throwaway package layout.
|
||||||
|
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
import {
|
import {
|
||||||
|
beginRunnerBuild,
|
||||||
recordRunnerBuild,
|
recordRunnerBuild,
|
||||||
repoRootFromRunnerPackage,
|
repoRootFromRunnerPackage,
|
||||||
runnerPackageRootFromScripts,
|
runnerPackageRootFromScripts,
|
||||||
@@ -17,8 +24,14 @@ import {
|
|||||||
|
|
||||||
export function parseArguments(argv) {
|
export function parseArguments(argv) {
|
||||||
let packageRoot = null;
|
let packageRoot = null;
|
||||||
|
let phase = null;
|
||||||
for (let index = 0; index < argv.length; index += 1) {
|
for (let index = 0; index < argv.length; index += 1) {
|
||||||
const argument = argv[index];
|
const argument = argv[index];
|
||||||
|
if (argument === "--begin" || argument === "--finish") {
|
||||||
|
if (phase) throw new Error(`${argument} cannot be combined with --${phase}`);
|
||||||
|
phase = argument.slice(2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (argument === "--package-root") {
|
if (argument === "--package-root") {
|
||||||
packageRoot = argv[index + 1];
|
packageRoot = argv[index + 1];
|
||||||
if (!packageRoot) throw new Error("--package-root needs a directory");
|
if (!packageRoot) throw new Error("--package-root needs a directory");
|
||||||
@@ -27,17 +40,32 @@ export function parseArguments(argv) {
|
|||||||
}
|
}
|
||||||
throw new Error(`unknown argument ${argument}`);
|
throw new Error(`unknown argument ${argument}`);
|
||||||
}
|
}
|
||||||
return { packageRoot };
|
if (!phase) throw new Error("one of --begin or --finish is required");
|
||||||
|
return { phase, packageRoot };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function main(argv = process.argv.slice(2), log = console.log) {
|
export function main(argv = process.argv.slice(2), log = console.log) {
|
||||||
const { packageRoot: requested } = parseArguments(argv);
|
const { phase, packageRoot: requested } = parseArguments(argv);
|
||||||
const packageRoot = requested ? path.resolve(requested) : runnerPackageRootFromScripts();
|
const packageRoot = requested ? path.resolve(requested) : runnerPackageRootFromScripts();
|
||||||
const repoRoot = repoRootFromRunnerPackage(packageRoot);
|
const repoRoot = repoRootFromRunnerPackage(packageRoot);
|
||||||
|
|
||||||
|
if (phase === "begin") {
|
||||||
|
const pending = beginRunnerBuild({ repoRoot, packageRoot });
|
||||||
|
log(
|
||||||
|
`${pending.schema} begin: digest=${pending.digest.slice(0, 12)} files=${pending.fileCount} ` +
|
||||||
|
`bytes=${pending.byteCount}`,
|
||||||
|
);
|
||||||
|
return pending;
|
||||||
|
}
|
||||||
|
|
||||||
const record = recordRunnerBuild({ repoRoot, packageRoot });
|
const record = recordRunnerBuild({ repoRoot, packageRoot });
|
||||||
|
if (!record.recorded) {
|
||||||
|
log(`${record.code === "inputs_changed_during_build" ? "paperclip.runner-build-inputs" : record.code} not recorded: ${record.detail}`);
|
||||||
|
return record;
|
||||||
|
}
|
||||||
log(
|
log(
|
||||||
`${record.schema} recorded: digest=${record.digest.slice(0, 12)} files=${record.fileCount} ` +
|
`${record.schema} recorded: digest=${record.digest.slice(0, 12)} files=${record.fileCount} ` +
|
||||||
`bytes=${record.byteCount} stamp=${path.relative(packageRoot, record.stampPath)}`,
|
`bytes=${record.byteCount} outputs=${record.outputCount} stamp=${path.relative(packageRoot, record.stampPath)}`,
|
||||||
);
|
);
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,14 @@
|
|||||||
// 12-16s on the CI Build job's critical path (six master runs, 2026-10-11)
|
// 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`.
|
// and the same again in every other `pnpm build`.
|
||||||
//
|
//
|
||||||
// The Runner's `build` now records a digest of its inputs after it succeeds
|
// The Runner's `build` now records a digest of its inputs, captured before its
|
||||||
// (packages/paperclip-runner/scripts/build-inputs.mjs). This step recomputes
|
// first step and confirmed after its last, together with a manifest of every
|
||||||
// the digest and reuses the build when the stamp matches and every output a
|
// file it left under dist (packages/paperclip-runner/scripts/build-inputs.mjs).
|
||||||
// consumer reads exists; anything else runs the full Runner build exactly as
|
// This step recomputes the digest and reuses the build when the stamp matches
|
||||||
// before. The standalone guarantee therefore holds: a fresh checkout, a
|
// and every recorded output is still there at its recorded size; anything else
|
||||||
// changed input, or a deleted output always rebuilds. Set
|
// 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.
|
// PAPERCLIP_RUNNER_VENDOR_REBUILD=1 to rebuild regardless of the stamp.
|
||||||
//
|
//
|
||||||
// Usage: node scripts/prepare-runner-vendor.mjs [--repo-root <dir>]
|
// 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})`);
|
log(`prepare:runner-vendor: rebuilding the Runner (${decision.detail})`);
|
||||||
// A build that stops partway must not leave a stamp that vouches for it; the
|
// 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.
|
// 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);
|
removeBuildInputsStamp(assessment.stampPath);
|
||||||
const buildStart = now();
|
const buildStart = now();
|
||||||
const status = run(RUNNER_VENDOR_BUILD_COMMAND, { cwd: path.join(repoRoot, "server"), env });
|
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 {
|
import {
|
||||||
assessRunnerBuild,
|
assessRunnerBuild,
|
||||||
|
beginRunnerBuild,
|
||||||
buildInputsStampPath,
|
buildInputsStampPath,
|
||||||
readBuildInputsStamp,
|
readBuildInputsStamp,
|
||||||
recordRunnerBuild,
|
recordRunnerBuild,
|
||||||
@@ -48,12 +49,14 @@ function makeRepo() {
|
|||||||
"pnpm-lock.yaml": "lockfileVersion: 9\n",
|
"pnpm-lock.yaml": "lockfileVersion: 9\n",
|
||||||
"pnpm-workspace.yaml": "packages:\n - packages/*\n - server\n",
|
"pnpm-workspace.yaml": "packages:\n - packages/*\n - server\n",
|
||||||
"tsconfig.base.json": "{}\n",
|
"tsconfig.base.json": "{}\n",
|
||||||
|
"patches/acpx@0.13.1.patch": "--- a\n+++ b\n",
|
||||||
"server/package.json": '{"name":"@paperclipai/server"}\n',
|
"server/package.json": '{"name":"@paperclipai/server"}\n',
|
||||||
"packages/paperclip-runner/package.json": '{"name":"@paperclipai/paperclip-runner"}\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/src/index.ts": "export const one = 1;\n",
|
||||||
"packages/paperclip-runner/dist/index.js": "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/live/index.js": "export {};\n",
|
||||||
"packages/paperclip-runner/dist/testing.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-runner/dist/bin/${executable}`]: "binary\n",
|
||||||
"packages/paperclip-eval-kernel/src/index.ts": "export const kernel = 1;\n",
|
"packages/paperclip-eval-kernel/src/index.ts": "export const kernel = 1;\n",
|
||||||
});
|
});
|
||||||
@@ -61,6 +64,12 @@ function makeRepo() {
|
|||||||
return { repoRoot, packageRoot };
|
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(() => {
|
afterEach(() => {
|
||||||
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true });
|
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", () => {
|
it("skips the rebuild when the recorded build is current and reports the check time", () => {
|
||||||
const { repoRoot, packageRoot } = makeRepo();
|
const { repoRoot, packageRoot } = makeRepo();
|
||||||
recordRunnerBuild({ repoRoot, packageRoot });
|
recordCurrentBuild({ repoRoot, packageRoot });
|
||||||
const runs = [];
|
const runs = [];
|
||||||
const lines = [];
|
const lines = [];
|
||||||
|
|
||||||
@@ -155,7 +164,7 @@ describe("prepareRunnerVendor", () => {
|
|||||||
|
|
||||||
it("rebuilds when the inputs changed, removing the stale stamp before the build starts", () => {
|
it("rebuilds when the inputs changed, removing the stale stamp before the build starts", () => {
|
||||||
const { repoRoot, packageRoot } = makeRepo();
|
const { repoRoot, packageRoot } = makeRepo();
|
||||||
recordRunnerBuild({ repoRoot, packageRoot });
|
recordCurrentBuild({ repoRoot, packageRoot });
|
||||||
writeFileSync(path.join(packageRoot, "src", "index.ts"), "export const one = 2;\n");
|
writeFileSync(path.join(packageRoot, "src", "index.ts"), "export const one = 2;\n");
|
||||||
const stampPath = buildInputsStampPath(packageRoot);
|
const stampPath = buildInputsStampPath(packageRoot);
|
||||||
const observed = [];
|
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", () => {
|
it("returns the build's failure status and leaves no stamp behind", () => {
|
||||||
const { repoRoot, packageRoot } = makeRepo();
|
const { repoRoot, packageRoot } = makeRepo();
|
||||||
const lines = [];
|
const lines = [];
|
||||||
@@ -201,7 +235,7 @@ describe("prepareRunnerVendor", () => {
|
|||||||
|
|
||||||
it("rebuilds a current build when PAPERCLIP_RUNNER_VENDOR_REBUILD=1", () => {
|
it("rebuilds a current build when PAPERCLIP_RUNNER_VENDOR_REBUILD=1", () => {
|
||||||
const { repoRoot, packageRoot } = makeRepo();
|
const { repoRoot, packageRoot } = makeRepo();
|
||||||
recordRunnerBuild({ repoRoot, packageRoot });
|
recordCurrentBuild({ repoRoot, packageRoot });
|
||||||
let runs = 0;
|
let runs = 0;
|
||||||
const lines = [];
|
const lines = [];
|
||||||
|
|
||||||
@@ -221,12 +255,12 @@ describe("prepareRunnerVendor", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it.skipIf(process.platform === "win32")(
|
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 () => {
|
async () => {
|
||||||
const { repoRoot, packageRoot } = makeRepo();
|
const { repoRoot, packageRoot } = makeRepo();
|
||||||
// A stand-in pnpm that behaves like the Runner build: it records how it
|
// 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
|
// was called, then brackets its (empty) step list with the same two
|
||||||
// as its final step.
|
// record-build-inputs.mjs calls the real build makes.
|
||||||
const binDir = path.join(repoRoot, "bin");
|
const binDir = path.join(repoRoot, "bin");
|
||||||
const argvLog = path.join(repoRoot, "pnpm-argv.log");
|
const argvLog = path.join(repoRoot, "pnpm-argv.log");
|
||||||
mkdirSync(binDir);
|
mkdirSync(binDir);
|
||||||
@@ -237,7 +271,8 @@ describe("prepareRunnerVendor", () => {
|
|||||||
"#!/bin/sh",
|
"#!/bin/sh",
|
||||||
"set -e",
|
"set -e",
|
||||||
`printf '%s\\n' "$*" >> "${argvLog}"`,
|
`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`,
|
].join("\n")}\n`,
|
||||||
);
|
);
|
||||||
chmodSync(pnpm, 0o755);
|
chmodSync(pnpm, 0o755);
|
||||||
@@ -262,6 +297,16 @@ describe("prepareRunnerVendor", () => {
|
|||||||
const third = await run();
|
const third = await run();
|
||||||
expect(calls()).toHaveLength(2);
|
expect(calls()).toHaveLength(2);
|
||||||
expect(third.stdout).toMatch(/action:rebuild,reason:inputs_changed,/);
|
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,/);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -74,15 +74,21 @@ describe("server package build script", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("records the Runner's build inputs as the last step of its build", () => {
|
it("brackets the Runner's build with its input recording", () => {
|
||||||
// The stamp prepare-runner-vendor.mjs trusts must only exist for a build
|
// The stamp prepare-runner-vendor.mjs trusts must only exist for a build
|
||||||
// that completed every step and check, so it has to be written last.
|
// that completed every step and check, so it has to be written last; and
|
||||||
|
// it must vouch for the inputs the build read, not for whatever the
|
||||||
|
// sources are when it ends, so the digest has to be captured before the
|
||||||
|
// first step reads anything (--begin) and compared again at the end
|
||||||
|
// (--finish). Nothing else in the chain may touch the stamp.
|
||||||
const runner = JSON.parse(readFileSync(new URL(
|
const runner = JSON.parse(readFileSync(new URL(
|
||||||
"../../../packages/paperclip-runner/package.json", import.meta.url,
|
"../../../packages/paperclip-runner/package.json", import.meta.url,
|
||||||
), "utf8")) as { scripts: Record<string, string> };
|
), "utf8")) as { scripts: Record<string, string> };
|
||||||
const steps = runner.scripts.build.split(" && ");
|
const steps = runner.scripts.build.split(" && ");
|
||||||
expect(steps.at(-1)).toBe("node scripts/record-build-inputs.mjs");
|
expect(steps.at(0)).toBe("node scripts/record-build-inputs.mjs --begin");
|
||||||
expect(steps.filter((step) => step.includes("record-build-inputs"))).toHaveLength(1);
|
expect(steps.at(-1)).toBe("node scripts/record-build-inputs.mjs --finish");
|
||||||
|
expect(steps.filter((step) => step.includes("record-build-inputs"))).toHaveLength(2);
|
||||||
|
expect(steps.length).toBeGreaterThan(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("replaces an existing read-only image manifest with the build's copy step", () => {
|
it("replaces an existing read-only image manifest with the build's copy step", () => {
|
||||||
|
|||||||
Reference in new issue
Block a user