// Test-only helpers used by the resolver test suite. Coverage excluded via // vitest config's `*.test.ts` filter — this file is `.ts` rather than // `.test.ts` so it can be imported from multiple test files. import type { StorageLike } from "@suaveplan/types"; /** * Minimal in-memory `StorageLike` for resolver dispatch tests. NOT a mock — * it's a real implementation of the structural contract, written by hand * because rule 2 forbids `vi.mock`. Test files attach this to a * `UriPlugin` to exercise scheme dispatch. */ export class MemoryStorageLike implements StorageLike { public readonly store = new Map(); public lastSignal: AbortSignal | undefined; public getCalls = 0; public setCalls = 0; public deleteCalls = 0; public existsCalls = 0; public listCalls = 0; public async get(key: string): Promise { this.getCalls += 1; return this.store.get(key); } public async set(key: string, value: Uint8Array): Promise { this.setCalls += 1; this.store.set(key, value); } public async delete(key: string): Promise { this.deleteCalls += 1; return this.store.delete(key); } public async exists(key: string): Promise { this.existsCalls += 1; return this.store.has(key); } public async list(options?: { prefix?: string; limit?: number }): Promise<{ keys: string[]; total: number; hasMore: boolean; continuationToken?: string | undefined; }> { this.listCalls += 1; const prefix = options?.prefix ?? ""; const all = [...this.store.keys()].filter((k) => k.startsWith(prefix)); const limit = options?.limit ?? all.length; const keys = all.slice(0, limit); return { keys, total: all.length, hasMore: keys.length < all.length }; } public async clear(): Promise { this.store.clear(); } }