93 lines
2.7 KiB
TypeScript
93 lines
2.7 KiB
TypeScript
/**
|
|
* 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<string, StorageValue>();
|
|
|
|
export const LocalStorage = {
|
|
async getItem<T extends StorageValue>(key: string): Promise<T | undefined> {
|
|
return memory.get(key) as T | undefined;
|
|
},
|
|
async setItem(key: string, value: StorageValue): Promise<void> {
|
|
memory.set(key, value);
|
|
},
|
|
async removeItem(key: string): Promise<void> {
|
|
memory.delete(key);
|
|
},
|
|
async allItems(): Promise<Record<string, StorageValue>> {
|
|
return Object.fromEntries(memory);
|
|
},
|
|
async clear(): Promise<void> {
|
|
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<string, unknown> = {};
|
|
|
|
export function __setPreferenceValues(values: Record<string, unknown>): void {
|
|
preferenceOverride = values;
|
|
}
|
|
|
|
export function getPreferenceValues<T = Record<string, unknown>>(): 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<void> {
|
|
__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,
|
|
};
|