@synap-core/workspace-templates 0.74.1 → 0.76.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/src/crm.yaml CHANGED
@@ -2661,7 +2661,9 @@ playbooks:
2661
2661
  attention.count, sessions.list, lifecycle.home, lifecycle.moving,
2662
2662
  documents.get, lens.page, sessions.get, playbook.process,
2663
2663
  playbook.scorecard, project.pillars, views.get, views.execute,
2664
- profiles.get, propertyDefs.list, lifecycle.get, graph.of) and only that
2664
+ profiles.get, propertyDefs.list, lifecycle.get, graph.of,
2665
+ automations.list, automations.runs, playbooks.list, surfaces.of,
2666
+ connections.list, capabilities.list) and only that
2665
2667
  op's params; the host stamps the space, so never put a workspaceId, a token, a pod URL
2666
2668
  or a fetch in the page. What the bridge reads stays live: query it in
2667
2669
  the page, never
@@ -22,9 +22,19 @@
22
22
  * writes the first stage's status: a change further along must not be
23
23
  * pulled back), and it is a draft with no activators;
24
24
  * 5. Ship a change waits on the change with an entity hold.
25
+ * 6. "A pull request names its change's session" fills the change's Session
26
+ * from the session the pod stamps on its dev fact, only when the fact
27
+ * names one, the change exists and names none yet: run on two recorded
28
+ * facts (`__fixtures__/dev-facts.pull-request-opened.json`), and each case
29
+ * shown to rule a condition out (drop it, then that case writes).
25
30
  *
26
31
  * Not covered: a pod running it against GitHub's real payloads (NEEDS-DOGFOOD).
32
+ * The session flow runs here through `runFlow` below, a copy of the pod
33
+ * executor's semantics for the node types it uses (template paths, the
34
+ * condition grammar, a query matching properties, `yes` edges): the real
35
+ * executor (backend packages/jobs) is not run.
27
36
  */
37
+ import { readFileSync } from "node:fs";
28
38
  import { describe, expect, it } from "vitest";
29
39
  import { readYamlTemplates } from "./generate.mjs";
30
40
  import { validateFlowDefinition } from "./validate-flow.js";
@@ -190,3 +200,163 @@ describe("Ship a change waits on the change", () => {
190
200
  }
191
201
  });
192
202
  });
