fix(agent): warm up opencode on startup
Agent CI/CD / docker-image (push) Successful in 1m59s
Agent CI/CD / deploy-fallback-log (push) Has been skipped

This commit is contained in:
2026-06-08 20:19:46 +08:00
parent 8ed73b1da6
commit 873c169c2c
3 changed files with 53 additions and 1 deletions
+25
View File
@@ -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);
});
});