@transitrix/diagrams 1.2.0 → 1.4.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 (140) hide show
  1. package/dist/__tests__/yaml-normalize.test.js +9 -9
  2. package/dist/activities/__tests__/validate.test.js +77 -74
  3. package/dist/activities/validate.js +5 -12
  4. package/dist/activity-card/__tests__/example.test.js +3 -5
  5. package/dist/activity-card/__tests__/layout.test.js +2 -9
  6. package/dist/activity-card/__tests__/resolver.test.js +25 -0
  7. package/dist/activity-card/__tests__/validate.test.js +29 -18
  8. package/dist/activity-card/layout.js +1 -7
  9. package/dist/activity-card/resolver.js +11 -2
  10. package/dist/activity-card/types.d.ts +1 -1
  11. package/dist/activity-card/validate.js +3 -10
  12. package/dist/actor/__tests__/validate.test.js +6 -0
  13. package/dist/actor/types.d.ts +1 -1
  14. package/dist/actor/types.js +2 -0
  15. package/dist/applications/types.d.ts +7 -0
  16. package/dist/applications/validate.js +18 -0
  17. package/dist/blocks/__tests__/layout.test.js +1 -1
  18. package/dist/blocks/layout.js +1 -1
  19. package/dist/business-service/__tests__/validate.test.d.ts +1 -0
  20. package/dist/business-service/__tests__/validate.test.js +135 -0
  21. package/dist/business-service/index.d.ts +3 -0
  22. package/dist/business-service/index.js +2 -0
  23. package/dist/business-service/types.d.ts +20 -0
  24. package/dist/business-service/types.js +3 -0
  25. package/dist/business-service/validate.d.ts +2 -0
  26. package/dist/business-service/validate.js +74 -0
  27. package/dist/fgca/__tests__/parse-canonical.test.js +24 -11
  28. package/dist/fgca/__tests__/resolver.test.js +7 -7
  29. package/dist/fgca/__tests__/validate.test.js +11 -11
  30. package/dist/fgca/parse-canonical.js +18 -32
  31. package/dist/fgca/preview-layout.js +50 -1
  32. package/dist/fgca/resolver.d.ts +2 -2
  33. package/dist/fgca/resolver.js +5 -5
  34. package/dist/fgca/validate.js +4 -13
  35. package/dist/index.d.ts +5 -0
  36. package/dist/index.js +5 -0
  37. package/dist/integration/__tests__/validate.test.d.ts +1 -0
  38. package/dist/integration/__tests__/validate.test.js +169 -0
  39. package/dist/integration/index.d.ts +2 -0
  40. package/dist/integration/index.js +1 -0
  41. package/dist/integration/types.d.ts +27 -0
  42. package/dist/integration/types.js +5 -0
  43. package/dist/integration/validate.d.ts +2 -0
  44. package/dist/integration/validate.js +94 -0
  45. package/dist/location/__tests__/validate.test.d.ts +1 -0
  46. package/dist/location/__tests__/validate.test.js +107 -0
  47. package/dist/location/index.d.ts +3 -0
  48. package/dist/location/index.js +2 -0
  49. package/dist/location/types.d.ts +20 -0
  50. package/dist/location/types.js +3 -0
  51. package/dist/location/validate.d.ts +2 -0
  52. package/dist/location/validate.js +63 -0
  53. package/dist/node/__tests__/validate.test.d.ts +1 -0
  54. package/dist/node/__tests__/validate.test.js +100 -0
  55. package/dist/node/index.d.ts +2 -0
  56. package/dist/node/index.js +1 -0
  57. package/dist/node/types.d.ts +18 -0
  58. package/dist/node/types.js +3 -0
  59. package/dist/node/validate.d.ts +2 -0
  60. package/dist/node/validate.js +53 -0
  61. package/dist/repo-validate/__tests__/validate-repo.test.js +444 -0
  62. package/dist/repo-validate/validate-repo.js +224 -10
  63. package/dist/technology-service/__tests__/validate.test.d.ts +1 -0
  64. package/dist/technology-service/__tests__/validate.test.js +121 -0
  65. package/dist/technology-service/index.d.ts +2 -0
  66. package/dist/technology-service/index.js +1 -0
  67. package/dist/technology-service/types.d.ts +18 -0
  68. package/dist/technology-service/types.js +3 -0
  69. package/dist/technology-service/validate.d.ts +2 -0
  70. package/dist/technology-service/validate.js +64 -0
  71. package/dist/webview/__tests__/entry-notations.test.js +2 -4
  72. package/dist/webview/__tests__/render-activities.test.d.ts +1 -0
  73. package/dist/webview/__tests__/render-activities.test.js +91 -0
  74. package/dist/webview/__tests__/render-blocks.test.d.ts +1 -0
  75. package/dist/webview/__tests__/render-blocks.test.js +130 -0
  76. package/dist/webview/entry.d.ts +1 -1
  77. package/dist/webview/entry.js +8 -15
  78. package/dist/webview/render-activities.d.ts +12 -0
  79. package/dist/webview/render-activities.js +9 -3
  80. package/dist/webview/render-activity-card.js +2 -3
  81. package/dist/webview/render-blocks.js +97 -18
  82. package/dist/webview/render-fgca.js +1 -1
  83. package/dist/webview/render-goals.js +28 -5
  84. package/package.json +1 -1
  85. package/src/__tests__/yaml-normalize.test.ts +11 -11
  86. package/src/activities/__tests__/validate.test.ts +77 -74
  87. package/src/activities/validate.ts +5 -12
  88. package/src/activity-card/__tests__/example.test.ts +3 -5
  89. package/src/activity-card/__tests__/layout.test.ts +2 -9
  90. package/src/activity-card/__tests__/resolver.test.ts +27 -0
  91. package/src/activity-card/__tests__/validate.test.ts +30 -18
  92. package/src/activity-card/layout.ts +1 -8
  93. package/src/activity-card/resolver.ts +11 -2
  94. package/src/activity-card/types.ts +1 -1
  95. package/src/activity-card/validate.ts +3 -9
  96. package/src/actor/__tests__/validate.test.ts +8 -0
  97. package/src/actor/types.ts +2 -0
  98. package/src/applications/types.ts +8 -0
  99. package/src/applications/validate.ts +20 -0
  100. package/src/blocks/__tests__/layout.test.ts +1 -1
  101. package/src/blocks/layout.ts +1 -1
  102. package/src/business-service/__tests__/validate.test.ts +160 -0
  103. package/src/business-service/index.ts +3 -0
  104. package/src/business-service/types.ts +29 -0
  105. package/src/business-service/validate.ts +82 -0
  106. package/src/fgca/__tests__/parse-canonical.test.ts +25 -11
  107. package/src/fgca/__tests__/resolver.test.ts +7 -7
  108. package/src/fgca/__tests__/validate.test.ts +11 -11
  109. package/src/fgca/parse-canonical.ts +18 -38
  110. package/src/fgca/preview-layout.ts +53 -1
  111. package/src/fgca/resolver.ts +5 -5
  112. package/src/fgca/validate.ts +4 -12
  113. package/src/index.ts +5 -0
  114. package/src/integration/__tests__/validate.test.ts +203 -0
  115. package/src/integration/index.ts +2 -0
  116. package/src/integration/types.ts +38 -0
  117. package/src/integration/validate.ts +104 -0
  118. package/src/location/__tests__/validate.test.ts +127 -0
  119. package/src/location/index.ts +3 -0
  120. package/src/location/types.ts +29 -0
  121. package/src/location/validate.ts +70 -0
  122. package/src/node/__tests__/validate.test.ts +118 -0
  123. package/src/node/index.ts +2 -0
  124. package/src/node/types.ts +27 -0
  125. package/src/node/validate.ts +59 -0
  126. package/src/repo-validate/__tests__/validate-repo.test.ts +550 -0
  127. package/src/repo-validate/validate-repo.ts +233 -10
  128. package/src/technology-service/__tests__/validate.test.ts +143 -0
  129. package/src/technology-service/index.ts +2 -0
  130. package/src/technology-service/types.ts +27 -0
  131. package/src/technology-service/validate.ts +71 -0
  132. package/src/webview/__tests__/entry-notations.test.ts +2 -4
  133. package/src/webview/__tests__/render-activities.test.ts +100 -0
  134. package/src/webview/__tests__/render-blocks.test.ts +155 -0
  135. package/src/webview/entry.ts +10 -19
  136. package/src/webview/render-activities.ts +29 -4
  137. package/src/webview/render-activity-card.ts +2 -3
  138. package/src/webview/render-blocks.ts +101 -20
  139. package/src/webview/render-fgca.ts +1 -1
  140. package/src/webview/render-goals.ts +26 -5
