Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

proxy.test.ts

32 lines1.1 KB

1// @effect-diagnostics nodeBuiltinImport:off
2import * as NodeFS from "node:fs";
3import * as NodeOS from "node:os";
4import * as NodePath from "node:path";
5import { describe, expect, it, vi } from "vite-plus/test";
6import { proxyConfig } from "./proxy.ts";
7​
8const config = `model_provider = "cliproxy"
9​
10[model_providers.cliproxy]
11base_url = "https://proxy.example/v1"
12requires_openai_auth = true
13`;
14​
15describe("proxyConfig", () => {
16 it.each([
17 ["no auth.json", undefined],
18 ["a ChatGPT-login auth.json", { OPENAI_API_KEY: null, tokens: { access_token: "t" } }],
19 ])("fails when the provider requires OpenAI auth and %s has no key", (_, auth) => {
20 const home = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-evals-proxy-"));
21 using _home = {
22 [Symbol.dispose]: () => {
23 vi.unstubAllEnvs();
24 NodeFS.rmSync(home, { recursive: true });
25 },
26 };
27 NodeFS.writeFileSync(NodePath.join(home, "config.toml"), config);
28 if (auth) NodeFS.writeFileSync(NodePath.join(home, "auth.json"), JSON.stringify(auth));
29 vi.stubEnv("CODEX_HOME", home);
30 expect(() => proxyConfig()).toThrow(/requires_openai_auth/);
31 });
32});