Skip to content

Commit d2c9b9f

Browse files
committed
test(limrun): harden sync coverage and deadline fixtures
1 parent e7bdceb commit d2c9b9f

5 files changed

Lines changed: 44 additions & 21 deletions

File tree

‎packages/platform-apple/src/launch-confirmation.test.ts‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect, test, vi } from 'vitest';
2+
import { setTimeout as realDelay } from 'node:timers/promises';
23
import { DEFAULT_ALERT_TIMEOUT_MS } from '@agent-device/contracts/alert-contract';
34
import { awaitAppleAlert, readAppleAlert } from './alert.ts';
45
import { runAppleRunnerCommand } from './core/runner-client.ts';
@@ -218,17 +219,20 @@ test.each([
218219
*/
219220
function wedgedCoreSimulator(
220221
answers: Readonly<Record<string, string>> = {},
222+
onSpawn?: (count: number) => void,
221223
): AppleToolProvider & { spawns: () => number } {
222224
let spawns = 0;
223225
const answered = (key: string): ExecResult | undefined => {
224226
const stdout = answers[key];
225227
if (stdout === undefined) return undefined;
226228
spawns += 1;
229+
onSpawn?.(spawns);
227230
return { stdout, stderr: '', exitCode: 0 } as ExecResult;
228231
};
229232
const hang = async (options?: ExecOptions): Promise<ExecResult> =>
230233
await new Promise((_resolve, reject) => {
231234
spawns += 1;
235+
onSpawn?.(spawns);
232236
if (options?.signal?.aborted) {
233237
reject(options.signal.reason);
234238
return;
@@ -257,14 +261,6 @@ function wedgedCoreSimulator(
257261
};
258262
}
259263

260-
/** Real I/O turns until the provider saw `count` spawns; bounded so a lookup that stops early fails here, not at the test timeout. */
261-
async function untilSpawned(coreSimulator: { spawns: () => number }, count: number): Promise<void> {
262-
for (let turn = 0; turn < 1000 && coreSimulator.spawns() < count; turn += 1) {
263-
await new Promise((resolve) => setImmediate(resolve));
264-
}
265-
expect(coreSimulator.spawns()).toBe(count);
266-
}
267-
268264
const LISTED_APP = JSON.stringify({
269265
'com.example.app': {
270266
ApplicationType: 'User',
@@ -286,21 +282,42 @@ test.each([
286282
// spawns plutil, and that I/O must complete before the budget is advanced past.
287283
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] });
288284
vi.mocked(emitDiagnostic).mockClear();
285+
const lookupAbort = new AbortController();
289286
try {
290287
const { interactor, acceptAlert } = confirmationRunner();
291-
const coreSimulator = wedgedCoreSimulator(answers);
288+
let signalLookupStarted: () => void;
289+
const lookupStarted = new Promise<void>((resolve) => {
290+
signalLookupStarted = resolve;
291+
});
292+
const coreSimulator = wedgedCoreSimulator(answers, (count) => {
293+
if (count === 2) signalLookupStarted();
294+
});
292295
let answered: unknown = 'pending';
293296
const answer = withAppleToolProvider(coreSimulator, async () =>
294297
answerSimulatorLaunchConfirmation(
295298
simulator,
296299
{ url: 'example://automation', appBundleId: 'com.example.app' },
297300
Promise.resolve(interactor),
298-
new AbortController().signal,
301+
lookupAbort.signal,
299302
undefined,
300303
).then((value) => (answered = value)),
301304
);
302305

303-
await untilSpawned(coreSimulator, 2);
306+
const ioWait = new AbortController();
307+
try {
308+
await Promise.race([
309+
lookupStarted,
310+
answer.then(() => {
311+
throw new Error('Owner lookup completed before the second command started');
312+
}),
313+
realDelay(1_000, undefined, { signal: ioWait.signal }).then(() => {
314+
throw new Error('Owner lookup did not start its second command');
315+
}),
316+
]);
317+
} finally {
318+
ioWait.abort();
319+
}
320+
expect(coreSimulator.spawns()).toBe(2);
304321
await vi.advanceTimersByTimeAsync(URL_OWNER_LOOKUP_TIMEOUT_MS + 1);
305322
expect(answered).toEqual({ outcome: 'unreadable', step: 'url-owner' });
306323
await answer;
@@ -311,6 +328,7 @@ test.each([
311328
}),
312329
);
313330
} finally {
331+
lookupAbort.abort();
314332
vi.useRealTimers();
315333
}
316334
},

‎packages/provider-limrun/src/request-cancellation.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { awaitWithSignal } from '@agent-device/kernel/await-with-signal';
22
/**
3-
* The Limrun SDK does not expose an AbortSignal parameter. Keep the request-bound
3+
* The instance-client operations wrapped here do not accept an AbortSignal. Keep the request-bound
44
* caller cancellable while retaining a handled continuation for the provider operation it started.
55
*/
66
export async function awaitLimrunOperation<Value>(

‎packages/provider-limrun/src/sync-cache.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ test('cache teardown waits for serialized APK syncs to finish reading their basi
5454
});
5555
await entered;
5656
let secondRan = false;
57-
const second = cache.run(apk, 'android', async () => {
57+
const second = cache.run(apk, 'android', async (directory) => {
58+
expect(await fs.readFile(path.join(directory, 'Example.apk'), 'utf8')).toBe('apk');
5859
secondRan = true;
5960
});
6061
const disposal = cache.dispose();

‎scripts/__tests__/bundled-license-notices.test.ts‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,13 @@ test('output overrides write notices beside the bundle without creating the defa
358358
await assert.rejects(fs.stat(path.join(root, 'dist')), { code: 'ENOENT' });
359359
});
360360

361-
test.each(['0.2.0', '0.2.1'])(
362-
'bundled xdelta WASM %s requires the matching retained license',
363-
async (version) => {
361+
test.each([
362+
{ version: '0.2.0', newline: '\n', lineEnding: 'LF' },
363+
{ version: '0.2.0', newline: '\r\n', lineEnding: 'CRLF' },
364+
{ version: '0.2.1', newline: '\n', lineEnding: 'LF' },
365+
])(
366+
'bundled xdelta WASM $version requires matching complete notices with $lineEnding line endings',
367+
async ({ version, newline }) => {
364368
const [sourceNotices, apacheLicense] = await Promise.all([
365369
fs.readFile(new URL('../../LICENSES/xdelta3-wasm.txt', import.meta.url), 'utf8'),
366370
fs.readFile(new URL('../../LICENSES/Apache-2.0.txt', import.meta.url), 'utf8'),
@@ -375,16 +379,16 @@ test.each(['0.2.0', '0.2.1'])(
375379
}),
376380
'node_modules/@limrun/xdelta3-wasm/index.js':
377381
'export const value = process.env.FIXTURE_NUMBER;',
378-
'LICENSES/xdelta3-wasm.txt': sourceNotices,
379-
'LICENSES/Apache-2.0.txt': apacheLicense,
382+
'LICENSES/xdelta3-wasm.txt': sourceNotices.replaceAll('\r\n', '\n').replaceAll('\n', newline),
383+
'LICENSES/Apache-2.0.txt': apacheLicense.replaceAll('\r\n', '\n').replaceAll('\n', newline),
380384
});
381385
if (version !== '0.2.0') {
382386
await assert.rejects(bundle(root), /Refresh LICENSES/);
383387
return;
384388
}
385389
await bundle(root);
386390
const notices = await fs.readFile(path.join(root, 'dist/THIRD_PARTY_NOTICES.txt'), 'utf8');
387-
assert.ok(notices.includes('Copyright 2016 Joshua MacDonald'));
388-
assert.ok(notices.includes(apacheLicense.trim()));
391+
assert.ok(notices.includes(sourceNotices.replaceAll('\r\n', '\n').trim()));
392+
assert.ok(notices.includes(apacheLicense.replaceAll('\r\n', '\n').trim()));
389393
},
390394
);

‎src/commands/schema/cli-help.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ Limrun direct-device flow:
628628
agent-device connect limrun --platform android
629629
630630
Limrun creates remote iOS simulators and Android emulators only. Do not pass local device selectors such as --udid, --serial, or --device.
631-
To drive an existing instance without the API key, set LIM_IOS_INSTANCE_URL and LIM_IOS_INSTANCE_TOKEN, or LIM_ANDROID_INSTANCE_URL, LIM_ANDROID_INSTANCE_TOKEN, and LIM_ANDROID_INSTANCE_ADB_URL, from the instance status before connect. agent-device then never creates or deletes that instance; install and reinstall sync local app files without LIMRUN_API_KEY. Android still needs its ADB URL to connect. apps before the first open needs LIMRUN_API_KEY to list stored assets.
631+
To drive an existing instance without the API key, set LIM_IOS_INSTANCE_URL and LIM_IOS_INSTANCE_TOKEN, or LIM_ANDROID_INSTANCE_URL, LIM_ANDROID_INSTANCE_TOKEN, and LIM_ANDROID_INSTANCE_ADB_URL, from the instance status before connect. agent-device then never creates or deletes that instance; install and reinstall sync local app files without LIMRUN_API_KEY. Android still needs its ADB URL to connect. The apps command before the first open requires LIMRUN_API_KEY to list stored assets.
632632
Set LIMRUN_KEEP_ALIVE=1 to ping the instance every 30 seconds while a session is open, so an idle session does not hit the Limrun inactivity timeout. It is off by default.
633633
To capture network traffic, connect with --provider-network-logs --provider-network-hosts <app API hosts>. artifacts and close write the HAR and print its path and any capture failures; the HAR holds raw headers and bodies, and captured traffic exits through the daemon host.
634634
agent-device apps

0 commit comments

Comments
 (0)