Skip to content

Commit f4f2ca5

Browse files
committed
fix(provider-webdriver): an orientation refused by every route reports dispatched no
1 parent 8c0edab commit f4f2ca5

5 files changed

Lines changed: 59 additions & 3 deletions

File tree

‎contracts/fixtures/dispatch-disclosure.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,5 +474,11 @@
474474
"producer": "webdriver",
475475
"trigger": "a mutating POST the driver answered 503: it received the request, but not whether the mutation completed",
476476
"dispatched": "unknown"
477+
},
478+
{
479+
"id": "webdriver.orientation.every-route-unsupported",
480+
"producer": "webdriver",
481+
"trigger": "orientation refused by both the rotation route and the orientation route: each answer said the route is not implemented, so nothing ran",
482+
"dispatched": "no"
477483
}
478484
]

‎packages/contracts/src/dispatch-disclosure.fixtures.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const DISPATCH_DISCLOSURE_DRIVER_OWNERS: Readonly<Record<string, string>>
5151
'android-helper.gesture-session.':
5252
'packages/platform-android/src/__tests__/touch-helper-session.test.ts',
5353
'webdriver.': 'packages/provider-webdriver/src/webdriver-transport.test.ts',
54+
'webdriver.orientation.': 'packages/provider-webdriver/src/webdriver-orientation.test.ts',
5455
'maestro-direct.':
5556
'src/daemon/interaction/internal/__tests__/interaction-touch-direct-ios.test.ts',
5657
};

‎packages/provider-webdriver/src/webdriver-orientation.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import { AppError } from '@agent-device/kernel/errors';
55
import type { WebDriverClient } from './webdriver-client.ts';
66
import { setWebDriverOrientation } from './webdriver-orientation.ts';
77
import { WebDriverTransport } from './webdriver-transport.ts';
8+
import fs from 'node:fs';
9+
import {
10+
assertDispatchDisclosureDriversMatchRows,
11+
DISPATCH_DISCLOSURE_TABLE_PATH,
12+
dispatchDisclosureRowsOwnedBy,
13+
} from '@agent-device/contracts/dispatch-disclosure-fixtures';
814

915
type Call = { method: string; args: unknown[] };
1016

@@ -181,6 +187,8 @@ test('exhausting both endpoints reports the rotation and each attempt', async ()
181187
assert.ok(error instanceof AppError);
182188
assert.equal(error.code, 'COMMAND_FAILED');
183189
assert.match(error.message, /landscape-left/);
190+
assert.equal(error.details?.reason, 'webdriver_route_unsupported');
191+
assert.equal(error.details?.dispatched, 'no');
184192
assert.match(String(error.details?.hint), /--provider-device-orientation/);
185193
const attempts = error.details?.attempts;
186194
assert.ok(Array.isArray(attempts));
@@ -192,3 +200,33 @@ test('exhausting both endpoints reports the rotation and each attempt', async ()
192200
},
193201
);
194202
});
203+
204+
const DRIVERS: Record<string, () => Promise<unknown>> = {
205+
'webdriver.orientation.every-route-unsupported': async () =>
206+
await setWebDriverOrientation(
207+
makeClient({ reject: ['setRotation', 'setOrientation'] }).client,
208+
'android',
209+
'landscape-left',
210+
),
211+
};
212+
213+
const ROWS = dispatchDisclosureRowsOwnedBy(
214+
import.meta.url,
215+
fs.readFileSync(DISPATCH_DISCLOSURE_TABLE_PATH, 'utf8'),
216+
);
217+
218+
test('every webdriver orientation dispatch-disclosure row has exactly one driver', () => {
219+
assertDispatchDisclosureDriversMatchRows(ROWS, Object.keys(DRIVERS));
220+
});
221+
222+
for (const row of ROWS) {
223+
test(`${row.id}: ${row.trigger} → dispatched ${row.dispatched}`, async () => {
224+
const drive = DRIVERS[row.id];
225+
assert.ok(drive, `no driver for ${row.id}`);
226+
await assert.rejects(drive(), (error: unknown) => {
227+
assert.ok(error instanceof AppError);
228+
assert.equal(error.details?.dispatched, row.dispatched);
229+
return true;
230+
});
231+
});
232+
}

‎packages/provider-webdriver/src/webdriver-orientation.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '@agent-device/contracts/device';
66
import { AppError } from '@agent-device/kernel/errors';
77
import type { WebDriverClient } from './webdriver-client.ts';
8-
import { isWebDriverRouteUnsupported } from './webdriver-transport.ts';
8+
import { isWebDriverRouteUnsupported, unsupportedRouteRefusal } from './webdriver-transport.ts';
99

1010
export type WebDriverOrientationBackend = 'android' | 'xctest';
1111

@@ -58,6 +58,7 @@ export async function setWebDriverOrientation(
5858
'COMMAND_FAILED',
5959
`Could not set device orientation to ${rotation} on the hosted WebDriver session.`,
6060
{
61+
...unsupportedRouteRefusal(),
6162
hint: 'The provider driver rejected both orientation endpoints. Set the orientation as a session capability instead, for example connect --provider-device-orientation portrait.',
6263
rotation,
6364
attempts,

‎packages/provider-webdriver/src/webdriver-transport.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,9 @@ function webdriverError(status: number, payload: unknown): AppError {
334334
: `WebDriver request failed with HTTP ${status}.`;
335335
if (isUnsupportedRouteAnswer(status, payload)) {
336336
return new AppError('COMMAND_FAILED', message, {
337-
reason: WEBDRIVER_ROUTE_UNSUPPORTED_REASON,
337+
...unsupportedRouteRefusal(),
338338
status,
339339
response: payload,
340-
...dispatchDisclosure('no'),
341340
});
342341
}
343342
return new AppError('COMMAND_FAILED', message, {
@@ -352,6 +351,17 @@ function webdriverError(status: number, payload: unknown): AppError {
352351
/** Machine-readable `details.reason` of a driver answer that it does not implement the route. */
353352
const WEBDRIVER_ROUTE_UNSUPPORTED_REASON = 'webdriver_route_unsupported';
354353

354+
/**
355+
* The details of a refusal the driver answered before running anything: it does not implement
356+
* the route. A command that tried every route it has and was refused by each carries the same.
357+
*/
358+
export function unsupportedRouteRefusal(): {
359+
reason: typeof WEBDRIVER_ROUTE_UNSUPPORTED_REASON;
360+
dispatched: DispatchDisclosure;
361+
} {
362+
return { reason: WEBDRIVER_ROUTE_UNSUPPORTED_REASON, ...dispatchDisclosure('no') };
363+
}
364+
355365
/** W3C `error` codes a driver answers with when it does not implement the route. */
356366
const UNSUPPORTED_ROUTE_ERROR_CODES: ReadonlySet<string> = new Set([
357367
'unknown command',

0 commit comments

Comments
 (0)