Skip to content

Commit 679a96a

Browse files
committed
fix(command-registry): set test device claim policy to none (#4228)
1 parent 9a0fc7c commit 679a96a

4 files changed

Lines changed: 40 additions & 2 deletions

File tree

‎.changeset/device-selector-session-claim-guard.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'agent-device': patch
33
---
44

5-
Refuse `require-owner` commands run under a session this daemon does not hold with `DEVICE_IN_USE` when another session of this daemon holds the device (without reading the host-global claim store). Enforce the in-memory holder guard in the request scope's device access before inspecting device facts or binding, covering snapshot, wait, find, clipboard, keyboard, trigger-app-event, port-reverse, and record. Preserve `NO_ACTIVE_SESSION` for sessionless requests without a device selector.
5+
Refuse `require-owner` commands run under a session this daemon does not hold with `DEVICE_IN_USE` when another session of this daemon holds the device (without reading the host-global claim store). Enforce the in-memory holder guard in the request scope's device access before inspecting device facts or binding, covering every device-touching `require-owner` command. Give `test` the suite-orchestrator claim policy `none` so suite cleanup and recording can act through child case sessions without triggering false device contention. Preserve `NO_ACTIVE_SESSION` for sessionless requests without a device selector.

‎packages/command-registry/src/__tests__/registry-device-claim-policy.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ test('every command that deviates from require-owner is a reviewed, diffable set
7676
'session',
7777
'session_list',
7878
'session_save_script',
79+
'test',
7980
'web',
8081
],
8182
});

‎packages/command-registry/src/descriptors/session-operations.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export const SESSION_OPERATION_COMMAND_DESCRIPTORS = [
183183
},
184184
{
185185
name: 'test',
186-
deviceClaimPolicy: 'require-owner',
186+
deviceClaimPolicy: 'none',
187187
...(ownerFilesEnabled
188188
? { ownerFiles: ['packages/command-surface/src/replay/index.ts'] as const }
189189
: {}),

‎packages/daemon/src/server/__tests__/request-router-replay-scope.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,43 @@ test('fresh replay retains a dynamically selected device through finalization',
257257
expect(externalRequestSettled).toBe(true);
258258
});
259259

260+
test('test runs a one-case suite whose script leaves a session open, passes, and closes the session', async () => {
261+
const root = mkdtempForTestSync('agent-device-replay-test-leak-');
262+
const scriptPath = path.join(root, '01-case.ad');
263+
fs.writeFileSync(scriptPath, 'context platform=ios\nopen "com.example.app"\n');
264+
const sessionStore = makeSessionStore('agent-device-replay-test-leak-');
265+
266+
const handler = createRequestHandler({
267+
host: createTestHostEnvironment(),
268+
createCommandSurface: testCreateCommandSurface,
269+
logPath: path.join(mkdtempForTestSync('daemon'), 'daemon.log'),
270+
token: 'test-token',
271+
sessionStore,
272+
leaseRegistry: new LeaseRegistry(),
273+
deviceRuntimeGateway: lifecycleDeviceRuntimeGateway,
274+
deviceInventoryGateways: createTestDeviceInventoryGateways(),
275+
trackDownloadableArtifact: () => 'artifact-id',
276+
});
277+
278+
const response = await handler({
279+
token: 'test-token',
280+
session: 'default',
281+
command: 'test',
282+
positionals: [root],
283+
flags: { platform: 'ios' },
284+
meta: { cwd: root, requestId: 'suite-unclosed-session' },
285+
});
286+
287+
expect(response).toMatchObject({
288+
ok: true,
289+
data: expect.objectContaining({
290+
passed: 1,
291+
failed: 0,
292+
}),
293+
});
294+
expect(sessionStore.listRefs()).toHaveLength(0);
295+
});
296+
260297
function requestPlatformProvidersFake(): {
261298
providers: RequestPlatformProviders;
262299
contexts: PlatformProviderRequestContext[];

0 commit comments

Comments
 (0)