@@ -0,0 +1,2 @@
1
+ import type { ValidationResult } from '../validation-types.js';
2
+ export declare function validateNode(input: unknown): ValidationResult;
@@ -0,0 +1,53 @@
1
+ // NODE validator — methodology notations/elements/25-nodes.md §5.
2
+ //
3
+ // Implements NOD-001, NOD-002. The shared HDR-/LIFECYCLE- rules are
4
+ // cross-cutting concerns (CONTRACT.md §8) and out of scope for the
5
+ // single-artefact validator.
6
+ import { isCanonicalIdOfType } from '../typed-id.js';
7
+ import { NODE_TYPES } from './types.js';
8
+ const REQUIRED_STRING_FIELDS = [
9
+ 'name', 'admitted_at', 'admitted_by', 'valid_from',
10
+ ];
11
+ const TYPES = NODE_TYPES;
12
+ export function validateNode(input) {
13
+ const errors = [];
14
+ const warnings = [];
15
+ if (input === null || typeof input !== 'object' || Array.isArray(input)) {
16
+ errors.push({ code: 'NOD-001', message: 'Node must be a YAML mapping.' });
17
+ return { valid: false, errors, warnings };
18
+ }
19
+ const a = input;
20
+ // NOD-001 — id grammar + notation tag + envelope.
21
+ if (!isCanonicalIdOfType(a.id, 'NODE')) {
22
+ errors.push({ code: 'NOD-001', message: `id "${String(a.id)}" must match NODE-[<middle>-]<INTEGER>.`, path: 'id' });
23
+ }
24
+ if (a.notation !== 'node') {
25
+ errors.push({ code: 'NOD-001', message: 'notation must be the fixed value "node".', path: 'notation' });
26
+ }
27
+ if (a.zone !== undefined && a.zone !== 'canon') {
28
+ errors.push({ code: 'NOD-001', message: 'zone must be "canon" for a NODE.', path: 'zone' });
29
+ }
30
+ else if (a.zone === undefined) {
31
+ errors.push({ code: 'NOD-001', message: 'zone is required.', path: 'zone' });
32
+ }
33
+ for (const field of REQUIRED_STRING_FIELDS) {
34
+ const v = a[field];
35
+ if (typeof v !== 'string' || v.trim() === '') {
36
+ errors.push({ code: 'NOD-001', message: `${field} is required.`, path: field });
37
+ }
38
+ }
39
+ if (a.gate_checks === null || typeof a.gate_checks !== 'object') {
40
+ errors.push({ code: 'NOD-001', message: 'gate_checks is required and must be a mapping.', path: 'gate_checks' });
41
+ }
42
+ if (!('valid_to' in a) || !(typeof a.valid_to === 'string' || a.valid_to === null)) {
43
+ errors.push({ code: 'NOD-001', message: 'valid_to is required (an ISO date string or null).', path: 'valid_to' });
44
+ }
45
+ if (typeof a.type !== 'string' || a.type.trim() === '') {
46
+ errors.push({ code: 'NOD-001', message: 'type is required.', path: 'type' });
47
+ }
48
+ else if (!TYPES.includes(a.type)) {
49
+ // NOD-002 — type enum.
50
+ errors.push({ code: 'NOD-002', message: `type "${a.type}" must be one of ${TYPES.join(', ')}.`, path: 'type' });
51
+ }
52
+ return { valid: errors.length === 0, errors, warnings };
53
+ }
@@ -130,3 +130,447 @@ describe('validateRepoModel — syntax', () => {
130
130
  expect(findings[0].message).toContain('broken.yaml');
131
131
  });
