Skip to content

Commit c44cadf

Browse files
committed
test(daemon): restore dropped bind/inspectFacts assertions in prepare ios-runner tests
PR #2304 review found the router-seam rewrite silently dropped two assertions the original suite had: that `prepare ios-runner` inspects facts and binds exactly once on an explicit iOS selector, and that it inspects facts once but never binds before rejecting a non-Apple device. The shared `lifecycleDeviceRuntimeGateway` fixture is frozen and reused across many suites, so it can't be spied on in place. Add `createLifecycleDeviceRuntimeGatewaySpies()` to test-device-runtime-gateway.ts: a fresh, unfrozen gateway whose inspectFacts/bind are vi.fn() spies backed by the same binding logic, scoped per test so no call counts leak across files. Use it in the two affected tests to reassert the original call-count expectations. Planted red: flipped each restored assertion's expected count/call and confirmed the test failed, then reverted. Command: npx vitest run --project unit-core -t "prepare ios-runner starts the XCTest runner on an explicit iOS selector" src/daemon/session-lifecycle/internal/__tests__/session-open-url-prewarm.test.ts Message: AssertionError: expected "vi.fn()" to be called 2 times, but got 1 times Command: npx vitest run --project unit-core -t "prepare ios-runner rejects non-Apple runner devices" src/daemon/session-lifecycle/internal/__tests__/session-open-url-prewarm.test.ts Message: AssertionError: expected "vi.fn()" to be called at least once
1 parent 130942e commit c44cadf

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

‎src/daemon/__tests__/test-device-runtime-gateway.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
availableApplicationLifecycleOperations,
66
} from '@agent-device/contracts/application-lifecycle-runtime';
77
import {
8+
type DeviceBindingRequest,
89
type DeviceRuntimeGateway,
910
localRuntimeOwner,
1011
narrowDeviceBinding,
@@ -84,6 +85,28 @@ export const lifecycleDeviceRuntimeGateway: DeviceRuntimeGateway<PlatformRuntime
8485
shutdown: async () => {},
8586
});
8687

88+
/**
89+
* A fresh, unfrozen `lifecycleDeviceRuntimeGateway`-equivalent whose `inspectFacts`/`bind` are
90+
* `vi.fn()` spies. The shared `lifecycleDeviceRuntimeGateway` above is `Object.freeze`d and reused
91+
* across many router-seam suites, so it can't be spied on in place (and spying on it in place
92+
* would leak call counts between tests in other files) — call this per test that needs to observe
93+
* fact-inspection/binding call counts through the router seam.
94+
*/
95+
export function createLifecycleDeviceRuntimeGatewaySpies() {
96+
const inspectFacts = vi.fn(
97+
async (device: DeviceInfo) => (await lifecycleBindingForTest(device)).facts,
98+
);
99+
const bind = vi.fn(
100+
async (request: DeviceBindingRequest) => await lifecycleBindingForTest(request.device),
101+
);
102+
const gateway: DeviceRuntimeGateway<PlatformRuntimeOperations> = {
103+
inspectFacts,
104+
bind,
105+
shutdown: async () => {},
106+
};
107+
return { gateway, inspectFacts, bind };
108+
}
109+
87110
export const unavailableDeviceRuntimeGateway: DeviceRuntimeGateway<PlatformRuntimeOperations> =
88111
Object.freeze({
89112
inspectFacts: async (device) => (await unavailableBinding(device)).facts,

‎src/daemon/session-lifecycle/internal/__tests__/session-open-url-prewarm.test.ts‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ vi.mock('../../../../platform-runtime-open-target.ts', async (importOriginal) =>
4545
});
4646

4747
import {
48+
createLifecycleDeviceRuntimeGatewaySpies,
4849
createRequestHandler,
4950
lifecycleDeviceRuntimeGateway,
5051
} from '../../../__tests__/test-device-runtime-gateway.ts';
@@ -98,13 +99,16 @@ beforeEach(() => {
9899
mockResolveIosSimulatorDeepLinkBundleId.mockResolvedValue(undefined);
99100
});
100101

101-
function createHandler(sessionStore: ReturnType<typeof makeSessionStore>) {
102+
function createHandler(
103+
sessionStore: ReturnType<typeof makeSessionStore>,
104+
deviceRuntimeGateway = lifecycleDeviceRuntimeGateway,
105+
) {
102106
return createRequestHandler({
103107
logPath: path.join(os.tmpdir(), 'daemon.log'),
104108
token: 'test-token',
105109
sessionStore,
106110
leaseRegistry: new LeaseRegistry(),
107-
deviceRuntimeGateway: lifecycleDeviceRuntimeGateway,
111+
deviceRuntimeGateway,
108112
deviceInventoryGateways: createTestDeviceInventoryGateways(),
109113
trackDownloadableArtifact: () => 'artifact-id',
110114
});
@@ -571,8 +575,12 @@ test('prepare ios-runner starts the XCTest runner on an explicit iOS selector',
571575
kind: 'simulator',
572576
booted: true,
573577
});
578+
const { gateway, inspectFacts, bind } = createLifecycleDeviceRuntimeGatewaySpies();
574579

575-
const response = await createHandler(sessionStore)(
580+
const response = await createHandler(
581+
sessionStore,
582+
gateway,
583+
)(
576584
sessionRequest(sessionName, 'prepare', {
577585
positionals: ['ios-runner'],
578586
flags: { platform: 'ios', udid: 'sim-1', timeoutMs: 240000 },
@@ -581,6 +589,10 @@ test('prepare ios-runner starts the XCTest runner on an explicit iOS selector',
581589
);
582590

583591
expect(response.ok).toBe(true);
592+
expect(inspectFacts).toHaveBeenCalledTimes(1);
593+
expect(bind).toHaveBeenCalledTimes(1);
594+
// Readiness runs inside the admitted Apple binding, so `prepare` proves it by reaching the
595+
// runner at all rather than by observing a retired root readiness call.
584596
expect(mockPrepareIosRunner).toHaveBeenCalledTimes(1);
585597
expect(mockPrepareIosRunner).toHaveBeenCalledWith(
586598
expect.objectContaining({ platform: 'apple', id: 'sim-1' }),
@@ -732,8 +744,12 @@ test('prepare ios-runner rejects non-Apple runner devices', async () => {
732744
kind: 'emulator',
733745
booted: true,
734746
});
747+
const { gateway, inspectFacts, bind } = createLifecycleDeviceRuntimeGatewaySpies();
735748

736-
const response = await createHandler(sessionStore)(
749+
const response = await createHandler(
750+
sessionStore,
751+
gateway,
752+
)(
737753
sessionRequest('prepare-android', 'prepare', {
738754
positionals: ['ios-runner'],
739755
flags: { platform: 'android', serial: 'emulator-5554' },
@@ -745,6 +761,8 @@ test('prepare ios-runner rejects non-Apple runner devices', async () => {
745761
expect(response.error.code).toBe('UNSUPPORTED_OPERATION');
746762
expect(response.error.message).toBe('prepare is not supported on this device');
747763
}
764+
expect(inspectFacts).toHaveBeenCalledTimes(1);
765+
expect(bind).not.toHaveBeenCalled();
748766
expect(mockPrepareIosRunner).not.toHaveBeenCalled();
749767
});
750768

0 commit comments

Comments
 (0)