|
| 1 | +import { test } from 'vitest'; |
| 2 | +import assert from 'node:assert/strict'; |
| 3 | +import { createAgentDeviceClient } from '../agent-device-client.ts'; |
| 4 | +import { createTransport } from './client-transport-fixture.ts'; |
| 5 | + |
| 6 | +// The box a capture's rects are measured in reaches Node.js callers as one optional field on the |
| 7 | +// snapshot result (#3182). These cases own the client half of that wire: the pair survives verbatim, |
| 8 | +// and every payload the kernel guard refuses becomes the absence meaning "the producer measured no |
| 9 | +// box" — never the zero the broken producer wrote. |
| 10 | + |
| 11 | +function clientAnswering(data: Record<string, unknown>) { |
| 12 | + const setup = createTransport(async () => ({ ok: true, data: { nodes: [], ...data } })); |
| 13 | + return createAgentDeviceClient(setup.config, { transport: setup.transport }); |
| 14 | +} |
| 15 | + |
| 16 | +test('client capture.snapshot preserves the viewport the producer published (#3182)', async () => { |
| 17 | + const client = clientAnswering({ truncated: false, viewport: { width: 1080, height: 2400 } }); |
| 18 | + |
| 19 | + assert.deepEqual((await client.capture.snapshot()).viewport, { width: 1080, height: 2400 }); |
| 20 | +}); |
| 21 | + |
| 22 | +test('client capture.snapshot reports no viewport field for a capture that carried none (#3182)', async () => { |
| 23 | + const client = clientAnswering({ truncated: false }); |
| 24 | + |
| 25 | + assert.equal('viewport' in (await client.capture.snapshot()), false); |
| 26 | +}); |
| 27 | + |
| 28 | +test('client capture.snapshot restates an unusable viewport payload as absence (#3182)', async () => { |
| 29 | + for (const viewport of [ |
| 30 | + 'screen', |
| 31 | + [], |
| 32 | + {}, |
| 33 | + { width: 1080 }, |
| 34 | + { width: '1080', height: 2400 }, |
| 35 | + // A zero is the claim a producer may never make; the client refuses to hand it on as a size. |
| 36 | + { width: 0, height: 2400 }, |
| 37 | + { width: 1080, height: 0 }, |
| 38 | + { width: Number.NaN, height: 2400 }, |
| 39 | + { |
| 40 | + width: Number.MAX_VALUE, |
| 41 | + height: Number.MAX_VALUE, |
| 42 | + x: -Number.MAX_VALUE / 2, |
| 43 | + y: -Number.MAX_VALUE / 2, |
| 44 | + }, |
| 45 | + ]) { |
| 46 | + const client = clientAnswering({ truncated: false, viewport }); |
| 47 | + const result = await client.capture.snapshot(); |
| 48 | + |
| 49 | + assert.equal(result.viewport, undefined, `payload ${JSON.stringify(viewport)}`); |
| 50 | + assert.equal('viewport' in result, false, `payload ${JSON.stringify(viewport)}`); |
| 51 | + } |
| 52 | +}); |
0 commit comments