MCPcopy Create free account
hub / github.com/clawbot7/cli-gateway / FakeRpc

Class FakeRpc

test/bindingRuntime.policy.test.ts:25–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23} from '../src/acp/jsonrpc.js';
24
25class FakeRpc implements StdioProcess {
26 private messageHandlers: Array<(m: JsonRpcMessage) => void> = [];
27 written: JsonRpcMessage[] = [];
28
29 private promptId: number | null = null;
30 private sessionId = 'sess-1';
31 private workspaceFile: string;
32
33 constructor(params: { workspaceFile: string }) {
34 this.workspaceFile = params.workspaceFile;
35 }
36
37 write(message: JsonRpcMessage): void {
38 this.written.push(message);
39
40 if ('method' in message) {
41 const req = message as JsonRpcRequest;
42
43 if (req.method === 'initialize') {
44 queueMicrotask(() =>
45 this.emit({
46 jsonrpc: '2.0',
47 id: req.id,
48 result: { protocolVersion: 1, agentCapabilities: {} },
49 } as any),
50 );
51 return;
52 }
53
54 if (req.method === 'session/new') {
55 queueMicrotask(() =>
56 this.emit({
57 jsonrpc: '2.0',
58 id: req.id,
59 result: { sessionId: this.sessionId },
60 } as any),
61 );
62 return;
63 }
64
65 if (req.method === 'session/prompt') {
66 this.promptId = Number(req.id);
67
68 queueMicrotask(() => {
69 this.emit({
70 jsonrpc: '2.0',
71 id: 999,
72 method: 'session/request_permission',
73 params: {
74 sessionId: this.sessionId,
75 toolCall: { title: 'fs/read_text_file', kind: 'read' },
76 options: [
77 { optionId: 'a1', name: 'Allow once', kind: 'allow_once' },
78 { optionId: 'r1', name: 'Reject once', kind: 'reject_once' },
79 ],
80 },
81 } as any);
82 });

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected