From 2cf9c3abe420c68428438afe8f8ec91ef9dedadf Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 21 Feb 2026 22:51:06 +0000 Subject: [PATCH] test(models): dedupe auth-sync command assertions --- src/commands/models.list.auth-sync.test.ts | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/commands/models.list.auth-sync.test.ts b/src/commands/models.list.auth-sync.test.ts index 5b2e71c1f..75eb98cc0 100644 --- a/src/commands/models.list.auth-sync.test.ts +++ b/src/commands/models.list.auth-sync.test.ts @@ -68,6 +68,17 @@ function getProviderRow(payloadText: string, providerPrefix: string) { 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", () => { it("marks models available when auth exists only in auth-profiles.json", async () => { await withAuthSyncFixture(async ({ agentDir, authPath }) => { @@ -87,13 +98,7 @@ describe("models list auth-profile sync", () => { expect(await pathExists(authPath)).toBe(false); - const runtime = createRuntime(); - 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(); + const openrouter = await runModelsListAndGetProvider("openrouter/"); expect(openrouter?.available).toBe(true); expect(await pathExists(authPath)).toBe(true); }); @@ -115,11 +120,7 @@ describe("models list auth-profile sync", () => { agentDir, ); - const runtime = createRuntime(); - await modelsListCommand({ all: true, json: true }, runtime as never); - - expect(runtime.error).not.toHaveBeenCalled(); - expect(runtime.log).toHaveBeenCalledTimes(1); + await runModelsListAndGetProvider("openrouter/"); if (await pathExists(authPath)) { const parsed = JSON.parse(await fs.readFile(authPath, "utf8")) as Record< string,