fix(pi): upstream completion test sends a sessionId (OpenCode x-opencode-session)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
975a14ace7
commit
4cd9ec8390
2 files changed
+33
-1
No files matched your search
@@ -133,6 +133,31 @@ describe("按上游装配", () => {
|
||||
expect(t).toMatchObject({ model: "claude-future-9", inCatalog: false, source: "stored credential" });
|
||||
});
|
||||
|
||||
it("测试补全带 sessionId:OpenCode Go 请求头有 x-opencode-session", async () => {
|
||||
const seen: { url: string; headers: Headers }[] = [];
|
||||
const orig = globalThis.fetch;
|
||||
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const req = new Request(input, init);
|
||||
seen.push({ url: req.url, headers: req.headers });
|
||||
return new Response(JSON.stringify({ error: { message: "stubbed" } }), {
|
||||
status: 500,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
}) as typeof fetch;
|
||||
try {
|
||||
const c = new PiUpstreamClient(
|
||||
spec({ provider: "opencode-go", authKind: "api_key" }),
|
||||
memStore({ type: "api_key", key: "sk-opencode-test" }),
|
||||
);
|
||||
await expect(c.test({ mode: "completion" })).rejects.toBeInstanceOf(UpstreamError);
|
||||
} finally {
|
||||
globalThis.fetch = orig;
|
||||
}
|
||||
const call = seen.find((x) => x.headers.get("x-opencode-session"));
|
||||
expect(call, `请求:${seen.map((x) => x.url).join(", ")}`).toBeDefined();
|
||||
expect(call?.headers.get("x-opencode-session")).toMatch(/^umt-upstream-test-/);
|
||||
});
|
||||
|
||||
it("自定义兼容端点:baseUrl/模型必填;authKind none 不需要 key", async () => {
|
||||
expect(() => new PiUpstreamClient(spec({ provider: "openai-compatible", authKind: "none" }), memStore())).toThrow(
|
||||
UpstreamError,
|
||||
|
||||
Reference in new issue
Block a user