132
132
  });
133
+ describe('validateRepoModel — layer-semantics (unit_located_at / located_at)', () => {
134
+ function locationModel() {
135
+ const model = cleanModel();
136
+ model.elements.push(el('canon/elements/02_business/actors/ACTOR-OPS-1.yaml', {
137
+ notation: 'actor',
138
+ id: 'ACTOR-OPS-1',
139
+ type: 'business_unit',
140
+ }), el('canon/elements/02_business/actors/ACTOR-JANE-1.yaml', {
141
+ notation: 'actor',
142
+ id: 'ACTOR-JANE-1',
143
+ type: 'person',
144
+ }), el('canon/elements/02_business/locations/LOCATION-TBILISI-1.yaml', {
145
+ notation: 'location',
146
+ id: 'LOCATION-TBILISI-1',
147
+ }));
148
+ return model;
149
+ }
150
+ it('accepts a valid unit_located_at (business_unit → LOCATION)', () => {
151
+ const model = locationModel();
152
+ model.relations.push(el('canon/relations/REL-LOC-1.yaml', {
153
+ notation: 'relation',
154
+ id: 'REL-LOC-1',
155
+ type: 'unit_located_at',
156
+ from: 'ACTOR-OPS-1',
157
+ to: 'LOCATION-TBILISI-1',
158
+ }));
159
+ expect(validateRepoModel(model)).toEqual([]);
160
+ });
161
+ it('accepts a valid located_at for a business_unit', () => {
162
+ const model = locationModel();
163
+ model.relations.push(el('canon/relations/REL-LOC-2.yaml', {
164
+ notation: 'relation',
165
+ id: 'REL-LOC-2',
166
+ type: 'located_at',
167
+ from: 'ACTOR-OPS-1',
168
+ to: 'LOCATION-TBILISI-1',
169
+ }));
170
+ expect(validateRepoModel(model)).toEqual([]);
171
+ });
172
+ it('accepts a valid located_at for a person', () => {
173
+ const model = locationModel();
174
+ model.relations.push(el('canon/relations/REL-LOC-3.yaml', {
175
+ notation: 'relation',
176
+ id: 'REL-LOC-3',
177
+ type: 'located_at',
178
+ from: 'ACTOR-JANE-1',
179
+ to: 'LOCATION-TBILISI-1',
180
+ }));
181
+ expect(validateRepoModel(model)).toEqual([]);
182
+ });
183
+ it('flags unit_located_at with a wrong from type (person instead of business_unit)', () => {
184
+ const model = locationModel();
185
+ model.relations.push(el('canon/relations/REL-BAD-1.yaml', {
186
+ notation: 'relation',
187
+ id: 'REL-BAD-1',
188
+ type: 'unit_located_at',
189
+ from: 'ACTOR-JANE-1',
190
+ to: 'LOCATION-TBILISI-1',
191
+ }));
192
+ const findings = validateRepoModel(model);
193
+ expect(findings).toHaveLength(1);
194
+ expect(findings[0]).toMatchObject({ scope: 'repo', id: 'REL-BAD-1' });
195
+ expect(findings[0].message).toContain('unit_located_at');
196
+ expect(findings[0].message).toContain('business_unit');
197
+ });
198
+ it('flags unit_located_at with a non-ACTOR from element', () => {
199
+ const model = locationModel();
200
+ model.relations.push(el('canon/relations/REL-BAD-2.yaml', {
201
+ notation: 'relation',
202
+ id: 'REL-BAD-2',
203
+ type: 'unit_located_at',
204
+ from: 'GOAL-OPS-1',
205
+ to: 'LOCATION-TBILISI-1',
206
+ }));
207
+ const findings = validateRepoModel(model);
208
+ expect(findings).toHaveLength(1);
209
+ expect(findings[0]).toMatchObject({ scope: 'repo', id: 'REL-BAD-2' });
210
+ expect(findings[0].message).toContain('unit_located_at');
211
+ });
212
+ it('flags unit_located_at with a non-LOCATION to element', () => {
213
+ const model = locationModel();
214
+ model.relations.push(el('canon/relations/REL-BAD-3.yaml', {
215
+ notation: 'relation',
216
+ id: 'REL-BAD-3',
217
+ type: 'unit_located_at',
218
+ from: 'ACTOR-OPS-1',
219
+ to: 'GOAL-OPS-1',
220
+ }));
221
+ const findings = validateRepoModel(model);
222
+ expect(findings).toHaveLength(1);
223
+ expect(findings[0]).toMatchObject({ scope: 'repo', id: 'REL-BAD-3' });
224
+ expect(findings[0].message).toContain('LOCATION');
225
+ });
226
+ it('flags located_at with a non-actor from element', () => {
227
+ const model = locationModel();
228
+ model.relations.push(el('canon/relations/REL-BAD-4.yaml', {
229
+ notation: 'relation',
230
+ id: 'REL-BAD-4',
231
+ type: 'located_at',
232
+ from: 'CAPABILITY-V1',
233
+ to: 'LOCATION-TBILISI-1',
234
+ }));
235
+ const findings = validateRepoModel(model);
236
+ expect(findings).toHaveLength(1);
237
+ expect(findings[0]).toMatchObject({ scope: 'repo', id: 'REL-BAD-4' });
238
+ expect(findings[0].message).toContain('located_at');
239
+ });
240
+ it('does not emit layer-semantic findings for unknown endpoints (ref-integrity handles those)', () => {
241
+ const model = locationModel();
242
+ model.relations.push(el('canon/relations/REL-MISSING.yaml', {
243
+ notation: 'relation',
244
+ id: 'REL-MISSING',
245
+ type: 'unit_located_at',
246
+ from: 'ACTOR-UNKNOWN-99',
247
+ to: 'LOCATION-UNKNOWN-99',
248
+ }));
249
+ const findings = validateRepoModel(model);
250
+ // ref-integrity fires for missing endpoints; no duplicate layer-semantic finding
251
+ expect(findings.every((f) => !f.message.includes('Layer-semantics'))).toBe(true);
252
+ expect(findings.some((f) => f.message.includes('ACTOR-UNKNOWN-99'))).toBe(true);
253
+ });
254
+ });
255
+ describe('validateRepoModel — layer-semantics (offers / realizes)', () => {
256
+ function serviceModel() {
257
+ const model = cleanModel();
258
+ model.elements.push(el('canon/elements/02_business/actors/ACTOR-OPS-1.yaml', {
259
+ notation: 'actor',
260
+ id: 'ACTOR-OPS-1',
261
+ type: 'business_unit',
262
+ }), el('canon/elements/02_business/roles/ROLE-OWNER-1.yaml', {
263
+ notation: 'role',
264
+ id: 'ROLE-OWNER-1',
265
+ }), el('canon/elements/02_business/business-services/BUSINESS_SERVICE-CRM-1.yaml', {
266
+ notation: 'business-service',
267
+ id: 'BUSINESS_SERVICE-CRM-1',
268
+ }), el('canon/elements/02_business/capabilities/CAPABILITY-V2.yaml', {
269
+ notation: 'capability',
270
+ id: 'CAPABILITY-V2',
271
+ }));
272
+ return model;
273
+ }
274
+ it('accepts a valid offers (ACTOR(business_unit) → BUSINESS_SERVICE)', () => {
275
+ const model = serviceModel();
276
+ model.relations.push(el('canon/relations/REL-SVC-1.yaml', {
277
+ notation: 'relation',
278
+ id: 'REL-SVC-1',
279
+ type: 'offers',
280
+ from: 'ACTOR-OPS-1',
281
+ to: 'BUSINESS_SERVICE-CRM-1',
282
+ }));
283
+ expect(validateRepoModel(model)).toEqual([]);
284
+ });
285
+ it('accepts a valid offers (ROLE → BUSINESS_SERVICE)', () => {
286
+ const model = serviceModel();
287
+ model.relations.push(el('canon/relations/REL-SVC-2.yaml', {
288
+ notation: 'relation',
289
+ id: 'REL-SVC-2',
290
+ type: 'offers',
291
+ from: 'ROLE-OWNER-1',
292
+ to: 'BUSINESS_SERVICE-CRM-1',
293
+ }));
294
+ expect(validateRepoModel(model)).toEqual([]);
295
+ });
296
+ it('accepts a valid realizes (BUSINESS_SERVICE → CAPABILITY)', () => {
297
+ const model = serviceModel();
298
+ model.relations.push(el('canon/relations/REL-SVC-3.yaml', {
299
+ notation: 'relation',
300
+ id: 'REL-SVC-3',
301
+ type: 'realizes',
302
+ from: 'BUSINESS_SERVICE-CRM-1',
303
+ to: 'CAPABILITY-V2',
304
+ }));
305
+ expect(validateRepoModel(model)).toEqual([]);
306
+ });
307
+ it('flags offers with a non-ACTOR/non-ROLE from element', () => {
308
+ const model = serviceModel();
309
+ model.relations.push(el('canon/relations/REL-SVC-BAD-1.yaml', {
310
+ notation: 'relation',
311
+ id: 'REL-SVC-BAD-1',
312
+ type: 'offers',
313
+ from: 'CAPABILITY-V2',
314
+ to: 'BUSINESS_SERVICE-CRM-1',
315
+ }));
316
+ const findings = validateRepoModel(model);
317
+ expect(findings).toHaveLength(1);
318
+ expect(findings[0]).toMatchObject({ scope: 'repo', id: 'REL-SVC-BAD-1' });
319
+ expect(findings[0].message).toContain('offers');
320
+ expect(findings[0].message).toContain('ACTOR');
321
+ });
322
+ it('flags offers with a non-BUSINESS_SERVICE to element', () => {
323
+ const model = serviceModel();
324
+ model.relations.push(el('canon/relations/REL-SVC-BAD-2.yaml', {
325
+ notation: 'relation',
326
+ id: 'REL-SVC-BAD-2',
327
+ type: 'offers',
328
+ from: 'ACTOR-OPS-1',
329
+ to: 'CAPABILITY-V2',
330
+ }));
331
+ const findings = validateRepoModel(model);
332
+ expect(findings).toHaveLength(1);
333
+ expect(findings[0]).toMatchObject({ scope: 'repo', id: 'REL-SVC-BAD-2' });
334
+ expect(findings[0].message).toContain('BUSINESS_SERVICE');
335
+ });
336
+ it('flags realizes with a non-BUSINESS_SERVICE from element', () => {
337
+ const model = serviceModel();
338
+ model.relations.push(el('canon/relations/REL-SVC-BAD-3.yaml', {
339
+ notation: 'relation',
340
+ id: 'REL-SVC-BAD-3',
341
+ type: 'realizes',
342
+ from: 'ACTOR-OPS-1',
343
+ to: 'CAPABILITY-V2',
344
+ }));
345
+ const findings = validateRepoModel(model);
346
+ expect(findings).toHaveLength(1);
347
+ expect(findings[0]).toMatchObject({ scope: 'repo', id: 'REL-SVC-BAD-3' });
348
+ expect(findings[0].message).toContain('realizes');
349
+ expect(findings[0].message).toContain('BUSINESS_SERVICE');
350
+ });
351
+ });
352
+ describe('validateRepoModel — layer-semantics (INT-002 integration endpoints)', () => {
353
+ function integrationModel() {
354
+ const model = cleanModel();
355
+ model.elements.push(el('canon/elements/03_application/applications/APPLICATION-OMS-1.yaml', {
356
+ notation: 'application',
357
+ id: 'APPLICATION-OMS-1',
358
+ }), el('canon/elements/03_application/applications/APPLICATION-CRM-1.yaml', {
359
+ notation: 'application',
360
+ id: 'APPLICATION-CRM-1',
361
+ }), el('canon/elements/02_business/actors/ACTOR-OPS-1.yaml', {
362
+ notation: 'actor',
363
+ id: 'ACTOR-OPS-1',
364
+ type: 'business_unit',
365
+ }));
366
+ return model;
367
+ }
368
+ it('accepts an interface_semantics integration whose endpoints resolve to APPLICATION elements', () => {
369
+ const model = integrationModel();
370
+ model.elements.push(el('canon/elements/03_application/integrations/INTEGRATION-OMS-EVENTS-1.yaml', {
371
+ notation: 'integration',
372
+ id: 'INTEGRATION-OMS-EVENTS-1',
373
+ interface_semantics: true,
374
+ source: 'APPLICATION-OMS-1',
375
+ target: 'APPLICATION-CRM-1',
376
+ }));
377
+ expect(validateRepoModel(model)).toEqual([]);
378
+ });
379
+ it('does not fire INT-002 for an integration without interface_semantics', () => {
380
+ const model = integrationModel();
381
+ model.elements.push(el('canon/elements/03_application/integrations/INTEGRATION-PLAIN-1.yaml', {
382
+ notation: 'integration',
383
+ id: 'INTEGRATION-PLAIN-1',
384
+ source: 'ACTOR-OPS-1',
385
+ target: 'APPLICATION-CRM-1',
386
+ }));
387
+ expect(validateRepoModel(model)).toEqual([]);
388
+ });
389
+ it('flags INT-002 when source resolves to a non-APPLICATION element', () => {
390
+ const model = integrationModel();
391
+ model.elements.push(el('canon/elements/03_application/integrations/INTEGRATION-BAD-1.yaml', {
392
+ notation: 'integration',
393
+ id: 'INTEGRATION-BAD-1',
394
+ interface_semantics: true,
395
+ source: 'ACTOR-OPS-1',
396
+ target: 'APPLICATION-CRM-1',
397
+ }));
398
+ const findings = validateRepoModel(model);
399
+ expect(findings).toHaveLength(1);
400
+ expect(findings[0]).toMatchObject({ scope: 'repo', id: 'INTEGRATION-BAD-1' });
401
+ expect(findings[0].message).toContain('INT-002');
402
+ expect(findings[0].message).toContain('ACTOR-OPS-1');
403
+ expect(findings[0].message).toContain('source');
404
+ });
405
+ it('flags INT-002 when target resolves to a non-APPLICATION element', () => {
406
+ const model = integrationModel();
407
+ model.elements.push(el('canon/elements/03_application/integrations/INTEGRATION-BAD-2.yaml', {
408
+ notation: 'integration',
409
+ id: 'INTEGRATION-BAD-2',
410
+ interface_semantics: true,
411
+ source: 'APPLICATION-OMS-1',
412
+ target: 'ACTOR-OPS-1',
413
+ }));
414
+ const findings = validateRepoModel(model);
415
+ expect(findings).toHaveLength(1);
416
+ expect(findings[0]).toMatchObject({ scope: 'repo', id: 'INTEGRATION-BAD-2' });
417
+ expect(findings[0].message).toContain('INT-002');
418
+ expect(findings[0].message).toContain('ACTOR-OPS-1');
419
+ expect(findings[0].message).toContain('target');
420
+ });
421
+ it('flags INT-002 for both endpoints when neither resolves to APPLICATION', () => {
422
+ const model = integrationModel();
423
+ model.elements.push(el('canon/elements/03_application/integrations/INTEGRATION-BAD-3.yaml', {
424
+ notation: 'integration',
425
+ id: 'INTEGRATION-BAD-3',
426
+ interface_semantics: true,
427
+ source: 'ACTOR-OPS-1',
428
+ target: 'GOAL-OPS-1',
429
+ }));
430
+ const findings = validateRepoModel(model);
431
+ expect(findings).toHaveLength(2);
432
+ expect(findings.every(f => f.message.includes('INT-002'))).toBe(true);
433
+ });
434
+ it('does not flag INT-002 when endpoint id is not in the element registry', () => {
435
+ // Unresolved IDs are caught by phase 4 (referential integrity), not INT-002.
436
+ const model = integrationModel();
437
+ model.elements.push(el('canon/elements/03_application/integrations/INTEGRATION-UNRESOLVED-1.yaml', {
438
+ notation: 'integration',
439
+ id: 'INTEGRATION-UNRESOLVED-1',
440
+ interface_semantics: true,
441
+ source: 'APPLICATION-MISSING-99',
442
+ target: 'APPLICATION-CRM-1',
443
+ }));
444
+ const findings = validateRepoModel(model).filter(f => f.message.includes('INT-002'));
445
+ expect(findings).toHaveLength(0);
446
+ });
447
+ });
448
+ describe('validateRepoModel — layer-semantics (hosts / uses / TSVC-003)', () => {
449
+ function techModel() {
450
+ const model = cleanModel();
451
+ model.elements.push(el('canon/elements/04_technology/nodes/NODE-KAFKA-HOST-1.yaml', {
452
+ notation: 'node',
453
+ id: 'NODE-KAFKA-HOST-1',
454
+ type: 'cloud_instance',
455
+ }), el('canon/elements/04_technology/services/TECHNOLOGY_SERVICE-KAFKA-1.yaml', {
456
+ notation: 'technology-service',
457
+ id: 'TECHNOLOGY_SERVICE-KAFKA-1',
458
+ type: 'messaging',
459
+ node: 'NODE-KAFKA-HOST-1',
460
+ }), el('canon/elements/03_application/applications/APPLICATION-OMS-1.yaml', {
461
+ notation: 'application',
462
+ id: 'APPLICATION-OMS-1',
463
+ }));
464
+ return model;
465
+ }
466
+ it('accepts a valid hosts relation (NODE → TECHNOLOGY_SERVICE)', () => {
467
+ const model = techModel();
468
+ model.relations.push(el('canon/relations/REL-HOSTS-1.yaml', {
469
+ notation: 'relation',
470
+ id: 'REL-HOSTS-1',
471
+ type: 'hosts',
472
+ from: 'NODE-KAFKA-HOST-1',
473
+ to: 'TECHNOLOGY_SERVICE-KAFKA-1',
474
+ }));
475
+ expect(validateRepoModel(model)).toEqual([]);
476
+ });
477
+ it('accepts a valid uses relation (APPLICATION → TECHNOLOGY_SERVICE)', () => {
478
+ const model = techModel();
479
+ model.relations.push(el('canon/relations/REL-USES-1.yaml', {
480
+ notation: 'relation',
481
+ id: 'REL-USES-1',
482
+ type: 'uses',
483
+ from: 'APPLICATION-OMS-1',
484
+ to: 'TECHNOLOGY_SERVICE-KAFKA-1',
485
+ }));
486
+ expect(validateRepoModel(model)).toEqual([]);
487
+ });
488
+ it('flags hosts with a non-NODE from element', () => {
489
+ const model = techModel();
490
+ model.relations.push(el('canon/relations/REL-HOSTS-BAD-1.yaml', {
491
+ notation: 'relation',
492
+ id: 'REL-HOSTS-BAD-1',
493
+ type: 'hosts',
494
+ from: 'APPLICATION-OMS-1',
495
+ to: 'TECHNOLOGY_SERVICE-KAFKA-1',
496
+ }));
497
+ const findings = validateRepoModel(model);
498
+ expect(findings).toHaveLength(1);
499
+ expect(findings[0]).toMatchObject({ scope: 'repo', id: 'REL-HOSTS-BAD-1' });
500
+ expect(findings[0].message).toContain('hosts');
501
+ expect(findings[0].message).toContain('NODE');
502
+ });
503
+ it('flags hosts with a non-TECHNOLOGY_SERVICE to element', () => {
504
+ const model = techModel();
505
+ model.relations.push(el('canon/relations/REL-HOSTS-BAD-2.yaml', {
506
+ notation: 'relation',
507
+ id: 'REL-HOSTS-BAD-2',
508
+ type: 'hosts',
509
+ from: 'NODE-KAFKA-HOST-1',
510
+ to: 'APPLICATION-OMS-1',
511
+ }));
512
+ const findings = validateRepoModel(model);
513
+ expect(findings).toHaveLength(1);
514
+ expect(findings[0]).toMatchObject({ scope: 'repo', id: 'REL-HOSTS-BAD-2' });
515
+ expect(findings[0].message).toContain('hosts');
516
+ expect(findings[0].message).toContain('TECHNOLOGY_SERVICE');
517
+ });
518
+ it('flags uses with a non-APPLICATION from element', () => {
519
+ const model = techModel();
520
+ model.relations.push(el('canon/relations/REL-USES-BAD-1.yaml', {
521
+ notation: 'relation',
522
+ id: 'REL-USES-BAD-1',
523
+ type: 'uses',
524
+ from: 'NODE-KAFKA-HOST-1',
525
+ to: 'TECHNOLOGY_SERVICE-KAFKA-1',
526
+ }));
527
+ const findings = validateRepoModel(model);
528
+ expect(findings).toHaveLength(1);
529
+ expect(findings[0]).toMatchObject({ scope: 'repo', id: 'REL-USES-BAD-1' });
530
+ expect(findings[0].message).toContain('uses');
531
+ expect(findings[0].message).toContain('APPLICATION');
532
+ });
533
+ it('flags uses with a non-TECHNOLOGY_SERVICE to element', () => {
534
+ const model = techModel();
535
+ model.relations.push(el('canon/relations/REL-USES-BAD-2.yaml', {
536
+ notation: 'relation',
537
+ id: 'REL-USES-BAD-2',
538
+ type: 'uses',
539
+ from: 'APPLICATION-OMS-1',
540
+ to: 'NODE-KAFKA-HOST-1',
541
+ }));
542
+ const findings = validateRepoModel(model);
543
+ expect(findings).toHaveLength(1);
544
+ expect(findings[0]).toMatchObject({ scope: 'repo', id: 'REL-USES-BAD-2' });
545
+ expect(findings[0].message).toContain('uses');
546
+ expect(findings[0].message).toContain('TECHNOLOGY_SERVICE');
547
+ });
548
+ it('TSVC-003: does not flag a technology-service whose node resolves to a NODE element', () => {
549
+ const model = techModel();
550
+ expect(validateRepoModel(model)).toEqual([]);
551
+ });
552
+ it('TSVC-003: flags a technology-service whose node resolves to a non-NODE element', () => {
553
+ const model = techModel();
554
+ model.elements.push(el('canon/elements/04_technology/services/TECHNOLOGY_SERVICE-BAD-1.yaml', {
555
+ notation: 'technology-service',
556
+ id: 'TECHNOLOGY_SERVICE-BAD-1',
557
+ type: 'messaging',
558
+ node: 'APPLICATION-OMS-1',
559
+ }));
560
+ const findings = validateRepoModel(model).filter(f => f.message.includes('TSVC-003'));
561
+ expect(findings).toHaveLength(1);
562
+ expect(findings[0]).toMatchObject({ scope: 'repo', id: 'TECHNOLOGY_SERVICE-BAD-1' });
563
+ expect(findings[0].message).toContain('APPLICATION-OMS-1');
564
+ });
565
+ it('TSVC-003: does not flag a technology-service with an unresolved node (phase 4 handles that)', () => {
566
+ const model = techModel();
567
+ model.elements.push(el('canon/elements/04_technology/services/TECHNOLOGY_SERVICE-UNRESOLVED-1.yaml', {
568
+ notation: 'technology-service',
569
+ id: 'TECHNOLOGY_SERVICE-UNRESOLVED-1',
570
+ type: 'storage',
571
+ node: 'NODE-MISSING-99',
572
+ }));
573
+ const findings = validateRepoModel(model).filter(f => f.message.includes('TSVC-003'));
574
+ expect(findings).toHaveLength(0);
575
+ });
576
+ });