Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opencode-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"typecheck": "tsc -p tsconfig.json"
},
"dependencies": {
"@opencode/client": "2.1.4"
"@opencode/client": "2.2.0"
},
"devDependencies": {
"@opencode2-mobile/test-fixtures": "workspace:*",
Expand Down
40 changes: 29 additions & 11 deletions packages/opencode-adapter/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1718,8 +1718,8 @@ it("classifies a malformed fake API event frame", async () => {
it.each([404, 405])(
"classifies a missing required V2 endpoint HTTP %s as incompatible",
async (status) => {
// Project-list 404 is a declared API error in 2.0.23. Server info still
// treats missing routes as unexpected statuses, including its legacy fallback.
// Server info treats missing routes as unexpected statuses, including its
// legacy fallback.
const api = createFakeOpenCodeApi({
failures: {
"/api/info": { body: {}, status },
Expand All @@ -1736,10 +1736,26 @@ it.each([404, 405])(
},
);

it("classifies a declared project-list 404 as not found", async () => {
it.each([404, 405])(
"classifies a missing project-list route HTTP %s as incompatible",
async (status) => {
const api = createFakeOpenCodeApi({
failures: { "/api/project": { body: {}, status } },
});
const client = createOpenCodeClient({
baseUrl: "https://fake.invalid",
fetch: api.fetch,
});

const error = await client.project.list().catch((caught: unknown) => caught);
expect(classifyOpenCodeError(error)).toBe("INCOMPATIBLE");
},
);

it("classifies a declared project-update 404 as not found", async () => {
const api = createFakeOpenCodeApi({
failures: {
"/api/project": {
"/api/project/missing-project": {
body: {
_tag: "ProjectNotFoundError",
projectID: "missing-project",
Expand All @@ -1754,7 +1770,9 @@ it("classifies a declared project-list 404 as not found", async () => {
fetch: api.fetch,
});

const error = await client.project.list().catch((caught: unknown) => caught);
const error = await client.project
.update({ projectID: "missing-project", name: "Fixture" })
.catch((caught: unknown) => caught);
expect(classifyOpenCodeError(error)).toBe("NOT_FOUND");
});

Expand Down Expand Up @@ -1837,7 +1855,7 @@ it("reports an event stream that ignores cancellation", async () => {
},
}),
},
};
} satisfies Parameters<typeof probeEventStream>[0];

await expect(
probeEventStream(client, { cancellationTimeoutMs: 10, firstEventTimeoutMs: 10 }),
Expand All @@ -1849,7 +1867,7 @@ it("keeps an event generation open until lifecycle cancellation", async () => {
const event: OpenCodeEvent = { data: {}, id: "evt_test", type: "server.connected" };
const client = {
event: {
subscribe: ({ signal }: { signal: AbortSignal }) => ({
subscribe: ({ signal }) => ({
async *[Symbol.asyncIterator]() {
yield event;
if (signal.aborted) {
Expand All @@ -1865,7 +1883,7 @@ it("keeps an event generation open until lifecycle cancellation", async () => {
},
}),
},
} as unknown as Parameters<typeof openEventStreamGeneration>[0];
} satisfies Parameters<typeof openEventStreamGeneration>[0];

const generation = await openEventStreamGeneration(client);
expect(generation.eventType).toBe("server.connected");
Expand All @@ -1886,7 +1904,7 @@ it("reports a pending event read that ignores lifecycle cancellation", async ()
},
}),
},
} as unknown as Parameters<typeof openEventStreamGeneration>[0];
} satisfies Parameters<typeof openEventStreamGeneration>[0];

const generation = await openEventStreamGeneration(client, { cancellationTimeoutMs: 10 });
await expect(generation.cancel()).rejects.toMatchObject({ reason: "CANCELLATION_IGNORED" });
Expand All @@ -1896,7 +1914,7 @@ it("can stop an event probe before its first event", async () => {
let aborted = false;
const client = {
event: {
subscribe: ({ signal }: { signal: AbortSignal }) => ({
subscribe: ({ signal }) => ({
[Symbol.asyncIterator]() {
return {
next: () =>
Expand All @@ -1910,7 +1928,7 @@ it("can stop an event probe before its first event", async () => {
},
}),
},
} as unknown as Parameters<typeof startEventStreamProbe>[0];
} satisfies Parameters<typeof startEventStreamProbe>[0];
const probe = startEventStreamProbe(client);

await expect(Promise.all([probe.stop(), probe.stop()])).resolves.toEqual([undefined, undefined]);
Expand Down
22 changes: 12 additions & 10 deletions packages/opencode-adapter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {

import { ensurePromiseWithResolvers } from "./promise-with-resolvers";

export const openCodeClientContractVersion = "2.1.4";
export const openCodeClientContractVersion = "2.2.0";

export type OpenCodeClientOptions = {
authorization?: string;
Expand Down Expand Up @@ -1743,18 +1743,23 @@ export async function probePtyTransport(
return result as NonNullable<typeof result>;
}

export async function probeEventStream(
client: Pick<OpenCodeClient, "event">,
options: EventProbeOptions = {},
) {
// Probes consume all events and only need subscriber-local cancellation, not
// the generated client's generic event-filter signature.
type EventProbeClient = {
event: {
subscribe(options: { signal: AbortSignal }): AsyncIterable<OpenCodeEvent>;
};
};

export async function probeEventStream(client: EventProbeClient, options: EventProbeOptions = {}) {
const probe = startEventStreamProbe(client, options);
const first = await probe.firstEvent;
await probe.stop();
return { cancellation: true, eventType: first.eventType } as const;
}

export async function openEventStreamGeneration(
client: Pick<OpenCodeClient, "event">,
client: EventProbeClient,
options: EventProbeOptions = {},
) {
const probe = startEventStreamProbe(client, options);
Expand All @@ -1767,10 +1772,7 @@ export async function openEventStreamGeneration(
}
}

export function startEventStreamProbe(
client: Pick<OpenCodeClient, "event">,
options: EventProbeOptions = {},
) {
export function startEventStreamProbe(client: EventProbeClient, options: EventProbeOptions = {}) {
const controller = new AbortController();
const iterator = client.event.subscribe({ signal: controller.signal })[Symbol.asyncIterator]();
const firstRead = withDeadline(
Expand Down
28 changes: 14 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading