MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / createMockFileHandle

Function createMockFileHandle

src/app/repo/agent_chat.test.ts:17–39  ·  view source on GitHub ↗
(name: string, dir: Map<string, any>)

Source from the content-addressed store, hash-verified

15 }
16
17 function createMockFileHandle(name: string, dir: Map<string, any>) {
18 return {
19 kind: "file" as const,
20 getFile: vi.fn(async () => {
21 const content = dir.get(name);
22 if (content instanceof Blob) return content;
23 if (content instanceof ArrayBuffer) return new Blob([content]);
24 if (content instanceof Uint8Array) return new Blob([content.buffer as ArrayBuffer]);
25 if (typeof content === "string") return new Blob([content], { type: "application/octet-stream" });
26 return new Blob([""], { type: "application/octet-stream" });
27 }),
28 createWritable: vi.fn(async () => {
29 const writable = createMockWritable();
30 const origClose = writable.close;
31 writable.close = vi.fn(async () => {
32 const written = writable.getData();
33 dir.set(name, written);
34 await origClose();
35 });
36 return writable;
37 }),
38 };
39 }
40
41 function createMockDirHandle(store: Map<string, any>): any {
42 return {

Callers 1

createMockDirHandleFunction · 0.70

Calls 4

fnMethod · 0.80
createMockWritableFunction · 0.70
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected