MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / openSubscriber

Function openSubscriber

packages/server/test/approval.e2e.test.ts:130–161  ·  view source on GitHub ↗
(
  r: RunningServer,
  sid: string,
)

Source from the content-addressed store, hash-verified

128}
129
130async function openSubscriber(
131 r: RunningServer,
132 sid: string,
133): Promise<{
134 ws: WebSocket;
135 received: Record<string, unknown>[];
136}> {
137 const wsUrl = r.address.replace('http://', 'ws://') + '/api/v1/ws';
138 const received: Record<string, unknown>[] = [];
139 const ws = await new Promise<WebSocket>((resolve, reject) => {
140 const sock = new WebSocket(wsUrl, ['kimi-code.bearer.test-token']);
141 sock.on('message', (data) => {
142 try {
143 received.push(JSON.parse(rawDataToString(data)) as Record<string, unknown>);
144 } catch {
145 // ignore
146 }
147 });
148 sock.once('open', () => resolve(sock));
149 sock.once('error', reject);
150 });
151 await waitFor(received, (f) => f['type'] === 'server_hello');
152 ws.send(
153 JSON.stringify({
154 type: 'client_hello',
155 id: 'h1',
156 payload: { client_id: 'test', subscriptions: [sid] },
157 }),
158 );
159 await waitFor(received, (f) => f['type'] === 'ack' && f['id'] === 'h1');
160 return { ws, received };
161}
162
163async function waitFor(
164 received: Record<string, unknown>[],

Callers 1

Calls 7

rawDataToStringFunction · 0.90
waitForFunction · 0.70
onMethod · 0.65
onceMethod · 0.65
sendMethod · 0.65
resolveFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected