Files
OmniRoute/tests/unit/browserPool-proxy.test.ts
backryun 7ed8ada432 feat(providers): restore ChatGPT Web via clean-room browser transport (#12239)
Restores ChatGPT Web on a clean-room browser transport, merged on the operator's explicit decision.

Worth stating precisely, because this touches a provenance decision: the PR does not revert #11754. It narrows RETIRED_COMMON_CHATGPT_WEB_PROVIDER_IDS to the single GPL-derived alias cgpt-web and registers chatgpt-web as a separate clean-room id. The old implementation stays retired and blocked; the retirement machinery, its error code and its 410 contract are untouched. All four retirement suites agree with that distinction and pass unchanged.

The 44 protected agent-instruction surfaces this PR touches (AGENTS.md, llm.txt and its 42 mirrors, README) were verified rather than trusted: masking digits and comparing the removed and added line sets gives 264 lines on each side, identical — every change is a provider-count substitution, with no sentence added, removed or reworded.

Reconciled on merge: clean against the tip, with the two chat chokepoints this PR grows (src/sse/handlers/chat.ts +40, open-sse/handlers/chatCore.ts +30) recorded in the file-size baseline under an annotation. Verified that exactly those two caps move and nothing else, so the #12411 ratchet holds. The rebaseline is carried on this branch rather than left in a validation worktree — the propagation mistake that put the 2026-09-02 merge waves base-red in #12434.

Verified: 504/504 across the PR's 44 test files plus all four chatgpt-web retirement suites, check:provider-consistency OK (272 REGISTRY entries, 355 canonical providers), check-file-size OK, and every changed TypeScript file parses.

Thanks @backryun — separating the clean-room id from the retired alias, instead of reopening the old one, is what made this reviewable.
2026-09-02 10:31:41 -03:00

133 lines
4.3 KiB
TypeScript

import { describe, it } from "node:test";
import assert from "node:assert/strict";
import {
resolveBrowserContextProxy,
resolvePlainBrowserLaunchOptions,
resolvePlaywrightProxy,
} from "../../open-sse/services/browserPool.ts";
describe("resolvePlainBrowserLaunchOptions", () => {
it("keeps existing browser-pool callers headless by default", () => {
const options = resolvePlainBrowserLaunchOptions({});
assert.equal(options.headless, true);
assert.equal(options.executablePath, undefined);
assert.equal(options.args?.includes("--window-position=-32000,-32000"), false);
});
it("uses an explicitly selected system browser for headed first-party sessions", () => {
const options = resolvePlainBrowserLaunchOptions({
headless: false,
executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
});
assert.equal(options.headless, false);
assert.equal(
options.executablePath,
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
);
assert.equal(options.args?.includes("--window-position=-32000,-32000"), true);
});
});
describe("resolvePlaywrightProxy", () => {
it("returns undefined when no proxy is configured", async () => {
const proxy = await resolvePlaywrightProxy("gemini-web", {
resolveProxy: async () => null,
});
assert.strictEqual(proxy, undefined);
});
it("formats http proxy server string", async () => {
const proxy = await resolvePlaywrightProxy("gemini-web", {
resolveProxy: async () => ({ type: "http", host: "proxy.example.com", port: 8080 }),
});
assert.deepStrictEqual(proxy, { server: "http://proxy.example.com:8080" });
});
it("formats socks5 proxy server string", async () => {
const proxy = await resolvePlaywrightProxy("gemini-web", {
resolveProxy: async () => ({ type: "socks5", host: "socks.example.com", port: 1080 }),
});
assert.deepStrictEqual(proxy, { server: "socks5://socks.example.com:1080" });
});
it("defaults to http scheme when type is absent", async () => {
const proxy = await resolvePlaywrightProxy("claude-web", {
resolveProxy: async () => ({ host: "proxy.example.com", port: 3128 }),
});
assert.deepStrictEqual(proxy, { server: "http://proxy.example.com:3128" });
});
it("includes credentials when username is set", async () => {
const proxy = await resolvePlaywrightProxy("claude-web", {
resolveProxy: async () => ({
type: "http",
host: "proxy.example.com",
port: 3128,
username: "user",
password: "pass",
}),
});
assert.deepStrictEqual(proxy, {
server: "http://proxy.example.com:3128",
username: "user",
password: "pass",
});
});
it("uses empty string for password when null", async () => {
const proxy = await resolvePlaywrightProxy("claude-web", {
resolveProxy: async () => ({
type: "http",
host: "proxy.example.com",
port: 3128,
username: "user",
password: null,
}),
});
assert.deepStrictEqual(proxy, {
server: "http://proxy.example.com:3128",
username: "user",
password: "",
});
});
it("swallows DB errors and returns undefined", async () => {
const proxy = await resolvePlaywrightProxy("gemini-web", {
resolveProxy: async () => {
throw new Error("no such table: proxy_registry");
},
});
assert.strictEqual(proxy, undefined);
});
it("passes the actual provider key to the resolver", async () => {
let capturedKey = "";
await resolvePlaywrightProxy("gemini-web", {
resolveProxy: async (id) => {
capturedKey = id;
return null;
},
});
assert.strictEqual(capturedKey, "gemini-web");
});
it("allows a scoped context key to use its stable provider key for proxy lookup", async () => {
let capturedKey = "";
const proxy = await resolveBrowserContextProxy(
"claude-web:account-scope",
{ proxyProviderKey: "claude-web" },
{
resolveProxy: async (id) => {
capturedKey = id;
return { type: "http", host: "proxy.example.com", port: 8080 };
},
}
);
assert.equal(capturedKey, "claude-web");
assert.deepEqual(proxy, { server: "http://proxy.example.com:8080" });
});
});