@arkitektio/bsx 4.1.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +28 -7
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/index.d.ts +83 -27
- package/dist/catalogs/index.d.ts.map +1 -1
- package/dist/catalogs/parts/data.d.ts +1 -1
- package/dist/catalogs/parts/feedback.d.ts +3 -3
- package/dist/catalogs/parts/forms.d.ts +35 -7
- package/dist/catalogs/parts/forms.d.ts.map +1 -1
- package/dist/catalogs/parts/forms.js +32 -0
- package/dist/catalogs/parts/forms.js.map +1 -1
- package/dist/catalogs/parts/icons.d.ts +2 -2
- package/dist/catalogs/parts/index.d.ts +63 -27
- package/dist/catalogs/parts/index.d.ts.map +1 -1
- package/dist/catalogs/parts/navigation.d.ts +4 -4
- package/dist/catalogs/parts/overlays.d.ts +11 -11
- package/dist/catalogs/parts/run.d.ts +8 -0
- package/dist/catalogs/parts/run.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.d.ts +8 -0
- package/dist/catalogs/parts/scene.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.js +4 -0
- package/dist/catalogs/parts/scene.js.map +1 -1
- package/dist/catalogs/props.d.ts +1 -1
- package/dist/catalogs/scene.d.ts +8 -0
- package/dist/catalogs/scene.d.ts.map +1 -1
- package/dist/catalogs/shadcn.d.ts +59 -11
- package/dist/catalogs/shadcn.d.ts.map +1 -1
- package/dist/catalogs/shadcn.js +2 -0
- package/dist/catalogs/shadcn.js.map +1 -1
- package/dist/catalogs/ui.d.ts +16 -16
- package/dist/ports/dependencies/DependenciesContainer.d.ts +13 -8
- package/dist/ports/dependencies/DependenciesContainer.d.ts.map +1 -1
- package/dist/ports/dependencies/DependenciesContainer.js +130 -118
- package/dist/ports/dependencies/DependenciesContainer.js.map +1 -1
- package/dist/ports/dependencies/DependencyTreeNotice.d.ts +3 -2
- package/dist/ports/dependencies/DependencyTreeNotice.d.ts.map +1 -1
- package/dist/ports/dependencies/DependencyTreeNotice.js +7 -6
- package/dist/ports/dependencies/DependencyTreeNotice.js.map +1 -1
- package/dist/ports/dependencies/tree.d.ts +24 -0
- package/dist/ports/dependencies/tree.d.ts.map +1 -1
- package/dist/ports/dependencies/tree.js +52 -0
- package/dist/ports/dependencies/tree.js.map +1 -1
- package/dist/ports/dependencies/useDependencyTree.d.ts +5 -0
- package/dist/ports/dependencies/useDependencyTree.d.ts.map +1 -1
- package/dist/ports/dependencies/useDependencyTree.js +11 -5
- package/dist/ports/dependencies/useDependencyTree.js.map +1 -1
- package/dist/renderer/BlokRenderer.d.ts +4 -1
- package/dist/renderer/BlokRenderer.d.ts.map +1 -1
- package/dist/renderer/BlokRenderer.js +5 -1
- package/dist/renderer/BlokRenderer.js.map +1 -1
- package/dist/renderer/bloks/control.d.ts +12 -0
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +92 -5
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/data.d.ts +1 -1
- package/dist/renderer/bloks/feedback.d.ts +3 -3
- package/dist/renderer/bloks/forms.d.ts +31 -7
- package/dist/renderer/bloks/forms.d.ts.map +1 -1
- package/dist/renderer/bloks/forms.js +56 -0
- package/dist/renderer/bloks/forms.js.map +1 -1
- package/dist/renderer/bloks/icons.d.ts +1 -1
- package/dist/renderer/bloks/index.d.ts +51 -27
- package/dist/renderer/bloks/index.d.ts.map +1 -1
- package/dist/renderer/bloks/navigation.d.ts +4 -4
- package/dist/renderer/bloks/overlays.d.ts +11 -11
- package/dist/renderer/bloks/run/components.d.ts +4 -0
- package/dist/renderer/bloks/run/components.d.ts.map +1 -1
- package/dist/renderer/bloks/run/host.d.ts +32 -3
- package/dist/renderer/bloks/run/host.d.ts.map +1 -1
- package/dist/renderer/bloks/run/host.js.map +1 -1
- package/dist/renderer/bloks/scene/index.d.ts +4 -0
- package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
- package/dist/renderer/functions/v2/index.d.ts.map +1 -1
- package/dist/renderer/functions/v2/index.js +39 -0
- package/dist/renderer/functions/v2/index.js.map +1 -1
- package/dist/renderer/runtime/context.d.ts +2 -0
- package/dist/renderer/runtime/context.d.ts.map +1 -1
- package/dist/renderer/runtime/context.js +4 -0
- package/dist/renderer/runtime/context.js.map +1 -1
- package/dist/renderer/runtime/hooks.d.ts.map +1 -1
- package/dist/renderer/runtime/hooks.js +1 -0
- package/dist/renderer/runtime/hooks.js.map +1 -1
- package/dist/renderer/runtime/resolution.d.ts +2 -0
- package/dist/renderer/runtime/resolution.d.ts.map +1 -1
- package/dist/renderer/runtime/resolution.js +17 -1
- package/dist/renderer/runtime/resolution.js.map +1 -1
- package/dist/renderer/runtime/schemas.d.ts +5 -5
- package/dist/renderer/runtime/task.d.ts +25 -2
- package/dist/renderer/runtime/task.d.ts.map +1 -1
- package/dist/renderer/runtime/task.js +11 -2
- package/dist/renderer/runtime/task.js.map +1 -1
- package/dist/renderer/runtime/types.d.ts +7 -2
- package/dist/renderer/runtime/types.d.ts.map +1 -1
- package/dist/shadcn.d.ts +51 -27
- package/dist/shadcn.d.ts.map +1 -1
- package/dist/shadcn.js +2 -0
- package/dist/shadcn.js.map +1 -1
- package/dist/spec/bsx_v2.json +64 -0
- package/dist/spec/catalogs/base@2.json +136 -3
- package/dist/spec/catalogs/base@2.json.js +136 -3
- package/dist/spec/catalogs/scene@1.json +20 -0
- package/dist/spec/catalogs/scene@1.json.js +20 -0
- package/dist/spec/catalogs/shadcn@1.json +142 -0
- package/dist/spec/catalogs/shadcn@1.json.js +142 -0
- package/dist/spec/vocabulary.d.ts +2 -0
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +1 -0
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +43 -11
- package/dist/spec/vocabulary.json.js +43 -11
- package/package.json +1 -1
- package/src/bsx/language.test.ts +1 -1
- package/src/bsx/references.test.ts +59 -0
- package/src/bsx/references.ts +28 -7
- package/src/catalogs/parts/forms.ts +32 -0
- package/src/catalogs/parts/scene.ts +6 -0
- package/src/catalogs/shadcn.ts +2 -0
- package/src/ports/dependencies/DependenciesContainer.test.tsx +176 -0
- package/src/ports/dependencies/DependenciesContainer.tsx +341 -304
- package/src/ports/dependencies/DependencyTreeNotice.tsx +7 -15
- package/src/ports/dependencies/tree.test.ts +75 -0
- package/src/ports/dependencies/tree.ts +54 -0
- package/src/ports/dependencies/useDependencyTree.test.tsx +55 -0
- package/src/ports/dependencies/useDependencyTree.ts +11 -5
- package/src/renderer/BlokRenderer.tsx +9 -0
- package/src/renderer/bloks/control.tsx +116 -5
- package/src/renderer/bloks/forms.tsx +126 -0
- package/src/renderer/bloks/run/host.tsx +33 -3
- package/src/renderer/bloks/run/space.test.tsx +76 -0
- package/src/renderer/functions/v2/functions.test.ts +40 -1
- package/src/renderer/functions/v2/index.ts +47 -0
- package/src/renderer/runtime/context.tsx +6 -0
- package/src/renderer/runtime/hooks.ts +1 -0
- package/src/renderer/runtime/resolution.test.ts +14 -0
- package/src/renderer/runtime/resolution.ts +15 -1
- package/src/renderer/runtime/task.ts +33 -4
- package/src/renderer/runtime/types.ts +7 -2
- package/src/shadcn.ts +2 -0
- package/src/spec/bsx_v2.json +64 -0
- package/src/spec/catalogs/base@2.json +136 -3
- package/src/spec/catalogs/scene@1.json +20 -0
- package/src/spec/catalogs/shadcn@1.json +142 -0
- package/src/spec/spec.test.ts +20 -0
- package/src/spec/vocabulary.json +43 -11
- package/src/spec/vocabulary.ts +3 -0
|
@@ -159,3 +159,62 @@ describe('findings', () => {
|
|
|
159
159
|
expect(checkBlokTree(tree, emptyBlokScope('agent'))).toEqual([]);
|
|
160
160
|
});
|
|
161
161
|
});
|
|
162
|
+
|
|
163
|
+
describe('what an assign blok places and reads of the run it prepares', () => {
|
|
164
|
+
const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
|
|
165
|
+
const assign = {...emptyBlokScope('assign'), args: ['image', 'exposure']};
|
|
166
|
+
|
|
167
|
+
it('reads assign.given.<key>, assign.missing and assign.ready', () => {
|
|
168
|
+
const source =
|
|
169
|
+
'<Html><if when={assign.given.image}><Text text={args.image} /></if><arg key="exposure" /><args /><deps /><Button onClick={assign.start()} disabled={!assign.ready}>Run</Button></Html>';
|
|
170
|
+
expect(codes(source, assign)).toEqual([]);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('refuses a given flag for an argument the action has not, and a field assign has not', () => {
|
|
174
|
+
expect(codes('<Html><Text text={assign.given.nope} /></Html>', assign)).toEqual(['args.unknown']);
|
|
175
|
+
expect(codes('<Html><Text text={assign.nope} /></Html>', assign)).toEqual(['path.unknown']);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('keeps <arg>, <deps>, <dep> and the assign root to an assign blok', () => {
|
|
179
|
+
const task = emptyBlokScope('task');
|
|
180
|
+
expect(codes('<Html><arg key="image" /></Html>', task)).toEqual(['assign.kind']);
|
|
181
|
+
expect(codes('<Html><deps /><dep key="robot" /></Html>', task)).toEqual(['assign.kind', 'assign.kind']);
|
|
182
|
+
expect(codes('<Html><Text text={assign.ready} /></Html>', task)).toEqual(['roots.not_in_kind']);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe('what a blok does to the task it is about', () => {
|
|
187
|
+
const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
|
|
188
|
+
|
|
189
|
+
it('cancels, pauses, resumes, steps and interrupts it, and reads whether it may', () => {
|
|
190
|
+
const source =
|
|
191
|
+
'<Html><Button onClick={task.cancel()} disabled={!task.can.cancel}>Stop</Button><Button onClick={task.pause()}>Pause</Button><Button onClick={task.resume()}>Resume</Button><Button onClick={task.step()}>Step</Button><Button onClick={task.interrupt()}>Kill</Button><Text text={deps.robot.connected ? task.started_at : task.status} /></Html>';
|
|
192
|
+
const scope = {...emptyBlokScope('action'), dependencies: [{key: 'robot'}]} as BlokCheckScope;
|
|
193
|
+
expect(codes(source, scope)).toEqual([]);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('starts no run again: a rerun is the page\'s, never a blok\'s', () => {
|
|
197
|
+
expect(() => parseBsx('<Html><Button onClick={task.rerun()}>Again</Button></Html>')).toThrow(/calls nothing/);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('refuses them where there is no task', () => {
|
|
201
|
+
expect(codes('<Html><Button onClick={task.cancel()}>Stop</Button></Html>', emptyBlokScope('assign'))).toEqual(['roots.not_in_kind']);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe('what a blok places of its task, and what it leaves the host', () => {
|
|
206
|
+
const codes = (source: string, scope: BlokCheckScope) => checkBlokTree(parseBsx(source).tree, scope).map(found => found.code);
|
|
207
|
+
|
|
208
|
+
it('places the result, the status line and the time slider, and says how much chrome it wants', () => {
|
|
209
|
+
const source = '<Html chrome="none"><status /><returns only="image" /><timeline /><Text text={task.paused ? "waiting" : task.duration} /></Html>';
|
|
210
|
+
expect(codes(source, emptyBlokScope('action'))).toEqual([]);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('keeps <returns> and <status> to a blok that has a task', () => {
|
|
214
|
+
expect(codes('<Html><returns /><status /></Html>', emptyBlokScope('assign'))).toEqual(['roots.not_in_kind', 'roots.not_in_kind']);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('reads what an assign blok knows of starting', () => {
|
|
218
|
+
expect(codes('<Html><Text text={assign.blocked} /><Button disabled={assign.starting} onClick={assign.start()}>Run</Button></Html>', emptyBlokScope('assign'))).toEqual([]);
|
|
219
|
+
});
|
|
220
|
+
});
|
package/src/bsx/references.ts
CHANGED
|
@@ -173,8 +173,14 @@ const DEPENDENCY_KEY_PROPS = new Set(['Placed.dep', 'Route.through']);
|
|
|
173
173
|
/** The kinds that have a run's dependencies: an action's own bloks, for a run and for starting one. */
|
|
174
174
|
const RUN_KINDS: readonly string[] = ['action', 'assign'];
|
|
175
175
|
const ASSIGN_KIND = 'assign';
|
|
176
|
-
/**
|
|
177
|
-
const
|
|
176
|
+
/** What an assign blok places of the host's own: the argument form or one argument, the dependency picker or one dependency. */
|
|
177
|
+
const ASSIGN_COMPONENTS: ReadonlySet<string> = new Set(['args', 'arg', 'deps', 'dep']);
|
|
178
|
+
/** What a blok places of the task it is about: only a kind with a `task`. */
|
|
179
|
+
const TASK_COMPONENTS: ReadonlySet<string> = new Set(['returns', 'status']);
|
|
180
|
+
/** The one field of an agent that is not text. */
|
|
181
|
+
const AGENT_CONNECTED = 'connected';
|
|
182
|
+
/** Where an assign blok reads which arguments the caller decided. */
|
|
183
|
+
const GIVEN_FIELD = 'given';
|
|
178
184
|
/** Starts the run an assign blok prepares. */
|
|
179
185
|
const START_EFFECT = 'assign.start';
|
|
180
186
|
|
|
@@ -575,8 +581,11 @@ class Checker {
|
|
|
575
581
|
this.shadowed.add(node.component);
|
|
576
582
|
this.add('catalog.shadow', node.id, {component: node.component, catalog: shadow.catalog, module: shadow.module, winner: shadow.winner});
|
|
577
583
|
}
|
|
578
|
-
if (node.component
|
|
579
|
-
this.
|
|
584
|
+
if (TASK_COMPONENTS.has(node.component) && !this.kind.roots.includes('task')) {
|
|
585
|
+
this.notInKind(node.id, `<${node.component}>`, 'task');
|
|
586
|
+
}
|
|
587
|
+
if (ASSIGN_COMPONENTS.has(node.component) && this.scope.kind !== ASSIGN_KIND) {
|
|
588
|
+
this.add('assign.kind', node.id, {what: `<${node.component}>`, n: article(this.scope.kind), kind: this.scope.kind});
|
|
580
589
|
}
|
|
581
590
|
for (const prop of node.props ?? []) this.checkProp(node, prop, spec);
|
|
582
591
|
}
|
|
@@ -667,8 +676,10 @@ class Checker {
|
|
|
667
676
|
}
|
|
668
677
|
}
|
|
669
678
|
}
|
|
670
|
-
|
|
671
|
-
|
|
679
|
+
// `task.answer(...)`, `task.cancel()` and their kin act on the task the blok is about.
|
|
680
|
+
const effect = prop.util_call?.operation;
|
|
681
|
+
if (effect?.startsWith('task.') && vocabulary.functions.get(effect)?.effect && !this.kind.roots.includes('task')) {
|
|
682
|
+
this.notInKind(node.id, effect, 'task', prop.key);
|
|
672
683
|
}
|
|
673
684
|
if (prop.key === BIND_PROP) {
|
|
674
685
|
const path = prop.dynamic_value?.path ?? null;
|
|
@@ -979,6 +990,16 @@ class Checker {
|
|
|
979
990
|
return null;
|
|
980
991
|
}
|
|
981
992
|
return openMatch(path);
|
|
993
|
+
case 'assign':
|
|
994
|
+
// `assign.given.<key>` is open below `given`: one flag per argument of the action.
|
|
995
|
+
if (rest[0] === GIVEN_FIELD && rest.length > 1) {
|
|
996
|
+
if (this.scope.args !== null && !this.scope.args.includes(rest[1])) {
|
|
997
|
+
report('args.unknown', {path, key: rest[1], keys: this.scope.args.join(', ') || 'none'});
|
|
998
|
+
return null;
|
|
999
|
+
}
|
|
1000
|
+
return {key: rest[1], kind: 'BOOL'};
|
|
1001
|
+
}
|
|
1002
|
+
return this.descend(recordMatch('assign', vocabulary.records.assign.fields), rest, path, nodeId, propKey);
|
|
982
1003
|
case 'task':
|
|
983
1004
|
this.checkReturns(path, rest, nodeId, propKey);
|
|
984
1005
|
return this.descend(taskRecordMatch('task'), rest, path, nodeId, propKey);
|
|
@@ -1050,7 +1071,7 @@ class Checker {
|
|
|
1050
1071
|
const report = (code: string, fields: DiagnosticFields) => this.add(code, nodeId, fields, propKey);
|
|
1051
1072
|
if (head in agentSegments.fields) {
|
|
1052
1073
|
if (tail.length) report('path.unknown', {path, detail: `${head} of an agent has no fields`});
|
|
1053
|
-
return {key: head, kind: 'STRING'};
|
|
1074
|
+
return {key: head, kind: head === AGENT_CONNECTED ? 'BOOL' : 'STRING'};
|
|
1054
1075
|
}
|
|
1055
1076
|
if (head === agentSegments.tasks) {
|
|
1056
1077
|
if (!tail.length) {
|
|
@@ -320,6 +320,38 @@ export const formContracts = {
|
|
|
320
320
|
})
|
|
321
321
|
.describe('A labelled form field with description and error slots.'),
|
|
322
322
|
},
|
|
323
|
+
Combobox: {
|
|
324
|
+
schema: z
|
|
325
|
+
.object({
|
|
326
|
+
bind: markBindSchema(bindSchema.describe('Data-model path holding the picked value.')),
|
|
327
|
+
value: BlokPropSchemas.DynamicString.optional().describe('Controlled value.'),
|
|
328
|
+
defaultValue: BlokPropSchemas.DynamicString.optional().describe('Initial value.'),
|
|
329
|
+
options: z
|
|
330
|
+
.array(z.union([z.string(), z.object({value: z.string(), label: z.string().optional()})]))
|
|
331
|
+
.optional()
|
|
332
|
+
.describe('What can be picked: strings, or `{value, label}` objects. Typing narrows them.'),
|
|
333
|
+
placeholder: BlokPropSchemas.DynamicString.optional().describe('Shown while nothing is picked.'),
|
|
334
|
+
searchPlaceholder: BlokPropSchemas.DynamicString.optional().describe('Shown in the search field.'),
|
|
335
|
+
emptyText: BlokPropSchemas.DynamicString.optional().describe('Shown when typing matches nothing.'),
|
|
336
|
+
disabled: disabledSchema,
|
|
337
|
+
className: classNameSchema,
|
|
338
|
+
onChange: actionProp('Runs on selection. Arguments may read event.value.'),
|
|
339
|
+
})
|
|
340
|
+
.describe('A select with a search field: for a list too long to scan.'),
|
|
341
|
+
},
|
|
342
|
+
DatePicker: {
|
|
343
|
+
schema: z
|
|
344
|
+
.object({
|
|
345
|
+
bind: markBindSchema(bindSchema.describe('Data-model path holding an ISO date string (YYYY-MM-DD).')),
|
|
346
|
+
value: BlokPropSchemas.DynamicString.optional().describe('Controlled ISO date.'),
|
|
347
|
+
defaultValue: BlokPropSchemas.DynamicString.optional().describe('Initial ISO date.'),
|
|
348
|
+
placeholder: BlokPropSchemas.DynamicString.optional().describe('Shown while no date is picked.'),
|
|
349
|
+
disabled: disabledSchema,
|
|
350
|
+
className: classNameSchema,
|
|
351
|
+
onChange: actionProp('Runs on selection. Arguments may read event.value.'),
|
|
352
|
+
})
|
|
353
|
+
.describe('A button that opens a calendar and shows the date picked.'),
|
|
354
|
+
},
|
|
323
355
|
Calendar: {
|
|
324
356
|
schema: z
|
|
325
357
|
.object({
|
|
@@ -19,6 +19,12 @@ import {actionProp, bindSchema, describedString} from '../props';
|
|
|
19
19
|
|
|
20
20
|
export const sceneSchema = z
|
|
21
21
|
.object({
|
|
22
|
+
chrome: z
|
|
23
|
+
.enum(['auto', 'none'])
|
|
24
|
+
.optional()
|
|
25
|
+
.describe(
|
|
26
|
+
"What the host draws around the blok of its own: `auto` (the default) adds what the blok does not place (the time slider, the open ask, the rest of the argument form, its buttons); `none` adds nothing, the blok places what it wants.",
|
|
27
|
+
),
|
|
22
28
|
camera: z
|
|
23
29
|
.enum(['iso', 'front', 'side', 'top'])
|
|
24
30
|
.optional()
|
package/src/catalogs/shadcn.ts
CHANGED
|
@@ -26,6 +26,8 @@ export const shadcnCatalog = defineBlokCatalog({
|
|
|
26
26
|
ButtonGroup: parts.ButtonGroup,
|
|
27
27
|
Calendar: {...parts.Calendar, events: {onChange: [{key: "value", kind: "STRING", description: "The date picked, as an ISO date (YYYY-MM-DD)."}]}, bindKinds: {bind: "STRING"}},
|
|
28
28
|
Carousel: parts.Carousel,
|
|
29
|
+
Combobox: {...parts.Combobox, events: {onChange: [{key: "value", kind: "STRING", description: "The value picked."}]}, bindKinds: {bind: "STRING"}},
|
|
30
|
+
DatePicker: {...parts.DatePicker, events: {onChange: [{key: "value", kind: "STRING", description: "The date picked, as an ISO date (YYYY-MM-DD)."}]}, bindKinds: {bind: "STRING"}},
|
|
29
31
|
CarouselItem: parts.CarouselItem,
|
|
30
32
|
Chart: parts.Chart,
|
|
31
33
|
Collapsible: {...parts.Collapsible, events: {onChange: [{key: "value", kind: "BOOL", description: "Whether it is open now."}]}},
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
import { FormProvider, useForm } from "react-hook-form";
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
|
|
7
|
+
// A popover over cmdk needs a layout engine; what is under test is what the
|
|
8
|
+
// rows say and write into the form, so both are flattened to what they contain.
|
|
9
|
+
vi.mock("../../vendor/core/ui/popover", () => ({
|
|
10
|
+
Popover: ({ children, open, onOpenChange }: { children: ReactNode; open: boolean; onOpenChange: (open: boolean) => void }) => (
|
|
11
|
+
<div data-open={open}>
|
|
12
|
+
<button type="button" onClick={() => onOpenChange(!open)}>toggle list</button>
|
|
13
|
+
{children}
|
|
14
|
+
</div>
|
|
15
|
+
),
|
|
16
|
+
PopoverTrigger: ({ children }: { children: ReactNode }) => <>{children}</>,
|
|
17
|
+
PopoverContent: ({ children }: { children: ReactNode }) => <div data-testid="list">{children}</div>,
|
|
18
|
+
}));
|
|
19
|
+
vi.mock("../../vendor/core/ui/command", () => ({
|
|
20
|
+
Command: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
21
|
+
CommandList: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
22
|
+
CommandGroup: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
|
23
|
+
CommandSeparator: () => null,
|
|
24
|
+
CommandInput: (props: { value: string; onValueChange: (value: string) => void }) => (
|
|
25
|
+
<input aria-label="search" value={props.value} onChange={(event) => props.onValueChange(event.target.value)} />
|
|
26
|
+
),
|
|
27
|
+
CommandItem: ({ children, onSelect, disabled, ...rest }: { children: ReactNode; onSelect: () => void; disabled?: boolean; "data-checked"?: boolean }) => (
|
|
28
|
+
<button type="button" data-testid="row" data-checked={rest["data-checked"]} disabled={disabled} onClick={onSelect}>
|
|
29
|
+
{children}
|
|
30
|
+
</button>
|
|
31
|
+
),
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
import { configurePortHost } from "../host";
|
|
35
|
+
import type { ListDependencyFragment } from "../rekuest";
|
|
36
|
+
import { DependenciesContainer } from "./DependenciesContainer";
|
|
37
|
+
import type { DependencyAgent, DependencyNode, ResolvedDependencyInput } from "./tree";
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
cleanup();
|
|
41
|
+
configurePortHost({});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const agent = (id: string, name: string, connected = true): DependencyAgent => ({
|
|
45
|
+
id,
|
|
46
|
+
name,
|
|
47
|
+
connected,
|
|
48
|
+
app: { identifier: "live.mikro" },
|
|
49
|
+
release: { version: "1.2" },
|
|
50
|
+
user: { sub: "1" },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const declared = (key: string, over: Partial<ListDependencyFragment> = {}): ListDependencyFragment => ({
|
|
54
|
+
id: key,
|
|
55
|
+
key,
|
|
56
|
+
autoResolvable: true,
|
|
57
|
+
optional: false,
|
|
58
|
+
singular: true,
|
|
59
|
+
...over,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const resolvedTo = (key: string, bound: DependencyAgent, below: DependencyNode[] = []): DependencyNode => ({
|
|
63
|
+
key,
|
|
64
|
+
mappedAgents: [{ agentId: bound.id, agent: bound, mappedImplementations: [{ key, resolvedDependencies: below }] }],
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
/** The container in a form, and a way to read what it wrote. */
|
|
68
|
+
const mount = (
|
|
69
|
+
dependencies: ListDependencyFragment[],
|
|
70
|
+
extra: { tree?: DependencyNode[]; pins?: ResolvedDependencyInput[]; agents?: DependencyAgent[] } = {},
|
|
71
|
+
) => {
|
|
72
|
+
const query = vi.fn(async () => ({ agents: extra.agents ?? [] }));
|
|
73
|
+
configurePortHost({ useServiceQuery: () => query });
|
|
74
|
+
let read: () => ResolvedDependencyInput[] = () => [];
|
|
75
|
+
const Harness = () => {
|
|
76
|
+
const form = useForm({ defaultValues: { dependencies: extra.pins ?? [] } });
|
|
77
|
+
read = () => form.getValues("dependencies");
|
|
78
|
+
return (
|
|
79
|
+
<FormProvider {...form}>
|
|
80
|
+
<DependenciesContainer dependencies={dependencies} bound="1" tree={extra.tree} />
|
|
81
|
+
</FormProvider>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
render(<Harness />);
|
|
85
|
+
return { query, pins: () => read() };
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
describe("the dependencies of a run", () => {
|
|
89
|
+
it("are one line while they resolve by themselves, and ask for no agents", () => {
|
|
90
|
+
const { query, pins } = mount([declared("storage"), declared("segmenter")], {
|
|
91
|
+
tree: [resolvedTo("storage", agent("7", "lab-nas")), resolvedTo("segmenter", agent("8", "gpu-box"))],
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
expect(screen.getByText("Runs with")).toBeInTheDocument();
|
|
95
|
+
expect(screen.getByText("lab-nas")).toBeInTheDocument();
|
|
96
|
+
expect(screen.getByText("gpu-box")).toBeInTheDocument();
|
|
97
|
+
expect(screen.queryByText("storage")).not.toBeInTheDocument();
|
|
98
|
+
expect(query).not.toHaveBeenCalled();
|
|
99
|
+
// Seeded: each resolves by itself until someone is named.
|
|
100
|
+
expect(pins()).toEqual([
|
|
101
|
+
{ key: "storage", autoResolve: true, mappedAgents: [] },
|
|
102
|
+
{ key: "segmenter", autoResolve: true, mappedAgents: [] },
|
|
103
|
+
]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("open by themselves when one waits to be picked", () => {
|
|
107
|
+
mount([declared("stage", { autoResolvable: false })]);
|
|
108
|
+
expect(screen.getByText("stage")).toBeInTheDocument();
|
|
109
|
+
expect(screen.getByText("Pick an agent…")).toBeInTheDocument();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("open on what is unmet, and say why at its row", () => {
|
|
113
|
+
mount([declared("stage")], { tree: [{ key: "stage", unmet: "No connected agent provides this.", mappedAgents: [] }] });
|
|
114
|
+
expect(screen.getByText("stage")).toBeInTheDocument();
|
|
115
|
+
expect(screen.getByText("No connected agent provides this.")).toBeInTheDocument();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("count what is unmet once folded again", () => {
|
|
119
|
+
mount([declared("stage")], { tree: [{ key: "stage", unmet: "No connected agent provides this.", mappedAgents: [] }] });
|
|
120
|
+
fireEvent.click(screen.getByText("Runs with"));
|
|
121
|
+
expect(screen.getByText("1 not met")).toBeInTheDocument();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("pin the agent picked, and go back to automatic when it is unpicked", async () => {
|
|
125
|
+
const nas = agent("7", "lab-nas");
|
|
126
|
+
const { query, pins } = mount([declared("storage")], { agents: [nas, agent("9", "cold-nas", false)] });
|
|
127
|
+
fireEvent.click(screen.getByText("Runs with"));
|
|
128
|
+
// In the closed field, and as the list's first entry (the mock shows the list always).
|
|
129
|
+
expect(screen.getAllByText("Automatic")).toHaveLength(2);
|
|
130
|
+
|
|
131
|
+
fireEvent.click(screen.getByText("toggle list"));
|
|
132
|
+
expect(query).toHaveBeenCalledWith(expect.any(String), { search: "", dependency: "storage" });
|
|
133
|
+
fireEvent.click(await screen.findByText("cold-nas"));
|
|
134
|
+
expect(pins()).toEqual([{ key: "storage", autoResolve: false, mappedAgents: [{ agent: "9", key: "storage" }] }]);
|
|
135
|
+
|
|
136
|
+
fireEvent.click(screen.getByText("toggle list"));
|
|
137
|
+
fireEvent.click((await screen.findAllByText("cold-nas")).at(-1)!);
|
|
138
|
+
expect(pins()).toEqual([{ key: "storage", autoResolve: true, mappedAgents: [] }]);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("take no more agents than the dependency allows", async () => {
|
|
142
|
+
mount([declared("workers", { singular: false, autoResolvable: false, maxViableInstances: 2 })], {
|
|
143
|
+
agents: [agent("1", "one"), agent("2", "two"), agent("3", "three")],
|
|
144
|
+
pins: [{ key: "workers", mappedAgents: [{ key: "workers", agent: "1" }, { key: "workers", agent: "2" }] }],
|
|
145
|
+
});
|
|
146
|
+
fireEvent.click(screen.getByText("toggle list"));
|
|
147
|
+
const third = (await screen.findByText("three")).closest("button")!;
|
|
148
|
+
expect(third).toBeDisabled();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("offer none for an optional dependency, which drops its pin", async () => {
|
|
152
|
+
const { pins } = mount([declared("notifier", { optional: true })]);
|
|
153
|
+
fireEvent.click(screen.getByText("Runs with"));
|
|
154
|
+
fireEvent.click(screen.getByText("toggle list"));
|
|
155
|
+
await act(async () => {});
|
|
156
|
+
fireEvent.click(screen.getAllByText("None").at(-1)!);
|
|
157
|
+
expect(pins()).toEqual([]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("fold what a bound agent needs itself, until something there is unmet", () => {
|
|
161
|
+
const nas = agent("7", "lab-nas");
|
|
162
|
+
mount([declared("storage", { autoResolvable: false })], {
|
|
163
|
+
tree: [resolvedTo("storage", nas, [resolvedTo("database", agent("8", "pg"))])],
|
|
164
|
+
});
|
|
165
|
+
expect(screen.getByText("lab-nas needs database")).toBeInTheDocument();
|
|
166
|
+
expect(screen.queryByText("pg")).not.toBeInTheDocument();
|
|
167
|
+
fireEvent.click(screen.getByText("lab-nas needs database"));
|
|
168
|
+
expect(screen.getByText("pg")).toBeInTheDocument();
|
|
169
|
+
|
|
170
|
+
cleanup();
|
|
171
|
+
mount([declared("storage", { autoResolvable: false })], {
|
|
172
|
+
tree: [resolvedTo("storage", nas, [{ key: "database", unmet: "Nobody runs a database.", mappedAgents: [] }])],
|
|
173
|
+
});
|
|
174
|
+
expect(screen.getByText("Nobody runs a database.")).toBeInTheDocument();
|
|
175
|
+
});
|
|
176
|
+
});
|