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) <noreply@anthropic.com>
This commit is contained in:
Mikael Hugo 2026-05-15 16:37:11 +02:00
parent d8f56e6704
commit 3a14fe86a7

View file

@ -7,6 +7,13 @@ import { afterEach, beforeEach, describe, it } from "vitest";
import type { ModelRegistry } from "../core/model-registry.js"; import type { ModelRegistry } from "../core/model-registry.js";
import { listModels } from "./list-models.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<any> => ({ const model = (provider: string, id: string): Model<any> => ({
id, id,
name: id, name: id,
@ -66,7 +73,7 @@ describe("listModels", () => {
m.provider === "zai" && m.id === "glm-5.1", m.provider === "zai" && m.id === "glm-5.1",
} as unknown as ModelRegistry; } as unknown as ModelRegistry;
await listModels(registry, { searchPattern: "zai" }); await listModels(registry, { searchPattern: "zai", _discoveryCacheFilePath: NO_CACHE });
const rendered = output.join("\n"); const rendered = output.join("\n");
assert.match(rendered, /glm-5\.1/); assert.match(rendered, /glm-5\.1/);
@ -91,7 +98,7 @@ describe("listModels", () => {
isDiscovered: () => false, isDiscovered: () => false,
} as unknown as ModelRegistry; } as unknown as ModelRegistry;
await listModels(registry, { discover: true }); await listModels(registry, { discover: true, _discoveryCacheFilePath: NO_CACHE });
const rendered = output.join("\n"); const rendered = output.join("\n");
assert.doesNotMatch(rendered, /zai/); assert.doesNotMatch(rendered, /zai/);