Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
75 lines
2.8 KiB
TypeScript
75 lines
2.8 KiB
TypeScript
import { assert, it } from "@effect/vitest";
|
|
import * as Effect from "effect/Effect";
|
|
import { HttpClient, HttpClientResponse } from "effect/http";
|
|
import { chatGptModels } from "./CodexChatGptModels.ts";
|
|
|
|
it.effect(
|
|
"uses each selected profile's token and the server's visible catalog order and names",
|
|
() =>
|
|
Effect.gen(function* () {
|
|
const requests: string[] = [];
|
|
const http = HttpClient.make((request) =>
|
|
Effect.sync(() => {
|
|
assert.strictEqual(request.url, "https://api.openai.com/v1/models");
|
|
requests.push(request.headers.authorization!);
|
|
return HttpClientResponse.fromWeb(
|
|
request,
|
|
new Response(
|
|
JSON.stringify({
|
|
models:
|
|
request.headers.authorization === "Bearer account-a"
|
|
? [
|
|
{ slug: "second", display_name: "Second from OpenAI", visibility: "list" },
|
|
{ slug: "hidden", display_name: "Hidden", visibility: "hidden" },
|
|
{ slug: "first", display_name: "First from OpenAI", visibility: "list" },
|
|
]
|
|
: [{ slug: "account-b-only", display_name: "B", visibility: "list" }],
|
|
}),
|
|
),
|
|
);
|
|
}),
|
|
);
|
|
const native = [
|
|
{
|
|
slug: "first",
|
|
name: "Cached first",
|
|
isCustom: false,
|
|
capabilities: { optionDescriptors: [] },
|
|
},
|
|
{ slug: "not-entitled", name: "Cached other", isCustom: false, capabilities: null },
|
|
];
|
|
const a = yield* chatGptModels("account-a", native).pipe(
|
|
Effect.provideService(HttpClient.HttpClient, http),
|
|
);
|
|
assert.deepEqual(
|
|
a.map((model) => [model.slug, model.name]),
|
|
[
|
|
["second", "Second from OpenAI"],
|
|
["first", "First from OpenAI"],
|
|
],
|
|
);
|
|
assert.deepEqual(a[1]!.capabilities, native[0]!.capabilities);
|
|
assert.isNull(a[0]!.capabilities);
|
|
const b = yield* chatGptModels("account-b", native).pipe(
|
|
Effect.provideService(HttpClient.HttpClient, http),
|
|
);
|
|
assert.deepEqual(
|
|
b.map((model) => model.slug),
|
|
["account-b-only"],
|
|
);
|
|
assert.deepEqual(requests, ["Bearer account-a", "Bearer account-b"]);
|
|
}),
|
|
);
|
|
|
|
it.effect("does not present a cached catalog as account entitlements when discovery fails", () =>
|
|
Effect.gen(function* () {
|
|
const http = HttpClient.make((request) =>
|
|
Effect.succeed(HttpClientResponse.fromWeb(request, new Response(null, { status: 503 }))),
|
|
);
|
|
const error = yield* Effect.flip(
|
|
chatGptModels("account-a", []).pipe(Effect.provideService(HttpClient.HttpClient, http)),
|
|
);
|
|
assert.strictEqual(error._tag, "ChatGptCatalogError");
|
|
}),
|
|
);
|