|
1 | | -import assert from 'node:assert/strict'; |
2 | 1 | import { test, vi, expect } from 'vitest'; |
3 | 2 | import type { DeviceLease } from '@agent-device/contracts/device'; |
4 | 3 | import { createLimrunRuntime } from './runtime.ts'; |
5 | 4 | import { stubLimrunRuntimeDependencies } from './runtime-dependencies.fixtures.ts'; |
6 | 5 | import { mkdtempForTestSync } from './tmp-dir.fixtures.ts'; |
7 | 6 | import type { LimrunRuntimeDependencies } from './runtime-dependencies.ts'; |
| 7 | +import { watchUnhandledRejections } from './lifecycle.fixtures.ts'; |
8 | 8 |
|
9 | 9 | /* |
10 | 10 | * A disposal starts its capture end and its local teardown beside the instance delete and joins them only |
@@ -200,34 +200,6 @@ function warningsOf(record: Record<string, unknown>): Array<Record<string, unkno |
200 | 200 | return Array.isArray(record.warnings) ? (record.warnings as Record<string, unknown>[]) : []; |
201 | 201 | } |
202 | 202 |
|
203 | | -/** |
204 | | - * Collects the rejections the process would die on: the daemon's failure mode for one is to take every |
205 | | - * other session down with it, so a case whose disposal looses one fails here rather than in production. |
206 | | - * The check yields to a macrotask first: Node reports a rejection only after the current microtask drain, |
207 | | - * so asserting before that yield, or removing the listener without one, could pass a leaked rejection |
208 | | - * unseen. |
209 | | - */ |
210 | | -function watchUnhandledRejections(): { |
211 | | - assertIsSilent: () => Promise<void>; |
212 | | - stop: () => void; |
213 | | -} { |
214 | | - const seen: unknown[] = []; |
215 | | - const watch = (reason: unknown): void => { |
216 | | - seen.push(reason); |
217 | | - }; |
218 | | - process.on('unhandledRejection', watch); |
219 | | - return { |
220 | | - assertIsSilent: async () => { |
221 | | - await new Promise<void>((resolve) => { |
222 | | - setTimeout(resolve, 0); |
223 | | - }); |
224 | | - if (seen.length === 0) return; |
225 | | - assert.fail(`expected no unhandled rejection, got ${String(seen[0])}`); |
226 | | - }, |
227 | | - stop: () => process.off('unhandledRejection', watch), |
228 | | - }; |
229 | | -} |
230 | | - |
231 | 203 | function androidLease(leaseId: string): DeviceLease { |
232 | 204 | return { |
233 | 205 | leaseId, |
|
0 commit comments