@arkitektio/bsx 4.0.1 → 4.2.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.
Files changed (74) hide show
  1. package/dist/bsx/references.d.ts.map +1 -1
  2. package/dist/bsx/references.js +17 -4
  3. package/dist/bsx/references.js.map +1 -1
  4. package/dist/ports/dependencies/DependenciesContainer.d.ts +13 -8
  5. package/dist/ports/dependencies/DependenciesContainer.d.ts.map +1 -1
  6. package/dist/ports/dependencies/DependenciesContainer.js +130 -118
  7. package/dist/ports/dependencies/DependenciesContainer.js.map +1 -1
  8. package/dist/ports/dependencies/DependencyTreeNotice.d.ts +3 -2
  9. package/dist/ports/dependencies/DependencyTreeNotice.d.ts.map +1 -1
  10. package/dist/ports/dependencies/DependencyTreeNotice.js +7 -6
  11. package/dist/ports/dependencies/DependencyTreeNotice.js.map +1 -1
  12. package/dist/ports/dependencies/tree.d.ts +24 -0
  13. package/dist/ports/dependencies/tree.d.ts.map +1 -1
  14. package/dist/ports/dependencies/tree.js +52 -0
  15. package/dist/ports/dependencies/tree.js.map +1 -1
  16. package/dist/ports/dependencies/useDependencyTree.d.ts +5 -0
  17. package/dist/ports/dependencies/useDependencyTree.d.ts.map +1 -1
  18. package/dist/ports/dependencies/useDependencyTree.js +11 -5
  19. package/dist/ports/dependencies/useDependencyTree.js.map +1 -1
  20. package/dist/renderer/BlokRenderer.d.ts +3 -1
  21. package/dist/renderer/BlokRenderer.d.ts.map +1 -1
  22. package/dist/renderer/BlokRenderer.js +5 -1
  23. package/dist/renderer/BlokRenderer.js.map +1 -1
  24. package/dist/renderer/bloks/control.d.ts +1 -0
  25. package/dist/renderer/bloks/control.d.ts.map +1 -1
  26. package/dist/renderer/bloks/control.js +10 -0
  27. package/dist/renderer/bloks/control.js.map +1 -1
  28. package/dist/renderer/bloks/run/host.d.ts +2 -0
  29. package/dist/renderer/bloks/run/host.d.ts.map +1 -1
  30. package/dist/renderer/bloks/run/host.js.map +1 -1
  31. package/dist/renderer/runtime/context.d.ts +1 -0
  32. package/dist/renderer/runtime/context.d.ts.map +1 -1
  33. package/dist/renderer/runtime/context.js +4 -0
  34. package/dist/renderer/runtime/context.js.map +1 -1
  35. package/dist/renderer/runtime/hooks.d.ts.map +1 -1
  36. package/dist/renderer/runtime/hooks.js +1 -0
  37. package/dist/renderer/runtime/hooks.js.map +1 -1
  38. package/dist/renderer/runtime/resolution.d.ts +1 -0
  39. package/dist/renderer/runtime/resolution.d.ts.map +1 -1
  40. package/dist/renderer/runtime/resolution.js +13 -2
  41. package/dist/renderer/runtime/resolution.js.map +1 -1
  42. package/dist/renderer/runtime/types.d.ts +5 -0
  43. package/dist/renderer/runtime/types.d.ts.map +1 -1
  44. package/dist/spec/bsx_v2.json +287 -0
  45. package/dist/spec/catalogs/base@2.json +12 -0
  46. package/dist/spec/catalogs/base@2.json.js +12 -0
  47. package/dist/spec/vocabulary.d.ts +1 -1
  48. package/dist/spec/vocabulary.d.ts.map +1 -1
  49. package/dist/spec/vocabulary.js +1 -1
  50. package/dist/spec/vocabulary.js.map +1 -1
  51. package/dist/spec/vocabulary.json +11 -3
  52. package/dist/spec/vocabulary.json.js +11 -3
  53. package/package.json +1 -1
  54. package/src/bsx/references.ts +18 -4
  55. package/src/ports/dependencies/DependenciesContainer.test.tsx +176 -0
  56. package/src/ports/dependencies/DependenciesContainer.tsx +341 -304
  57. package/src/ports/dependencies/DependencyTreeNotice.tsx +7 -15
  58. package/src/ports/dependencies/tree.test.ts +75 -0
  59. package/src/ports/dependencies/tree.ts +54 -0
  60. package/src/ports/dependencies/useDependencyTree.test.tsx +55 -0
  61. package/src/ports/dependencies/useDependencyTree.ts +11 -5
  62. package/src/renderer/BlokRenderer.tsx +8 -0
  63. package/src/renderer/bloks/control.tsx +15 -0
  64. package/src/renderer/bloks/run/host.tsx +2 -0
  65. package/src/renderer/bloks/run/space.test.tsx +17 -1
  66. package/src/renderer/runtime/context.tsx +5 -0
  67. package/src/renderer/runtime/hooks.ts +1 -0
  68. package/src/renderer/runtime/resolution.test.ts +8 -0
  69. package/src/renderer/runtime/resolution.ts +11 -2
  70. package/src/renderer/runtime/types.ts +5 -0
  71. package/src/spec/bsx_v2.json +287 -0
  72. package/src/spec/catalogs/base@2.json +12 -0
  73. package/src/spec/vocabulary.json +11 -3
  74. package/src/spec/vocabulary.ts +2 -2
