mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-31 13:42:50 +00:00
* fix(opencode): support v2 while preserving v1 provider behavior * fix(opencode): target v2.0.7, keeping v1 support OpenCode 2.0.4 removed the /api/health endpoint and the plugin await-activation endpoint, and moved form reply/cancel under the session namespace. The v2 adapter was pinned to the 2.0.3 SDK, so any 2.0.4+ binary failed at helper-server startup with an opaque HTTP 404. - Pin @opencode/client to 2.0.7 and require v2 >= 2.0.4 at runtime selection, with a clear error for older binaries. - Use server.info for helper-server readiness. - Move form reply/cancel/list to session.form and send the permission decision field instead of reply. - Replace plugin.awaitActivation with a plugin.list readiness wait. A cold location registers its config-derived commands, skills, and providers asynchronously; an empty inventory means it is still warming. - Send session.command.name, which replaced command, and drop the removed SkillInfo.slash field. - Update the v2 test harness, unit tests, dependency lockfile, CI matrix, and provider docs to 2.0.7. * fix(opencode): target 2.0.10 and address v2 review findings * test(opencode): colocate v2 suites with their modules Greptile's review flagged that the v2 tests lived in top-level opencode-agent.*.test.ts files and imported the readiness helper, v2 client, harness, and API types from a distance. Move each v2 suite beside the module it describes and leave the top-level files to the v1 public path: - opencode/v2/agent.test.ts: session lifecycle, structured output, resume, reconciliation, interrupt/replacement, helper isolation. - opencode/v2/readiness.test.ts: location readiness deadline behavior. - opencode/v2/permissions.test.ts: question and approval routing. - opencode/v2/configuration.test.ts: permissionRules, feature flags, and helper-isolation decisions, exercised directly through the module. - opencode/v2/mapping.test.ts: model and mode normalization. - opencode/runtime-client.test.ts: runtime version selection. The v1 recovery, permission-action, and catalog-deadline suites stay in place. Test counts are preserved, with deeper per-module coverage for configuration. * test(opencode): split v2 local E2E by behavior and add harness helpers The re-review flagged the v2 scenarios in opencode-bridge.local.e2e.test.ts for inline event filtering, permission-kind branching, and polling in test bodies. Move stream, permission, and subagent coordination behind helpers in opencode/test-utils/v2-local-e2e-helpers.ts, and split the session scenarios into opencode-v2.local.e2e.test.ts so each file covers one behavior: - opencode-bridge.local.e2e.test.ts: process sharing, shell.env scoping, the native tool bridge, and runtime version selection. - opencode-v2.local.e2e.test.ts: session lifecycle, structured output, streaming, approvals, MCP preapproval, stop/replacement, rewind and subagents, commands, and skills/attachments. Each helper waits on or answers the provider directly, so the tests state domain intent and assert the collected result instead of polling or branching inline. The CI-selected "versioned runtime" case stays in the bridge file, and the live approvals and stop/replacement scenarios were re-run green through the new helpers. * fix(ci): preserve required server checks across OpenCode versions Run v1 and v2 integration coverage sequentially so branch protection keeps its existing static check names. * fix(agents): load startup history before registering sessions A failed history stream while adding a runtime notice must close the unregistered session instead of leaving an initializing agent behind. * fix(agents): limit startup history before buffering it Apply the existing timeline content limits to each incoming history event so raw cumulative tool output is not retained until registration completes. * fix(opencode): resolve Windows executables from platform packages Recent v1 npm releases place opencode.exe in the architecture dependency rather than the CLI bin directory. Resolve that dependency from the CLI package while retaining support for the older layout. * refactor(opencode): name public runtime option types * test(opencode): let the spec own both runtime versions Install each version in an isolated temporary directory and select it through provider configuration. Restore the CI workflow unchanged so version coverage is owned by the spec rather than workflow orchestration. * test(opencode): launch native Windows binaries in isolated specs Avoid npm command wrappers retaining locked executable files after helper shutdown during temporary installation cleanup. * fix(opencode): preserve the legacy path when adding v2 support Fall back to the existing client when version probing is inconclusive. Load v2 code and its bridge plugin only after positive v2 selection, keep v1 sessions undecorated, and restore original v1 discovery errors. * fix(opencode): retry inconclusive version selection A failed or unrecognized version probe previously cached the legacy fallback, pinning an upgraded binary to the v1 API until client recreation. Retry detection on the next operation while keeping the legacy path available. * fix(opencode): release legacy runtime after inconclusive probe Retryable version detection can clear the selected client after falling back to v1. Track whether the legacy client was selected so shutdown still releases its server without touching an unused v1 manager during a v2-only run. * test(opencode): assert full runtime notice history * fix(opencode): restore notice and retry behavior after rebase --------- Co-authored-by: Jonathan karras <6307688+karrots@users.noreply.github.com> Co-authored-by: Dhruv Singal <dhruvsingalabc@gmail.com>
212 lines
8.2 KiB
TypeScript
212 lines
8.2 KiB
TypeScript
import { expect, test } from "vitest";
|
|
import { openCodeMajorVersion } from "./runtime-client.js";
|
|
|
|
test.each([
|
|
["1.14.46", 1],
|
|
["unexpected wrapper output", 1],
|
|
["", 1],
|
|
["opencode v2.0.10\n", 2],
|
|
["v2.0.10-beta.1", 2],
|
|
])("identifies the OpenCode runtime version %s", (output, major) => {
|
|
expect(openCodeMajorVersion(String(output))).toBe(major);
|
|
});
|
|
|
|
test.each(["3.0.0", "2.0.9", "2.0.7", "2.0.4", "2.0.3", "v2.0.1"])(
|
|
"rejects unsupported OpenCode version output %s",
|
|
(output) => {
|
|
expect(() => openCodeMajorVersion(output)).toThrow();
|
|
},
|
|
);
|
|
|
|
test("records the runtime once and retains its position across resume", async () => {
|
|
const { withOpenCodeRuntimeNotice } = await import("./runtime-notice.js");
|
|
const { V2Harness } = await import("./test-utils/v2-harness.js");
|
|
const { OpenCodeV2AgentClient } = await import("./v2/agent.js");
|
|
const { createTestLogger } = await import("../../../../test-utils/test-logger.js");
|
|
const harness = new V2Harness();
|
|
const client = new OpenCodeV2AgentClient({
|
|
logger: createTestLogger(),
|
|
runtime: harness.runtime,
|
|
});
|
|
const original = withOpenCodeRuntimeNotice(
|
|
await client.createSession({ provider: "opencode", cwd: "/tmp/project" }),
|
|
2,
|
|
);
|
|
const notice = { type: "notification", level: "info", message: "This chat uses OpenCode v2." };
|
|
try {
|
|
expect(original.initialTimeline?.map((entry) => entry.item)).toEqual([notice]);
|
|
const handle = original.describePersistence()!;
|
|
await original.close();
|
|
const resumed = withOpenCodeRuntimeNotice(await client.resumeSession(handle), 2, handle);
|
|
try {
|
|
expect(resumed.initialTimeline).toEqual([]);
|
|
const history = [];
|
|
for await (const event of resumed.streamHistory()) history.push(event);
|
|
expect(history).toEqual([
|
|
{ type: "timeline", provider: "opencode", ...original.initialTimeline![0] },
|
|
]);
|
|
expect(resumed.describePersistence()?.metadata?.openCodeRuntimeNotices).toEqual(
|
|
handle.metadata?.openCodeRuntimeNotices,
|
|
);
|
|
} finally {
|
|
await resumed.close();
|
|
}
|
|
} finally {
|
|
await client.shutdown();
|
|
}
|
|
});
|
|
|
|
test("retries a rejected version probe after the configured binary changes", async () => {
|
|
const { mkdtemp, writeFile, rm } = await import("node:fs/promises");
|
|
const { tmpdir } = await import("node:os");
|
|
const { join } = await import("node:path");
|
|
const { OpenCodeRuntimeClient } = await import("./runtime-client.js");
|
|
const { createTestLogger } = await import("../../../../test-utils/test-logger.js");
|
|
const root = await mkdtemp(join(tmpdir(), "opencode-version-probe-"));
|
|
const script = join(root, "version.cjs");
|
|
const client = new OpenCodeRuntimeClient(createTestLogger(), {
|
|
command: { mode: "replace", argv: [process.execPath, script] },
|
|
});
|
|
try {
|
|
await writeFile(script, 'console.log("opencode v2.0.3")');
|
|
await expect(client.fetchCatalog({ scope: "global", force: true })).rejects.toThrow(
|
|
"Update OpenCode to 2.0.10 or newer, then refresh the provider in Paseo",
|
|
);
|
|
await writeFile(script, 'console.log("opencode v3.0.0")');
|
|
await expect(client.fetchCatalog({ scope: "global", force: true })).rejects.toThrow(
|
|
"Unsupported OpenCode major version 3",
|
|
);
|
|
} finally {
|
|
await client.shutdown();
|
|
await rm(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test.each([
|
|
["console.log('wrapper output')", "unrecognized output"],
|
|
["process.exit(1)", "failed command"],
|
|
])("retries a %s version probe after updating to v2 (%s)", async (initialSource) => {
|
|
const { mkdtemp, writeFile, rm } = await import("node:fs/promises");
|
|
const { tmpdir } = await import("node:os");
|
|
const { join } = await import("node:path");
|
|
const { OpenCodeRuntimeClient } = await import("./runtime-client.js");
|
|
const { createTestLogger } = await import("../../../../test-utils/test-logger.js");
|
|
const root = await mkdtemp(join(tmpdir(), "opencode-version-retry-"));
|
|
const script = join(root, "version.cjs");
|
|
const client = new OpenCodeRuntimeClient(createTestLogger(), {
|
|
command: { mode: "replace", argv: [process.execPath, script] },
|
|
});
|
|
try {
|
|
await writeFile(script, initialSource);
|
|
expect((await client.listFeatures({ provider: "opencode", cwd: root }))[0]?.label).toBe(
|
|
"Auto Accept",
|
|
);
|
|
await writeFile(script, 'console.log("opencode v2.0.10")');
|
|
expect((await client.listFeatures({ provider: "opencode", cwd: root }))[0]?.label).toBe(
|
|
"Auto-accept",
|
|
);
|
|
} finally {
|
|
await client.shutdown();
|
|
await rm(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("appends a first notice after old history and records a changed major version", async () => {
|
|
const { withOpenCodeRuntimeNotice } = await import("./runtime-notice.js");
|
|
const { V2Harness } = await import("./test-utils/v2-harness.js");
|
|
const { OpenCodeV2AgentClient } = await import("./v2/agent.js");
|
|
const { createTestLogger } = await import("../../../../test-utils/test-logger.js");
|
|
const harness = new V2Harness();
|
|
harness.history.push({ id: "old", type: "user", text: "Earlier prompt", time: { created: 1 } });
|
|
const client = new OpenCodeV2AgentClient({
|
|
logger: createTestLogger(),
|
|
runtime: harness.runtime,
|
|
});
|
|
const previous = {
|
|
provider: "opencode",
|
|
sessionId: "session",
|
|
metadata: { cwd: "/tmp/project" },
|
|
};
|
|
const session = withOpenCodeRuntimeNotice(await client.resumeSession(previous), 2, previous);
|
|
try {
|
|
const history = [];
|
|
for await (const event of session.streamHistory()) history.push(event);
|
|
expect(history).toEqual([
|
|
expect.objectContaining({
|
|
type: "timeline",
|
|
item: { type: "user_message", text: "Earlier prompt", messageId: "old" },
|
|
}),
|
|
expect.objectContaining({
|
|
type: "timeline",
|
|
item: { type: "notification", level: "info", message: "This chat uses OpenCode v2." },
|
|
}),
|
|
]);
|
|
await session.close();
|
|
const v1Handle = {
|
|
...previous,
|
|
metadata: {
|
|
...previous.metadata,
|
|
openCodeRuntimeNotices: [{ major: 1, timestamp: "2026-01-01T00:00:00.000Z" }],
|
|
},
|
|
};
|
|
const changed = withOpenCodeRuntimeNotice(await client.resumeSession(v1Handle), 2, v1Handle);
|
|
try {
|
|
expect(changed.initialTimeline?.map((entry) => entry.item)).toEqual([
|
|
{ type: "notification", level: "info", message: "This chat uses OpenCode v2." },
|
|
]);
|
|
expect(changed.describePersistence()?.metadata?.openCodeRuntimeNotices).toHaveLength(2);
|
|
} finally {
|
|
await changed.close();
|
|
}
|
|
} finally {
|
|
await session.close();
|
|
await client.shutdown();
|
|
}
|
|
});
|
|
|
|
test.each([
|
|
"process.exit(1)",
|
|
'console.log("custom wrapper output")',
|
|
"setTimeout(() => {}, 30000)",
|
|
])(
|
|
"preserves legacy operations when the version probe is inconclusive: %s",
|
|
async (source) => {
|
|
const { mkdtemp, writeFile, rm } = await import("node:fs/promises");
|
|
const { tmpdir } = await import("node:os");
|
|
const { join } = await import("node:path");
|
|
const { OpenCodeRuntimeClient } = await import("./runtime-client.js");
|
|
const { OpenCodeAgentClient } = await import("../opencode-agent.js");
|
|
const { createTestLogger } = await import("../../../../test-utils/test-logger.js");
|
|
const { OpenCodeServerManager } = await import("./server-manager.js");
|
|
const root = await mkdtemp(join(tmpdir(), "opencode-legacy-probe-"));
|
|
const script = join(root, "version.cjs");
|
|
await writeFile(script, source);
|
|
const logger = createTestLogger();
|
|
let legacyShutdown = false;
|
|
class TrackedServerManager extends OpenCodeServerManager {
|
|
override async shutdown() {
|
|
legacyShutdown = true;
|
|
await super.shutdown();
|
|
}
|
|
}
|
|
const client = new OpenCodeRuntimeClient(
|
|
logger,
|
|
{
|
|
command: { mode: "replace", argv: [process.execPath, script] },
|
|
},
|
|
{ serverManager: new TrackedServerManager({ logger }) },
|
|
);
|
|
const legacy = new OpenCodeAgentClient(logger);
|
|
const config = { provider: "opencode", cwd: root };
|
|
try {
|
|
expect(await client.listFeatures(config)).toEqual(await legacy.listFeatures(config));
|
|
} finally {
|
|
await client.shutdown();
|
|
await legacy.shutdown();
|
|
await rm(root, { recursive: true, force: true });
|
|
}
|
|
expect(legacyShutdown).toBe(true);
|
|
},
|
|
10000,
|
|
);
|