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:
parent
d8f56e6704
commit
3a14fe86a7
1 changed files with 9 additions and 2 deletions
|
|
@ -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<any> => ({
|
||||
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/);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue