diff --git a/scripts/acpx-patch-packaging.test.mjs b/scripts/acpx-patch-packaging.test.mjs index beea369944..b37155b9ef 100644 --- a/scripts/acpx-patch-packaging.test.mjs +++ b/scripts/acpx-patch-packaging.test.mjs @@ -26,6 +26,9 @@ const rootPackage = JSON.parse(await readFile(new URL("../package.json", import. const adapterUtilsPackage = JSON.parse( await readFile(new URL("../packages/adapter-utils/package.json", import.meta.url), "utf8"), ); +const serverPackage = JSON.parse( + await readFile(new URL("../server/package.json", import.meta.url), "utf8"), +); const dbPackage = JSON.parse( await readFile(new URL("../packages/db/package.json", import.meta.url), "utf8"), ); @@ -38,8 +41,14 @@ test("published packages preserve the patched ACPX runtime", () => { rootPackage.pnpm.patchedDependencies["acpx@0.12.0"], "patches/acpx@0.12.0.patch", ); + assert.equal( + rootPackage.pnpm.patchedDependencies["acpx@0.13.1"], + "patches/acpx@0.13.1.patch", + ); assert.equal(adapterUtilsPackage.dependencies.acpx, "0.12.0"); assert.deepEqual(adapterUtilsPackage.bundleDependencies, ["acpx"]); + assert.equal(serverPackage.dependencies.acpx, "0.13.1"); + assert.deepEqual(serverPackage.bundleDependencies, ["acpx"]); assert.equal(bundledCliNpmDependencies.has("acpx"), true); assert.equal(cliEsbuildConfig.external.includes("acpx"), false); }); @@ -181,7 +190,7 @@ test("bundled package patch selection rejects an unpatched installed version", ( ); }); -test("bundled package staging rebuilds npm dependencies and applies the acpx patch", (t) => { +test("server package staging bundles and patches the vendored runner's acpx runtime", (t) => { const fixtureDir = mkdtempSync(join(tmpdir(), "paperclip-bundled-stage-")); const sourceDir = join(fixtureDir, "source"); const destinationDir = join(fixtureDir, "destination"); @@ -192,7 +201,10 @@ test("bundled package staging rebuilds npm dependencies and applies the acpx pat writeFileSync(join(sourceDir, "dist", "index.js"), "export {};\n"); mkdirSync(destinationDir); mkdirSync(binDir); - writeFileSync(join(sourceDir, "package.json"), JSON.stringify(adapterUtilsPackage)); + writeFileSync( + join(sourceDir, "package.json"), + JSON.stringify({ ...serverPackage, files: ["dist"] }), + ); writeFileSync(callLog, ""); t.after(() => rmSync(fixtureDir, { recursive: true, force: true })); @@ -217,7 +229,7 @@ printf 'npm %s\\n' "$*" >> "$FAKE_CALL_LOG" [ "$*" = "install --omit=dev --ignore-scripts --no-audit --no-fund" ] mkdir -p node_modules/acpx/dist printf 'unpatched runtime\\n' > node_modules/acpx/dist/runtime.js -printf '{"name":"acpx","version":"0.12.0"}\\n' > node_modules/acpx/package.json +printf '{"name":"acpx","version":"0.13.1"}\\n' > node_modules/acpx/package.json `, ); writeExecutable( @@ -235,9 +247,9 @@ while [ "$#" -gt 0 ]; do fi done patch_input="$(cat)" -grep -q onAgentStderr <<< "$patch_input" -! grep -q spawnEnvironment <<< "$patch_input" -printf 'patched onAgentStderr runtime\\n' > "$target/dist/runtime.js" +grep -q spawnEnvironment <<< "$patch_input" +! grep -q onAgentStderr <<< "$patch_input" +printf 'patched spawnEnvironment runtime\\n' > "$target/dist/runtime.js" `, ); @@ -259,7 +271,10 @@ printf 'patched onAgentStderr runtime\\n' > "$target/dist/runtime.js" assert.equal(lstatSync(stagedAcpxDir).isDirectory(), true); assert.equal(lstatSync(stagedAcpxDir).isSymbolicLink(), false); assert.equal(existsSync(join(destinationDir, "node_modules/.pnpm")), false); - assert.match(readFileSync(join(stagedAcpxDir, "dist/runtime.js"), "utf8"), /onAgentStderr/); + assert.match( + readFileSync(join(stagedAcpxDir, "dist/runtime.js"), "utf8"), + /spawnEnvironment/, + ); assert.match( readFileSync(callLog, "utf8"), /patch -p1 --forward -d .*node_modules\/acpx/, diff --git a/scripts/prepare-bundled-package.mjs b/scripts/prepare-bundled-package.mjs index 84cef8d001..db5ad596ca 100644 --- a/scripts/prepare-bundled-package.mjs +++ b/scripts/prepare-bundled-package.mjs @@ -166,13 +166,23 @@ export function prepareBundledPackage(sourceDir, destinationDir) { writeFileSync(deployedPackagePath, `${JSON.stringify(publishManifest, null, 2)}\n`); applyBundledDependencyPatches(destinationDir, bundledDependencies); - if ( - bundledDependencies.includes("acpx") && - !readFileSync(resolve(destinationDir, "node_modules/acpx/dist/runtime.js"), "utf8").includes( - "onAgentStderr", - ) - ) { - throw new Error("staged acpx runtime is missing the repository patch"); + if (bundledDependencies.includes("acpx")) { + const acpxPackage = JSON.parse( + readFileSync(resolve(destinationDir, "node_modules/acpx/package.json"), "utf8"), + ); + const expectedPatchMarker = { + "0.12.0": "onAgentStderr", + "0.13.1": "spawnEnvironment", + }[acpxPackage.version]; + const acpxRuntime = readFileSync( + resolve(destinationDir, "node_modules/acpx/dist/runtime.js"), + "utf8", + ); + if (!expectedPatchMarker || !acpxRuntime.includes(expectedPatchMarker)) { + throw new Error( + `staged acpx@${acpxPackage.version} runtime is missing the repository patch`, + ); + } } if (bundledDependencies.includes("embedded-postgres")) { diff --git a/server/package.json b/server/package.json index 9d8300cfb1..baecc3805a 100644 --- a/server/package.json +++ b/server/package.json @@ -63,6 +63,7 @@ "@paperclipai/shared": "workspace:*", "@paperclipai/skills-catalog": "workspace:*", "@vercel/connect": "0.6.1", + "acpx": "0.13.1", "ajv": "^8.20.0", "ajv-formats": "^3.0.1", "better-auth": "1.7.0", @@ -84,6 +85,9 @@ "ws": "^8.21.3", "zod": "^4.4.3" }, + "bundleDependencies": [ + "acpx" + ], "devDependencies": { "@paperclipai/paperclip-runner": "workspace:*", "@types/express": "^5.0.0",