MCPcopy
hub / github.com/rohitg00/agentmemory / mockKV

Function mockKV

test/replay-import-key.test.ts:13–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11import { KV } from "../src/state/schema.js";
12
13function mockKV() {
14 const store = new Map<string, Map<string, unknown>>();
15 const setCalls: Array<{ scope: string; key: string | undefined; value: any }> = [];
16 return {
17 get: async <T>(scope: string, key: string): Promise<T | null> =>
18 (store.get(scope)?.get(key) as T) ?? null,
19 set: async <T>(scope: string, key: string, value: T): Promise<T> => {
20 setCalls.push({ scope, key, value });
21 if (!store.has(scope)) store.set(scope, new Map());
22 // Mirror the engine: a state::set with key=undefined fails. We
23 // surface this via setCalls so the test can assert key !== undefined.
24 if (key === undefined) {
25 throw new Error("missing field `key`");
26 }
27 store.get(scope)!.set(key, value);
28 return value;
29 },
30 delete: async (scope: string, key: string) => {
31 store.get(scope)?.delete(key);
32 },
33 list: async <T>(scope: string): Promise<T[]> =>
34 Array.from(store.get(scope)?.values() ?? []) as T[],
35 getSetCalls: () => setCalls,
36 };
37}
38
39function mockSdk(kv: ReturnType<typeof mockKV>) {
40 const fns = new Map<string, Function>();

Callers 1

Calls 5

pushMethod · 0.80
hasMethod · 0.80
getMethod · 0.45
setMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected