MCPcopy Create free account
hub / github.com/cloudflare/computer / fakeRpc

Function fakeRpc

packages/computer/src/workspace.test.ts:43–133  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41}
42
43function fakeRpc(): import("@cloudflare/computer-rpc").SyncRPC {
44 const blobs = new Map<string, Uint8Array>();
45 const files = new Map<
46 string,
47 { mode: number; mtime: number; size: number; chunks: { hash: Uint8Array; size: number }[] }
48 >();
49
50 function hex(bytes: Uint8Array): string {
51 let s = "";
52 for (let i = 0; i < bytes.byteLength; i++) s += bytes[i].toString(16).padStart(2, "0");
53 return s;
54 }
55
56 return {
57 async push(input) {
58 const reader = input.changes.getReader();
59 try {
60 while (true) {
61 const { value, done } = await reader.read();
62 if (done) break;
63 if (value.kind === "file") {
64 files.set(value.path, {
65 mode: value.mode,
66 mtime: value.mtime,
67 size: value.size,
68 chunks: value.chunks,
69 });
70 } else if (value.kind === "delete") {
71 files.delete(value.path);
72 }
73 }
74 } finally {
75 reader.releaseLock();
76 }
77 return { rev: 0, appliedPushCursor: { rev: input.senderRev, path: null } };
78 },
79 async fetchChanges() {
80 return {
81 currentCursor: { rev: 0, path: null },
82 appliedPushCursor: { rev: 0, path: null },
83 stream: new ReadableStream<import("@cloudflare/dofs").ChangeEntry>({
84 start(c) {
85 c.close();
86 },
87 }),
88 };
89 },
90 async readEntry(path) {
91 const entry = files.get(path);
92 if (entry === undefined) return null;
93 return {
94 kind: "file",
95 rev: 0,
96 path,
97 mode: entry.mode,
98 mtime: entry.mtime,
99 size: entry.size,
100 chunks: entry.chunks,

Callers 3

connectFunction · 0.70
workspace.test.tsFile · 0.70
transportFailingBackendFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected