The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
test(runner): isolate provider fixture targets and executables (#16701)
Dotta5623304586c0
diff --git a/packages/paperclip-runner/src/drivers/acpx/installation-integrity.test.ts b/packages/paperclip-runner/src/drivers/acpx/installation-integrity.test.tsindex a1a881d080..ccf0c1d2fb 100644--- a/packages/paperclip-runner/src/drivers/acpx/installation-integrity.test.ts+++ b/packages/paperclip-runner/src/drivers/acpx/installation-integrity.test.ts@@ -42,6 +42,20 @@ import {} from "./installation-integrity.js";import { stageManagedCodexCredential } from "./codex-credentials.js";+async function withLinuxX64TestPlatform<T>(run: () => Promise<T>): Promise<T> {+ const platformDescriptor = Object.getOwnPropertyDescriptor(process, "platform");+ const archDescriptor = Object.getOwnPropertyDescriptor(process, "arch");+ if (!platformDescriptor || !archDescriptor) throw new Error("Missing process platform descriptors");+ try {+ Object.defineProperty(process, "platform", { ...platformDescriptor, value: "linux" });+ Object.defineProperty(process, "arch", { ...archDescriptor, value: "x64" });+ return await run();+ } finally {+ try { Object.defineProperty(process, "platform", platformDescriptor); }+ finally { Object.defineProperty(process, "arch", archDescriptor); }+ }+}+const temporaryDirectories: string[] = [];const descriptorCommandPath = "/proc/self/fd/4/server.js";@@ -786,11 +800,11 @@ describe("ACPX installation integrity", () => {expect(resolveQualifiedAcpxProfile("grok", "grok-4.7").agentServerPackage).toBe("builtin:grok-acp");});- it("reports a missing environment prerequisite before launching Grok", async () => {+ it("reports a missing environment prerequisite before launching Grok", () => withLinuxX64TestPlatform(async () => {const fixture = await installationFixture();await expect(verifyProvisionedGrokExecutable(join(fixture.commandDirectory, "missing"))).rejects.toThrow(/Grok Build 1.0.13 prerequisite missing/);- });+ }));it("resolves a controller-owned builtin root for descriptor-loaded sidecars and rejects relative roots", () => {vi.stubEnv("PAPERCLIP_ACPX_BUILTIN_ROOT", "/verified/dist/providers");@@ -801,7 +815,7 @@ describe("ACPX installation integrity", () => {finally { vi.unstubAllEnvs(); }});- it("rejects a tampered native Grok executable and symlink substitution", async () => {+ it("rejects a tampered native Grok executable and symlink substitution", () => withLinuxX64TestPlatform(async () => {const fixture = await installationFixture();const native = join(fixture.commandDirectory, "grok");@@ -810,7 +824,7 @@ describe("ACPX installation integrity", () => {await rm(native);await symlink(fixture.commandPath, native);await expect(verifyProvisionedGrokExecutable(native)).rejects.toThrow(/regular file|symlink|no-follow/);- });+ }));it("rejects package version and executable digest drift", async () => {const fixture = await installationFixture();diff --git a/packages/paperclip-runner/src/drivers/acpx/pi-provision.test.ts b/packages/paperclip-runner/src/drivers/acpx/pi-provision.test.tsindex b9dfcd6868..6f31ccc00c 100644--- a/packages/paperclip-runner/src/drivers/acpx/pi-provision.test.ts+++ b/packages/paperclip-runner/src/drivers/acpx/pi-provision.test.ts@@ -11,6 +11,20 @@ vi.mock("node:fs/promises", async (importOriginal) => {});vi.mock("./pi-installation.ts", () => ({ verifyPiInstallation: mocks.verify }));vi.mock("../../../scripts/materialize-pi-distribution.mjs", () => ({ materializePiDistribution: mocks.build }));+async function withLinuxX64TestPlatform<T>(run: () => Promise<T>): Promise<T> {+ const platformDescriptor = Object.getOwnPropertyDescriptor(process, "platform");+ const archDescriptor = Object.getOwnPropertyDescriptor(process, "arch");+ if (!platformDescriptor || !archDescriptor) throw new Error("Missing process platform descriptors");+ try {+ Object.defineProperty(process, "platform", { ...platformDescriptor, value: "linux" });+ Object.defineProperty(process, "arch", { ...archDescriptor, value: "x64" });+ return await run();+ } finally {+ try { Object.defineProperty(process, "platform", platformDescriptor); }+ finally { Object.defineProperty(process, "arch", archDescriptor); }+ }+}+const roots: string[] = [];afterEach(async () => { vi.unstubAllEnvs(); await Promise.all(roots.splice(0).map(root => rm(root, { recursive: true, force: true }))); });beforeEach(() => {@@ -31,7 +45,7 @@ async function fixture(vendored = true) {it("recognizes both published layouts without resolving a private npm package", async () => {for (const vendored of [true, false]) { const f = await fixture(vendored); expect(await provisionPackageRoot(f.entry)).toMatchObject({ root: f.root, assetRoot: f.assetRoot }); }});-it("rejects wrong package, linked entrypoint and escaping asset roots before materialization", async () => {+it("rejects wrong package, linked entrypoint and escaping asset roots before materialization", () => withLinuxX64TestPlatform(async () => {const f = await fixture(); const other = await fixture();await writeFile(join(f.root, "package.json"), '{"name":"foreign"}');await expect(provisionPi(f.entry)).rejects.toThrow("identity");@@ -41,50 +55,50 @@ it("rejects wrong package, linked entrypoint and escaping asset roots before matawait rm(f.entry); await writeFile(f.entry, "fixture"); await symlink(other.root, join(f.assetRoot, "provider-assets"));await expect(provisionPi(f.entry)).rejects.toThrow("escapes");expect(mocks.build).not.toHaveBeenCalled();-});-it("verifies an existing cache in full and never repairs a rejected cache automatically", async () => {+}));+it("verifies an existing cache in full and never repairs a rejected cache automatically", () => withLinuxX64TestPlatform(async () => {const f = await fixture(); await mkdir(f.output, { recursive: true }); await writeFile(join(f.output, "original"), "retain");expect(await provisionPi(f.entry)).toMatchObject({ status: "verified_existing" });mocks.verify.mockRejectedValueOnce(new Error("closure differs"));await expect(provisionPi(f.entry)).rejects.toThrow("closure differs");expect(await readFile(join(f.output, "original"), "utf8")).toBe("retain");expect(mocks.build).not.toHaveBeenCalled(); expect(await readdir(f.parent)).toEqual([`${process.platform}-${process.arch}`]);-});-it("publishes only after staging verification, then verifies the actual package authority", async () => {+}));+it("publishes only after staging verification, then verifies the actual package authority", () => withLinuxX64TestPlatform(async () => {const f = await fixture(); vi.stubEnv("PAPERCLIP_ACPX_PROVIDER_PACKAGE_ROOT", "untrusted-ambient");expect(await provisionPi(f.entry)).toMatchObject({ status: "installed_verified" });expect(mocks.verify).toHaveBeenCalledTimes(2); expect(mocks.close).toHaveBeenCalledTimes(2);expect(process.env.PAPERCLIP_ACPX_PROVIDER_PACKAGE_ROOT).toBe("untrusted-ambient");expect(await readdir(f.parent)).toEqual([`${process.platform}-${process.arch}`]);-});-it.each(["build", "staging", "published"])("cleans only its owned transaction after %s failure", async stage => {+}));+it.each(["build", "staging", "published"])("cleans only its owned transaction after %s failure", stage => withLinuxX64TestPlatform(async () => {const f = await fixture();if (stage === "build") mocks.build.mockRejectedValueOnce(new Error("failed"));if (stage === "staging") mocks.verify.mockRejectedValueOnce(new Error("failed"));if (stage === "published") mocks.verify.mockResolvedValueOnce({ openCommand: async () => ({ close: mocks.close }) }).mockRejectedValueOnce(new Error("failed"));await expect(provisionPi(f.entry)).rejects.toThrow("failed");expect(await readdir(f.parent)).toEqual([]);-});-it("refuses a concurrent setup without deleting its lock or launching work", async () => {+}));+it("refuses a concurrent setup without deleting its lock or launching work", () => withLinuxX64TestPlatform(async () => {const f = await fixture(); await mkdir(f.parent, { recursive: true });const name = `.setup-${process.platform}-${process.arch}.lock`; await writeFile(join(f.parent, name), "other");await expect(provisionPi(f.entry)).rejects.toThrow(); expect(mocks.build).not.toHaveBeenCalled();expect(await readFile(join(f.parent, name), "utf8")).toBe("other");-});-it("honors cancellation after owned materialization without publishing or leaving temporary files", async () => {+}));+it("honors cancellation after owned materialization without publishing or leaving temporary files", () => withLinuxX64TestPlatform(async () => {const f = await fixture(); let cancelled = false;mocks.build.mockImplementationOnce(async ({ outputRoot }: { outputRoot: string }) => { await mkdir(outputRoot, { recursive: true }); cancelled = true; });await expect(provisionPi(f.entry, () => { if (cancelled) throw new Error("cancelled"); })).rejects.toThrow("cancelled");expect(await readdir(f.parent)).toEqual([]);-});+}));-it("does not replace an empty destination that appears during preparation", async () => {+it("does not replace an empty destination that appears during preparation", () => withLinuxX64TestPlatform(async () => {const f = await fixture();mocks.verify.mockImplementationOnce(async () => { await mkdir(f.output); return { openCommand: async () => ({ close: mocks.close }) }; });await expect(provisionPi(f.entry)).rejects.toThrow("destination appeared");expect(await readdir(f.output)).toEqual([]);-});-it("retains a replaced staging root while still releasing its own lock", async () => {+}));+it("retains a replaced staging root while still releasing its own lock", () => withLinuxX64TestPlatform(async () => {const f = await fixture();let moved: string | undefined;mocks.build.mockImplementationOnce(async ({ outputRoot }: { outputRoot: string }) => {@@ -99,9 +113,9 @@ it("retains a replaced staging root while still releasing its own lock", async (const replaced = names.find(name => !name.endsWith("-original"))!;expect(await readFile(join(f.parent, replaced, "foreign"), "utf8")).toBe("retain");expect(moved).toBeDefined(); // fixture teardown owns both test-created roots-});+}));-it("uses exclusive publication when an empty target appears after the absence check", async () => {+it("uses exclusive publication when an empty target appears after the absence check", () => withLinuxX64TestPlatform(async () => {const f = await fixture();const actual = await vi.importActual<typeof import("node:fs/promises")>("node:fs/promises");mocks.beforeMkdir.mockImplementationOnce(() => undefined);@@ -111,4 +125,4 @@ it("uses exclusive publication when an empty target appears after the absence chawait expect(provisionPi(f.entry)).rejects.toThrow(/EEXIST/);expect(await readdir(f.output)).toEqual([]);expect(await readdir(f.parent)).toEqual([`${process.platform}-${process.arch}`]);-});+}));diff --git a/packages/paperclip-runner/src/drivers/opencode/opencode-server-driver.test.ts b/packages/paperclip-runner/src/drivers/opencode/opencode-server-driver.test.tsindex 6e9c9b8459..fa345625b0 100644--- a/packages/paperclip-runner/src/drivers/opencode/opencode-server-driver.test.ts+++ b/packages/paperclip-runner/src/drivers/opencode/opencode-server-driver.test.ts@@ -1,5 +1,6 @@import {chmod,+ copyFile,lstat,mkdir,mkdtemp,@@ -17,7 +18,7 @@ import { execFile } from "node:child_process";import { promisify } from "node:util";import { getCACertificates } from "node:tls";import { join, resolve } from "node:path";-import { afterAll, afterEach, describe, expect, it } from "vitest";+import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";import {NATIVE_RUNTIME_ASSET_SCHEMA,@@ -36,7 +37,14 @@ import {} from "./opencode-server-driver.js";const roots: string[] = [];-const fixture = resolve("test/fixtures/fake-opencode-server.mjs");+let fixtureRoot: string | undefined;+let fixture: string;++beforeAll(async () => {+ fixtureRoot = await mkdtemp(join(tmpdir(), "paperclip-opencode-fixture-"));+ fixture = join(fixtureRoot, "fake-opencode-server.mjs");+ await copyFile(resolve("test/fixtures/fake-opencode-server.mjs"), fixture);+});const TURN_TERMINAL_EVENT_TYPES = new Set(["turn.completed",@@ -128,7 +136,7 @@ afterEach(async () => {});afterAll(async () => {- await chmod(fixture, 0o644);+ if (fixtureRoot) await rm(fixtureRoot, { recursive: true, force: true });});describe("OpenCodeServerDriver", () => {diff --git a/packages/paperclip-runner/src/drivers/opencode/prepared-context-transport.test.ts b/packages/paperclip-runner/src/drivers/opencode/prepared-context-transport.test.tsindex c4710a971e..d359dbcf1a 100644--- a/packages/paperclip-runner/src/drivers/opencode/prepared-context-transport.test.ts+++ b/packages/paperclip-runner/src/drivers/opencode/prepared-context-transport.test.ts@@ -1,4 +1,4 @@-import { chmod, mkdtemp, rm } from "node:fs/promises";+import { chmod, copyFile, mkdtemp, rm } from "node:fs/promises";import { tmpdir } from "node:os";import { join, resolve } from "node:path";import { afterEach, describe, expect, it } from "vitest";@@ -7,7 +7,6 @@ import {OpenCodeServerDriver,} from "./opencode-server-driver.js";-const fixture = resolve("test/fixtures/fake-opencode-server.mjs");const roots: string[] = [];afterEach(async () => {@@ -18,12 +17,15 @@ afterEach(async () => {describe("prepared OpenCode context transport", () => {it("sends prepared initial prompts without the proxy task envelope", async () => {- await chmod(fixture, 0o755);const root = await mkdtemp(join(tmpdir(), "paperclip-opencode-prepared-"));+ roots.push(root);+ const fixture = join(root, "fake-opencode-server.mjs");+ await copyFile(resolve("test/fixtures/fake-opencode-server.mjs"), fixture);+ await chmod(fixture, 0o755);const workspace = await mkdtemp(join(tmpdir(), "paperclip-opencode-prepared-workspace-"),);- roots.push(root, workspace);+ roots.push(workspace);const submitted: Record<string, unknown>[] = [];const driver = new OpenCodeServerDriver({model: "openrouter/deepseek/deepseek-v4-flash-0731",diff --git a/packages/paperclip-runner/src/drivers/opencode/reasoning-mode.test.ts b/packages/paperclip-runner/src/drivers/opencode/reasoning-mode.test.tsindex db5e747d46..d6d9263046 100644--- a/packages/paperclip-runner/src/drivers/opencode/reasoning-mode.test.ts+++ b/packages/paperclip-runner/src/drivers/opencode/reasoning-mode.test.ts@@ -1,4 +1,4 @@-import { chmod, mkdtemp, readFile, rm } from "node:fs/promises";+import { chmod, copyFile, mkdtemp, readFile, rm } from "node:fs/promises";import { tmpdir } from "node:os";import { join, resolve } from "node:path";import { describe, expect, it } from "vitest";@@ -15,8 +15,7 @@ describe("per-turn OpenCode reasoning", () => {});it("selects reasoning independently on successive turns and sends instructions once", async () => {const root = await mkdtemp(join(tmpdir(), "paperclip-turn-reasoning-"));- const fixture = resolve("test/fixtures/fake-opencode-server.mjs");- await chmod(fixture, 0o755);+ const fixture = join(root, "fake-opencode-server.mjs");const submitted: Array<{ variant?: string; system?: string; parts: Array<{ text: string }> }> = [];const instructions = "Unique shared agent instructions. Keep the requested scope.";const driver = new OpenCodeServerDriver({@@ -34,6 +33,8 @@ describe("per-turn OpenCode reasoning", () => {});let session: Awaited<ReturnType<OpenCodeServerDriver["openSession"]>> | undefined;try {+ await copyFile(resolve("test/fixtures/fake-opencode-server.mjs"), fixture);+ await chmod(fixture, 0o755);session = await driver.openSession({ runId: "turn-reasoning", normalizedSessionId: "reasoning", workingDirectory: root });await expect(session.startTurn({ message: { role: "user", text: "invalid" }, reasoningMode: "bad" as never })).rejects.toThrow("turn.reasoningMode");expect(submitted).toHaveLength(0);@@ -56,8 +57,8 @@ describe("per-turn OpenCode reasoning", () => {});expect(config.provider.openrouter.models["deepseek/deepseek-v4-flash-0731"].options).toBeUndefined();} finally {- await session?.close();- await rm(root, { recursive: true, force: true });+ try { await session?.close(); }+ finally { await rm(root, { recursive: true, force: true }); }}});});