Skip to content

Commit c598ae2

Browse files
thymikeeclaude
andcommitted
refactor(contracts): route the fact parser and Apple recording refusals through unavailableFact
Adds the contracts test that pins the frozen shape and the absent hint key. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 6c60bac commit c598ae2

3 files changed

Lines changed: 19 additions & 15 deletions

File tree

‎packages/contracts/src/platform-runtime.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
sameRuntimeOwner,
1414
type BoundDeviceRuntime,
1515
type DeviceBinding,
16+
unavailableFact,
1617
} from './platform-runtime.ts';
1718
import { runtimeUse } from './platform-runtime-use.ts';
1819

@@ -306,3 +307,17 @@ function testBinding(
306307
[Symbol.asyncDispose]: async () => undefined,
307308
};
308309
}
310+
311+
test('unavailableFact freezes the cell and omits hint when none is given', () => {
312+
const bare = unavailableFact('unsupported-device-kind');
313+
const hinted = unavailableFact('unsupported-provider-mode', 'provider-owned');
314+
assert.deepEqual(bare, { available: false, reason: 'unsupported-device-kind' });
315+
assert.equal('hint' in bare, false);
316+
assert.deepEqual(hinted, {
317+
available: false,
318+
reason: 'unsupported-provider-mode',
319+
hint: 'provider-owned',
320+
});
321+
assert.equal(Object.isFrozen(bare), true);
322+
assert.equal(Object.isFrozen(hinted), true);
323+
});

‎packages/contracts/src/platform-runtime.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,7 @@ function normalizeRuntimeFact(value: RuntimeFactInput): RuntimeOperationFact | u
392392
if (value.available !== false) return undefined;
393393
if (!isRuntimeOperationUnavailabilityReason(value.reason)) return undefined;
394394
if (value.hint !== undefined && typeof value.hint !== 'string') return undefined;
395-
return Object.freeze({
396-
available: false,
397-
reason: value.reason,
398-
...(value.hint === undefined ? {} : { hint: value.hint }),
399-
});
395+
return unavailableFact(value.reason, value.hint);
400396
}
401397

402398
function requireRuntimeOperation<Operations extends object>(

‎packages/platform-apple/src/recording/runtime.ts‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AppError, asAppError } from '@agent-device/kernel/errors';
33
import { execFailureDetails } from '@agent-device/host-kit/command';
44
import type { CleanupOutcome, FinishOutcome } from '@agent-device/contracts/durable-resource';
55
import type { HostCommandResult } from '@agent-device/contracts/platform-runtime-host';
6-
import type { RuntimeOwnerRef } from '@agent-device/contracts/platform-runtime';
6+
import { type RuntimeOwnerRef, unavailableFact } from '@agent-device/contracts/platform-runtime';
77
import type { ScreenRecordingRuntimeHost } from '@agent-device/contracts/screen-recording-runtime-host';
88
import {
99
RECORDING_OUTPUT_UNPLAYABLE_REASON,
@@ -40,13 +40,13 @@ const SIMULATOR_BACKEND_LABEL = 'simctl recordVideo';
4040

4141
export function appleScreenRecordingFacts(device: DeviceInfo) {
4242
if (device.appleOs === 'watchos')
43-
return unavailable('unsupported-platform-leaf', 'watchOS recording is not supported.');
43+
return unavailableFact('unsupported-platform-leaf', 'watchOS recording is not supported.');
4444
if (
4545
isIosFamily(device) &&
4646
device.kind === 'device' &&
4747
device.iosPhysicalDeviceBackend === 'xctest'
4848
) {
49-
return unavailable(
49+
return unavailableFact(
5050
'unsupported-device-backend',
5151
'This command requires a CoreDevice-backed physical iOS device. The selected XCTest backend supports open, close, interactions, snapshots, and screenshots.',
5252
);
@@ -504,10 +504,3 @@ function snapshot(
504504
...(timing.runnerSessionId === undefined ? {} : { runnerSessionId: timing.runnerSessionId }),
505505
});
506506
}
507-
508-
function unavailable(
509-
reason: 'unsupported-platform-leaf' | 'unsupported-device-backend',
510-
hint: string,
511-
) {
512-
return Object.freeze({ available: false, reason, hint } as const);
513-
}

0 commit comments

Comments
 (0)