|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import fs from 'node:fs'; |
| 3 | +import { test } from 'vitest'; |
| 4 | +import { assertFlatToolCall, assertPngFile } from './assertions.ts'; |
| 5 | +import { PROVIDER_SCENARIO_WEB } from './fixtures.ts'; |
| 6 | +import { createProviderScenarioTempPath, withProviderScenarioResource } from './harness.ts'; |
| 7 | +import { runProviderScenario } from './scenario.ts'; |
| 8 | +import { createWebDesktopWorld } from './web-world.ts'; |
| 9 | + |
| 10 | +const WEB_URL = 'https://example.test/dashboard'; |
| 11 | + |
| 12 | +test('Provider-backed integration web desktop flow uses semantic web provider calls', async () => { |
| 13 | + await withProviderScenarioResource(createWebDesktopWorld, async ({ daemon, semanticCalls }) => { |
| 14 | + const screenshotPath = createProviderScenarioTempPath( |
| 15 | + 'agent-device-provider-scenario-web', |
| 16 | + 'png', |
| 17 | + ); |
| 18 | + |
| 19 | + try { |
| 20 | + const devices = await daemon.client().devices.list({ platform: 'web' }); |
| 21 | + assert.equal(devices.length, 1); |
| 22 | + assert.equal(devices[0]?.platform, 'web'); |
| 23 | + assert.equal(devices[0]?.id, PROVIDER_SCENARIO_WEB.id); |
| 24 | + assert.equal(devices[0]?.target, 'desktop'); |
| 25 | + |
| 26 | + await runProviderScenario(daemon, [ |
| 27 | + { |
| 28 | + name: 'open web URL', |
| 29 | + command: 'open', |
| 30 | + positionals: [WEB_URL], |
| 31 | + flags: { platform: 'web' }, |
| 32 | + }, |
| 33 | + { |
| 34 | + name: 'capture interactive web snapshot', |
| 35 | + command: 'snapshot', |
| 36 | + flags: { snapshotInteractiveOnly: true }, |
| 37 | + assert: (snapshot) => { |
| 38 | + const labels = snapshot.json?.result?.data?.nodes?.map( |
| 39 | + (node: { label?: string }) => node.label, |
| 40 | + ); |
| 41 | + assert.deepEqual(labels, [ |
| 42 | + WEB_URL, |
| 43 | + 'Ready', |
| 44 | + 'Email', |
| 45 | + 'Submit order', |
| 46 | + 'Ready', |
| 47 | + 'Below the fold', |
| 48 | + ]); |
| 49 | + }, |
| 50 | + }, |
| 51 | + { |
| 52 | + name: 'read snapshot ref text', |
| 53 | + command: 'get', |
| 54 | + positionals: ['text', '@e2'], |
| 55 | + expectData: { text: 'Ready' }, |
| 56 | + }, |
| 57 | + { |
| 58 | + name: 'find visible text', |
| 59 | + command: 'find', |
| 60 | + positionals: ['text', 'Submit order', 'exists'], |
| 61 | + expectData: { found: true }, |
| 62 | + }, |
| 63 | + { |
| 64 | + name: 'assert visible text', |
| 65 | + command: 'is', |
| 66 | + positionals: ['visible', 'label="Submit order"'], |
| 67 | + expectData: { pass: true }, |
| 68 | + }, |
| 69 | + { |
| 70 | + name: 'wait for text', |
| 71 | + command: 'wait', |
| 72 | + positionals: ['text', 'Ready', '100'], |
| 73 | + expectData: { text: 'Ready' }, |
| 74 | + }, |
| 75 | + { |
| 76 | + name: 'click submit ref', |
| 77 | + command: 'click', |
| 78 | + positionals: ['@e4'], |
| 79 | + expectData: { x: 84, y: 166 }, |
| 80 | + }, |
| 81 | + { |
| 82 | + name: 'fill email ref', |
| 83 | + command: 'fill', |
| 84 | + positionals: ['@e3', 'qa@example.test'], |
| 85 | + flags: { delayMs: 1 }, |
| 86 | + expectData: { text: 'qa@example.test' }, |
| 87 | + }, |
| 88 | + { |
| 89 | + name: 'type suffix', |
| 90 | + command: 'type', |
| 91 | + positionals: [' ok'], |
| 92 | + expectData: { text: ' ok' }, |
| 93 | + }, |
| 94 | + { |
| 95 | + name: 'scroll by pixels', |
| 96 | + command: 'scroll', |
| 97 | + positionals: ['down'], |
| 98 | + flags: { pixels: 240 }, |
| 99 | + expectData: { pixels: 240 }, |
| 100 | + }, |
| 101 | + { |
| 102 | + name: 'capture web screenshot artifact', |
| 103 | + command: 'screenshot', |
| 104 | + positionals: [screenshotPath], |
| 105 | + flags: { |
| 106 | + screenshotFullscreen: true, |
| 107 | + screenshotNoStabilize: true, |
| 108 | + }, |
| 109 | + expectData: { path: screenshotPath }, |
| 110 | + assert: () => { |
| 111 | + assertPngFile(screenshotPath); |
| 112 | + }, |
| 113 | + }, |
| 114 | + ]); |
| 115 | + |
| 116 | + const actions = daemon.session()?.actions ?? []; |
| 117 | + assert.ok( |
| 118 | + actions.some( |
| 119 | + (action) => action.command === 'click' && action.positionals.join(' ') === '@e4', |
| 120 | + ), |
| 121 | + 'Expected ref click action to be recorded on the session', |
| 122 | + ); |
| 123 | + assert.ok( |
| 124 | + actions.some( |
| 125 | + (action) => |
| 126 | + action.command === 'fill' && |
| 127 | + action.positionals.join(' ') === '@e3 qa@example.test' && |
| 128 | + action.flags.delayMs === 1, |
| 129 | + ), |
| 130 | + 'Expected ref fill action to be recorded on the session', |
| 131 | + ); |
| 132 | + assert.ok( |
| 133 | + actions.some( |
| 134 | + (action) => action.command === 'type' && action.positionals.join(' ') === ' ok', |
| 135 | + ), |
| 136 | + 'Expected type action to be recorded on the session', |
| 137 | + ); |
| 138 | + |
| 139 | + const close = await daemon.callCommand('close', [WEB_URL]); |
| 140 | + assert.equal(close.statusCode, 200, JSON.stringify(close.json)); |
| 141 | + |
| 142 | + assertFlatToolCall(semanticCalls, ['web', 'open', WEB_URL, '']); |
| 143 | + assertFlatToolCall(semanticCalls, ['web', 'snapshot', 'true', '']); |
| 144 | + assertFlatToolCall(semanticCalls, ['web', 'click', '84', '166']); |
| 145 | + assertFlatToolCall(semanticCalls, ['web', 'fill', '144', '114', 'qa@example.test', '1']); |
| 146 | + assertFlatToolCall(semanticCalls, ['web', 'type', ' ok', '0']); |
| 147 | + assertFlatToolCall(semanticCalls, ['web', 'scroll', 'down', '', '240']); |
| 148 | + assertFlatToolCall(semanticCalls, [ |
| 149 | + 'web', |
| 150 | + 'screenshot', |
| 151 | + screenshotPath, |
| 152 | + 'true', |
| 153 | + 'false', |
| 154 | + 'app', |
| 155 | + ]); |
| 156 | + assertFlatToolCall(semanticCalls, ['web', 'close', WEB_URL]); |
| 157 | + } finally { |
| 158 | + fs.rmSync(screenshotPath, { force: true }); |
| 159 | + } |
| 160 | + }); |
| 161 | +}, 10_000); |
0 commit comments