|
1 | 1 | import assert from 'node:assert/strict'; |
2 | 2 | import { test, vi } from 'vitest'; |
3 | | -import { localRuntimeOwner, providerRuntimeOwner } from './platform-runtime.ts'; |
4 | 3 | import { |
| 4 | + localRuntimeOwner, |
| 5 | + providerRuntimeOwner, |
| 6 | + type RuntimeOperationKey, |
| 7 | +} from './platform-runtime.ts'; |
| 8 | +import { |
| 9 | + RUNTIME_OPERATION_NAMES, |
| 10 | + isRuntimeOperationName, |
| 11 | + type RuntimeOperationName, |
| 12 | +} from './runtime-operation-names.ts'; |
| 13 | +import { |
| 14 | + type PlatformRuntimeOperations, |
| 15 | + type PlatformRuntimeProviderModule, |
5 | 16 | bootTargetHeadlessUse, |
6 | 17 | bootTargetUse, |
7 | 18 | captureSnapshotUse, |
8 | 19 | resolveDeviceReadinessRuntimePlan, |
9 | 20 | resolveSnapshotRuntimePlan, |
10 | | - type PlatformRuntimeProviderModule, |
11 | 21 | } from './platform-runtime-operations.ts'; |
12 | 22 |
|
13 | 23 | function compileTimeProviderModuleProof(): void { |
@@ -99,3 +109,18 @@ test.each([ |
99 | 109 | }); |
100 | 110 | }, |
101 | 111 | ); |
| 112 | + |
| 113 | +// The value-level vocabulary must name exactly the operations union: a name missing from the list |
| 114 | +// or an extra name both collapse these assignments to a compile error. |
| 115 | +type OperationKey = RuntimeOperationKey<PlatformRuntimeOperations>; |
| 116 | +type MissingFromList = Exclude<OperationKey, RuntimeOperationName>; |
| 117 | +type ExtraInList = Exclude<RuntimeOperationName, OperationKey>; |
| 118 | +const noOperationIsMissingFromTheList: [MissingFromList] extends [never] ? true : never = true; |
| 119 | +const noListedNameIsUnknown: [ExtraInList] extends [never] ? true : never = true; |
| 120 | + |
| 121 | +test('the runtime operation vocabulary is the operations union, with no duplicates', () => { |
| 122 | + assert.equal(noOperationIsMissingFromTheList && noListedNameIsUnknown, true); |
| 123 | + assert.equal(new Set(RUNTIME_OPERATION_NAMES).size, RUNTIME_OPERATION_NAMES.length); |
| 124 | + assert.equal(isRuntimeOperationName('captureSnapshot'), true); |
| 125 | + assert.equal(isRuntimeOperationName('notAnOperation'), false); |
| 126 | +}); |
0 commit comments