/** * Vitest stub for `@vicinae/api`. * * The real package talks to the Vicinae runtime over JSON-RPC, which does not * exist under test. `vitest.config.ts` aliases the package here. * * `LocalStorage` is backed by a real in-memory map rather than being a set of * no-op spies, so the session store's read-after-write behaviour is actually * exercised instead of being mocked into false confidence. */ type StorageValue = string | number | boolean; const memory = new Map(); export const LocalStorage = { async getItem(key: string): Promise { return memory.get(key) as T | undefined; }, async setItem(key: string, value: StorageValue): Promise { memory.set(key, value); }, async removeItem(key: string): Promise { memory.delete(key); }, async allItems(): Promise> { return Object.fromEntries(memory); }, async clear(): Promise { memory.clear(); }, }; /** Test-only helper: wipes the fake store between cases. */ export function __resetLocalStorage(): void { memory.clear(); } /** Returns whatever the test sets on the override, otherwise an empty object. */ let preferenceOverride: Record = {}; export function __setPreferenceValues(values: Record): void { preferenceOverride = values; } export function getPreferenceValues>(): T { return preferenceOverride as T; } /** * Toast stubs. * * Recorded rather than discarded, so a test can assert that a sweep only speaks * up when it actually deleted something. */ export const __toasts: { title: string; message?: string }[] = []; export const Toast = { Style: { Success: "success", Failure: "failure", Animated: "animated" }, }; export async function showToast(options: { title: string; message?: string }): Promise { __toasts.push({ title: options.title, message: options.message }); } /** Test-only helper: forgets the toasts shown so far. */ export function __resetToasts(): void { __toasts.length = 0; } /** * The runtime `environment`. Only `supportPath` is exercised, by the snip * directory, and a stable fake path keeps those assertions independent of where * the test happens to run. */ export const environment = { supportPath: "/tmp/lam-agent-support", assetsPath: "/tmp/lam-agent-assets", extensionName: "lam-agent", ownerOrAuthorName: "adrianbonpin", commandName: "chat", commandMode: "view" as const, isDevelopment: true, appearance: "dark" as const, theme: "dark" as const, textSize: "medium" as const, launchType: "userInitiated" as const, raycastVersion: "0.0.0", vicinaeVersion: { tag: "test", commit: "test" }, isRaycast: false, canAccess: () => true, };