b279db1790
- Replaced time-based sleeps and polling loops with event-driven promise resolvers and fake timers across agent and tool tests. - Migrated test suites to share in-memory auth storage and fixtures using lifecycle hooks. - Updated catalog model definitions, metadata, and configurations.
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { createReferenceResolver } from "../src/provider-models/bundled-references";
|
|
import type { ModelSpec } from "../src/types";
|
|
|
|
const FIXTURE = `${import.meta.dir}/fixtures/bundled-reference-laziness.ts`;
|
|
|
|
function runFixture(fixture: string): string {
|
|
const result = Bun.spawnSync({
|
|
cmd: [process.execPath, fixture],
|
|
env: process.env,
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
expect(result.exitCode, result.stderr.toString()).toBe(0);
|
|
return result.stdout.toString();
|
|
}
|
|
|
|
describe("bundled model laziness", () => {
|
|
test("provider options and the bundled registry stay lazy", () => {
|
|
const { retainedRssBytes } = JSON.parse(runFixture(FIXTURE)) as { retainedRssBytes: number };
|
|
expect(retainedRssBytes).toBeLessThan(8 * 1024 * 1024);
|
|
}, 60_000);
|
|
test("a lazy provider-reference factory initializes on first resolution and only once", () => {
|
|
const reference = {
|
|
id: "fixture-model",
|
|
name: "Fixture Model",
|
|
api: "openai-completions",
|
|
provider: "fixture",
|
|
baseUrl: "https://example.test/v1",
|
|
reasoning: false,
|
|
input: ["text"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 8192,
|
|
maxTokens: 1024,
|
|
} satisfies ModelSpec<"openai-completions">;
|
|
let factoryCalls = 0;
|
|
const resolveReference = createReferenceResolver(() => {
|
|
factoryCalls++;
|
|
return new Map([[reference.id, reference]]);
|
|
});
|
|
|
|
expect(factoryCalls).toBe(0);
|
|
expect(resolveReference(reference.id)).toBe(reference);
|
|
expect(resolveReference(reference.id)).toBe(reference);
|
|
expect(factoryCalls).toBe(1);
|
|
});
|
|
});
|