Repository navigation
refactor(daemon): relocate the session-lifecycle tests by what they assert #3670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thymikee
merged 9 commits into
refactor/daemon-handlers-tests
from
refactor/daemon-session-lifecycle-tests
Oct 15, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1209d3b
test(daemon): add lifecycle-operations spy fixture for close finaliza…
thymikee ccb40de
test: redesign session-close composition tests (a/c splits)
thymikee 024690c
test: redesign session-open composition tests (a/c splits)
thymikee 3a50cdc
test: redesign device-ready, replay flag-policy and replay-target-gua…
thymikee e48c0b5
test(daemon): type the prepare handler binding spy
thymikee 54836eb
chore(daemon): drop the four testing subpaths the session-lifecycle b…
thymikee 73c65f1
test(platform-apple): move the added lifecycle cases beside lifecycle…
thymikee f9d77d5
test: scope the call-history assertions per case and make the Maestro…
thymikee 4338018
test: restore the simulator web-URL-with-stale-app case beside the op…
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/daemon/src/__tests__/support/lifecycle-operations-spy.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { vi } from 'vitest'; | ||
| import type { ApplicationLifecycleRuntimeOperations } from '@agent-device/contracts/application-lifecycle-runtime'; | ||
| import { | ||
| applicationLifecycleRuntimeFixture, | ||
| type LifecycleOperationsLoader, | ||
| } from './application-lifecycle-runtime-fixture.ts'; | ||
|
|
||
| /** | ||
| * The canned lifecycle port with `finalizeApplicationClose` answered by a spy (an empty result by | ||
| * default) and any other operation replaceable per case. Daemon close tests read the spy to prove | ||
| * the neutral orchestration asked the platform for close finalization, and with which arguments, | ||
| * without encoding how a platform performs it. | ||
| */ | ||
| export function lifecycleOperationsSpy( | ||
| overrides: Partial<ApplicationLifecycleRuntimeOperations> = {}, | ||
| ) { | ||
| const finalizeApplicationClose = vi.fn< | ||
| ApplicationLifecycleRuntimeOperations['finalizeApplicationClose'] | ||
| >(async () => ({})); | ||
| const loader: LifecycleOperationsLoader = async (device, signal, shutdownTarget) => | ||
| Object.freeze({ | ||
| ...(await applicationLifecycleRuntimeFixture(device, signal, shutdownTarget)), | ||
| ...overrides, | ||
| finalizeApplicationClose, | ||
| }); | ||
| return { loader, finalizeApplicationClose }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { afterEach, beforeEach, expect, test, vi } from 'vitest'; | ||
| import type { DeviceInfo } from '@agent-device/kernel/device'; | ||
| import { | ||
| ANDROID_EMULATOR, | ||
| IOS_DEVICE, | ||
| IOS_SIMULATOR, | ||
| } from '@agent-device/test-kit/device-fixtures'; | ||
| import { daemonPlatformServicesFixture } from '../../__tests__/support/platform-services-fixture.ts'; | ||
| import { DEVICE_READY_CACHE_TTL_MS, ensureDeviceReady } from './device-ready.ts'; | ||
|
|
||
| const ensureLocalDeviceReady = vi.fn(async (_device: DeviceInfo) => true); | ||
| const platformServices = daemonPlatformServicesFixture({ ensureLocalDeviceReady }); | ||
|
|
||
| beforeEach(() => { | ||
| vi.useFakeTimers(); | ||
| vi.setSystemTime(new Date('2026-04-01T10:00:00.000Z')); | ||
| ensureLocalDeviceReady.mockReset(); | ||
| ensureLocalDeviceReady.mockResolvedValue(true); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers(); | ||
| }); | ||
|
|
||
| test('ensureDeviceReady caches successful simulator readiness checks', async () => { | ||
| const device: DeviceInfo = { ...IOS_SIMULATOR, simulatorSetPath: '/tmp/simset-a' }; | ||
|
|
||
| await ensureDeviceReady(device, platformServices); | ||
| await ensureDeviceReady({ ...device }, platformServices); | ||
|
|
||
| expect(ensureLocalDeviceReady).toHaveBeenCalledTimes(1); | ||
| expect(ensureLocalDeviceReady).toHaveBeenCalledWith(device); | ||
| }); | ||
|
|
||
| test('ensureDeviceReady caches successful iOS physical device readiness checks', async () => { | ||
| await ensureDeviceReady(IOS_DEVICE, platformServices); | ||
| await ensureDeviceReady( | ||
| { ...IOS_DEVICE, simulatorSetPath: '/ignored-for-physical-device' }, | ||
| platformServices, | ||
| ); | ||
|
|
||
| expect(ensureLocalDeviceReady).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| test('ensureDeviceReady includes simulator set path in the cache key', async () => { | ||
| await ensureDeviceReady( | ||
| { ...IOS_SIMULATOR, simulatorSetPath: '/tmp/simset-a' }, | ||
| platformServices, | ||
| ); | ||
| await ensureDeviceReady( | ||
| { ...IOS_SIMULATOR, simulatorSetPath: '/tmp/simset-b' }, | ||
| platformServices, | ||
| ); | ||
|
|
||
| expect(ensureLocalDeviceReady).toHaveBeenCalledTimes(2); | ||
| }); | ||
|
|
||
| test('ensureDeviceReady expires cached readiness checks after the ttl', async () => { | ||
| await ensureDeviceReady(ANDROID_EMULATOR, platformServices); | ||
| vi.setSystemTime(new Date(Date.now() + DEVICE_READY_CACHE_TTL_MS - 1)); | ||
| await ensureDeviceReady({ ...ANDROID_EMULATOR }, platformServices); | ||
| vi.setSystemTime(new Date(Date.now() + 1)); | ||
| await ensureDeviceReady({ ...ANDROID_EMULATOR }, platformServices); | ||
|
|
||
| expect(ensureLocalDeviceReady).toHaveBeenCalledTimes(2); | ||
| }); | ||
|
|
||
| test('ensureDeviceReady does not cache failed readiness checks', async () => { | ||
| ensureLocalDeviceReady.mockRejectedValueOnce(new Error('boot failed')); | ||
|
|
||
| await expect(ensureDeviceReady(IOS_SIMULATOR, platformServices)).rejects.toThrow('boot failed'); | ||
| await ensureDeviceReady(IOS_SIMULATOR, platformServices); | ||
|
|
||
| expect(ensureLocalDeviceReady).toHaveBeenCalledTimes(2); | ||
| }); | ||
|
|
||
| test('ensureDeviceReady does not cache a device the platform has no readiness step for', async () => { | ||
| ensureLocalDeviceReady.mockResolvedValue(false); | ||
|
|
||
| await ensureDeviceReady(ANDROID_EMULATOR, platformServices); | ||
| await ensureDeviceReady(ANDROID_EMULATOR, platformServices); | ||
|
|
||
| expect(ensureLocalDeviceReady).toHaveBeenCalledTimes(2); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.