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

Function openSubscriber

packages/server/test/ws-abort.e2e.test.ts:142–167  ·  view source on GitHub ↗
(r: RunningServer, sid: string)

Source from the content-addressed store, hash-verified

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