203
+
204
+ describe("A pull request names its change's session", () => {
205
+ const named = (builder.automations ?? []).find((a: any) => a.key === "pull-request-names-change-session");
206
+ type Flow = { nodes: FlowNode[]; edges: FlowEdge[] };
207
+ const flow: Flow = named?.flow;
208
+ const recorded = JSON.parse(
209
+ readFileSync(new URL("./__fixtures__/dev-facts.pull-request-opened.json", import.meta.url), "utf8")
210
+ ) as {
211
+ facts: Record<"namesSession" | "namesNone", { eventType: string; data: Record<string, unknown> }>;
212
+ changes: { id: string; properties: Record<string, unknown> }[];
213
+ };
214
+
215
+ /** `{{a.b[0].c}}` read the way the pod reads it: a miss or a null renders "". */
216
+ function lookup(path: string, ctx: Record<string, unknown>): unknown {
217
+ let cur: any = ctx;
218
+ for (const part of path.trim().replace(/\[(\d+)\]/g, ".$1").split(".")) {
219
+ if (cur == null || typeof cur !== "object") return undefined;
220
+ cur = cur[part];
221
+ }
222
+ return cur;
223
+ }
224
+ const render = (t: string, ctx: Record<string, unknown>) =>
225
+ t.replace(/\{\{(.+?)\}\}/g, (_, p: string) => {
226
+ const v = lookup(p, ctx);
227
+ return v == null ? "" : typeof v === "object" ? JSON.stringify(v) : String(v);
228
+ });
229
+ /** The pod's condition grammar (condition-eval.ts), for the operators this flow uses. */
230
+ function condition(expr: string, ctx: Record<string, unknown>): boolean {
231
+ const m = /^(.+?)\s*(===|!==|==|!=|>=|<=|>|<)\s*(.+)$/.exec(expr)!;
232
+ const [, leftPath, op, rightRaw] = m;
233
+ const r = rightRaw.trim();
234
+ const right: string | number = /^(["']).*\1$/.test(r) ? r.slice(1, -1) : r !== "" && !isNaN(Number(r)) ? Number(r) : r;
235
+ const leftStr = render(`{{${leftPath}}}`, ctx);
236
+ const left = typeof right === "number" ? (leftStr === "" ? NaN : Number(leftStr)) : leftStr;
237
+ switch (op) {
238
+ case "==": case "===": return left === right;
239
+ case "!=": case "!==": return left !== right;
240
+ case ">=": return Number(left) >= Number(right);
241
+ default: throw new Error(`operator ${op} is not simulated`);
242
+ }
243
+ }
244
+ /** Walk the flow on one fact: what it writes (entity_update), given the changes on the pod. */
245
+ function runFlow(f: Flow, fact: { eventType: string; data: Record<string, unknown> }, changes: typeof recorded.changes) {
246
+ const ctx: Record<string, any> = { trigger: { payload: { eventType: fact.eventType, data: fact.data } }, steps: {} };
247
+ const writes: { entityId: string; properties: Record<string, string> }[] = [];
248
+ const queue = f.nodes.filter((n) => n.type === "trigger").map((n) => n.id);
249
+ const done = new Set<string>();
250
+ while (queue.length) {
251
+ const next = queue.shift()!;
252
+ const n = f.nodes.find((x) => x.id === next)!;
253
+ if (done.has(n.id)) continue;
254
+ done.add(n.id);
255
+ let handle: string | undefined;
256
+ if (n.type === "condition") {
257
+ handle = condition(n.data.expression, ctx) ? "yes" : "no";
258
+ ctx.steps[n.id] = { output: { result: handle === "yes" } };
259
+ } else if (n.type === "query") {
260
+ const filter = JSON.parse(render(n.data.filter, ctx)) as Record<string, string>;
261
+ const hits = changes.filter((c) => Object.entries(filter).every(([k, v]) => String(c.properties[k]) === v));
262
+ const entities = hits.slice(0, n.data.limit);
263
+ ctx.steps[n.id] = { output: { count: entities.length, entities } };
264
+ } else if (n.type === "output") {
265
+ expect(n.data.outputType).toBe("entity_update");
266
+ const props = Object.fromEntries(
267
+ Object.entries(n.data.config.properties as Record<string, string>).map(([k, v]) => [k, render(v, ctx)])
268
+ );
269
+ writes.push({ entityId: render(n.data.config.entityId, ctx), properties: props });
270
+ } else if (!["trigger", "delay"].includes(n.type)) {
271
+ throw new Error(`node type ${n.type} is not simulated`);
272
+ }
273
+ for (const e of f.edges.filter((e) => e.source === n.id)) {
274
+ if (e.sourceHandle === undefined || e.sourceHandle === handle) queue.push(e.target);
275
+ }
276
+ }
277
+ return writes;
278
+ }
279
+ /** The flow with one node cut out, its predecessor wired straight to its successors. */
280
+ function without(id: string): Flow {
281
+ const into = flow.edges.filter((e) => e.target === id);
282
+ const out = flow.edges.filter((e) => e.source === id);
283
+ const kept = flow.edges.filter((e) => e.source !== id && e.target !== id);
284
+ const bridged = into.flatMap((i) => out.map((o) => ({ ...i, id: `${i.id}~${o.id}`, target: o.target })));
285
+ return { nodes: flow.nodes.filter((n) => n.id !== id), edges: [...kept, ...bridged] };
286
+ }
287
+ const change1504 = recorded.changes.find((c) => c.properties.prRef === "Synap-core/backend#1504")!;
288
+ const sessionOf1504 = recorded.facts.namesSession.data.sessionId as string;
289
+
290
+ it("listens to the pod's dev facts, passes the flow validator, and writes the change's Session only", () => {
291
+ expect(named.triggerType).toBe("event");
292
+ expect(named.triggerConfig).toEqual({ eventPattern: "dev.*" });
293
+ expect(flow.nodes.find((n) => n.type === "trigger")!.data.config).toEqual({ eventPattern: "dev.*" });
294
+ expect(validateFlowDefinition(flow).errors).toEqual([]);
295
+ const outs = flow.nodes.filter((n) => n.type === "output");
296
+ expect(outs.map((n) => [n.data.outputType, Object.keys(n.data.config.properties)])).toEqual([
297
+ ["entity_update", ["session"]],
298
+ ]);
299
+ expect(propertySlugs.has("session")).toBe(true);
300
+ expect(outs[0].data.config.properties.session).toBe("{{trigger.payload.data.sessionId}}");
301
+ });
302
+
303
+ it("finds the change by the prRef 'A pull request moves its change' writes", () => {
304
+ const find = flow.nodes.find((n) => n.type === "query")!;
305
+ expect(find.data.profileSlug).toBe("change");
306
+ const written = (node("upsert").data.config.properties.prRef as string).replace(/\{\{[^}]*\}\}/g, "x");
307
+ const read = (JSON.parse(find.data.filter).prRef as string).replace(/\{\{[^}]*\}\}/g, "x");
308
+ expect(read).toBe(written); // both "x#x": owner/name, then the number
309
+ });
310
+
311
+ it("the write is reachable only through each of its three conditions (yes)", () => {
312
+ const reach = (f: Flow, blocked: string) => {
313
+ const seen = new Set<string>();
314
+ const q = ["t"];
315
+ while (q.length) {
316
+ const id = q.shift()!;
317
+ if (seen.has(id) || id === blocked) continue;
318
+ seen.add(id);
319
+ q.push(...f.edges.filter((e) => e.source === id).map((e) => e.target));
320
+ }
321
+ return seen.has("name-session");
322
+ };
323
+ const conditions = flow.nodes.filter((n) => n.type === "condition").map((n) => n.id);
324
+ expect(conditions).toEqual(["names-session", "has-change", "no-session-yet"]);
325
+ expect(reach(flow, "none")).toBe(true);
326
+ for (const id of conditions) {
327
+ expect(reach(flow, id), id).toBe(false);
328
+ expect(flow.edges.filter((e) => e.source === id).map((e) => e.sourceHandle), id).toEqual(["yes"]);
329
+ }
330
+ // It waits before it looks: the delay sits before the query.
331
+ expect(flow.edges.find((e) => e.target === "find")!.source).toBe("wait");
332
+ expect(flow.nodes.find((n) => n.id === "wait")!.data.duration).toMatch(/^\d+\s*(s|m)$/);
333
+ });
334
+
335
+ it("a recorded fact that names a session fills the change's Session with it", () => {
336
+ expect(String(recorded.facts.namesSession.data.body)).toContain(`Pod session: ${sessionOf1504}`);
337
+ expect(change1504.properties.session).toBeUndefined();
338
+ expect(runFlow(flow, recorded.facts.namesSession, recorded.changes)).toEqual([
339
+ { entityId: change1504.id, properties: { session: sessionOf1504 } },
340
+ ]);
341
+ });
342
+
343
+ it("a fact that names no session writes nothing (and the case rules out dropping that condition)", () => {
344
+ expect(recorded.facts.namesNone.data.sessionId).toBeUndefined();
345
+ expect(runFlow(flow, recorded.facts.namesNone, recorded.changes)).toEqual([]);
346
+ expect(runFlow(without("names-session"), recorded.facts.namesNone, recorded.changes)).not.toEqual([]);
347
+ });
348
+
349
+ it("a change that already names a session keeps it (and the case rules out dropping that condition)", () => {
350
+ const taken = recorded.changes.map((c) =>
351
+ c.id === change1504.id ? { ...c, properties: { ...c.properties, session: "00000000-0000-4000-8000-000000000001" } } : c
352
+ );
353
+ expect(runFlow(flow, recorded.facts.namesSession, taken)).toEqual([]);
354
+ expect(runFlow(without("no-session-yet"), recorded.facts.namesSession, taken)).not.toEqual([]);
355
+ });
356
+
357
+ it("a pull request with no change yet writes nothing (and the case rules out dropping that condition)", () => {
358
+ const none = recorded.changes.filter((c) => c.id !== change1504.id);
359
+ expect(runFlow(flow, recorded.facts.namesSession, none)).toEqual([]);
360
+ expect(runFlow(without("has-change"), recorded.facts.namesSession, none)).not.toEqual([]);
361
+ });
362
+ });
@@ -3,4 +3,4 @@ export declare const FRAME_HOST_MODULES: readonly string[];
3
3
  export declare const FRAME_HOST_MODULE_RE: RegExp;
