From 3a14fe86a79b203ec53a69c258c8f8c865ac6c07 Mon Sep 17 00:00:00 2001 From: Mikael Hugo Date: Fri, 15 May 2026 16:37:11 +0200 Subject: [PATCH] test(list-models): isolate from developer's discovery-cache Tests were picking up the developer's real ~/.sf/agent/discovery-cache.json and seeing unexpected models in output. Pin tests to a guaranteed-missing path via the new _discoveryCacheFilePath option so the env they observe is solely what the test constructs. Co-Authored-By: Claude Opus 4.7 (1M context) --- packages/coding-agent/src/cli/list-models.test.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/coding-agent/src/cli/list-models.test.ts b/packages/coding-agent/src/cli/list-models.test.ts index b98493d8e..0e7b8a733 100644 --- a/packages/coding-agent/src/cli/list-models.test.ts +++ b/packages/coding-agent/src/cli/list-models.test.ts @@ -7,6 +7,13 @@ import { afterEach, beforeEach, describe, it } from "vitest"; import type { ModelRegistry } from "../core/model-registry.js"; import { listModels } from "./list-models.js"; +/** + * Path to a guaranteed-missing file — used to prevent tests from picking up + * the developer's real ~/.sf/agent/discovery-cache.json and thus seeing + * unexpected models in output. + */ +const NO_CACHE = join(tmpdir(), `no-discovery-cache-${process.pid}.json`); + const model = (provider: string, id: string): Model => ({ id, name: id, @@ -66,7 +73,7 @@ describe("listModels", () => { m.provider === "zai" && m.id === "glm-5.1", } as unknown as ModelRegistry; - await listModels(registry, { searchPattern: "zai" }); + await listModels(registry, { searchPattern: "zai", _discoveryCacheFilePath: NO_CACHE }); const rendered = output.join("\n"); assert.match(rendered, /glm-5\.1/); @@ -91,7 +98,7 @@ describe("listModels", () => { isDiscovered: () => false, } as unknown as ModelRegistry; - await listModels(registry, { discover: true }); + await listModels(registry, { discover: true, _discoveryCacheFilePath: NO_CACHE }); const rendered = output.join("\n"); assert.doesNotMatch(rendered, /zai/);