Skip to content

Commit 0c24cfd

Browse files
thymikeeclaude
andcommitted
test(android): refuse a package relaunch whose stop fence expires
#3600 routed package relaunch through the same stop helper as close, so the fence refusal now also guards relaunch before any launch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 46805b0 commit 0c24cfd

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎packages/platform-android/src/__tests__/app-lifecycle-open.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,40 @@ test('openAndroidApp stops a resolved package before launching it when terminati
675675
});
676676
});
677677

678+
test('openAndroidApp refuses to relaunch a package whose stop fence expires', async () => {
679+
vi.useFakeTimers();
680+
const calls: (readonly string[])[] = [];
681+
try {
682+
await withAndroidAdbProvider(
683+
{
684+
exec: async (args) => {
685+
calls.push(args);
686+
const stdout =
687+
args[1] === 'dumpsys'
688+
? 'mCurrentFocus=Window{42 u0 com.example.app/.MainActivity}\n'
689+
: '';
690+
return { stdout, stderr: '', exitCode: 0 };
691+
},
692+
},
693+
{ serial: ANDROID_EMULATOR.id },
694+
async () => {
695+
const rejection = assert.rejects(
696+
openAndroidApp(ANDROID_EMULATOR, 'com.example.app', { terminateRunningApp: true }),
697+
(error: unknown) =>
698+
error instanceof AppError &&
699+
error.details?.reason === 'android-app-close-timeout' &&
700+
error.details?.phase === 'foreground',
701+
);
702+
await Promise.all([rejection, vi.runAllTimersAsync()]);
703+
},
704+
);
705+
assert.deepEqual(calls[0], ['shell', 'am', 'force-stop', 'com.example.app']);
706+
assert.equal(calls.filter((args) => args[2] === 'start').length, 0, 'no launch after refusal');
707+
} finally {
708+
vi.useRealTimers();
709+
}
710+
});
711+
678712
test('openAndroidApp appends launchArgs to am start when launching by package', async () => {
679713
await withFakeAdb(androidOpenFakeAdb, async ({ calls, device }) => {
680714
await openAndroidApp(device, 'com.example.app', {

0 commit comments

Comments
 (0)