mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 23:56:43 +01:00
Scope the existing Grok and Pi fixture callbacks to their declared Linux x64
target, and restore the original process descriptors after each callback.
Keep OpenCode executable mode changes inside test-owned temporary copies.
Adapt the two-file OpenCode fixture isolation from caniko's PR #14580,
commit f329db3d6f. Extend the same isolation
to the remaining per-turn reasoning fixture. Preserve every existing test
assertion, case, skip and budget without changing provider support or pins.
Co-Authored-By: Can H. Tartanoglu <gpg@rotas.mozmail.com>
Co-Authored-By: Paperclip <noreply@paperclip.ing>
79 lines
3.0 KiB
TypeScript
79 lines
3.0 KiB
TypeScript
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";
|
|
|
|
import {
|
|
OpenCodeServerDriver,
|
|
} from "./opencode-server-driver.js";
|
|
|
|
const roots: string[] = [];
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(
|
|
roots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
|
|
);
|
|
});
|
|
|
|
describe("prepared OpenCode context transport", () => {
|
|
it("sends prepared initial prompts without the proxy task envelope", async () => {
|
|
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(workspace);
|
|
const submitted: Record<string, unknown>[] = [];
|
|
const driver = new OpenCodeServerDriver({
|
|
model: "openrouter/deepseek/deepseek-v4-flash-0731",
|
|
runtimeDirectory: root,
|
|
command: fixture,
|
|
conversationMode: "prepared",
|
|
systemInstructions: "Prepared agent instructions.",
|
|
environment: { PATH: process.env.PATH, OPENROUTER_API_KEY: "fixture-key" },
|
|
fetch: async (input, init) => {
|
|
if (String(input).endsWith("/prompt_async"))
|
|
submitted.push(JSON.parse(String(init?.body)) as Record<string, unknown>);
|
|
return fetch(input, init);
|
|
},
|
|
});
|
|
|
|
const session = await driver.openSession({
|
|
runId: "run-prepared-opencode",
|
|
normalizedSessionId: "prepared-opencode",
|
|
workingDirectory: workspace,
|
|
});
|
|
await session.startTurn({
|
|
message: { role: "user", text: "prepared OpenCode initial wake" },
|
|
reasoningMode: "disabled",
|
|
});
|
|
for await (const event of session.events()) {
|
|
if (event.eventType === "turn.completed") break;
|
|
}
|
|
const snapshot = await session.snapshot();
|
|
await session.close({ reason: "prepared-test" });
|
|
const recovered = await driver.recoverSession?.(snapshot);
|
|
expect(recovered?.recovered).toBe(true);
|
|
await recovered!.session!.startTurn({
|
|
message: {
|
|
role: "user",
|
|
text: "completion-only OpenCode continuation",
|
|
},
|
|
});
|
|
for await (const event of recovered!.session!.events()) {
|
|
if (event.eventType === "turn.completed") break;
|
|
}
|
|
expect(submitted.map((body) => body.parts)).toEqual([
|
|
[{ type: "text", text: "prepared OpenCode initial wake" }],
|
|
[{ type: "text", text: "completion-only OpenCode continuation" }],
|
|
]);
|
|
expect(JSON.stringify(submitted)).not.toContain('"task"');
|
|
expect(submitted.map(body => body.variant)).toEqual(["paperclip-no-reasoning", "paperclip-default"]);
|
|
expect(submitted.map(body => body.system)).toEqual(["Prepared agent instructions.", "Prepared agent instructions."]);
|
|
await recovered!.session!.close({ reason: "prepared-test-recovery" });
|
|
});
|
|
});
|