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

Function openSubscriber

packages/server/test/prompt.e2e.test.ts:212–244  ·  view source on GitHub ↗

* Open a WS subscriber and wait for server_hello + client_hello ack. * Returns a handle exposing the received frame queue. * * Mirrors the queueing pattern from `ws-broadcast.e2e.test.ts` — message * listener is attached BEFORE the `open` event resolves, so frames that land * in the same tick a

(
  r: RunningServer,
  sid: string,
)

Source from the content-addressed store, hash-verified

210 * in the same tick as the upgrade aren't lost.
211 */
212async function openSubscriber(
213 r: RunningServer,
214 sid: string,
215): Promise<{
216 ws: WebSocket;
217 received: Record<string, unknown>[];
218}> {
219 const wsUrl = r.address.replace('http://', 'ws://') + '/api/v1/ws';
220 const received: Record<string, unknown>[] = [];
221 const ws = await new Promise<WebSocket>((resolve, reject) => {
222 const sock = new WebSocket(wsUrl, ['kimi-code.bearer.test-token']);
223 sock.on('message', (data) => {
224 try {
225 received.push(JSON.parse(wsDataToString(data)) as Record<string, unknown>);
226 } catch {
227 // ignore
228 }
229 });
230 sock.once('open', () => resolve(sock));
231 sock.once('error', reject);
232 });
233 // Wait for server_hello.
234 await waitFor(received, (f) => f['type'] === 'server_hello');
235 ws.send(
236 JSON.stringify({
237 type: 'client_hello',
238 id: 'h1',
239 payload: { client_id: 'test', subscriptions: [sid] },
240 }),
241 );
242 await waitFor(received, (f) => f['type'] === 'ack' && f['id'] === 'h1');
243 return { ws, received };
244}
245
246async function waitFor(
247 received: Record<string, unknown>[],

Callers 1

prompt.e2e.test.tsFile · 0.70

Calls 7

wsDataToStringFunction · 0.70
waitForFunction · 0.70
onMethod · 0.65
onceMethod · 0.65
sendMethod · 0.65
resolveFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected