@synap-core/workspace-templates 0.66.0 → 0.68.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.
@@ -56,7 +56,13 @@ const WIDGET_LIFECYCLE = {
56
56
  ],
57
57
  };
58
58
  const owner = {
59
- meta: { slug: "owner", name: "Owner", description: "d", icon: "x", color: "gray" },
59
+ meta: {
60
+ slug: "owner",
61
+ name: "Owner",
62
+ description: "d",
63
+ icon: "x",
64
+ color: "gray",
65
+ },
60
66
  workspace: { name: "Owner", description: "d" },
61
67
  profiles: [
62
68
  {
@@ -65,24 +71,51 @@ const owner = {
65
71
  scope: "shared",
66
72
  lifecycle: WIDGET_LIFECYCLE,
67
73
  properties: [
68
- { slug: "widget-stage", label: "Stage", valueType: "string", inputType: "select", enumValues: ["New", "Built", "Shipped", "Archived"] },
69
- { slug: "widget-notes", label: "Notes", valueType: "string", inputType: "text" },
74
+ {
75
+ slug: "widget-stage",
76
+ label: "Stage",
77
+ valueType: "string",
78
+ inputType: "select",
79
+ enumValues: ["New", "Built", "Shipped", "Archived"],
80
+ },
81
+ {
82
+ slug: "widget-notes",
83
+ label: "Notes",
84
+ valueType: "string",
85
+ inputType: "text",
86
+ },
70
87
  ],
71
88
  },
72
89
  ],
73
- entityLinks: [{ sourceProfileSlug: "widget", targetProfileSlug: "widget", type: "spawned_from", label: "Spawned from" }],
90
+ entityLinks: [
91
+ {
92
+ sourceProfileSlug: "widget",
93
+ targetProfileSlug: "widget",
94
+ type: "spawned_from",
95
+ label: "Spawned from",
96
+ },
97
+ ],
74
98
  } as unknown as WorkspaceYaml;
75
99
 
76
- function proc(mutate: (pb: Record<string, any>) => void = () => {}): WorkspaceYaml {
100
+ function proc(
101
+ mutate: (pb: Record<string, any>) => void = () => {}
102
+ ): WorkspaceYaml {
77
103
  const pb: Record<string, any> = {
78
104
  name: "Build Widget",
79
105
  goalTemplate: "Build {widget}",
80
106
  params: [{ name: "widget", type: "entity", required: true }],
81
107
  subjectProfile: { profileSlug: "widget" },
82
108
  activators: [{ on: "enters_status", status: "Built", mode: "propose" }],
83
- expectedOutputs: [{ kind: "widget", label: "Spin-off", relationToSubject: "spawned_from" }],
109
+ expectedOutputs: [
110
+ { kind: "widget", label: "Spin-off", relationToSubject: "spawned_from" },
111
+ ],
84
112
  stages: [
85
- { key: "build", name: "Build", category: "started", subjectStatus: "Built" },
113
+ {
114
+ key: "build",
115
+ name: "Build",
116
+ category: "started",
117
+ subjectStatus: "Built",
118
+ },
86
119
  {
87
120
  key: "ship",
88
121
  name: "Ship",
@@ -90,16 +123,35 @@ function proc(mutate: (pb: Record<string, any>) => void = () => {}): WorkspaceYa
90
123
  subjectStatus: "Shipped",
91
124
  gate: { kind: "human" },
92
125
  onFail: { toStage: "build" },
93
- expectedOutputs: [{ kind: "widget", label: "Release", relationToSubject: "spawned_from" }],
126
+ expectedOutputs: [
127
+ {
128
+ kind: "widget",
129
+ label: "Release",
130
+ relationToSubject: "spawned_from",
131
+ },
132
+ ],
94
133
  },
95
134
  ],
96
135
  };
97
136
  mutate(pb);
98
137
  return {
99
- meta: { slug: "proc", name: "Proc", description: "d", icon: "x", color: "gray" },
138
+ meta: {
139
+ slug: "proc",
140
+ name: "Proc",
141
+ description: "d",
142
+ icon: "x",
143
+ color: "gray",
144
+ },
100
145
  workspace: { name: "Proc", description: "d" },
101
146
  dependencies: [{ slug: "owner", kind: "workspace", relation: "require" }],
102
- profiles: [{ slug: "widget", displayName: "Widget", scope: "shared", properties: [] }],
147
+ profiles: [
148
+ {
149
+ slug: "widget",
150
+ displayName: "Widget",
151
+ scope: "shared",
152
+ properties: [],
153
+ },
154
+ ],
103
155
  playbooks: [pb],
104
156
  } as unknown as WorkspaceYaml;
105
157
  }
@@ -120,60 +172,88 @@ describe("process contract — each rule fires on its own fixture", () => {
120
172
  // Negative control: each assertion goes red with the `playbook-field-retired`
121
173
  // loop removed from checkProcessContract.
122
174
  it("each retired field is refused (statusProperty, onEnd, humanOnlyStatuses, schedule)", () => {
123
- expect(rulesOf(proc((pb) => (pb.subjectProfile.statusProperty = "widget-stage")))).toEqual([
124
- "playbook-field-retired",
125
- ]);
126
- expect(rulesOf(proc((pb) => (pb.subjectProfile.onEnd = { cancelled: "New" })))).toEqual([
175
+ expect(
176
+ rulesOf(proc((pb) => (pb.subjectProfile.statusProperty = "widget-stage")))
177
+ ).toEqual(["playbook-field-retired"]);
178
+ expect(
179
+ rulesOf(proc((pb) => (pb.subjectProfile.onEnd = { cancelled: "New" })))
180
+ ).toEqual(["playbook-field-retired"]);
181
+ expect(rulesOf(proc((pb) => (pb.humanOnlyStatuses = ["New"])))).toEqual([
127
182
  "playbook-field-retired",
128
183
  ]);
129
- expect(rulesOf(proc((pb) => (pb.humanOnlyStatuses = ["New"])))).toEqual(["playbook-field-retired"]);
130
- expect(rulesOf(proc((pb) => (pb.schedule = { cron: "0 8 * * *", enabled: true })))).toEqual(["playbook-field-retired"]);
184
+ expect(
185
+ rulesOf(
186
+ proc((pb) => (pb.schedule = { cron: "0 8 * * *", enabled: true }))
187
+ )
188
+ ).toEqual(["playbook-field-retired"]);
131
189
  });
132
190
 
133
191
  it("a stage subjectStatus outside the enum", () => {
134
- expect(rulesOf(proc((pb) => (pb.stages[0].subjectStatus = "Done")))).toEqual([
135
- "stage-subject-status-unknown",
136
- ]);
192
+ expect(
193
+ rulesOf(proc((pb) => (pb.stages[0].subjectStatus = "Done")))
194
+ ).toEqual(["stage-subject-status-unknown"]);
137
195
  });
138
196
 
139
197
  it("a stage subjectStatus on a kind that declares no lifecycle", () => {
140
- const noLifecycle = structuredClone(owner) as unknown as { profiles: Array<Record<string, unknown>> };
198
+ const noLifecycle = structuredClone(owner) as unknown as {
199
+ profiles: Array<Record<string, unknown>>;
200
+ };
141
201
  delete noLifecycle.profiles[0]!.lifecycle;
142
- const tpl = proc((pb) => (pb.activators = [{ on: "created", mode: "propose" }]));
143
- const { errors } = validateTemplate(tpl, { corpus: [noLifecycle as unknown as WorkspaceYaml, tpl] });
144
- expect(errors.filter((e) => PROCESS_RULES.has(e.rule)).map((e) => e.rule)).toEqual([
202
+ const tpl = proc(
203
+ (pb) => (pb.activators = [{ on: "created", mode: "propose" }])
204
+ );
205
+ const { errors } = validateTemplate(tpl, {
206
+ corpus: [noLifecycle as unknown as WorkspaceYaml, tpl],
207
+ });
208
+ expect(
209
+ errors.filter((e) => PROCESS_RULES.has(e.rule)).map((e) => e.rule)
210
+ ).toEqual([
145
211
  "stage-subject-status-unknown-no-lifecycle",
146
212
  "stage-subject-status-unknown-no-lifecycle",
147
213
  ]);
148
214
  });
149
215
 
150
216
  it("onFail.toStage naming no stage of the playbook", () => {
151
- expect(rulesOf(proc((pb) => (pb.stages[1].onFail = { toStage: "qa" })))).toEqual([
152
- "stage-onfail-unknown",
153
- ]);
217
+ expect(
218
+ rulesOf(proc((pb) => (pb.stages[1].onFail = { toStage: "qa" })))
219
+ ).toEqual(["stage-onfail-unknown"]);
154
220
  });
155
221
 
156
222
  it("onFail.toStage may name a stage by its name", () => {
157
- expect(rulesOf(proc((pb) => (pb.stages[1].onFail = { toStage: "Build" })))).toEqual([]);
223
+ expect(
224
+ rulesOf(proc((pb) => (pb.stages[1].onFail = { toStage: "Build" })))
225
+ ).toEqual([]);
158
226
  });
159
227
 
160
228
  it("an activator status outside the enum", () => {
161
229
  expect(
162
- rulesOf(proc((pb) => (pb.activators = [{ on: "enters_status", status: "Done", mode: "run" }])))
230
+ rulesOf(
231
+ proc(
232
+ (pb) =>
233
+ (pb.activators = [
234
+ { on: "enters_status", status: "Done", mode: "run" },
235
+ ])
236
+ )
237
+ )
163
238
  ).toEqual(["activator-status-unknown"]);
164
239
  });
165
240
 
166
241
  it("an enters_status activator with no status", () => {
167
- expect(rulesOf(proc((pb) => (pb.activators = [{ on: "enters_status", mode: "propose" }])))).toEqual([
168
- "activator-status-required",
169
- ]);
242
+ expect(
243
+ rulesOf(
244
+ proc(
245
+ (pb) => (pb.activators = [{ on: "enters_status", mode: "propose" }])
246
+ )
247
+ )
248
+ ).toEqual(["activator-status-required"]);
170
249
  });
171
250
 
172
251
  it("an activator with an unknown trigger or mode", () => {
173
- expect(rulesOf(proc((pb) => (pb.activators = [{ on: "updated", mode: "always" }])))).toEqual([
174
- "activator-on-invalid",
175
- "activator-mode-invalid",
176
- ]);
252
+ expect(
253
+ rulesOf(
254
+ proc((pb) => (pb.activators = [{ on: "updated", mode: "always" }]))
255
+ )
256
+ ).toEqual(["activator-on-invalid", "activator-mode-invalid"]);
177
257
  });
178
258
 
179
259
  /**
@@ -188,22 +268,52 @@ describe("process contract — each rule fires on its own fixture", () => {
188
268
  proc(
189
269
  (pb) =>
190
270
  (pb.activators = [
191
- { on: "count", status: "Built", min: 5, size: "per_moment", mode: "propose", maxPendingApprovals: 10 },
192
- { on: "schedule", cron: "0 9 * * 1", status: "Built", mode: "run" },
271
+ {
272
+ on: "count",
273
+ status: "Built",
274
+ min: 5,
275
+ size: "per_moment",
276
+ mode: "propose",
277
+ maxPendingApprovals: 10,
278
+ },
279
+ {
280
+ on: "schedule",
281
+ cron: "0 9 * * 1",
282
+ status: "Built",
283
+ mode: "run",
284
+ },
193
285
  { on: "manual", mode: "propose" },
194
286
  ])
195
287
  )
196
288
  )
197
289
  ).toEqual([]);
198
290
  expect(
199
- rulesOf(proc((pb) => (pb.activators = [{ on: "count", status: "Done", min: 5, mode: "propose" }])))
291
+ rulesOf(
292
+ proc(
293
+ (pb) =>
294
+ (pb.activators = [
295
+ { on: "count", status: "Done", min: 5, mode: "propose" },
296
+ ])
297
+ )
298
+ )
200
299
  ).toEqual(["activator-status-unknown"]);
201
- expect(rulesOf(proc((pb) => (pb.activators = [{ on: "count", min: 5, mode: "propose" }])))).toEqual([
202
- "activator-status-required",
203
- ]);
204
- expect(rulesOf(proc((pb) => (pb.activators = [{ on: "manual", status: "Built", mode: "propose" }])))).toEqual([
205
- "activator-status-unexpected",
206
- ]);
300
+ expect(
301
+ rulesOf(
302
+ proc(
303
+ (pb) => (pb.activators = [{ on: "count", min: 5, mode: "propose" }])
304
+ )
305
+ )
306
+ ).toEqual(["activator-status-required"]);
307
+ expect(
308
+ rulesOf(
309
+ proc(
310
+ (pb) =>
311
+ (pb.activators = [
312
+ { on: "manual", status: "Built", mode: "propose" },
313
+ ])
314
+ )
315
+ )
316
+ ).toEqual(["activator-status-unexpected"]);
207
317
  });
208
318
 
209
319
  it("an activator on a playbook with no subject kind", () => {
@@ -231,26 +341,35 @@ describe("process contract — each rule fires on its own fixture", () => {
231
341
  });
232
342
 
233
343
  it("a playbook-level relationToSubject the corpus does not define", () => {
234
- expect(rulesOf(proc((pb) => (pb.expectedOutputs[0].relationToSubject = "spawned_by")))).toEqual([
235
- "output-relation-unknown",
236
- ]);
344
+ expect(
345
+ rulesOf(
346
+ proc((pb) => (pb.expectedOutputs[0].relationToSubject = "spawned_by"))
347
+ )
348
+ ).toEqual(["output-relation-unknown"]);
237
349
  });
238
350
 
239
351
  it("a stage-level relationToSubject the corpus does not define", () => {
240
352
  expect(
241
- rulesOf(proc((pb) => (pb.stages[1].expectedOutputs[0].relationToSubject = "spawned_by")))
353
+ rulesOf(
354
+ proc(
355
+ (pb) =>
356
+ (pb.stages[1].expectedOutputs[0].relationToSubject = "spawned_by")
357
+ )
358
+ )
242
359
  ).toEqual(["output-relation-unknown"]);
243
360
  });
244
361
 
245
362
  it("an output `optional` that is not a boolean, at playbook and stage level", () => {
246
363
  // The pod reads `optional` strictly (only a real `true`): a quoted value
247
364
  // would leave the slot owed while the YAML reads as if it were not.
248
- expect(rulesOf(proc((pb) => (pb.expectedOutputs[0].optional = "true")))).toEqual([
249
- "output-optional-not-boolean",
250
- ]);
251
- expect(rulesOf(proc((pb) => (pb.stages[1].expectedOutputs[0].optional = "false")))).toEqual([
252
- "output-optional-not-boolean",
253
- ]);
365
+ expect(
366
+ rulesOf(proc((pb) => (pb.expectedOutputs[0].optional = "true")))
367
+ ).toEqual(["output-optional-not-boolean"]);
368
+ expect(
369
+ rulesOf(
370
+ proc((pb) => (pb.stages[1].expectedOutputs[0].optional = "false"))
371
+ )
372
+ ).toEqual(["output-optional-not-boolean"]);
254
373
  // A real boolean is clean at both levels.
255
374
  expect(
256
375
  rulesOf(
@@ -263,8 +382,11 @@ describe("process contract — each rule fires on its own fixture", () => {
263
382
  });
264
383
 
265
384
  it("a DEFAULT relation (base.yaml relationDefs) resolves through the corpus", () => {
266
- const base = readYamlTemplates().find((t) => t.slug === "base")!.data as WorkspaceYaml;
267
- const tpl = proc((pb) => (pb.expectedOutputs[0].relationToSubject = "relates_to"));
385
+ const base = readYamlTemplates().find((t) => t.slug === "base")!
386
+ .data as WorkspaceYaml;
387
+ const tpl = proc(
388
+ (pb) => (pb.expectedOutputs[0].relationToSubject = "relates_to")
389
+ );
268
390
  const { errors } = validateTemplate(tpl, { corpus: [owner, base, tpl] });
269
391
  expect(errors.filter((e) => PROCESS_RULES.has(e.rule))).toEqual([]);
270
392
  // …and the same value is refused when base is not in the corpus.
@@ -290,12 +412,20 @@ describe("process contract — each rule fires on its own fixture", () => {
290
412
  });
291
413
 
292
414
  describe("process contract — a session keeps at most MAX_SESSION_CRITERIA criteria", () => {
293
- const crit = (key: string) => ({ key, statement: `${key} holds.`, check: { kind: "judge" } });
415
+ const crit = (key: string) => ({
416
+ key,
417
+ statement: `${key} holds.`,
418
+ check: { kind: "judge" },
419
+ });
294
420
  const withCriteria = (playbookLevel: number, perStage: number) =>
295
421
  proc((pb) => {
296
- pb.criteria = Array.from({ length: playbookLevel }, (_, i) => crit(`pb-${i}`));
422
+ pb.criteria = Array.from({ length: playbookLevel }, (_, i) =>
423
+ crit(`pb-${i}`)
424
+ );
297
425
  pb.stages.forEach((s: Record<string, any>) => {
298
- s.criteria = Array.from({ length: perStage }, (_, i) => crit(`${s.key}-${i}`));
426
+ s.criteria = Array.from({ length: perStage }, (_, i) =>
427
+ crit(`${s.key}-${i}`)
428
+ );
299
429
  });
300
430
  });
301
431
 
@@ -306,7 +436,9 @@ describe("process contract — a session keeps at most MAX_SESSION_CRITERIA crit
306
436
 
307
437
  it("one over the cap is refused (the pod drops the extra one silently)", () => {
308
438
  // 3 + 2 × 5 = 13
309
- expect(rulesOf(withCriteria(3, 5))).toEqual(["playbook-criteria-over-session-cap"]);
439
+ expect(rulesOf(withCriteria(3, 5))).toEqual([
440
+ "playbook-criteria-over-session-cap",
441
+ ]);
310
442
  });
311
443
 
312
444
  it("a key repeated across stages counts once, as the pod keeps it once", () => {
@@ -322,23 +454,37 @@ const BACKEND_PLAYBOOKS = resolve(
322
454
  dirname(fileURLToPath(import.meta.url)),
323
455
  "../../../../synap-backend/packages/playbooks/src/index.ts"
324
456
  );
325
- describe.skipIf(!existsSync(BACKEND_PLAYBOOKS))("MAX_SESSION_CRITERIA mirrors the pod's cap", () => {
326
- if (!existsSync(BACKEND_PLAYBOOKS))
327
- console.warn(`[process-contract] SKIP: no synap-backend checkout at ${BACKEND_PLAYBOOKS}`);
328
- it("equals @synap/playbooks MAX_SESSION_CRITERIA", () => {
329
- const m = readFileSync(BACKEND_PLAYBOOKS, "utf8").match(/export const MAX_SESSION_CRITERIA = (\d+);/);
330
- expect(m, "the pod's MAX_SESSION_CRITERIA declaration was not found").not.toBeNull();
331
- expect(MAX_SESSION_CRITERIA).toBe(Number(m![1]));
332
- });
333
- });
457
+ describe.skipIf(!existsSync(BACKEND_PLAYBOOKS))(
458
+ "MAX_SESSION_CRITERIA mirrors the pod's cap",
459
+ () => {
460
+ if (!existsSync(BACKEND_PLAYBOOKS))
461
+ console.warn(
462
+ `[process-contract] SKIP: no synap-backend checkout at ${BACKEND_PLAYBOOKS}`
463
+ );
464
+ it("equals @synap/playbooks MAX_SESSION_CRITERIA", () => {
465
+ const m = readFileSync(BACKEND_PLAYBOOKS, "utf8").match(
466
+ /export const MAX_SESSION_CRITERIA = (\d+);/
467
+ );
468
+ expect(
469
+ m,
470
+ "the pod's MAX_SESSION_CRITERIA declaration was not found"
471
+ ).not.toBeNull();
472
+ expect(MAX_SESSION_CRITERIA).toBe(Number(m![1]));
473
+ });
474
+ }
475
+ );
334
476
 
335
477
  describe("process contract — the shipped corpus", () => {
336
478
  it("non-vacuity: Content OS declares the contract, and the whole corpus passes it", () => {
337
479
  const corpus = readYamlTemplates().map((t) => t.data as WorkspaceYaml);
338
480
  const contentOs = corpus.find((t) => t.meta.slug === "content-os")!;
339
- const produce = contentOs.playbooks!.find((p) => p.name === "Produce Content")!;
481
+ const produce = contentOs.playbooks!.find(
482
+ (p) => p.name === "Produce Content"
483
+ )!;
340
484
  expect(produce.subjectProfile).toEqual({ profileSlug: "post" });
341
- expect(contentOs.profiles.find((p) => p.slug === "post")?.lifecycle?.property).toBe("post-status");
485
+ expect(
486
+ contentOs.profiles.find((p) => p.slug === "post")?.lifecycle?.property
487
+ ).toBe("post-status");
342
488
  // D2: two statuses held while worked (In Draft, Review), four reached on
343
489
  // approval (Briefed, Scripted, Scheduled, Published).
344
490
  expect(produce.stages!.filter((s) => s.subjectStatus).length).toBe(2);