test(models): dedupe auth-sync command assertions

This commit is contained in:
Peter Steinberger
2026-02-21 22:51:06 +00:00
parent b791ac2167
commit 2cf9c3abe4

View File

@@ -68,6 +68,17 @@ function getProviderRow(payloadText: string, providerPrefix: string) {
return payload.models?.find((model) => String(model.key ?? "").startsWith(providerPrefix)); return payload.models?.find((model) => String(model.key ?? "").startsWith(providerPrefix));
} }
async function runModelsListAndGetProvider(providerPrefix: string) {
const runtime = createRuntime();
await modelsListCommand({ all: true, json: true }, runtime as never);
expect(runtime.error).not.toHaveBeenCalled();
expect(runtime.log).toHaveBeenCalledTimes(1);
const provider = getProviderRow(String(runtime.log.mock.calls[0]?.[0]), providerPrefix);
expect(provider).toBeDefined();
return provider;
}
describe("models list auth-profile sync", () => { describe("models list auth-profile sync", () => {
it("marks models available when auth exists only in auth-profiles.json", async () => { it("marks models available when auth exists only in auth-profiles.json", async () => {
await withAuthSyncFixture(async ({ agentDir, authPath }) => { await withAuthSyncFixture(async ({ agentDir, authPath }) => {
@@ -87,13 +98,7 @@ describe("models list auth-profile sync", () => {
expect(await pathExists(authPath)).toBe(false); expect(await pathExists(authPath)).toBe(false);
const runtime = createRuntime(); const openrouter = await runModelsListAndGetProvider("openrouter/");
await modelsListCommand({ all: true, json: true }, runtime as never);
expect(runtime.error).not.toHaveBeenCalled();
expect(runtime.log).toHaveBeenCalledTimes(1);
const openrouter = getProviderRow(String(runtime.log.mock.calls[0]?.[0]), "openrouter/");
expect(openrouter).toBeDefined();
expect(openrouter?.available).toBe(true); expect(openrouter?.available).toBe(true);
expect(await pathExists(authPath)).toBe(true); expect(await pathExists(authPath)).toBe(true);
}); });
@@ -115,11 +120,7 @@ describe("models list auth-profile sync", () => {
agentDir, agentDir,
); );
const runtime = createRuntime(); await runModelsListAndGetProvider("openrouter/");
await modelsListCommand({ all: true, json: true }, runtime as never);
expect(runtime.error).not.toHaveBeenCalled();
expect(runtime.log).toHaveBeenCalledTimes(1);
if (await pathExists(authPath)) { if (await pathExists(authPath)) {
const parsed = JSON.parse(await fs.readFile(authPath, "utf8")) as Record< const parsed = JSON.parse(await fs.readFile(authPath, "utf8")) as Record<
string, string,