@@ -53,6 +53,12 @@
53
53
  "locals": true,
54
54
  "contexts": ["HTML", "SCENE"]
55
55
  },
56
+ "assign": {
57
+ "description": "An action's own blok for starting a run of it (assign_bloks): shown before there is a task, with the arguments being filled in as args and the agents a run would get as deps.",
58
+ "roots": ["self", "deps", "args", "queries", "subscriptions", "viewer"],
59
+ "locals": true,
60
+ "contexts": ["HTML", "SCENE"]
61
+ },
56
62
  "action_logo": {
57
63
  "description": "An action's logo, drawn against the task the viewer last ran of it (null until then).",
58
64
  "roots": ["task"],
@@ -141,7 +147,7 @@
141
147
  ]
142
148
  },
143
149
  "functions": {
144
- "description": "Pure functions by namespace, snake_case. Positional arguments map onto params in order. `lazy`: arguments are read only as needed. `effect`: allowed only as a callback's one thing (ui.*, task.answer, query.*). `sees_status`: sees pending/failed instead of suspending. No function reads the wall clock. `null` says what the function does with a null argument (known absence); a missing path reads as null.",
150
+ "description": "Pure functions by namespace, snake_case. Positional arguments map onto params in order. `lazy`: arguments are read only as needed. `effect`: allowed only as a callback's one thing (ui.*, task.answer, assign.start, query.*). `sees_status`: sees pending/failed instead of suspending. No function reads the wall clock. `null` says what the function does with a null argument (known absence); a missing path reads as null.",
145
151
  "cmp.eq": {"params": [["a", "ANY"], ["b", "ANY"]], "returns": "BOOL", "description": "Deep JSON equality.", "null": "null equals only null"},
146
152
  "cmp.ne": {"params": [["a", "ANY"], ["b", "ANY"]], "returns": "BOOL", "description": "Not deep-equal.", "null": "null equals only null"},
147
153
  "cmp.gt": {"params": [["a", "ANY"], ["b", "ANY"]], "returns": "BOOL", "description": "a > b, numbers or strings.", "null": "false"},
@@ -251,6 +257,7 @@
251
257
  "time.diff": {"params": [["start", "STRING"], ["end", "STRING"]], "returns": "FLOAT", "description": "Seconds from start to end (ISO 8601 datetimes); negative when end is earlier. Pure: relative time to the viewed moment is the <Time> component's.", "null": "null"},
252
258
  "ui.copy": {"params": [["text", "ANY"]], "returns": "ANY", "effect": true, "description": "Copies text to the viewer's clipboard: the only non-task effect.", "null": "copies an empty string"},
253
259
  "task.answer": {"params": [["values", "DICT"]], "returns": "ANY", "effect": true, "task_operation": true, "description": "Answers the open ask of `task`. Counts as a task operation.", "null": "answers with no values"},
260
+ "assign.start": {"params": [], "returns": "ANY", "effect": true, "description": "Starts the run an assign blok prepares, with the arguments as they are filled in and the agents the blok was shown (deps) pinned. An assign blok only.", "null": "starts the run"},
254
261
  "query.refetch": {"params": [["query", "STRING"]], "returns": "ANY", "effect": true, "description": "Re-reads the declared query named by the literal `query`; never suspends, queries.<name>.refetching is true meanwhile. BSX writes it queries.<name>.refetch().", "null": "refused: the query is named by a literal"},
255
262
  "query.fetch_more": {"params": [["query", "STRING"], ["variables", "DICT", false]], "returns": "ANY", "effect": true, "description": "Reads the next page of the declared query named by the literal `query`, its variables overridden by `variables`, and appends the page's list at the query's `more` field to what is shown; queries.<name>.fetching_more is true meanwhile. BSX writes it queries.<name>.fetch_more(name: value, ...). Refused on a query without `more`.", "null": "refused: the query is named by a literal; null variables fetch with the query's own"}
256
263
  },
