|
| 1 | +import { expect, test } from 'vitest'; |
| 2 | +import { |
| 3 | + commandDescriptors, |
| 4 | + commandRuntimeUseRequirements, |
| 5 | +} from '../../core/command-descriptor/registry.ts'; |
| 6 | +import { |
| 7 | + conformedRuntimeBindings, |
| 8 | + refusedRuntimeOperation, |
| 9 | + refuseUnavailableExactOwnerFact, |
| 10 | + type ConformedRuntimeCommand, |
| 11 | +} from './runtime-binding-conformance.ts'; |
| 12 | + |
| 13 | +/** |
| 14 | + * The command registry's `platformExecution` declarations are the production enumeration of |
| 15 | + * daemon runtime bindings: every device-runtime descriptor names the uses its route admits, and |
| 16 | + * `admitRuntimeOperations` is one seam with no table of its own. The generic and interaction routes |
| 17 | + * admit through per-command `src/daemon/<command>-runtime.ts` resolvers, so every single-use |
| 18 | + * descriptor on those routes owes the family its conformance entry; the other direction holds any |
| 19 | + * entry to a cell its descriptor actually declares. |
| 20 | + */ |
| 21 | +const CONFORMED_ROUTES = new Set(['generic', 'interaction']); |
| 22 | + |
| 23 | +function singleUseConformedRouteCommands(): string[] { |
| 24 | + return commandDescriptors |
| 25 | + .filter((descriptor) => { |
| 26 | + const route = 'daemon' in descriptor ? descriptor.daemon?.route : undefined; |
| 27 | + return route !== undefined && CONFORMED_ROUTES.has(route); |
| 28 | + }) |
| 29 | + .map((descriptor) => descriptor.name) |
| 30 | + .filter((command) => commandRuntimeUseRequirements(command)?.length === 1) |
| 31 | + .sort(); |
| 32 | +} |
| 33 | + |
| 34 | +const conformedCommands = Object.keys(conformedRuntimeBindings) as ConformedRuntimeCommand[]; |
| 35 | + |
| 36 | +test('every single-use generic or interaction route descriptor has a conformance entry', () => { |
| 37 | + const missing = singleUseConformedRouteCommands().filter( |
| 38 | + (command) => !conformedCommands.includes(command as ConformedRuntimeCommand), |
| 39 | + ); |
| 40 | + |
| 41 | + expect(missing).toEqual([]); |
| 42 | +}); |
| 43 | + |
| 44 | +test('every conformance entry refuses on a cell its registry descriptor declares', () => { |
| 45 | + const undeclared = conformedCommands.filter((command) => { |
| 46 | + const declared = commandRuntimeUseRequirements(command)?.flat() ?? []; |
| 47 | + return !declared.includes(refusedRuntimeOperation(command)); |
| 48 | + }); |
| 49 | + |
| 50 | + expect(undeclared).toEqual([]); |
| 51 | +}); |
| 52 | + |
| 53 | +const conformanceDevice = { |
| 54 | + id: 'runtime-binding-conformance-device', |
| 55 | + name: 'Pixel', |
| 56 | + platform: 'android', |
| 57 | + kind: 'emulator', |
| 58 | + target: 'mobile', |
| 59 | + booted: true, |
| 60 | +} as const; |
| 61 | + |
| 62 | +test.each(conformedCommands)( |
| 63 | + '%s refuses its unavailable declared cell before binding', |
| 64 | + async (command) => { |
| 65 | + const response = await refuseUnavailableExactOwnerFact({ |
| 66 | + command, |
| 67 | + device: conformanceDevice, |
| 68 | + unavailable: { available: false, reason: 'owner-capability-missing' }, |
| 69 | + }); |
| 70 | + |
| 71 | + expect(response.error.code).toBe('UNSUPPORTED_OPERATION'); |
| 72 | + }, |
| 73 | +); |
0 commit comments