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

Function openSubscriber

packages/server/test/question.e2e.test.ts:131–162  ·  view source on GitHub ↗
(
  r: RunningServer,
  sid: string,
)

Source from the content-addressed store, hash-verified

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