Skip to content

Commit 1952bfd

Browse files
committed
refactor: compact conditional runtime declarations
1 parent 4d0fb8a commit 1952bfd

34 files changed

Lines changed: 161 additions & 216 deletions

packages/contracts/src/command-platform-execution.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe('command platform execution declaration', () => {
88
{ kind: 'none' },
99
{ kind: 'legacy' },
1010
{ kind: 'inventory', use: inventoryUse },
11+
{ kind: 'device-runtime', use: { required: ['capture'], preferred: [] } },
1112
{
1213
kind: 'device-runtime',
1314
use: { required: ['capture'], preferred: ['inspect'], conditional: ['observe'] },
@@ -24,16 +25,16 @@ describe('command platform execution declaration', () => {
2425
{ kind: 'inventory', use: inventoryUse, legacy: true },
2526
{
2627
kind: 'device-runtime',
27-
use: { required: [], preferred: [], conditional: [] },
28+
use: { required: [], preferred: [] },
2829
inventory: true,
2930
},
3031
{
3132
kind: 'device-runtime',
32-
use: { required: ['capture', 'capture'], preferred: [], conditional: [] },
33+
use: { required: ['capture', 'capture'], preferred: [] },
3334
},
3435
{
3536
kind: 'device-runtime',
36-
use: { required: ['capture'], preferred: ['capture'], conditional: [] },
37+
use: { required: ['capture'], preferred: ['capture'] },
3738
},
3839
{
3940
kind: 'device-runtime',
@@ -59,7 +60,7 @@ describe('command platform execution declaration', () => {
5960
{ kind: 'device-runtime', uses: [appLogRuntimePlanUses[0], appLogRuntimePlanUses[0]] },
6061
{
6162
kind: 'device-runtime',
62-
uses: [{ required: ['appLogStart'], preferred: ['appLogStart'], conditional: [] }],
63+
uses: [{ required: ['appLogStart'], preferred: ['appLogStart'] }],
6364
},
6465
])('rejects empty, duplicate, overlapping, or both-form runtime uses: %j', (value) => {
6566
expect(() => assertCommandPlatformExecution(value)).toThrow(/exactly one/);

packages/contracts/src/command-platform-execution.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,17 @@ function hasRuntimeUseDeclaration(value: unknown): boolean {
6767
const categories = [
6868
stringArray(use['required']),
6969
stringArray(use['preferred']),
70-
stringArray(use['conditional']),
70+
stringArray(use['conditional'] ?? []),
7171
];
7272
if (!hasValidRuntimeUseCategories(categories)) return false;
73-
if (!arePairwiseDisjoint(categories)) return false;
74-
return sameKeys(Object.keys(use).sort(), ['conditional', 'preferred', 'required']);
73+
const operations = categories.flat();
74+
if (new Set(operations).size !== operations.length) return false;
75+
return sameKeys(
76+
Object.keys(use).sort(),
77+
use['conditional'] === undefined
78+
? ['preferred', 'required']
79+
: ['conditional', 'preferred', 'required'],
80+
);
7581
}
7682

7783
function hasValidRuntimeUseCategories(
@@ -82,17 +88,6 @@ function hasValidRuntimeUseCategories(
8288
);
8389
}
8490

85-
function arePairwiseDisjoint(categories: readonly string[][]): boolean {
86-
for (let leftIndex = 0; leftIndex < categories.length; leftIndex += 1) {
87-
const left = categories[leftIndex];
88-
if (!left) return false;
89-
for (const right of categories.slice(leftIndex + 1)) {
90-
if (!areDisjoint(left, right)) return false;
91-
}
92-
}
93-
return true;
94-
}
95-
9691
function stringArray(value: unknown): string[] | null {
9792
if (!Array.isArray(value)) return null;
9893
return value.every((key): key is string => typeof key === 'string') ? value : null;
@@ -102,11 +97,6 @@ function hasUniqueValues(values: readonly string[]): boolean {
10297
return new Set(values).size === values.length;
10398
}
10499

105-
function areDisjoint(left: readonly string[], right: readonly string[]): boolean {
106-
const leftValues = new Set(left);
107-
return right.every((value) => !leftValues.has(value));
108-
}
109-
110100
function sameKeys(actual: readonly string[], expected: readonly string[]): boolean {
111101
return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
112102
}

packages/contracts/src/facades/platform.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,18 @@ export {
263263
captureSnapshotSignal,
264264
snapshotRuntimeOperationFacts,
265265
} from '../snapshot-runtime.ts';
266-
export { findTextRuntimeOperationFacts } from '../find-text-runtime.ts';
267-
export type {
268-
FindTextInput,
269-
FindTextResult,
270-
FindTextRuntimeOperationFacts,
271-
FindTextRuntimeOperations,
272-
} from '../find-text-runtime.ts';
273-
export { findSelectorRuntimeOperationFacts } from '../find-selector-runtime.ts';
266+
export { selectorObservationRuntimeOperationFacts } from '../selector-observation-runtime.ts';
274267
export type {
275268
FindSelectorInput,
276269
FindSelectorResult,
277-
FindSelectorRuntimeOperationFacts,
278270
FindSelectorRuntimeOperations,
279-
} from '../find-selector-runtime.ts';
271+
FindTextInput,
272+
FindTextResult,
273+
FindTextRuntimeOperations,
274+
SelectorObservationRuntimeOperationFacts,
275+
SelectorObservationRuntimeOperations,
276+
SelectorObservationResult,
277+
} from '../selector-observation-runtime.ts';
280278
export type {
281279
CaptureSnapshotInput,
282280
LocalSnapshotInteractorResolver,

packages/contracts/src/find-selector-runtime.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

packages/contracts/src/find-text-runtime.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

packages/contracts/src/logs-runtime-cutover.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test.each([
3030
appLogInspectUse,
3131
appLogDoctorUse,
3232
appLogStartUse,
33-
{ required: ['appLogCleanup'], preferred: [], conditional: [] },
33+
{ required: ['appLogCleanup'], preferred: [] },
3434
],
3535
},
3636
},

packages/contracts/src/logs-runtime-plan.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,17 @@ test('normalizes all seven logs plans with their exact non-superset runtime use'
5252
assert.deepEqual(appLogDoctorUse, {
5353
required: ['appLogInspect', 'appLogDoctor'],
5454
preferred: [],
55-
conditional: [],
5655
});
5756
assert.deepEqual(startUse, {
5857
required: ['appLogInspect', 'appLogStart'],
5958
preferred: [],
60-
conditional: [],
6159
});
6260
});
6361

6462
test('keeps fact-derived admission separate from every execution plan', () => {
6563
assert.deepEqual(appLogAdmissionUse, {
6664
required: [],
6765
preferred: ['appLogInspect'],
68-
conditional: [],
6966
});
7067
assert.equal((appLogRuntimePlanUses as readonly object[]).includes(appLogAdmissionUse), false);
7168
});

packages/contracts/src/network-runtime-plan.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ test('normalizes defaults and retains the requested alias and projection', () =>
4343
assert.deepEqual(networkDumpUse, {
4444
required: ['networkDump'],
4545
preferred: [],
46-
conditional: [],
4746
});
4847
assert.deepEqual(networkAdmissionUse, {
4948
required: [],
5049
preferred: ['networkDump'],
51-
conditional: [],
5250
});
5351
});
5452

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ test.each([
6363
{
6464
required: ['captureSnapshot', 'captureSnapshotWithCustomActions'],
6565
preferred: [],
66-
conditional: [],
6766
},
6867
],
6968
[
@@ -74,7 +73,6 @@ test.each([
7473
{
7574
required: ['captureSnapshot', 'captureSnapshotWithoutActiveApp'],
7675
preferred: [],
77-
conditional: [],
7876
},
7977
],
8078
[
@@ -89,7 +87,6 @@ test.each([
8987
'captureSnapshotWithoutActiveApp',
9088
],
9189
preferred: [],
92-
conditional: [],
9390
},
9491
],
9592
] as const)(

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import type { ScreenRecordingRuntimeHost } from './screen-recording-runtime-host
1414
import type { ScreenRecordingRuntimeOperations } from './screen-recording-runtime.ts';
1515
import type { ScreenshotRuntimeOperations } from './screenshot-runtime.ts';
1616
import type { SnapshotRuntimeHost, SnapshotRuntimeOperations } from './snapshot-runtime.ts';
17-
import type { FindTextRuntimeOperations } from './find-text-runtime.ts';
18-
import type { FindSelectorRuntimeOperations } from './find-selector-runtime.ts';
17+
import type { SelectorObservationRuntimeOperations } from './selector-observation-runtime.ts';
1918
import type { ViewportRuntimeOperations } from './viewport-runtime.ts';
2019
import type { ElementTextRuntimeOperations } from './element-text-runtime.ts';
2120
import type {
@@ -49,8 +48,7 @@ export type PlatformRuntimeOperations = AppLogRuntimeOperations &
4948
ScreenRecordingRuntimeOperations &
5049
ScreenshotRuntimeOperations &
5150
SnapshotRuntimeOperations &
52-
FindTextRuntimeOperations &
53-
FindSelectorRuntimeOperations &
51+
SelectorObservationRuntimeOperations &
5452
ViewportRuntimeOperations &
5553
ElementTextRuntimeOperations &
5654
DeviceReadinessRuntimeOperations &

0 commit comments

Comments
 (0)