opencode-copilot-delegate 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +14 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14141 -215
- package/dist/runtime/cancel-helper.d.ts +10 -0
- package/dist/runtime/envelope.d.ts +1 -1
- package/dist/runtime/notify.d.ts +2 -1
- package/dist/runtime/rpc-contract.d.ts +39 -0
- package/dist/runtime/rpc-server.d.ts +32 -0
- package/dist/tui/__tests__/confirm-card.test.d.ts +2 -0
- package/dist/tui/__tests__/index.test.d.ts +1 -0
- package/dist/tui/__tests__/modal-list.test.d.ts +1 -0
- package/dist/tui/__tests__/rpc-client.test.d.ts +1 -0
- package/dist/tui/components/confirm-card.d.ts +12 -0
- package/dist/tui/components/modal-list.d.ts +16 -0
- package/dist/tui/components/row.d.ts +6 -0
- package/dist/tui/index.d.ts +7 -0
- package/dist/tui/index.js +14107 -0
- package/dist/tui/rpc-client.d.ts +43 -0
- package/package.json +32 -9
- package/src/tui/.gitkeep +1 -0
- package/src/tui/__tests__/confirm-card.test.tsx +516 -0
- package/src/tui/__tests__/index.test.ts +438 -0
- package/src/tui/__tests__/modal-list.test.tsx +518 -0
- package/src/tui/__tests__/rpc-client.test.ts +507 -0
- package/src/tui/components/confirm-card.tsx +252 -0
- package/src/tui/components/modal-list.tsx +232 -0
- package/src/tui/components/row.tsx +41 -0
- package/src/tui/index.tsx +67 -0
- package/src/tui/rpc-client.ts +379 -0
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'bun:test'
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import {
|
|
4
|
+
createServer,
|
|
5
|
+
type IncomingMessage,
|
|
6
|
+
type ServerResponse,
|
|
7
|
+
} from 'node:http'
|
|
8
|
+
import type { AddressInfo } from 'node:net'
|
|
9
|
+
import { tmpdir } from 'node:os'
|
|
10
|
+
import { join } from 'node:path'
|
|
11
|
+
|
|
12
|
+
type RpcClient = {
|
|
13
|
+
health(): Promise<unknown>
|
|
14
|
+
tasksList(): Promise<unknown>
|
|
15
|
+
tasksCancel(taskId: string): Promise<unknown>
|
|
16
|
+
dispose(): void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type ErrorClass = abstract new (...args: unknown[]) => Error
|
|
20
|
+
|
|
21
|
+
type RpcClientModule = {
|
|
22
|
+
createRpcClient(options?: {
|
|
23
|
+
baseDir?: string
|
|
24
|
+
sessionDiscriminator?: string
|
|
25
|
+
fetchImpl?: typeof fetch
|
|
26
|
+
requestTimeoutMs?: number
|
|
27
|
+
}): RpcClient
|
|
28
|
+
RpcUnreachableError: ErrorClass
|
|
29
|
+
RpcServerError: ErrorClass
|
|
30
|
+
RpcAuthError: ErrorClass
|
|
31
|
+
RpcValidationError: ErrorClass
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type RecordedRequest = {
|
|
35
|
+
method: string
|
|
36
|
+
url: string
|
|
37
|
+
authorization?: string
|
|
38
|
+
body: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type StartedStubServer = {
|
|
42
|
+
port: number
|
|
43
|
+
requests: RecordedRequest[]
|
|
44
|
+
close(): Promise<void>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const tempPaths: string[] = []
|
|
48
|
+
const startedServers: StartedStubServer[] = []
|
|
49
|
+
|
|
50
|
+
afterEach(async () => {
|
|
51
|
+
for (const server of startedServers.splice(0)) {
|
|
52
|
+
await server.close()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (const tempPath of tempPaths.splice(0)) {
|
|
56
|
+
rmSync(tempPath, { force: true, recursive: true })
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
async function loadRpcClientModule(): Promise<RpcClientModule> {
|
|
61
|
+
const module = await import('../rpc-client')
|
|
62
|
+
const createRpcClient = Reflect.get(module, 'createRpcClient')
|
|
63
|
+
const RpcUnreachableError = Reflect.get(module, 'RpcUnreachableError')
|
|
64
|
+
const RpcServerError = Reflect.get(module, 'RpcServerError')
|
|
65
|
+
const RpcAuthError = Reflect.get(module, 'RpcAuthError')
|
|
66
|
+
const RpcValidationError = Reflect.get(module, 'RpcValidationError')
|
|
67
|
+
|
|
68
|
+
expect(typeof createRpcClient).toBe('function')
|
|
69
|
+
expect(typeof RpcUnreachableError).toBe('function')
|
|
70
|
+
expect(typeof RpcServerError).toBe('function')
|
|
71
|
+
expect(typeof RpcAuthError).toBe('function')
|
|
72
|
+
expect(typeof RpcValidationError).toBe('function')
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
createRpcClient: createRpcClient as RpcClientModule['createRpcClient'],
|
|
76
|
+
RpcUnreachableError:
|
|
77
|
+
RpcUnreachableError as RpcClientModule['RpcUnreachableError'],
|
|
78
|
+
RpcServerError: RpcServerError as RpcClientModule['RpcServerError'],
|
|
79
|
+
RpcAuthError: RpcAuthError as RpcClientModule['RpcAuthError'],
|
|
80
|
+
RpcValidationError:
|
|
81
|
+
RpcValidationError as RpcClientModule['RpcValidationError'],
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function makeCacheDir(): string {
|
|
86
|
+
const dir = mkdtempSync(join(tmpdir(), 'tui-rpc-client-'))
|
|
87
|
+
tempPaths.push(dir)
|
|
88
|
+
return dir
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function writePortFile(
|
|
92
|
+
baseDir: string,
|
|
93
|
+
sessionDiscriminator: string,
|
|
94
|
+
contents: unknown,
|
|
95
|
+
): string {
|
|
96
|
+
const sessionDir = join(baseDir, sessionDiscriminator)
|
|
97
|
+
mkdirSync(sessionDir, { recursive: true })
|
|
98
|
+
|
|
99
|
+
const portFilePath = join(sessionDir, 'server-port.json')
|
|
100
|
+
writeFileSync(portFilePath, JSON.stringify(contents))
|
|
101
|
+
|
|
102
|
+
return portFilePath
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function readRequestBody(request: IncomingMessage): Promise<string> {
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
const chunks: Buffer[] = []
|
|
108
|
+
|
|
109
|
+
request.on('data', (chunk: Buffer) => {
|
|
110
|
+
chunks.push(chunk)
|
|
111
|
+
})
|
|
112
|
+
request.on('end', () => {
|
|
113
|
+
resolve(Buffer.concat(chunks).toString('utf8'))
|
|
114
|
+
})
|
|
115
|
+
request.on('error', reject)
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function respondJson(
|
|
120
|
+
response: ServerResponse,
|
|
121
|
+
status: number,
|
|
122
|
+
body: unknown,
|
|
123
|
+
): void {
|
|
124
|
+
response.writeHead(status, { 'content-type': 'application/json' })
|
|
125
|
+
response.end(JSON.stringify(body))
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function startStubServer(
|
|
129
|
+
handler: (
|
|
130
|
+
request: IncomingMessage,
|
|
131
|
+
response: ServerResponse,
|
|
132
|
+
requests: RecordedRequest[],
|
|
133
|
+
) => Promise<void> | void,
|
|
134
|
+
): Promise<StartedStubServer> {
|
|
135
|
+
const requests: RecordedRequest[] = []
|
|
136
|
+
|
|
137
|
+
const server = createServer(async (request, response) => {
|
|
138
|
+
const body = await readRequestBody(request)
|
|
139
|
+
requests.push({
|
|
140
|
+
method: request.method ?? 'GET',
|
|
141
|
+
url: request.url ?? '/',
|
|
142
|
+
authorization: request.headers.authorization,
|
|
143
|
+
body,
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
await handler(request, response, requests)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
const port = await new Promise<number>((resolve, reject) => {
|
|
150
|
+
server.once('error', reject)
|
|
151
|
+
server.listen(0, '127.0.0.1', () => {
|
|
152
|
+
server.off('error', reject)
|
|
153
|
+
resolve((server.address() as AddressInfo).port)
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const started: StartedStubServer = {
|
|
158
|
+
port,
|
|
159
|
+
requests,
|
|
160
|
+
close: async () => {
|
|
161
|
+
await new Promise<void>((resolve, reject) => {
|
|
162
|
+
server.close((error) => {
|
|
163
|
+
if (error) reject(error)
|
|
164
|
+
else resolve()
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
},
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
startedServers.push(started)
|
|
171
|
+
return started
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function captureError<T>(promise: Promise<T>): Promise<unknown> {
|
|
175
|
+
try {
|
|
176
|
+
await promise
|
|
177
|
+
} catch (error) {
|
|
178
|
+
return error
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
throw new Error('Expected promise to reject')
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
describe('tui rpc client', () => {
|
|
185
|
+
it('reads a valid port file and returns parsed health responses', async () => {
|
|
186
|
+
const rpcClientModule = await loadRpcClientModule()
|
|
187
|
+
const server = await startStubServer((_request, response) => {
|
|
188
|
+
respondJson(response, 200, { ok: true, version: '0.9.0' })
|
|
189
|
+
})
|
|
190
|
+
const baseDir = makeCacheDir()
|
|
191
|
+
|
|
192
|
+
writePortFile(baseDir, 'session-a', {
|
|
193
|
+
port: server.port,
|
|
194
|
+
pid: process.pid,
|
|
195
|
+
token: 'token-health',
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
const client = rpcClientModule.createRpcClient({
|
|
199
|
+
baseDir,
|
|
200
|
+
sessionDiscriminator: 'session-a',
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
expect(await client.health()).toEqual({ ok: true, version: '0.9.0' })
|
|
204
|
+
expect(server.requests).toEqual([
|
|
205
|
+
{
|
|
206
|
+
method: 'GET',
|
|
207
|
+
url: '/health',
|
|
208
|
+
authorization: undefined,
|
|
209
|
+
body: '',
|
|
210
|
+
},
|
|
211
|
+
])
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
it('rejects missing port files with a clear unreachable error', async () => {
|
|
215
|
+
const rpcClientModule = await loadRpcClientModule()
|
|
216
|
+
const baseDir = makeCacheDir()
|
|
217
|
+
const client = rpcClientModule.createRpcClient({
|
|
218
|
+
baseDir,
|
|
219
|
+
sessionDiscriminator: 'missing-session',
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
const error = await captureError(client.health())
|
|
223
|
+
|
|
224
|
+
expect(error).toBeInstanceOf(rpcClientModule.RpcUnreachableError)
|
|
225
|
+
expect((error as Error).message).toContain('server-port.json')
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
it('rejects invalid port file schemas with a clear validation error', async () => {
|
|
229
|
+
const rpcClientModule = await loadRpcClientModule()
|
|
230
|
+
const baseDir = makeCacheDir()
|
|
231
|
+
|
|
232
|
+
writePortFile(baseDir, 'invalid-port-file', {
|
|
233
|
+
port: 43123,
|
|
234
|
+
pid: process.pid,
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
const client = rpcClientModule.createRpcClient({
|
|
238
|
+
baseDir,
|
|
239
|
+
sessionDiscriminator: 'invalid-port-file',
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
const error = await captureError(client.health())
|
|
243
|
+
|
|
244
|
+
expect(error).toBeInstanceOf(rpcClientModule.RpcValidationError)
|
|
245
|
+
expect((error as Error).message).toContain('token')
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
it('sends bearer auth for tasksList and tasksCancel', async () => {
|
|
249
|
+
const rpcClientModule = await loadRpcClientModule()
|
|
250
|
+
const server = await startStubServer((request, response) => {
|
|
251
|
+
if (request.url === '/tasks/list') {
|
|
252
|
+
respondJson(response, 200, { tasks: [] })
|
|
253
|
+
return
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (request.url === '/tasks/cancel') {
|
|
257
|
+
respondJson(response, 200, { cancelled: true })
|
|
258
|
+
return
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
respondJson(response, 404, { error: 'not found' })
|
|
262
|
+
})
|
|
263
|
+
const baseDir = makeCacheDir()
|
|
264
|
+
|
|
265
|
+
writePortFile(baseDir, 'auth-session', {
|
|
266
|
+
port: server.port,
|
|
267
|
+
pid: process.pid,
|
|
268
|
+
token: 'token-auth',
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
const client = rpcClientModule.createRpcClient({
|
|
272
|
+
baseDir,
|
|
273
|
+
sessionDiscriminator: 'auth-session',
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
expect(await client.tasksList()).toEqual({ tasks: [] })
|
|
277
|
+
expect(await client.tasksCancel('cpl_auth-task')).toEqual({
|
|
278
|
+
cancelled: true,
|
|
279
|
+
})
|
|
280
|
+
expect(server.requests).toEqual([
|
|
281
|
+
{
|
|
282
|
+
method: 'POST',
|
|
283
|
+
url: '/tasks/list',
|
|
284
|
+
authorization: 'Bearer token-auth',
|
|
285
|
+
body: '{}',
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
method: 'POST',
|
|
289
|
+
url: '/tasks/cancel',
|
|
290
|
+
authorization: 'Bearer token-auth',
|
|
291
|
+
body: '{"taskId":"cpl_auth-task"}',
|
|
292
|
+
},
|
|
293
|
+
])
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
it('turns 401 responses into auth errors', async () => {
|
|
297
|
+
const rpcClientModule = await loadRpcClientModule()
|
|
298
|
+
const server = await startStubServer((_request, response) => {
|
|
299
|
+
respondJson(response, 401, { error: 'unauthorized' })
|
|
300
|
+
})
|
|
301
|
+
const baseDir = makeCacheDir()
|
|
302
|
+
|
|
303
|
+
writePortFile(baseDir, 'auth-failure', {
|
|
304
|
+
port: server.port,
|
|
305
|
+
pid: process.pid,
|
|
306
|
+
token: 'token-auth-failure',
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
const client = rpcClientModule.createRpcClient({
|
|
310
|
+
baseDir,
|
|
311
|
+
sessionDiscriminator: 'auth-failure',
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
const error = await captureError(client.tasksList())
|
|
315
|
+
|
|
316
|
+
expect(error).toBeInstanceOf(rpcClientModule.RpcAuthError)
|
|
317
|
+
expect((error as Error & { status?: number }).status).toBe(401)
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
it('turns 500 responses into status-aware server errors', async () => {
|
|
321
|
+
const rpcClientModule = await loadRpcClientModule()
|
|
322
|
+
const server = await startStubServer((_request, response) => {
|
|
323
|
+
respondJson(response, 500, { error: 'server exploded' })
|
|
324
|
+
})
|
|
325
|
+
const baseDir = makeCacheDir()
|
|
326
|
+
|
|
327
|
+
writePortFile(baseDir, 'server-failure', {
|
|
328
|
+
port: server.port,
|
|
329
|
+
pid: process.pid,
|
|
330
|
+
token: 'token-server-failure',
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
const client = rpcClientModule.createRpcClient({
|
|
334
|
+
baseDir,
|
|
335
|
+
sessionDiscriminator: 'server-failure',
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
const error = await captureError(client.tasksCancel('cpl_server-task'))
|
|
339
|
+
|
|
340
|
+
expect(error).toBeInstanceOf(rpcClientModule.RpcServerError)
|
|
341
|
+
expect(error).not.toBeInstanceOf(rpcClientModule.RpcAuthError)
|
|
342
|
+
expect((error as Error & { status?: number }).status).toBe(500)
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
it('rejects invalid JSON responses', async () => {
|
|
346
|
+
const rpcClientModule = await loadRpcClientModule()
|
|
347
|
+
const server = await startStubServer((_request, response) => {
|
|
348
|
+
response.writeHead(200, { 'content-type': 'application/json' })
|
|
349
|
+
response.end('{"tasks":')
|
|
350
|
+
})
|
|
351
|
+
const baseDir = makeCacheDir()
|
|
352
|
+
|
|
353
|
+
writePortFile(baseDir, 'invalid-json', {
|
|
354
|
+
port: server.port,
|
|
355
|
+
pid: process.pid,
|
|
356
|
+
token: 'token-invalid-json',
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
const client = rpcClientModule.createRpcClient({
|
|
360
|
+
baseDir,
|
|
361
|
+
sessionDiscriminator: 'invalid-json',
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
const error = await captureError(client.tasksList())
|
|
365
|
+
|
|
366
|
+
expect(error).toBeInstanceOf(rpcClientModule.RpcValidationError)
|
|
367
|
+
expect((error as Error).message).toContain('JSON')
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
it('rejects invalid response schemas', async () => {
|
|
371
|
+
const rpcClientModule = await loadRpcClientModule()
|
|
372
|
+
const server = await startStubServer((_request, response) => {
|
|
373
|
+
respondJson(response, 200, {
|
|
374
|
+
tasks: [
|
|
375
|
+
{
|
|
376
|
+
taskId: 'task-without-prefix',
|
|
377
|
+
status: 'running',
|
|
378
|
+
agent: 'default',
|
|
379
|
+
model: 'gpt-5',
|
|
380
|
+
elapsedMs: 5,
|
|
381
|
+
toolCallCount: 1,
|
|
382
|
+
startedAt: 1,
|
|
383
|
+
},
|
|
384
|
+
],
|
|
385
|
+
})
|
|
386
|
+
})
|
|
387
|
+
const baseDir = makeCacheDir()
|
|
388
|
+
|
|
389
|
+
writePortFile(baseDir, 'invalid-response', {
|
|
390
|
+
port: server.port,
|
|
391
|
+
pid: process.pid,
|
|
392
|
+
token: 'token-invalid-response',
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
const client = rpcClientModule.createRpcClient({
|
|
396
|
+
baseDir,
|
|
397
|
+
sessionDiscriminator: 'invalid-response',
|
|
398
|
+
})
|
|
399
|
+
|
|
400
|
+
const error = await captureError(client.tasksList())
|
|
401
|
+
|
|
402
|
+
expect(error).toBeInstanceOf(rpcClientModule.RpcValidationError)
|
|
403
|
+
expect((error as Error).message).toContain('taskId')
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
it('turns fetch failures into unreachable errors', async () => {
|
|
407
|
+
const rpcClientModule = await loadRpcClientModule()
|
|
408
|
+
const baseDir = makeCacheDir()
|
|
409
|
+
|
|
410
|
+
writePortFile(baseDir, 'network-failure', {
|
|
411
|
+
port: 65_000,
|
|
412
|
+
pid: process.pid,
|
|
413
|
+
token: 'token-network-failure',
|
|
414
|
+
})
|
|
415
|
+
|
|
416
|
+
const client = rpcClientModule.createRpcClient({
|
|
417
|
+
baseDir,
|
|
418
|
+
sessionDiscriminator: 'network-failure',
|
|
419
|
+
})
|
|
420
|
+
|
|
421
|
+
const error = await captureError(client.health())
|
|
422
|
+
|
|
423
|
+
expect(error).toBeInstanceOf(rpcClientModule.RpcUnreachableError)
|
|
424
|
+
expect((error as Error).message).toContain('127.0.0.1')
|
|
425
|
+
})
|
|
426
|
+
|
|
427
|
+
it('aborts in-flight requests when disposed', async () => {
|
|
428
|
+
const rpcClientModule = await loadRpcClientModule()
|
|
429
|
+
const baseDir = makeCacheDir()
|
|
430
|
+
let capturedSignal: AbortSignal | undefined
|
|
431
|
+
|
|
432
|
+
writePortFile(baseDir, 'dispose-session', {
|
|
433
|
+
port: 43123,
|
|
434
|
+
pid: process.pid,
|
|
435
|
+
token: 'token-dispose',
|
|
436
|
+
})
|
|
437
|
+
|
|
438
|
+
const client = rpcClientModule.createRpcClient({
|
|
439
|
+
baseDir,
|
|
440
|
+
sessionDiscriminator: 'dispose-session',
|
|
441
|
+
fetchImpl: ((_input, init) => {
|
|
442
|
+
capturedSignal = init?.signal as AbortSignal | undefined
|
|
443
|
+
|
|
444
|
+
return new Promise<Response>((_resolve, reject) => {
|
|
445
|
+
if (capturedSignal?.aborted) {
|
|
446
|
+
reject(new Error('aborted'))
|
|
447
|
+
return
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
capturedSignal?.addEventListener(
|
|
451
|
+
'abort',
|
|
452
|
+
() => {
|
|
453
|
+
reject(new Error('aborted'))
|
|
454
|
+
},
|
|
455
|
+
{ once: true },
|
|
456
|
+
)
|
|
457
|
+
})
|
|
458
|
+
}) as typeof fetch,
|
|
459
|
+
})
|
|
460
|
+
|
|
461
|
+
const pending = client.tasksList()
|
|
462
|
+
client.dispose()
|
|
463
|
+
|
|
464
|
+
const error = await captureError(pending)
|
|
465
|
+
|
|
466
|
+
expect(capturedSignal?.aborted).toBe(true)
|
|
467
|
+
expect(error).toBeInstanceOf(rpcClientModule.RpcUnreachableError)
|
|
468
|
+
expect((error as Error).message).toContain('aborted')
|
|
469
|
+
})
|
|
470
|
+
|
|
471
|
+
it('times out in-flight requests that never resolve', async () => {
|
|
472
|
+
const rpcClientModule = await loadRpcClientModule()
|
|
473
|
+
const baseDir = makeCacheDir()
|
|
474
|
+
let capturedSignal: AbortSignal | undefined
|
|
475
|
+
|
|
476
|
+
writePortFile(baseDir, 'timeout-session', {
|
|
477
|
+
port: 43123,
|
|
478
|
+
pid: process.pid,
|
|
479
|
+
token: 'token-timeout',
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
const client = rpcClientModule.createRpcClient({
|
|
483
|
+
baseDir,
|
|
484
|
+
sessionDiscriminator: 'timeout-session',
|
|
485
|
+
requestTimeoutMs: 1,
|
|
486
|
+
fetchImpl: ((_input, init) => {
|
|
487
|
+
capturedSignal = init?.signal as AbortSignal | undefined
|
|
488
|
+
|
|
489
|
+
return new Promise<Response>((_resolve, reject) => {
|
|
490
|
+
capturedSignal?.addEventListener(
|
|
491
|
+
'abort',
|
|
492
|
+
() => {
|
|
493
|
+
reject(new Error('aborted by timeout'))
|
|
494
|
+
},
|
|
495
|
+
{ once: true },
|
|
496
|
+
)
|
|
497
|
+
})
|
|
498
|
+
}) as typeof fetch,
|
|
499
|
+
})
|
|
500
|
+
|
|
501
|
+
const error = await captureError(client.tasksList())
|
|
502
|
+
|
|
503
|
+
expect(capturedSignal?.aborted).toBe(true)
|
|
504
|
+
expect(error).toBeInstanceOf(rpcClientModule.RpcUnreachableError)
|
|
505
|
+
expect((error as Error).message).toContain('aborted by timeout')
|
|
506
|
+
})
|
|
507
|
+
})
|