agent-console 1.3.5: Windows reconnect through wails.localhost (Windows, http, no port only), model picker refresh keyed on a per-provider fingerprint of magpie's and the agent's own files, Magpie per-agent model filter, explicit picks forced past the snapshot, gateway URL anchored after the port.
Reviewed at 44661c8 on mote (fresh HOME, npm ci --ignore-scripts, Node 22): npm run check ok; vitest 535 passed, 17 skipped, 1 known flake also on main 749e9dd1 (claude-cli mid-turn CLI crash, manager.ts lastTurnStatus before idle); verify:build byte for byte; hostile wails.localhost and gateway URLs rejected on win32/darwin/linux; each of 17 new guards broken by hand turned its test red. PR CI green.
72 lines
2.8 KiB
TypeScript
72 lines
2.8 KiB
TypeScript
import { describe, it, expect, beforeEach } from "vitest";
|
|
import { cachedDetect, cachedModels, clearProviderCache, dropPlaceholder } from "../../daemon/src/providers/infoCache.js";
|
|
import type { Provider } from "../../daemon/src/providers/types.js";
|
|
|
|
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
|
|
function slowProvider(id: string, counter: { detect: number; models: number }): Provider {
|
|
return {
|
|
id,
|
|
name: id,
|
|
capabilities: { resume: false, interrupt: true, steer: false, images: false, plan: false, questions: false, cost: false, effort: [], modes: ["default"] },
|
|
async detect() { counter.detect++; await sleep(200); return { available: true }; },
|
|
async listModels() { counter.models++; await sleep(200); return [{ id: "m1", name: "M1" }]; },
|
|
async createSession() { throw new Error("unused"); },
|
|
} as Provider;
|
|
}
|
|
|
|
beforeEach(() => clearProviderCache());
|
|
|
|
describe("Provider info cache", () => {
|
|
it("second detection/model fetch hits the cache", async () => {
|
|
const c = { detect: 0, models: 0 };
|
|
const p = slowProvider("slow", c);
|
|
await cachedDetect(p);
|
|
await cachedModels(p);
|
|
const t0 = Date.now();
|
|
await cachedDetect(p);
|
|
await cachedModels(p);
|
|
expect(Date.now() - t0).toBeLessThan(50);
|
|
expect(c).toEqual({ detect: 1, models: 1 });
|
|
});
|
|
|
|
it("concurrent requests run only once", async () => {
|
|
const c = { detect: 0, models: 0 };
|
|
const p = slowProvider("conc", c);
|
|
await Promise.all([cachedModels(p), cachedModels(p), cachedModels(p)]);
|
|
expect(c.models).toBe(1);
|
|
});
|
|
|
|
it("detects again after clearProviderCache", async () => {
|
|
const c = { detect: 0, models: 0 };
|
|
const p = slowProvider("clr", c);
|
|
await cachedDetect(p);
|
|
clearProviderCache();
|
|
await cachedDetect(p);
|
|
expect(c.detect).toBe(2);
|
|
});
|
|
|
|
it("a model list with only a default placeholder counts as empty", () => {
|
|
expect(dropPlaceholder([{ id: "default", name: "默认", isDefault: true }])).toEqual([]);
|
|
expect(dropPlaceholder([{ id: "gpt", name: "GPT" }])).toHaveLength(1);
|
|
});
|
|
});
|
|
|
|
describe("Codex modelCache clears with clearProviderCache", () => {
|
|
it("registerProviderCacheClear hook runs for codex and for a full clear", async () => {
|
|
const { registerProviderCacheClear, clearProviderCache } = await import("../../daemon/src/providers/infoCache.js");
|
|
const { clearCodexModelCache } = await import("../../daemon/src/providers/codex/provider.js");
|
|
// clearCodexModelCache is idempotent; calling clearProviderCache must invoke registered hooks
|
|
let hits = 0;
|
|
registerProviderCacheClear((id) => {
|
|
if (!id || id === "codex") {
|
|
clearCodexModelCache();
|
|
hits++;
|
|
}
|
|
});
|
|
clearProviderCache("codex");
|
|
clearProviderCache();
|
|
expect(hits).toBeGreaterThanOrEqual(2);
|
|
});
|
|
});
|