fix(agent): warm up opencode on startup
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { type OpencodeClient } from "@opencode-ai/sdk/v2";
|
||||
|
||||
import { OpencodeRuntimeAdapter } from "../../src/runtime/opencode.js";
|
||||
|
||||
@@ -60,3 +61,27 @@ describe("OpencodeRuntimeAdapter.revertToUserMessage", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("OpencodeRuntimeAdapter.ensureClient", () => {
|
||||
it("retries bootstrap after a failed startup attempt", async () => {
|
||||
let attempts = 0;
|
||||
const client = {
|
||||
global: { health: async () => ({ data: { healthy: true } }) },
|
||||
} as unknown as OpencodeClient;
|
||||
const runtime = Object.assign(Object.create(OpencodeRuntimeAdapter.prototype), {
|
||||
clientPromise: null,
|
||||
closeServer: null,
|
||||
bootstrapClient: async () => {
|
||||
attempts += 1;
|
||||
if (attempts === 1) {
|
||||
throw new Error("startup failed");
|
||||
}
|
||||
return client;
|
||||
},
|
||||
}) as OpencodeRuntimeAdapter;
|
||||
|
||||
await expect(runtime.ensureClient()).rejects.toThrow("startup failed");
|
||||
await expect(runtime.ensureClient()).resolves.toBe(client);
|
||||
expect(attempts).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user