Skip to content

Commit 524af99

Browse files
committed
refactor(contracts): key the snapshot backend guard on SnapshotBackend
isSnapshotBackend hand-listed the backends, so a backend added to SnapshotProvenance would compile and then be refused at runtime. The list is now a record that satisfies Record<SnapshotBackend, true>. Two type-only SnapshotState imports use import type.
1 parent 0d5b991 commit 524af99

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

‎packages/command-runtime/src/commands/capture/runtime/snapshot-unchanged.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
type SnapshotPresentation,
77
type SnapshotUnchanged,
88
} from '@agent-device/kernel/snapshot';
9-
import { type SnapshotState } from '@agent-device/contracts/snapshot-model';
9+
import type { SnapshotState } from '@agent-device/contracts/snapshot-model';
1010

1111
type SnapshotIdentity = {
1212
previousAppBundleId?: string;

‎packages/command-runtime/src/commands/interaction/runtime/selector-read-shared.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
type SnapshotNode,
1717
type SnapshotPreferredBackend,
1818
} from '@agent-device/kernel/snapshot';
19-
import { type SnapshotState } from '@agent-device/contracts/snapshot-model';
19+
import type { SnapshotState } from '@agent-device/contracts/snapshot-model';
2020
import {
2121
formatSelectorFailure,
2222
selectorFailureHint,

‎packages/contracts/src/snapshot-model.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,18 @@ export function snapshotStateProvenance(
8686
}
8787
}
8888

89+
/** Keyed on `SnapshotBackend`, so a backend added to `SnapshotProvenance` must be listed here. */
90+
const SNAPSHOT_BACKENDS = {
91+
xctest: true,
92+
android: true,
93+
'harmonyos-arkui': true,
94+
'macos-helper': true,
95+
'linux-atspi': true,
96+
web: true,
97+
} as const satisfies Record<SnapshotBackend, true>;
98+
8999
export function isSnapshotBackend(value: unknown): value is SnapshotBackend {
90-
return (
91-
value === 'xctest' ||
92-
value === 'android' ||
93-
value === 'harmonyos-arkui' ||
94-
value === 'macos-helper' ||
95-
value === 'linux-atspi' ||
96-
value === 'web'
97-
);
100+
return typeof value === 'string' && Object.hasOwn(SNAPSHOT_BACKENDS, value);
98101
}
99102

100103
export function usesMobileSnapshotPresentation(backend: SnapshotBackend | undefined): boolean {

0 commit comments

Comments
 (0)