mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 20:05:46 -06:00
89643f6401
* fix(openai): stop retrying TLS certificate failures * fix(ai): centralize TLS certificate failover policy --------- Co-authored-by: Altay <altay@hey.com>
64 lines
2.0 KiB
TypeScript
64 lines
2.0 KiB
TypeScript
// Openai tests cover openai chatgpt oauth plugin behavior.
|
|
import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { runOpenAIOAuthTlsPreflight } from "./openai-chatgpt-oauth-preflight.runtime.js";
|
|
|
|
describe("OpenAI Codex OAuth runtime", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("caps oversized TLS preflight timeouts before creating an abort signal", async () => {
|
|
const timeoutSpy = vi.spyOn(AbortSignal, "timeout");
|
|
const fetchImpl = vi.fn(async () => new Response(null, { status: 302 }));
|
|
|
|
await expect(
|
|
runOpenAIOAuthTlsPreflight({
|
|
timeoutMs: Number.MAX_SAFE_INTEGER,
|
|
fetchImpl,
|
|
}),
|
|
).resolves.toEqual({ ok: true });
|
|
|
|
expect(timeoutSpy).toHaveBeenCalledWith(MAX_TIMER_TIMEOUT_MS);
|
|
expect(fetchImpl).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("cancels reachable TLS preflight response bodies", async () => {
|
|
const response = new Response("reachable", { status: 302 });
|
|
const cancel = vi.spyOn(response.body!, "cancel").mockResolvedValue(undefined);
|
|
const fetchImpl = vi.fn(async () => response);
|
|
|
|
await expect(
|
|
runOpenAIOAuthTlsPreflight({
|
|
timeoutMs: 20,
|
|
fetchImpl,
|
|
}),
|
|
).resolves.toEqual({ ok: true });
|
|
|
|
expect(cancel).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it("uses the shared classifier for hostname mismatch failures", async () => {
|
|
const fetchImpl = vi.fn(async () => {
|
|
throw new TypeError("fetch failed", {
|
|
cause: {
|
|
code: "ERR_TLS_CERT_ALTNAME_INVALID",
|
|
message: "Hostname/IP does not match certificate's altnames",
|
|
},
|
|
});
|
|
});
|
|
|
|
await expect(
|
|
runOpenAIOAuthTlsPreflight({
|
|
timeoutMs: 20,
|
|
fetchImpl,
|
|
}),
|
|
).resolves.toEqual({
|
|
ok: false,
|
|
kind: "tls-cert",
|
|
code: "ERR_TLS_CERT_ALTNAME_INVALID",
|
|
message: "Hostname/IP does not match certificate's altnames",
|
|
});
|
|
});
|
|
});
|