4
4
  export declare function hostRequiresIn(code: string): string[];
5
5
  export declare const FRAME_KIT_MODULE: string;
6
- export declare function kitImportsIn(code: string): string[];
6
+ export declare function kitImportsIn(code: string, specifier?: string): string[];
@@ -24,10 +24,13 @@ export const FRAME_KIT_MODULE = '@synap/kit';
24
24
  * Every name a bundle imports from the kit: `import{A as b,C}from"@synap/kit"`
25
25
  * → `['A', 'C']`. A namespace or default import of the kit is returned as
26
26
  * `*` / `default` so the build can refuse it (its names cannot be checked).
27
+ * `specifier`: another host module read the same way (a kit layer,
28
+ * `@synap/kit/editor`).
27
29
  */
28
- export function kitImportsIn(code) {
30
+ export function kitImportsIn(code, specifier = FRAME_KIT_MODULE) {
29
31
  const names = new Set();
30
- for (const m of code.matchAll(/import\s*([^;'"]*?)\s*from\s*["']@synap\/kit["']/g)) {
32
+ const quoted = specifier.replace(/[/.\-]/g, '\\$&');
33
+ for (const m of code.matchAll(new RegExp(`import\\s*([^;'"]*?)\\s*from\\s*["']${quoted}["']`, 'g'))) {
31
34
  const clause = m[1];
32
35
  const braces = /\{([^}]*)\}/.exec(clause);
33
36
  for (const part of braces ? braces[1].split(',') : []) {
@@ -303,6 +303,7 @@ describe("lifecycle declarations — coverage (derived from the playbooks)", ()
303
303
  "brand-library:brand-asset.deprecated",
304
304
  "brand-library:brand-voice-guide.approved",
305
305
  "brand-library:brand-voice-guide.deprecated",
306
+ "brand-library:content-guideline.approved",
306
307
  "brand-library:content-guideline.deprecated",
307
308
  "builder-workspace:devplane_feature.cancelled",
308
309
  "builder-workspace:devplane_story.dropped",
@@ -320,6 +321,8 @@ describe("lifecycle declarations — coverage (derived from the playbooks)", ()
320
321
  "content-os:content-composition.approved",
321
322
  "content-os:newsletter.Archived",
322
323
  "content-os:post.Archived",
324
+ "content-os:post.Idea",
325
+ "content-os:post.Scheduled",
323
326
  "crm:campaign.cancelled",
324
327
  "crm:campaign.paused",
325
328
  "crm:deal.lost",
@@ -340,6 +343,8 @@ describe("lifecycle declarations — coverage (derived from the playbooks)", ()
340
343
  "operations:engagement.cancelled",
341
344
  "operations:engagement.on-hold",
342
345
  "social:post.Archived",
346
+ "social:post.Idea",
347
+ "social:post.Scheduled",
343
348
  ];
344
349
 
345
350
  it("humanOnly sits on the kind's lifecycle, exactly the ledger", () => {
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The declared requests of a space (`onboarding.intents`, space contract L3,
3
+ * backend #1521) are checked at authoring time with the pod's own caps, because
4
+ * the pod CLIPS, DROPS or never MATCHES what breaks them, silently:
5
+ * - more than 8 phrases: the first 8 are kept;
6
+ * - a phrase over 80 characters: clipped;
7
+ * - a phrase of fewer than two meaningful words: routes nothing (the pod's
8
+ * matcher needs two shared words, or the whole phrase);
9
+ * - a locale that is not a BCP 47 language: dropped;
10
+ * - a repeat: dropped.
11
+ *
12
+ * Each rule has a failing fixture built by mutating ONE field of a clean one,
13
+ * and the clean one is asserted clean, so a fixture that fails for another
14
+ * reason cannot pass for the wrong one. Does NOT cover what `find` does with
15
+ * the phrases at run time (the pod's own tests).
16
+ */
17
+
18
+ import { describe, expect, it } from "vitest";
19
+ import {
20
+ SPACE_INTENT_COUNT_CAP,
21
+ SPACE_INTENT_PHRASE_CAP,
22
+ intentMeaningfulWords,
23
+ validateTemplate,
24
+ } from "./validate.js";
25
+ import type { WorkspaceYaml } from "./types.js";
26
+
27
+ const tplWith = (intents: unknown): WorkspaceYaml =>
28
+ ({
29
+ meta: {
30
+ slug: "intents-fixture",
31
+ name: "Intents fixture",
32
+ description: "Validation fixture",
33
+ icon: "circle",
34
+ color: "blue",
35
+ },
36
+ workspace: { name: "Intents fixture", description: "Validation fixture" },
37
+ profiles: [{ slug: "record", displayName: "Record", properties: [] }],
38
+ onboarding: { purpose: "Keep records.", intents },
39
+ }) as unknown as WorkspaceYaml;
40
+
41
+ const rulesOf = (intents: unknown) =>
42
+ validateTemplate(tplWith(intents), {})
43
+ .errors.filter((e) => e.rule.startsWith("onboarding-intent"))
44
+ .map((e) => e.rule);
45
+
46
+ const CLEAN = [
47
+ { phrase: "write a LinkedIn post", locale: "en" },
48
+ { phrase: "rédiger un post LinkedIn", locale: "fr" },
49
+ ];
50
+
51
+ describe("onboarding.intents", () => {
52
+ it("mirrors the pod's caps (8 phrases of 80 characters)", () => {
53
+ expect(SPACE_INTENT_COUNT_CAP).toBe(8);
54
+ expect(SPACE_INTENT_PHRASE_CAP).toBe(80);
55
+ });
56
+
57
+ it("a clean list is clean (so each fixture below fails for its own reason)", () => {
58
+ expect(rulesOf(CLEAN)).toEqual([]);
59
+ expect(rulesOf(undefined)).toEqual([]);
60
+ });
61
+
62
+ it("more than 8 phrases", () => {
63
+ const nine = Array.from({ length: 9 }, (_, i) => ({ phrase: `plan thing number${i}`, locale: "en" }));
64
+ expect(rulesOf(nine)).toEqual(["onboarding-intents-too-many"]);
65
+ });
66
+
67
+ it("a phrase over 80 characters", () => {
68
+ expect(rulesOf([{ phrase: `write ${"x".repeat(80)}` }])).toEqual(["onboarding-intent-too-long"]);
69
+ });
70
+
71
+ it("a phrase of one meaningful word, or only glue words, routes nothing", () => {
72
+ expect(rulesOf([{ phrase: "write" }])).toEqual(["onboarding-intent-words"]);
73
+ expect(rulesOf([{ phrase: "how do I" }])).toEqual(["onboarding-intent-words"]);
74
+ expect(rulesOf([{ phrase: "pour le de" }])).toEqual(["onboarding-intent-words"]);
75
+ expect(intentMeaningfulWords("rédiger un post LinkedIn")).toBe(3);
76
+ expect(intentMeaningfulWords("écrire l’histoire de notre marque")).toBe(3);
77
+ });
78
+
79
+ it("a locale that is not a language, a bare string, a repeat, a non-list", () => {
80
+ expect(rulesOf([{ phrase: "write a post", locale: "english" }])).toEqual(["onboarding-intent-locale"]);
81
+ expect(rulesOf(["write a post"])).toEqual(["onboarding-intent-invalid"]);
82
+ expect(rulesOf([{ phrase: "write a post" }, { phrase: "Write A Post" }])).toEqual(["onboarding-intent-duplicate"]);
83
+ expect(rulesOf("write a post")).toEqual(["onboarding-intents-invalid"]);
84
+ });
85
+ });
@@ -0,0 +1,218 @@
1
+ /**
2
+ * A template property's `relation` is checked at authoring time
3
+ * (`checkPropertyRelations` in validate.ts) because the pod door
4
+ * (`resolvePropertyRelationDefs`, backend#1498) refuses the same four mistakes
5
+ * only as a report entry at apply time: the relation is then never set and no
6
+ * link is ever made.
7
+ *
8
+ * Each rule has a failing fixture built by mutating ONE field of a clean
9
+ * fixture, and the clean fixture is asserted clean, so a fixture that fails for
10
+ * an unrelated reason cannot pass for the wrong one.
11
+ */
12
+ import { describe, expect, it } from "vitest";
13
+ import { validateTemplate } from "./validate.js";
14
+ import { getWorkspaceTemplate, WORKSPACE_TEMPLATES } from "./templates.js";
15
+ import type { WorkspaceYaml } from "./types.js";
16
+
17
+ const RULES = new Set([
18
+ "property-relation-invalid",
19
+ "property-relation-exposure",
20
+ "property-relation-not-entity-id",
21
+ "property-relation-unknown",
22
+ "property-relation-duplicate",
23
+ ]);
24
+
25
+ const relErrors = (tpl: WorkspaceYaml, opts = {}) =>
26
+ validateTemplate(tpl, opts).errors.filter((e) => RULES.has(e.rule));
27
+
28
+ function fixture(
29
+ mutate: (
30
+ profiles: Record<string, any>[],
31
+ t: Record<string, any>
32
+ ) => void = () => {}
33
+ ): WorkspaceYaml {
34
+ const t: Record<string, any> = {
35
+ meta: {
36
+ slug: "rel",
37
+ name: "Rel",
38
+ description: "d",
39
+ icon: "x",
40
+ color: "gray",
41
+ },
42
+ workspace: { name: "Rel", description: "d" },
43
+ profiles: [
44
+ {
45
+ slug: "task",
46
+ displayName: "Task",
47
+ properties: [
48
+ {
49
+ slug: "task-project",
50
+ label: "Project",
51
+ valueType: "entity_id",
52
+ targetProfileSlug: "project",
53
+ inputType: "entity_select",
54
+ relation: "part_of_project",
55
+ },
56
+ {
57
+ slug: "task-owner",
58
+ label: "Owner",
59
+ valueType: "entity_id",
60
+ targetProfileSlug: "project",
61
+ inputType: "entity_select",
62
+ },
63
+ ],
64
+ },
65
+ { slug: "project", displayName: "Project", properties: [] },
66
+ ],
67
+ entityLinks: [
68
+ {
69
+ sourceProfileSlug: "task",
70
+ targetProfileSlug: "project",
71
+ type: "part_of_project",
72
+ label: "Project",
73
+ },
74
+ ],
75
+ relationDefs: [{ slug: "owned_by", displayName: "Owned by" }],
76
+ };
77
+ mutate(t.profiles, t);
78
+ return t as unknown as WorkspaceYaml;
79
+ }
80
+
81
+ describe("property.relation validation", () => {
82
+ it("accepts a relation an entityLink defines, and one only relationDefs defines", () => {
83
+ expect(relErrors(fixture())).toEqual([]);
84
+ expect(
85
+ relErrors(
86
+ fixture((p) => {
87
+ p[0].properties[1].relation = "owned_by";
88
+ })
89
+ )
90
+ ).toEqual([]);
91
+ });
92
+
93
+ it("rejects a relation no entityLinks / relationDefs defines", () => {
94
+ const errs = relErrors(
95
+ fixture((p) => {
96
+ p[0].properties[0].relation = "nope";
97
+ })
98
+ );
99
+ expect(errs.map((e) => e.rule)).toEqual(["property-relation-unknown"]);
100
+ });
101
+
102
+ it("rejects an exposure relation", () => {
103
+ const errs = relErrors(
104
+ fixture((p) => {
105
+ p[0].properties[0].relation = "visible_to";
106
+ })
107
+ );
108
+ expect(errs.map((e) => e.rule)).toEqual(["property-relation-exposure"]);
109
+ });
110
+
111
+ it("rejects a relation declared by two properties of one kind", () => {
112
+ const errs = relErrors(
113
+ fixture((p) => {
114
+ p[0].properties[1].relation = "part_of_project";
115
+ })
116
+ );
117
+ expect(errs.map((e) => e.rule)).toEqual(["property-relation-duplicate"]);
118
+ expect(errs[0].path).toBe("profiles.task.task-owner.relation");
119
+ });
120
+
121
+ it("accepts one relation declared by two properties of DIFFERENT kinds", () => {
122
+ // The sync is keyed on the source entity's profile: a task and a note
123
+ // pointing at a project through `part_of_project` write different rows.
124
+ expect(
125
+ relErrors(
126
+ fixture((p) => {
127
+ p[1].properties = [
128
+ {
129
+ slug: "project-parent",
130
+ label: "Parent",
131
+ valueType: "entity_id",
132
+ targetProfileSlug: "project",
133
+ inputType: "entity_select",
134
+ relation: "part_of_project",
135
+ },
136
+ ];
137
+ })
138
+ )
139
+ ).toEqual([]);
140
+ });
141
+
142
+ it("rejects a relation on a property that is not an entity_id", () => {
143
+ const errs = relErrors(
144
+ fixture((p) => {
145
+ p[0].properties[0].valueType = "string";
146
+ })
147
+ );
148
+ expect(errs.map((e) => e.rule)).toEqual([
149
+ "property-relation-not-entity-id",
150
+ ]);
151
+ });
152
+
153
+ it("rejects an empty relation", () => {
154
+ const errs = relErrors(
155
+ fixture((p) => {
156
+ p[0].properties[0].relation = "";
157
+ })
158
+ );
159
+ expect(errs.map((e) => e.rule)).toEqual(["property-relation-invalid"]);
160
+ });
161
+ });
162
+
163
+ describe("Content OS: the post's references declare the relation they create", () => {
164
+ const tpl = getWorkspaceTemplate("content-os")!;
165
+ const rel = (slug: string) =>
166
+ tpl.profiles
167
+ .find((p) => p.slug === "post")
168
+ ?.properties.find((d) => d.slug === slug);
169
+
170
+ it("post-campaign, post-pillar and post-series name the edge the template declares", () => {
171
+ expect(rel("post-campaign")?.relation).toBe("part_of_campaign");
172
+ expect(rel("post-pillar")?.relation).toBe("belongs_to_pillar");
173
+ expect(rel("post-series")?.relation).toBe("part_of_series");
174
+ });
175
+
176
+ it("an idea's pillar and campaign and a piece's campaign reuse the post's edges, one property per kind", () => {
177
+ const prop = (kind: string, slug: string) =>
178
+ tpl.profiles
179
+ .find((p) => p.slug === kind)
180
+ ?.properties.find((d) => d.slug === slug);
181
+ expect(prop("idea", "idea-pillar")?.relation).toBe("belongs_to_pillar");
182
+ expect(prop("idea", "idea-campaign")?.relation).toBe("part_of_campaign");
183
+ expect(prop("content-composition", "composition-campaign")?.relation).toBe(
184
+ "part_of_campaign"
185
+ );
186
+ });
187
+
188
+ it("no kind declares one relation on two of its properties", () => {
189
+ for (const p of tpl.profiles) {
190
+ const rels = p.properties.flatMap((d) =>
191
+ d.relation ? [d.relation] : []
192
+ );
193
+ expect(new Set(rels).size, p.slug).toBe(rels.length);
194
+ }
195
+ });
196
+
197
+ it("every relation property is an entity_id whose entityLink goes to the property's target", () => {
198
+ for (const p of tpl.profiles)
199
+ for (const d of p.properties) {
200
+ if (!d.relation) continue;
201
+ expect(d.valueType).toBe("entity_id");
202
+ expect(
203
+ (tpl.entityLinks ?? []).some(
204
+ (l) =>
205
+ l.sourceProfileSlug === p.slug &&
206
+ l.type === d.relation &&
207
+ l.targetProfileSlug === d.targetProfileSlug
208
+ ),
209
+ `${p.slug}.${d.slug}`
210
+ ).toBe(true);
211
+ }
212
+ });
213
+
214
+ it("validates clean against the whole corpus", () => {
215
+ const corpus = Object.values(WORKSPACE_TEMPLATES) as WorkspaceYaml[];
216
+ expect(relErrors(tpl as WorkspaceYaml, { corpus })).toEqual([]);
217
+ });
218
+ });
package/src/social.yaml CHANGED
@@ -162,13 +162,15 @@ profiles:
162
162
  lifecycle:
163
163
  property: post-status
164
164
  options:
165
- - { key: Idea, category: open }
165
+ # Byte-identical to content-os's lifecycle (one declaration per kind).
166
+ - { key: Idea, category: open, humanOnly: true }
166
167
  - { key: Briefed, category: active }
167
168
  - { key: Scripted, category: active }
168
169
  - { key: "In Draft", category: active }
169
170
  - { key: Review, category: active }
170
- - { key: Scheduled, category: active }
171
+ - { key: Scheduled, category: active, humanOnly: true }
171
172
  - { key: Published, category: done }
173
+ - { key: Measured, category: done }
172
174
  - { key: Archived, category: lost, humanOnly: true }
173
175
  # How it renders (entity rendering, decision 8): @synap-core/types/presentation.
174
176
  presentation:
@@ -187,6 +189,7 @@ profiles:
187
189
  "Review",
188
190
  "Scheduled",
189
191
  "Published",
192
+ "Measured",
190
193
  "Archived",
191
194
  ]
192
195
  - slug: post-account