@@ -265,7 +272,7 @@
265
272
  "description": "What a prop or an argument may hold besides a literal, a path or a util call.",
266
273
  "kinds": {
267
274
  "agent_call": "A task call: self.<action>(...) or deps.<key>.<action>(...), only as a callback's one thing, optionally named with `into <name>` (stored as the prop's declares_value).",
268
- "util_call": "A pure function, or an effect (ui.copy, task.answer, query.refetch, query.fetch_more) as a callback's one thing."
275
+ "util_call": "A pure function, or an effect (ui.copy, task.answer, assign.start, query.refetch, query.fetch_more) as a callback's one thing."
269
276
  },
270
277
  "reserved_kinds": {
271
278
  "service_call": "Reserved for mutations, should they ever exist. Renderers refuse a call kind they do not know."
@@ -370,7 +377,7 @@
370
377
  "callback.positional": {"level": "error", "message": "{call}: a task call names its arguments (name: value)."},
371
378
  "callback.into": {"level": "error", "message": "into names the record of a task call: `<call> into <name>`.", "hint": "Write `deps.<key>.<action>(name: value) into run`, then read run.running, run.returns.<port>."},
372
379
  "callback.not_callback": {"level": "error", "message": "{key} of <{component}> is not a callback prop, so it cannot hold {what}.", "hint": "Use a callback prop of <{component}> (the catalog lists them as CALLBACK), or compute {key} without a call."},
373
- "callback.unbound": {"level": "error", "message": "{key} of <{component}> is a callback prop: it holds one task call or one effect (queries.<name>.refetch(), queries.<name>.fetch_more(...), ui.copy, task.answer).", "hint": "Give {key} a task call (deps.<key>.<action>(name: value)) or one effect, not a value."},
380
+ "callback.unbound": {"level": "error", "message": "{key} of <{component}> is a callback prop: it holds one task call or one effect (queries.<name>.refetch(), queries.<name>.fetch_more(...), ui.copy, task.answer, assign.start).", "hint": "Give {key} a task call (deps.<key>.<action>(name: value)) or one effect, not a value."},
374
381
  "callback.event_field": {"level": "error", "message": "event has no field {field!r} in {key} of <{component}> (its fields: {fields}).", "hint": "Read one of the fields listed for {key}: {fields}."},
375
382
  "roots.unknown": {"level": "error", "message": "{path} reads {root!r}, which is no root, local, loop variable or record of this blok.", "hint": "Read a root this blok has (deps.<key>, args.<key>, queries.<name>, ...), a declared local, a foreach let, or an into record."},
376
383
  "roots.not_in_kind": {"level": "error", "message": "{path}: a{n} {kind} blok has no {root!r} (it reads {roots}).", "hint": "Read one of {roots} instead."},
@@ -416,6 +423,7 @@
416
423
  "context.root": {"level": "error", "message": "The root of a {context} blok is <{root}>, not <{component}>.", "hint": "Make <{root}> the root and put <{component}> inside it."},
417
424
  "context.root_unknown": {"level": "error", "message": "A blok's root names its context ({roots}), not <{component}>.", "hint": "Make the root one of {roots} and put <{component}> inside it."},
418
425
  "context.kind": {"level": "error", "message": "A{n} {kind} blok is drawn in {contexts}, not {context}."},
426
+ "assign.kind": {"level": "error", "message": "{what} belongs to starting a run, so only an action's assign blok holds it, not a{n} {kind} blok.", "hint": "Declare it with the action: @app.workflow(assign_bloks=[...])."},
419
427
  "space.kind": {"level": "error", "message": "<{component}> places the run's dependencies, so only an action's own blok holds it, not a{n} {kind} blok.", "hint": "Declare it with the action: @app.workflow(bloks=[...])."},
420
428
  "logo.complexity": {"level": "error", "message": "{detail}"},
421
429
  "catalog.unknown_component": {"level": "warning", "message": "<{component}> is in no catalog in force ({catalogs}).", "hint": "Look the component up in the catalog; names are case-sensitive."},
@@ -53,6 +53,12 @@ export default {
53
53
  "locals": true,
54
54
  "contexts": ["HTML", "SCENE"]
55
55
  },
56
+ "assign": {
57
+ "description": "An action's own blok for starting a run of it (assign_bloks): shown before there is a task, with the arguments being filled in as args and the agents a run would get as deps.",
58
+ "roots": ["self", "deps", "args", "queries", "subscriptions", "viewer"],
59
+ "locals": true,
60
+ "contexts": ["HTML", "SCENE"]
61
+ },
56
62
  "action_logo": {
57
63
  "description": "An action's logo, drawn against the task the viewer last ran of it (null until then).",
58
64
  "roots": ["task"],
@@ -141,7 +147,7 @@ export default {
141
147
  ]
142
148
  },
143
149
  "functions": {
144
- "description": "Pure functions by namespace, snake_case. Positional arguments map onto params in order. `lazy`: arguments are read only as needed. `effect`: allowed only as a callback's one thing (ui.*, task.answer, query.*). `sees_status`: sees pending/failed instead of suspending. No function reads the wall clock. `null` says what the function does with a null argument (known absence); a missing path reads as null.",
150
+ "description": "Pure functions by namespace, snake_case. Positional arguments map onto params in order. `lazy`: arguments are read only as needed. `effect`: allowed only as a callback's one thing (ui.*, task.answer, assign.start, query.*). `sees_status`: sees pending/failed instead of suspending. No function reads the wall clock. `null` says what the function does with a null argument (known absence); a missing path reads as null.",
145
151
  "cmp.eq": {"params": [["a", "ANY"], ["b", "ANY"]], "returns": "BOOL", "description": "Deep JSON equality.", "null": "null equals only null"},
146
152
  "cmp.ne": {"params": [["a", "ANY"], ["b", "ANY"]], "returns": "BOOL", "description": "Not deep-equal.", "null": "null equals only null"},
147
153
  "cmp.gt": {"params": [["a", "ANY"], ["b", "ANY"]], "returns": "BOOL", "description": "a > b, numbers or strings.", "null": "false"},
@@ -251,6 +257,7 @@ export default {
251
257
  "time.diff": {"params": [["start", "STRING"], ["end", "STRING"]], "returns": "FLOAT", "description": "Seconds from start to end (ISO 8601 datetimes); negative when end is earlier. Pure: relative time to the viewed moment is the <Time> component's.", "null": "null"},
252
258
  "ui.copy": {"params": [["text", "ANY"]], "returns": "ANY", "effect": true, "description": "Copies text to the viewer's clipboard: the only non-task effect.", "null": "copies an empty string"},
253
259
  "task.answer": {"params": [["values", "DICT"]], "returns": "ANY", "effect": true, "task_operation": true, "description": "Answers the open ask of `task`. Counts as a task operation.", "null": "answers with no values"},
260
+ "assign.start": {"params": [], "returns": "ANY", "effect": true, "description": "Starts the run an assign blok prepares, with the arguments as they are filled in and the agents the blok was shown (deps) pinned. An assign blok only.", "null": "starts the run"},
254
261
  "query.refetch": {"params": [["query", "STRING"]], "returns": "ANY", "effect": true, "description": "Re-reads the declared query named by the literal `query`; never suspends, queries.<name>.refetching is true meanwhile. BSX writes it queries.<name>.refetch().", "null": "refused: the query is named by a literal"},
255
262
  "query.fetch_more": {"params": [["query", "STRING"], ["variables", "DICT", false]], "returns": "ANY", "effect": true, "description": "Reads the next page of the declared query named by the literal `query`, its variables overridden by `variables`, and appends the page's list at the query's `more` field to what is shown; queries.<name>.fetching_more is true meanwhile. BSX writes it queries.<name>.fetch_more(name: value, ...). Refused on a query without `more`.", "null": "refused: the query is named by a literal; null variables fetch with the query's own"}
256
263
  },
@@ -265,7 +272,7 @@ export default {
265
272
  "description": "What a prop or an argument may hold besides a literal, a path or a util call.",
266
273
  "kinds": {
267
274
  "agent_call": "A task call: self.<action>(...) or deps.<key>.<action>(...), only as a callback's one thing, optionally named with `into <name>` (stored as the prop's declares_value).",
268
- "util_call": "A pure function, or an effect (ui.copy, task.answer, query.refetch, query.fetch_more) as a callback's one thing."
275
+ "util_call": "A pure function, or an effect (ui.copy, task.answer, assign.start, query.refetch, query.fetch_more) as a callback's one thing."
269
276
  },
270
277
  "reserved_kinds": {
271
278
  "service_call": "Reserved for mutations, should they ever exist. Renderers refuse a call kind they do not know."
@@ -370,7 +377,7 @@ export default {
370
377
  "callback.positional": {"level": "error", "message": "{call}: a task call names its arguments (name: value)."},
371
378
  "callback.into": {"level": "error", "message": "into names the record of a task call: `<call> into <name>`.", "hint": "Write `deps.<key>.<action>(name: value) into run`, then read run.running, run.returns.<port>."},
372
379
  "callback.not_callback": {"level": "error", "message": "{key} of <{component}> is not a callback prop, so it cannot hold {what}.", "hint": "Use a callback prop of <{component}> (the catalog lists them as CALLBACK), or compute {key} without a call."},
373
- "callback.unbound": {"level": "error", "message": "{key} of <{component}> is a callback prop: it holds one task call or one effect (queries.<name>.refetch(), queries.<name>.fetch_more(...), ui.copy, task.answer).", "hint": "Give {key} a task call (deps.<key>.<action>(name: value)) or one effect, not a value."},
380
+ "callback.unbound": {"level": "error", "message": "{key} of <{component}> is a callback prop: it holds one task call or one effect (queries.<name>.refetch(), queries.<name>.fetch_more(...), ui.copy, task.answer, assign.start).", "hint": "Give {key} a task call (deps.<key>.<action>(name: value)) or one effect, not a value."},
374
381
  "callback.event_field": {"level": "error", "message": "event has no field {field!r} in {key} of <{component}> (its fields: {fields}).", "hint": "Read one of the fields listed for {key}: {fields}."},
375
382
  "roots.unknown": {"level": "error", "message": "{path} reads {root!r}, which is no root, local, loop variable or record of this blok.", "hint": "Read a root this blok has (deps.<key>, args.<key>, queries.<name>, ...), a declared local, a foreach let, or an into record."},
376
383
  "roots.not_in_kind": {"level": "error", "message": "{path}: a{n} {kind} blok has no {root!r} (it reads {roots}).", "hint": "Read one of {roots} instead."},
@@ -416,6 +423,7 @@ export default {
416
423
  "context.root": {"level": "error", "message": "The root of a {context} blok is <{root}>, not <{component}>.", "hint": "Make <{root}> the root and put <{component}> inside it."},
417
424
  "context.root_unknown": {"level": "error", "message": "A blok's root names its context ({roots}), not <{component}>.", "hint": "Make the root one of {roots} and put <{component}> inside it."},
418
425
  "context.kind": {"level": "error", "message": "A{n} {kind} blok is drawn in {contexts}, not {context}."},
426
+ "assign.kind": {"level": "error", "message": "{what} belongs to starting a run, so only an action's assign blok holds it, not a{n} {kind} blok.", "hint": "Declare it with the action: @app.workflow(assign_bloks=[...])."},
419
427
  "space.kind": {"level": "error", "message": "<{component}> places the run's dependencies, so only an action's own blok holds it, not a{n} {kind} blok.", "hint": "Declare it with the action: @app.workflow(bloks=[...])."},
420
428
  "logo.complexity": {"level": "error", "message": "{detail}"},
421
429
  "catalog.unknown_component": {"level": "warning", "message": "<{component}> is in no catalog in force ({catalogs}).", "hint": "Look the component up in the catalog; names are case-sensitive."},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkitektio/bsx",
3
- "version": "4.0.1",
3
+ "version": "4.2.0",
4
4
  "description": "The BSX language, the blok spec, runtime and React renderer: one copy for every Arkitekt frontend.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -170,6 +170,14 @@ export const blokContextOf = (component: string): string | null => loadVocabular
170
170
  /** Props whose value is the blok's dependency keys, written out (not paths): each must be a dependency. */
171
171
  const DEPENDENCY_KEY_PROPS = new Set(['Placed.dep', 'Route.through']);
172
172
 
173
+ /** The kinds that have a run's dependencies: an action's own bloks, for a run and for starting one. */
174
+ const RUN_KINDS: readonly string[] = ['action', 'assign'];
175
+ const ASSIGN_KIND = 'assign';
176
+ /** The form of the run's arguments, placed by an assign blok. */
177
+ const ARGS_COMPONENT = 'args';
178
+ /** Starts the run an assign blok prepares. */
179
+ const START_EFFECT = 'assign.start';
180
+
173
181
  const OPEN_IDENTIFIER = '*';
174
182
  const ITEM = '...';
175
183
  const TOAST_COMPONENT = 'Toast';
@@ -313,7 +321,7 @@ const DIGITS = /^[0-9]+$/;
313
321
  * - an agent blok has none: ``agent bloks read only `self` ``.
314
322
  */
315
323
  export const dependencyHint = (key: string, kind: BlokKind): string => {
316
- if (kind === 'action' || kind === 'action_logo') return `add a dependency parameter \`${key}\` to the action`;
324
+ if (kind === 'action' || kind === 'assign' || kind === 'action_logo') return `add a dependency parameter \`${key}\` to the action`;
317
325
  if (kind === 'agent') return 'agent bloks read only `self`';
318
326
  return `dependencies=[AgentDependencyInput(key="${key}")]`;
319
327
  };
@@ -567,6 +575,9 @@ class Checker {
567
575
  this.shadowed.add(node.component);
568
576
  this.add('catalog.shadow', node.id, {component: node.component, catalog: shadow.catalog, module: shadow.module, winner: shadow.winner});
569
577
  }
578
+ if (node.component === ARGS_COMPONENT && this.scope.kind !== ASSIGN_KIND) {
579
+ this.add('assign.kind', node.id, {what: '<args>', n: article(this.scope.kind), kind: this.scope.kind});
580
+ }
570
581
  for (const prop of node.props ?? []) this.checkProp(node, prop, spec);
571
582
  }
572
583
 
@@ -609,7 +620,7 @@ class Checker {
609
620
 
610
621
  /** A ``Placed dep`` or ``Route through`` names dependencies of the blok, written out as keys. */
611
622
  private checkDependencyKeys(node: BlokComponentNode, prop: BlokComponentProp): void {
612
- if (this.scope.kind !== 'action') {
623
+ if (!RUN_KINDS.includes(this.scope.kind)) {
613
624
  this.add('space.kind', node.id, {component: node.component, n: article(this.scope.kind), kind: this.scope.kind}, prop.key);
614
625
  return;
615
626
  }
@@ -672,9 +683,12 @@ class Checker {
672
683
  }
673
684
  }
674
685
  }
686
+ if (prop.util_call?.operation === START_EFFECT && this.scope.kind !== ASSIGN_KIND) {
687
+ this.add('assign.kind', node.id, {what: 'assign.start()', n: article(this.scope.kind), kind: this.scope.kind}, prop.key);
688
+ }
675
689
  if (DEPENDENCY_KEY_PROPS.has(`${node.component}.${prop.key}`)) this.checkDependencyKeys(node, prop);
676
- if (node.component === 'Space' && prop.key === 'room' && this.scope.kind !== 'action') {
677
- // A Space places the run's dependencies: only an action's own blok has a run.
690
+ if (node.component === 'Space' && prop.key === 'room' && !RUN_KINDS.includes(this.scope.kind)) {
691
+ // A Space places the run's dependencies: only an action's own blok (for a run, or for starting one) has them.
678
692
  this.add('space.kind', node.id, {component: node.component, n: article(this.scope.kind), kind: this.scope.kind}, prop.key);
679
693
  }
680
694
  if (node.component === TOAST_COMPONENT && prop.key === TOAST_TASK_PROP) {
@@ -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
+ });