Skip to content

Commit f9a85fe

Browse files
committed
refactor(daemon): carry the typed reason in the one refusal both runtime seams build
The generic route and the request-scoped session handlers each owned a byte-identical UNSUPPORTED_OPERATION refusal, but only the session seam attached details.reason, so the shared default emitted the same sentence with a different wire shape and fold had to re-add the reason through a custom unavailableResponse. unsupportedOperationResponse now always attaches details: { reason } and unavailableRuntimeOperationResponse delegates to it, so one builder owns sentence + reason + hint for both seams. fold drops its override and its second 'fold' mention; conformance asserts the single shape. Nits: cross-link the scoped HID transport test to the owning fact that refuses the scope, and assert hint propagation with a sentinel instead of echoing production wording.
1 parent c791997 commit f9a85fe

7 files changed

Lines changed: 24 additions & 35 deletions

File tree

‎packages/platform-apple/src/foldable/simulator-hid.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ test('streams all keyframes in one process with a duration-derived timeout', asy
7070
expect(dispatches).toBe(1);
7171
});
7272

73+
// Transport-level only: this pins that a pose dispatch routes through runSimctlForDevice, which
74+
// targets the UDID inside its scoped set. It is NOT end-to-end scoped-fold support — `appleFoldFact`
75+
// refuses `unsupported-device-scope` at runtime admission before this dispatch is ever reached.
7376
test('HID dispatch addresses the UDID inside its scoped simulator set', async () => {
7477
const dispatches: string[][] = [];
7578
await withAppleToolProvider(

‎src/daemon/__tests__/fold-runtime.test.ts‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,24 +160,19 @@ test('rejects an unavailable exact-owner fact before binding', async () => {
160160
command: 'fold',
161161
device: testDevice,
162162
unavailable,
163-
// The fold route derives its refusal from the fact, so the wire error keeps the typed reason.
164-
refusal: {
165-
code: 'UNSUPPORTED_OPERATION',
166-
message: 'fold is not supported on this device',
167-
details: { reason: 'unsupported-platform-leaf' },
168-
},
169163
});
170164
});
171165

172166
// The scoped-set refusal is a real route outcome, not just a narrowed binding: a scoped session's
173-
// `setFoldPose` fact refuses on admission, so the wire error carries the typed reason and the set
174-
// name, and the device is never bound or posed.
167+
// `setFoldPose` fact refuses on admission, so the wire error carries the typed reason and the fact's
168+
// own hint, and the device is never bound or posed. The hint is a sentinel the route could never
169+
// compose, so the assertion proves propagation without re-typing production's wording.
175170
test('refuses a scoped simulator set on the route with the typed reason, never binding', async () => {
176171
const scopedDevice: DeviceInfo = { ...testDevice, simulatorSetPath: '/tmp/scoped-set' };
177172
const scopeRefusal = {
178173
available: false,
179174
reason: 'unsupported-device-scope',
180-
hint: 'fold cannot resolve a simulator scoped to the set at "/tmp/scoped-set".',
175+
hint: 'SCOPED-SET-HINT-SENTINEL',
181176
} as const;
182177
const harness = runtimeHarness(scopeRefusal, vi.fn(), scopedDevice);
183178

@@ -193,7 +188,7 @@ test('refuses a scoped simulator set on the route with the typed reason, never b
193188
expect(resolved.response.error).toMatchObject({
194189
code: 'UNSUPPORTED_OPERATION',
195190
message: 'fold is not supported on this device',
196-
hint: expect.stringContaining('/tmp/scoped-set'),
191+
hint: 'SCOPED-SET-HINT-SENTINEL',
197192
details: { reason: 'unsupported-device-scope' },
198193
});
199194
expect(harness.bindDevice).not.toHaveBeenCalled();

‎src/daemon/__tests__/keyboard-runtime.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ test('android status is refused on iOS with the retired in-handler hint', async
195195
code: 'UNSUPPORTED_OPERATION',
196196
message: 'keyboard status is not supported on this device',
197197
hint: unavailable.hint,
198+
details: { reason: unavailable.reason },
198199
},
199200
},
200201
});

‎src/daemon/__tests__/runtime-binding-conformance.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,15 @@ export async function refuseUnavailableExactOwnerFact(
226226
return resolved.response;
227227
}
228228

229-
/** The wording `admitRuntimeOperations` gives every single-use route it refuses. */
229+
/** The wording and shape `admitRuntimeOperations` gives every single-use route it refuses. */
230230
function unsupportedOperationRefusal(
231231
command: ConformedRuntimeCommand,
232232
unavailable: RuntimeOperationUnavailability,
233233
): DaemonFailureResponse['error'] {
234234
return {
235235
code: 'UNSUPPORTED_OPERATION',
236236
message: `${command} is not supported on this device`,
237+
details: { reason: unavailable.reason },
237238
...(unavailable.hint ? { hint: unavailable.hint } : {}),
238239
};
239240
}

‎src/daemon/fold-runtime.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import type { BoundDeviceRuntime } from '@agent-device/contracts/platform-runtim
1010
import type { DeviceInfo } from '@agent-device/kernel/device';
1111
import { successText } from '@agent-device/kernel/success-text';
1212
import type { ResolvedGenericExecution } from './request-generic-dispatch.ts';
13-
import {
14-
resolveBoundGenericRuntime,
15-
unsupportedOperationResponse,
16-
type RuntimeAdmissionBindings,
17-
} from './runtime-admission.ts';
13+
import { resolveBoundGenericRuntime, type RuntimeAdmissionBindings } from './runtime-admission.ts';
1814

1915
/** `fold <pose>`, parsed with the same aliases the CLI reader accepts. */
2016
export function readRequestedFoldPose(positionals: readonly string[]): FoldPose {
@@ -47,10 +43,6 @@ export async function resolveBoundFoldRuntime(
4743
use: foldRuntimeUse,
4844
inspectFacts: params.inspectFacts,
4945
bindDevice: params.bindDevice,
50-
// Reuse the shared generic-route refusal and add the fact's typed reason (e.g.
51-
// `unsupported-device-scope`), so capability and response derive from one fact and never drift.
52-
unavailableResponse: (unavailable) =>
53-
unsupportedOperationResponse('fold', unavailable, { reason: unavailable.reason }),
5446
},
5547
(runtime) => executeSetFoldPose(runtime, input),
5648
);

‎src/daemon/runtime-admission.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,19 @@ export type RuntimeAdmissionRequest = RuntimeAdmissionBindings &
4343
export type { RuntimeAdmissionBindings };
4444

4545
/**
46-
* The refusal every generic runtime-admitted route reports when its exact owner did not admit a
47-
* required operation. The `<command> is not supported on this device` wording and the hint are
48-
* owned here; a route that carries typed evidence passes it as `details` rather than restating the
49-
* refusal, so its response and the shared default can never drift apart.
46+
* The one refusal the daemon reports when a device's exact runtime owner did not admit an
47+
* operation. Both seams — this generic route and the request-scoped session handlers — build their
48+
* `UNSUPPORTED_OPERATION` here, so the `<command> is not supported on this device` sentence, the
49+
* typed `details.reason`, and the hint have a single owner and one wire shape.
5050
*/
5151
export function unsupportedOperationResponse(
5252
command: string,
5353
unavailable: RuntimeOperationUnavailability,
54-
details?: Record<string, unknown>,
5554
): DaemonFailureResponse {
5655
return errorResponse(
5756
'UNSUPPORTED_OPERATION',
5857
`${command} is not supported on this device`,
59-
details,
58+
{ reason: unavailable.reason },
6059
unavailable.hint ? { hint: unavailable.hint } : undefined,
6160
);
6261
}

‎src/daemon/session-runtime-admission.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { AppError } from '@agent-device/kernel/errors';
88
import type { BindDeviceRuntime, InspectDeviceRuntimeFacts } from './request-runtime-binding.ts';
99
import type { SessionStore } from './session-store.ts';
1010
import type { DaemonRequest, DaemonResponse } from './daemon-request.ts';
11-
import { errorResponse } from '@agent-device/kernel/contracts';
11+
import { unsupportedOperationResponse } from './runtime-admission.ts';
1212

1313
export type RuntimeCommandHandlerParams = Readonly<{
1414
req: DaemonRequest;
@@ -18,18 +18,16 @@ export type RuntimeCommandHandlerParams = Readonly<{
1818
bindDevice?: BindDeviceRuntime;
1919
}>;
2020

21-
/** Shared facts-first admission for request-scoped runtime command handlers. */
21+
/**
22+
* Shared facts-first admission for request-scoped runtime command handlers. Availability is the
23+
* only thing decided here; the refusal wording, `details.reason`, and hint come from the same
24+
* `unsupportedOperationResponse` the generic route uses, so both seams keep one wire shape.
25+
*/
2226
export function unavailableRuntimeOperationResponse(
2327
command: string,
2428
fact: RuntimeOperationFact,
2529
): DaemonResponse | undefined {
26-
if (fact.available) return undefined;
27-
return errorResponse(
28-
'UNSUPPORTED_OPERATION',
29-
`${command} is not supported on this device`,
30-
{ reason: fact.reason },
31-
fact.hint ? { hint: fact.hint } : undefined,
32-
);
30+
return fact.available ? undefined : unsupportedOperationResponse(command, fact);
3331
}
3432

3533
export function requireRuntimeFacts(

0 commit comments

Comments
 (0)