@transitrix/diagrams 1.8.4 → 1.8.7

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 (254) hide show
  1. package/dist/edge-path.js +10 -1
  2. package/dist/webview/render-activities.d.ts +1 -1
  3. package/dist/webview/render-activities.js +2 -2
  4. package/dist/webview/render-fgca.js +1 -4
  5. package/package.json +7 -2
  6. package/src/edge-path.ts +15 -1
  7. package/src/webview/render-activities.ts +2 -2
  8. package/src/webview/render-fgca.ts +1 -4
  9. package/dist/__tests__/edge-path.test.d.ts +0 -1
  10. package/dist/__tests__/edge-path.test.js +0 -47
  11. package/dist/__tests__/node-size-presets.test.d.ts +0 -1
  12. package/dist/__tests__/node-size-presets.test.js +0 -30
  13. package/dist/__tests__/scope.test.d.ts +0 -1
  14. package/dist/__tests__/scope.test.js +0 -23
  15. package/dist/__tests__/yaml-normalize.test.d.ts +0 -1
  16. package/dist/__tests__/yaml-normalize.test.js +0 -148
  17. package/dist/activities/__tests__/cpm.test.d.ts +0 -1
  18. package/dist/activities/__tests__/cpm.test.js +0 -146
  19. package/dist/activities/__tests__/gantt.test.d.ts +0 -1
  20. package/dist/activities/__tests__/gantt.test.js +0 -263
  21. package/dist/activities/__tests__/layout.test.d.ts +0 -1
  22. package/dist/activities/__tests__/layout.test.js +0 -98
  23. package/dist/activities/__tests__/validate.test.d.ts +0 -1
  24. package/dist/activities/__tests__/validate.test.js +0 -397
  25. package/dist/activity-card/__tests__/example.test.d.ts +0 -1
  26. package/dist/activity-card/__tests__/example.test.js +0 -73
  27. package/dist/activity-card/__tests__/layout.test.d.ts +0 -1
  28. package/dist/activity-card/__tests__/layout.test.js +0 -141
  29. package/dist/activity-card/__tests__/resolver.test.d.ts +0 -1
  30. package/dist/activity-card/__tests__/resolver.test.js +0 -325
  31. package/dist/activity-card/__tests__/validate.test.d.ts +0 -1
  32. package/dist/activity-card/__tests__/validate.test.js +0 -149
  33. package/dist/actor/__tests__/validate.test.d.ts +0 -1
  34. package/dist/actor/__tests__/validate.test.js +0 -95
  35. package/dist/applications/__tests__/validate.test.d.ts +0 -1
  36. package/dist/applications/__tests__/validate.test.js +0 -223
  37. package/dist/assertion/__tests__/example.test.d.ts +0 -1
  38. package/dist/assertion/__tests__/example.test.js +0 -32
  39. package/dist/assertion/__tests__/validate.test.d.ts +0 -1
  40. package/dist/assertion/__tests__/validate.test.js +0 -130
  41. package/dist/blocks/__tests__/layout.test.d.ts +0 -1
  42. package/dist/blocks/__tests__/layout.test.js +0 -153
  43. package/dist/blocks/__tests__/validate.test.d.ts +0 -1
  44. package/dist/blocks/__tests__/validate.test.js +0 -235
  45. package/dist/business-service/__tests__/validate.test.d.ts +0 -1
  46. package/dist/business-service/__tests__/validate.test.js +0 -135
  47. package/dist/capability-map/__tests__/CapabilityMapView.test.d.ts +0 -1
  48. package/dist/capability-map/__tests__/CapabilityMapView.test.js +0 -217
  49. package/dist/capability-map/__tests__/address.test.d.ts +0 -1
  50. package/dist/capability-map/__tests__/address.test.js +0 -49
  51. package/dist/capability-map/__tests__/dsm-layout.test.d.ts +0 -1
  52. package/dist/capability-map/__tests__/dsm-layout.test.js +0 -46
  53. package/dist/capability-map/__tests__/dsm-mutations.test.d.ts +0 -1
  54. package/dist/capability-map/__tests__/dsm-mutations.test.js +0 -125
  55. package/dist/capability-map/__tests__/dsm-validate.test.d.ts +0 -1
  56. package/dist/capability-map/__tests__/dsm-validate.test.js +0 -56
  57. package/dist/capability-map/__tests__/validate.test.d.ts +0 -1
  58. package/dist/capability-map/__tests__/validate.test.js +0 -212
  59. package/dist/change/__tests__/validate.test.d.ts +0 -1
  60. package/dist/change/__tests__/validate.test.js +0 -79
  61. package/dist/codex/__tests__/example.test.d.ts +0 -1
  62. package/dist/codex/__tests__/example.test.js +0 -33
  63. package/dist/codex/__tests__/validate.test.d.ts +0 -1
  64. package/dist/codex/__tests__/validate.test.js +0 -68
  65. package/dist/compliance/__tests__/canon-catalog.test.d.ts +0 -1
  66. package/dist/compliance/__tests__/canon-catalog.test.js +0 -60
  67. package/dist/compliance/__tests__/classify.test.d.ts +0 -1
  68. package/dist/compliance/__tests__/classify.test.js +0 -58
  69. package/dist/compliance/__tests__/confidence.test.d.ts +0 -1
  70. package/dist/compliance/__tests__/confidence.test.js +0 -78
  71. package/dist/compliance/__tests__/coverage-metric.test.d.ts +0 -1
  72. package/dist/compliance/__tests__/coverage-metric.test.js +0 -264
  73. package/dist/compliance/__tests__/demo-scenario.test.d.ts +0 -1
  74. package/dist/compliance/__tests__/demo-scenario.test.js +0 -226
  75. package/dist/compliance/__tests__/example.test.d.ts +0 -1
  76. package/dist/compliance/__tests__/example.test.js +0 -51
  77. package/dist/compliance/__tests__/gap-report.test.d.ts +0 -1
  78. package/dist/compliance/__tests__/gap-report.test.js +0 -113
  79. package/dist/compliance/__tests__/html.test.d.ts +0 -1
  80. package/dist/compliance/__tests__/html.test.js +0 -122
  81. package/dist/compliance/__tests__/impact.test.d.ts +0 -1
  82. package/dist/compliance/__tests__/impact.test.js +0 -913
  83. package/dist/compliance/__tests__/markdown.test.d.ts +0 -1
  84. package/dist/compliance/__tests__/markdown.test.js +0 -85
  85. package/dist/compliance/__tests__/trace.test.d.ts +0 -1
  86. package/dist/compliance/__tests__/trace.test.js +0 -144
  87. package/dist/compliance/__tests__/view-resolution.test.d.ts +0 -1
  88. package/dist/compliance/__tests__/view-resolution.test.js +0 -59
  89. package/dist/compliance/__tests__/views.test.d.ts +0 -1
  90. package/dist/compliance/__tests__/views.test.js +0 -59
  91. package/dist/compliance-matrix/__tests__/build.test.d.ts +0 -1
  92. package/dist/compliance-matrix/__tests__/build.test.js +0 -183
  93. package/dist/compliance-matrix/__tests__/example.test.d.ts +0 -1
  94. package/dist/compliance-matrix/__tests__/example.test.js +0 -49
  95. package/dist/confidence/__tests__/score.test.d.ts +0 -1
  96. package/dist/confidence/__tests__/score.test.js +0 -188
  97. package/dist/constraint/__tests__/example.test.d.ts +0 -1
  98. package/dist/constraint/__tests__/example.test.js +0 -14
  99. package/dist/constraint/__tests__/validate.test.d.ts +0 -1
  100. package/dist/constraint/__tests__/validate.test.js +0 -58
  101. package/dist/factor/__tests__/validate.test.d.ts +0 -1
  102. package/dist/factor/__tests__/validate.test.js +0 -112
  103. package/dist/fgca/__tests__/chain-table.test.d.ts +0 -1
  104. package/dist/fgca/__tests__/chain-table.test.js +0 -158
  105. package/dist/fgca/__tests__/layout.test.d.ts +0 -1
  106. package/dist/fgca/__tests__/layout.test.js +0 -140
  107. package/dist/fgca/__tests__/parse-canonical.test.d.ts +0 -1
  108. package/dist/fgca/__tests__/parse-canonical.test.js +0 -268
  109. package/dist/fgca/__tests__/preview-layout.test.d.ts +0 -1
  110. package/dist/fgca/__tests__/preview-layout.test.js +0 -106
  111. package/dist/fgca/__tests__/resolver.test.d.ts +0 -1
  112. package/dist/fgca/__tests__/resolver.test.js +0 -185
  113. package/dist/fgca/__tests__/validate.test.d.ts +0 -1
  114. package/dist/fgca/__tests__/validate.test.js +0 -125
  115. package/dist/goals/__tests__/GoalTreeView.test.d.ts +0 -1
  116. package/dist/goals/__tests__/GoalTreeView.test.js +0 -337
  117. package/dist/goals/__tests__/layout.test.d.ts +0 -1
  118. package/dist/goals/__tests__/layout.test.js +0 -153
  119. package/dist/goals/__tests__/mutations.test.d.ts +0 -1
  120. package/dist/goals/__tests__/mutations.test.js +0 -134
  121. package/dist/goals/__tests__/parse-canonical.test.d.ts +0 -1
  122. package/dist/goals/__tests__/parse-canonical.test.js +0 -131
  123. package/dist/goals/__tests__/validate.test.d.ts +0 -1
  124. package/dist/goals/__tests__/validate.test.js +0 -183
  125. package/dist/integration/__tests__/validate.test.d.ts +0 -1
  126. package/dist/integration/__tests__/validate.test.js +0 -169
  127. package/dist/location/__tests__/validate.test.d.ts +0 -1
  128. package/dist/location/__tests__/validate.test.js +0 -107
  129. package/dist/node/__tests__/validate.test.d.ts +0 -1
  130. package/dist/node/__tests__/validate.test.js +0 -100
  131. package/dist/process-blueprint/__tests__/compliance-lane.test.d.ts +0 -1
  132. package/dist/process-blueprint/__tests__/compliance-lane.test.js +0 -272
  133. package/dist/process-blueprint/__tests__/layout.test.d.ts +0 -1
  134. package/dist/process-blueprint/__tests__/layout.test.js +0 -196
  135. package/dist/process-blueprint/__tests__/validate.test.d.ts +0 -1
  136. package/dist/process-blueprint/__tests__/validate.test.js +0 -280
  137. package/dist/process-map/__tests__/validate.test.d.ts +0 -1
  138. package/dist/process-map/__tests__/validate.test.js +0 -199
  139. package/dist/products/__tests__/validate.test.d.ts +0 -1
  140. package/dist/products/__tests__/validate.test.js +0 -210
  141. package/dist/repo-validate/__tests__/validate-repo.test.d.ts +0 -1
  142. package/dist/repo-validate/__tests__/validate-repo.test.js +0 -576
  143. package/dist/requirement/__tests__/example.test.d.ts +0 -1
  144. package/dist/requirement/__tests__/example.test.js +0 -21
  145. package/dist/requirement/__tests__/validate.test.d.ts +0 -1
  146. package/dist/requirement/__tests__/validate.test.js +0 -80
  147. package/dist/scenarios/__tests__/validate.test.d.ts +0 -1
  148. package/dist/scenarios/__tests__/validate.test.js +0 -183
  149. package/dist/stakeholder/__tests__/validate.test.d.ts +0 -1
  150. package/dist/stakeholder/__tests__/validate.test.js +0 -88
  151. package/dist/target-state/__tests__/validate.test.d.ts +0 -1
  152. package/dist/target-state/__tests__/validate.test.js +0 -78
  153. package/dist/technology-service/__tests__/validate.test.d.ts +0 -1
  154. package/dist/technology-service/__tests__/validate.test.js +0 -121
  155. package/dist/theme/__tests__/tokens.test.d.ts +0 -1
  156. package/dist/theme/__tests__/tokens.test.js +0 -159
  157. package/dist/webview/__tests__/entity-text-layout.test.d.ts +0 -1
  158. package/dist/webview/__tests__/entity-text-layout.test.js +0 -155
  159. package/dist/webview/__tests__/entry-notations.test.d.ts +0 -1
  160. package/dist/webview/__tests__/entry-notations.test.js +0 -62
  161. package/dist/webview/__tests__/entry.test.d.ts +0 -1
  162. package/dist/webview/__tests__/entry.test.js +0 -56
  163. package/dist/webview/__tests__/render-activities.test.d.ts +0 -1
  164. package/dist/webview/__tests__/render-activities.test.js +0 -91
  165. package/dist/webview/__tests__/render-blocks.test.d.ts +0 -1
  166. package/dist/webview/__tests__/render-blocks.test.js +0 -175
  167. package/dist/webview/__tests__/render-goals.test.d.ts +0 -1
  168. package/dist/webview/__tests__/render-goals.test.js +0 -120
  169. package/dist/webview/__tests__/render-process.test.d.ts +0 -1
  170. package/dist/webview/__tests__/render-process.test.js +0 -463
  171. package/dist/webview/__tests__/render-util.test.d.ts +0 -1
  172. package/dist/webview/__tests__/render-util.test.js +0 -54
  173. package/src/__tests__/edge-path.test.ts +0 -58
  174. package/src/__tests__/node-size-presets.test.ts +0 -50
  175. package/src/__tests__/scope.test.ts +0 -27
  176. package/src/__tests__/yaml-normalize.test.ts +0 -158
  177. package/src/activities/__tests__/cpm.test.ts +0 -164
  178. package/src/activities/__tests__/gantt.test.ts +0 -290
  179. package/src/activities/__tests__/layout.test.ts +0 -112
  180. package/src/activities/__tests__/validate.test.ts +0 -446
  181. package/src/activity-card/__tests__/example.test.ts +0 -83
  182. package/src/activity-card/__tests__/layout.test.ts +0 -162
  183. package/src/activity-card/__tests__/resolver.test.ts +0 -357
  184. package/src/activity-card/__tests__/validate.test.ts +0 -167
  185. package/src/actor/__tests__/validate.test.ts +0 -114
  186. package/src/applications/__tests__/validate.test.ts +0 -256
  187. package/src/assertion/__tests__/example.test.ts +0 -37
  188. package/src/assertion/__tests__/validate.test.ts +0 -142
  189. package/src/blocks/__tests__/layout.test.ts +0 -169
  190. package/src/blocks/__tests__/validate.test.ts +0 -260
  191. package/src/business-service/__tests__/validate.test.ts +0 -160
  192. package/src/capability-map/__tests__/CapabilityMapView.test.tsx +0 -232
  193. package/src/capability-map/__tests__/address.test.ts +0 -59
  194. package/src/capability-map/__tests__/dsm-layout.test.ts +0 -52
  195. package/src/capability-map/__tests__/dsm-mutations.test.ts +0 -141
  196. package/src/capability-map/__tests__/dsm-validate.test.ts +0 -65
  197. package/src/capability-map/__tests__/validate.test.ts +0 -238
  198. package/src/change/__tests__/validate.test.ts +0 -97
  199. package/src/codex/__tests__/example.test.ts +0 -40
  200. package/src/codex/__tests__/validate.test.ts +0 -84
  201. package/src/compliance/__tests__/canon-catalog.test.ts +0 -68
  202. package/src/compliance/__tests__/classify.test.ts +0 -64
  203. package/src/compliance/__tests__/confidence.test.ts +0 -98
  204. package/src/compliance/__tests__/coverage-metric.test.ts +0 -300
  205. package/src/compliance/__tests__/demo-scenario.test.ts +0 -273
  206. package/src/compliance/__tests__/example.test.ts +0 -57
  207. package/src/compliance/__tests__/gap-report.test.ts +0 -129
  208. package/src/compliance/__tests__/html.test.ts +0 -142
  209. package/src/compliance/__tests__/impact.test.ts +0 -1060
  210. package/src/compliance/__tests__/markdown.test.ts +0 -95
  211. package/src/compliance/__tests__/trace.test.ts +0 -157
  212. package/src/compliance/__tests__/view-resolution.test.ts +0 -80
  213. package/src/compliance/__tests__/views.test.ts +0 -64
  214. package/src/compliance-matrix/__tests__/build.test.ts +0 -200
  215. package/src/compliance-matrix/__tests__/example.test.ts +0 -57
  216. package/src/confidence/__tests__/score.test.ts +0 -254
  217. package/src/constraint/__tests__/example.test.ts +0 -19
  218. package/src/constraint/__tests__/validate.test.ts +0 -68
  219. package/src/factor/__tests__/validate.test.ts +0 -133
  220. package/src/fgca/__tests__/chain-table.test.ts +0 -172
  221. package/src/fgca/__tests__/layout.test.ts +0 -179
  222. package/src/fgca/__tests__/parse-canonical.test.ts +0 -296
  223. package/src/fgca/__tests__/preview-layout.test.ts +0 -124
  224. package/src/fgca/__tests__/resolver.test.ts +0 -209
  225. package/src/fgca/__tests__/validate.test.ts +0 -142
  226. package/src/goals/__tests__/GoalTreeView.test.tsx +0 -361
  227. package/src/goals/__tests__/layout.test.ts +0 -175
  228. package/src/goals/__tests__/mutations.test.ts +0 -153
  229. package/src/goals/__tests__/parse-canonical.test.ts +0 -147
  230. package/src/goals/__tests__/validate.test.ts +0 -202
  231. package/src/integration/__tests__/validate.test.ts +0 -203
  232. package/src/location/__tests__/validate.test.ts +0 -127
  233. package/src/node/__tests__/validate.test.ts +0 -118
  234. package/src/process-blueprint/__tests__/compliance-lane.test.ts +0 -320
  235. package/src/process-blueprint/__tests__/layout.test.ts +0 -240
  236. package/src/process-blueprint/__tests__/validate.test.ts +0 -310
  237. package/src/process-map/__tests__/validate.test.ts +0 -223
  238. package/src/products/__tests__/validate.test.ts +0 -239
  239. package/src/repo-validate/__tests__/validate-repo.test.ts +0 -699
  240. package/src/requirement/__tests__/example.test.ts +0 -24
  241. package/src/requirement/__tests__/validate.test.ts +0 -96
  242. package/src/scenarios/__tests__/validate.test.ts +0 -209
  243. package/src/stakeholder/__tests__/validate.test.ts +0 -105
  244. package/src/target-state/__tests__/validate.test.ts +0 -95
  245. package/src/technology-service/__tests__/validate.test.ts +0 -143
  246. package/src/theme/__tests__/tokens.test.ts +0 -185
  247. package/src/webview/__tests__/entity-text-layout.test.ts +0 -182
  248. package/src/webview/__tests__/entry-notations.test.ts +0 -77
  249. package/src/webview/__tests__/entry.test.ts +0 -64
  250. package/src/webview/__tests__/render-activities.test.ts +0 -100
  251. package/src/webview/__tests__/render-blocks.test.ts +0 -206
  252. package/src/webview/__tests__/render-goals.test.ts +0 -128
  253. package/src/webview/__tests__/render-process.test.ts +0 -538
  254. package/src/webview/__tests__/render-util.test.ts +0 -66
@@ -1,95 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { readdirSync, readFileSync } from 'node:fs';
3
- import { fileURLToPath } from 'node:url';
4
- import path from 'node:path';
5
- import yaml from 'js-yaml';
6
- import { renderComplianceMarkdown } from '../markdown.js';
7
- import { emptyCanon, ingestComplianceDoc, type ComplianceCanon } from '../classify.js';
8
-
9
- function synthetic(): ComplianceCanon {
10
- const canon = emptyCanon();
11
- ingestComplianceDoc(canon, { notation: 'product', id: 'PRODUCT-M-1', name: 'Mobile App' });
12
- ingestComplianceDoc(canon, { notation: 'requirement', id: 'REQUIREMENT-ERASURE-1', name: 'Erasure', severity: 'high', derived_from: ['LAW-X-1'] });
13
- ingestComplianceDoc(canon, { notation: 'requirement', id: 'REQUIREMENT-LOG-1', name: 'Logs', severity: 'low' });
14
- ingestComplianceDoc(canon, { notation: 'assertion', id: 'ASSERTION-1', about: 'REQUIREMENT-ERASURE-1', subject: 'PRODUCT-M-1', status: 'compliant', evidence: [{ kind: 'note', text: 'x' }], next_review_at: '2026-09-01' });
15
- ingestComplianceDoc(canon, { id: 'LAW-X-1', name: 'Privacy Law', zone: 'codex', type: 'LAW' });
16
- return canon;
17
- }
18
-
19
- describe('renderComplianceMarkdown — matrix', () => {
20
- it('renders a table with status cells and gap dashes', () => {
21
- const md = renderComplianceMarkdown(synthetic(), { mode: 'matrix' });
22
- expect(md).toContain('# Compliance Matrix');
23
- expect(md).toContain('| Product \\ Requirement | Erasure | Logs |');
24
- expect(md).toMatch(/\| Mobile App \| Compliant \| — \|/);
25
- });
26
- });
27
-
28
- describe('renderComplianceMarkdown — law', () => {
29
- it('renders the law name and its requirement with the assertion bullet', () => {
30
- const md = renderComplianceMarkdown(synthetic(), { mode: 'law', id: 'LAW-X-1' });
31
- expect(md).toContain('# Compliance — Privacy Law');
32
- expect(md).toContain('## Erasure (`REQUIREMENT-ERASURE-1`) — severity: high');
33
- expect(md).toContain('- **Compliant** — `ASSERTION-1`');
34
- });
35
- });
36
-
37
- describe('renderComplianceMarkdown — product', () => {
38
- it('renders the product table of asserted requirements', () => {
39
- const md = renderComplianceMarkdown(synthetic(), { mode: 'product', id: 'PRODUCT-M-1' });
40
- expect(md).toContain('# Compliance — Mobile App');
41
- expect(md).toContain('| Requirement | Status | Assertion | Next review |');
42
- expect(md).toMatch(/\| Erasure \(`REQUIREMENT-ERASURE-1`\) \| Compliant \| `ASSERTION-1` \| 2026-09-01 \|/);
43
- });
44
- });
45
-
46
- describe('renderComplianceMarkdown — gap', () => {
47
- it('lists the un-asserted requirement as a checklist item', () => {
48
- const md = renderComplianceMarkdown(synthetic(), { mode: 'gap' }, { today: '2026-06-02' });
49
- expect(md).toContain('## Requirements without assertions (1)');
50
- expect(md).toContain('- [ ] `REQUIREMENT-LOG-1` Logs — severity: low');
51
- expect(md).toContain('## Assertions without evidence — ASSERT-007 (0)');
52
- });
53
- });
54
-
55
- // ── Conformance: build canon by ingesting the acme example files ────────────
56
-
57
- const examples = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../../tests/fixtures/notation-corpus');
58
- function ingestDir(canon: ComplianceCanon, dir: string): void {
59
- const full = path.join(examples, dir);
60
- for (const f of readdirSync(full)) {
61
- if (!f.endsWith('.yaml')) continue;
62
- ingestComplianceDoc(canon, yaml.load(readFileSync(path.join(full, f), 'utf-8')));
63
- }
64
- }
65
-
66
- describe('renderComplianceMarkdown — acme conformance', () => {
67
- const canon = emptyCanon();
68
- ingestDir(canon, 'product');
69
- ingestDir(canon, 'requirement');
70
- ingestDir(canon, 'assertion');
71
-
72
- it('matrix marks the dangling PRODUCT-MOBILE-1 row and shows compliant + gaps', () => {
73
- const md = renderComplianceMarkdown(canon, { mode: 'matrix' });
74
- expect(md).toContain('PRODUCT-MOBILE-1 ⚠');
75
- expect(md).toContain('Compliant');
76
- expect(md).toContain('—'); // at least one gap dash
77
- });
78
-
79
- it('gap report surfaces the un-asserted audit-log requirement', () => {
80
- const md = renderComplianceMarkdown(canon, { mode: 'gap' }, { today: '2026-06-02' });
81
- expect(md).toContain('`REQUIREMENT-AUDIT-LOG-RETENTION-1`');
82
- });
83
- });
84
-
85
- describe('gapMarkdown CV-5 pastDeadlineRequirements section', () => {
86
- it('includes the 4th section in output', () => {
87
- const canon = emptyCanon();
88
- ingestComplianceDoc(canon, { notation: 'requirement', id: 'REQ-PD-1', name: 'Past', deadline: '2020-01-01' });
89
- const md = renderComplianceMarkdown(canon, { mode: 'gap' }, { today: '2026-06-09' });
90
- expect(md).toContain('Past-deadline requirements');
91
- expect(md).toContain('REQ-PD-1');
92
- expect(md).toContain('2020-01-01');
93
- expect(md).toContain('4 checks');
94
- });
95
- });
@@ -1,157 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { buildComplianceIndex } from '../reverse-index.js';
3
- import { buildRequirementTrace, buildTraceElementCatalog } from '../trace.js';
4
- import type { ComplianceIndexInput } from '../types.js';
5
- import type { ComplianceCodexDoc } from '../classify.js';
6
-
7
- // Requirement traceability + hierarchy view.
8
- //
9
- // The two halves the view exposes:
10
- // 1. Trace chain — derived_from → REQUIREMENT → ASSERTION → subject +
11
- // realised_via.
12
- // 2. Hierarchy — parent chain + children via the `parent` field
13
- // (15-requirement.md §2.4 / ELEMENT_PRIMITIVES.md §7.13).
14
-
15
- const input: ComplianceIndexInput = {
16
- requirements: [
17
- // A broad legislative parent decomposed into two child requirements.
18
- { id: 'REQUIREMENT-DATA-PROTECTION-1', name: 'Personal-data protection', origin: 'legislative', derived_from: ['REGULATION-GDPR-2016-1'], element_kind: 'requirement' },
19
- { id: 'REQUIREMENT-DATA-ERASURE-1', name: 'Erase on request within 30 days', origin: 'legislative', parent: 'REQUIREMENT-DATA-PROTECTION-1', derived_from: ['REGULATION-GDPR-2016-1'], element_kind: 'requirement' },
20
- { id: 'REQUIREMENT-DATA-CONSENT-1', name: 'Obtain consent before processing', origin: 'legislative', parent: 'REQUIREMENT-DATA-PROTECTION-1', element_kind: 'requirement' },
21
- // A process-product sub-requirement below the erasure duty (cross-origin).
22
- { id: 'REQUIREMENT-ERASURE-SLA-1', name: 'Erasure SOP — 30d target', origin: 'process-product', parent: 'REQUIREMENT-DATA-ERASURE-1', element_kind: 'requirement' },
23
- // Constraint hierarchy (mirror pattern).
24
- { id: 'CONSTRAINT-EEA-TRANSFER-1', name: 'No transfer outside EEA without safeguards', element_kind: 'constraint' },
25
- { id: 'CONSTRAINT-EEA-ANALYTICS-1', name: 'No PII in analytics logs', parent: 'CONSTRAINT-EEA-TRANSFER-1', element_kind: 'constraint' },
26
- // Internal-only requirement — no source, no parent — for the empty-case sanity check.
27
- { id: 'REQUIREMENT-INTERNAL-1', name: 'Internal-only', element_kind: 'requirement' },
28
- ],
29
- assertions: [
30
- { id: 'ASSERTION-1', about: 'REQUIREMENT-DATA-ERASURE-1', subject: 'PRODUCT-MOBILE-1', realised_via: ['CAPABILITY-V1', 'PROCESS-PURGE-1'], status: 'compliant' },
31
- { id: 'ASSERTION-2', about: 'REQUIREMENT-DATA-ERASURE-1', subject: 'PRODUCT-WEB-1', status: 'partial' },
32
- { id: 'ASSERTION-3', about: 'REQUIREMENT-DATA-CONSENT-1', subject: 'PRODUCT-WEB-1', status: 'compliant' },
33
- ],
34
- };
35
-
36
- const codex: ComplianceCodexDoc[] = [
37
- { id: 'REGULATION-GDPR-2016-1', name: 'GDPR', type: 'REGULATION', jurisdiction: 'EU' },
38
- ];
39
-
40
- const catalog = buildTraceElementCatalog(
41
- [{ id: 'PRODUCT-MOBILE-1', name: 'Mobile app' }, { id: 'PRODUCT-WEB-1', name: 'Web app' }],
42
- [{ id: 'CAPABILITY-V1', name: 'Erasure capability v1' }, { id: 'PROCESS-PURGE-1', name: 'Purge process' }],
43
- );
44
-
45
- describe('buildComplianceIndex — requirementsByParent', () => {
46
- const idx = buildComplianceIndex(input);
47
- it('groups children of the same parent', () => {
48
- const children = idx.requirementsByParent.get('REQUIREMENT-DATA-PROTECTION-1');
49
- expect(children?.map(r => r.id).sort()).toEqual(['REQUIREMENT-DATA-CONSENT-1', 'REQUIREMENT-DATA-ERASURE-1']);
50
- });
51
- it('groups CONSTRAINT children the same way (element_kind-agnostic)', () => {
52
- const children = idx.requirementsByParent.get('CONSTRAINT-EEA-TRANSFER-1');
53
- expect(children?.map(r => r.id)).toEqual(['CONSTRAINT-EEA-ANALYTICS-1']);
54
- });
55
- it('returns undefined for a leaf with no children', () => {
56
- expect(idx.requirementsByParent.has('REQUIREMENT-INTERNAL-1')).toBe(false);
57
- });
58
- });
59
-
60
- describe('buildRequirementTrace — trace chain', () => {
61
- const idx = buildComplianceIndex(input);
62
- it('resolves derived_from codex artefacts on the sources block', () => {
63
- const trace = buildRequirementTrace('REQUIREMENT-DATA-ERASURE-1', idx, catalog, codex);
64
- expect(trace.sources).toHaveLength(1);
65
- expect(trace.sources[0].id).toBe('REGULATION-GDPR-2016-1');
66
- expect(trace.sources[0].codex?.jurisdiction).toBe('EU');
67
- });
68
- it('keeps a dangling derived_from ref with no codex when the artefact is missing', () => {
69
- const local: ComplianceIndexInput = {
70
- requirements: [{ id: 'REQUIREMENT-X-1', name: 'X', derived_from: ['LAW-MISSING-1'] }],
71
- assertions: [],
72
- };
73
- const trace = buildRequirementTrace('REQUIREMENT-X-1', buildComplianceIndex(local), catalog);
74
- expect(trace.sources).toEqual([{ id: 'LAW-MISSING-1' }]);
75
- });
76
- it('lists ASSERTIONs id-sorted, each with resolved subject + realised_via names', () => {
77
- const trace = buildRequirementTrace('REQUIREMENT-DATA-ERASURE-1', idx, catalog, codex);
78
- expect(trace.assertions.map(a => a.assertion.id)).toEqual(['ASSERTION-1', 'ASSERTION-2']);
79
- expect(trace.assertions[0].subject).toEqual({ id: 'PRODUCT-MOBILE-1', name: 'Mobile app' });
80
- expect(trace.assertions[0].realisedVia.map(r => r.name)).toEqual(['Erasure capability v1', 'Purge process']);
81
- });
82
- it('returns an empty assertions list for a REQUIREMENT with no filed claim', () => {
83
- const trace = buildRequirementTrace('REQUIREMENT-DATA-PROTECTION-1', idx, catalog);
84
- expect(trace.assertions).toEqual([]);
85
- });
86
- it('returns an empty assertions list for a CONSTRAINT (16-assertion.md §1 — CONSTRAINT-side out of v1)', () => {
87
- const trace = buildRequirementTrace('CONSTRAINT-EEA-TRANSFER-1', idx, catalog);
88
- expect(trace.assertions).toEqual([]);
89
- });
90
- it('falls back to id when the subject / realised_via element is not in the catalog (dangling ref)', () => {
91
- const local: ComplianceIndexInput = {
92
- requirements: [{ id: 'REQUIREMENT-Y-1', name: 'Y' }],
93
- assertions: [{ id: 'ASSERTION-9', about: 'REQUIREMENT-Y-1', subject: 'PRODUCT-GONE-1', realised_via: ['CAPABILITY-GONE-1'], status: 'n_a' }],
94
- };
95
- const trace = buildRequirementTrace('REQUIREMENT-Y-1', buildComplianceIndex(local), catalog);
96
- expect(trace.assertions[0].subject).toEqual({ id: 'PRODUCT-GONE-1' });
97
- expect(trace.assertions[0].realisedVia).toEqual([{ id: 'CAPABILITY-GONE-1' }]);
98
- });
99
- });
100
-
101
- describe('buildRequirementTrace — hierarchy', () => {
102
- const idx = buildComplianceIndex(input);
103
- it('walks ancestors: immediate parent first, root last', () => {
104
- const trace = buildRequirementTrace('REQUIREMENT-ERASURE-SLA-1', idx, catalog);
105
- expect(trace.ancestors.map(r => r.id)).toEqual([
106
- 'REQUIREMENT-DATA-ERASURE-1',
107
- 'REQUIREMENT-DATA-PROTECTION-1',
108
- ]);
109
- });
110
- it('lists direct children id-sorted', () => {
111
- const trace = buildRequirementTrace('REQUIREMENT-DATA-PROTECTION-1', idx, catalog);
112
- expect(trace.children.map(r => r.id)).toEqual([
113
- 'REQUIREMENT-DATA-CONSENT-1',
114
- 'REQUIREMENT-DATA-ERASURE-1',
115
- ]);
116
- });
117
- it('handles a top-level requirement (no ancestors) with no children', () => {
118
- const trace = buildRequirementTrace('REQUIREMENT-INTERNAL-1', idx, catalog);
119
- expect(trace.ancestors).toEqual([]);
120
- expect(trace.children).toEqual([]);
121
- });
122
- it('supports CONSTRAINT hierarchy the same way', () => {
123
- const trace = buildRequirementTrace('CONSTRAINT-EEA-ANALYTICS-1', idx, catalog);
124
- expect(trace.ancestors.map(r => r.id)).toEqual(['CONSTRAINT-EEA-TRANSFER-1']);
125
- });
126
- it('terminates at a missing parent without throwing (broken model)', () => {
127
- const local: ComplianceIndexInput = {
128
- requirements: [{ id: 'REQUIREMENT-ORPHAN-1', name: 'Orphan', parent: 'REQUIREMENT-GONE-1' }],
129
- assertions: [],
130
- };
131
- const trace = buildRequirementTrace('REQUIREMENT-ORPHAN-1', buildComplianceIndex(local), catalog);
132
- expect(trace.ancestors).toEqual([]);
133
- });
134
- it('breaks a parent cycle rather than looping', () => {
135
- // A → B → A (misauthored).
136
- const local: ComplianceIndexInput = {
137
- requirements: [
138
- { id: 'REQUIREMENT-A-1', name: 'A', parent: 'REQUIREMENT-B-1' },
139
- { id: 'REQUIREMENT-B-1', name: 'B', parent: 'REQUIREMENT-A-1' },
140
- ],
141
- assertions: [],
142
- };
143
- const trace = buildRequirementTrace('REQUIREMENT-A-1', buildComplianceIndex(local), catalog);
144
- expect(trace.ancestors.map(r => r.id)).toEqual(['REQUIREMENT-B-1']);
145
- });
146
- });
147
-
148
- describe('buildRequirementTrace — dangling target', () => {
149
- it('returns a stub carrying the id as name when the requirement is not scanned', () => {
150
- const trace = buildRequirementTrace('REQUIREMENT-UNKNOWN-1', buildComplianceIndex({ requirements: [], assertions: [] }), catalog);
151
- expect(trace.requirement).toEqual({ id: 'REQUIREMENT-UNKNOWN-1', name: 'REQUIREMENT-UNKNOWN-1' });
152
- expect(trace.sources).toEqual([]);
153
- expect(trace.assertions).toEqual([]);
154
- expect(trace.ancestors).toEqual([]);
155
- expect(trace.children).toEqual([]);
156
- });
157
- });
@@ -1,80 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
-
3
- import { emptyCanon } from '../classify.js';
4
- import { catalogFromMap } from '../canon-catalog.js';
5
- import { collectImpactViewResolutionFindings } from '../impact.js';
6
- import { collectCoverageViewResolutionFindings } from '../coverage-metric.js';
7
- import type { ImpactViewConfig } from '../impact.js';
8
- import type { CoverageMetricConfig } from '../coverage-metric.js';
9
-
10
- const catalog = catalogFromMap(
11
- new Map([
12
- ['PRODUCT-ECOMM-1', 'PRODUCT'],
13
- ['REQUIREMENT-GDPR-1', 'REQUIREMENT'],
14
- ['LAW-GDPR-1', 'LAW'],
15
- ]),
16
- );
17
-
18
- const complianceCanon = emptyCanon();
19
- complianceCanon.products.push({ id: 'PRODUCT-ECOMM-1', name: 'E-Commerce' });
20
- complianceCanon.requirements.push({ id: 'REQUIREMENT-GDPR-1', name: 'GDPR req' });
21
- complianceCanon.codex.push({ id: 'LAW-GDPR-1', name: 'GDPR' });
22
-
23
- describe('collectImpactViewResolutionFindings', () => {
24
- const base: ImpactViewConfig = {
25
- id: 'test-impact',
26
- name: 'Test',
27
- subjects: { products: ['PRODUCT-ECOMM-1'], processes: [], capabilities: [] },
28
- obligations: { filter: { derived_from_codex: ['LAW-GDPR-1'] } },
29
- status_display: { show: ['compliant'] },
30
- empty_cells: {},
31
- order_rows_by: 'id',
32
- };
33
-
34
- it('passes when subjects and regimes resolve', () => {
35
- expect(collectImpactViewResolutionFindings(base, catalog, complianceCanon)).toEqual([]);
36
- });
37
-
38
- it('flags unresolved subjects and regimes', () => {
39
- const findings = collectImpactViewResolutionFindings(
40
- {
41
- ...base,
42
- subjects: { products: ['PRODUCT-MISSING-1'], processes: [], capabilities: [] },
43
- obligations: { include: ['REQUIREMENT-MISSING-1'], filter: { derived_from_codex: ['LAW-MISSING-1'] } },
44
- },
45
- catalog,
46
- complianceCanon,
47
- );
48
- expect(findings.some((f) => f.code === 'COMPIMP-REF' && f.message.includes('PRODUCT-MISSING-1'))).toBe(true);
49
- expect(findings.some((f) => f.message.includes('REQUIREMENT-MISSING-1'))).toBe(true);
50
- expect(findings.some((f) => f.message.includes('LAW-MISSING-1'))).toBe(true);
51
- });
52
- });
53
-
54
- describe('collectCoverageViewResolutionFindings', () => {
55
- const base: CoverageMetricConfig = {
56
- id: 'test-coverage',
57
- name: 'Test',
58
- thresholds: { green: 0.9, amber: 0.7 },
59
- subjects: { products: ['PRODUCT-ECOMM-1'] },
60
- regimes: { include: ['LAW-GDPR-1'] },
61
- };
62
-
63
- it('passes when products and regimes resolve', () => {
64
- expect(collectCoverageViewResolutionFindings(base, catalog, complianceCanon)).toEqual([]);
65
- });
66
-
67
- it('flags unresolved product and regime refs', () => {
68
- const findings = collectCoverageViewResolutionFindings(
69
- {
70
- ...base,
71
- subjects: { products: ['PRODUCT-MISSING-1'] },
72
- regimes: { include: ['LAW-MISSING-1'] },
73
- },
74
- catalog,
75
- complianceCanon,
76
- );
77
- expect(findings.some((f) => f.code === 'COVMET-REF')).toBe(true);
78
- expect(findings).toHaveLength(2);
79
- });
80
- });
@@ -1,64 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { buildComplianceIndex } from '../reverse-index.js';
3
- import { buildLawTree, buildProductView } from '../views.js';
4
- import type { ComplianceIndexInput } from '../types.js';
5
-
6
- const input: ComplianceIndexInput = {
7
- requirements: [
8
- { id: 'REQUIREMENT-A-1', name: 'A', severity: 'high', derived_from: ['LAW-X-1'] },
9
- { id: 'REQUIREMENT-B-1', name: 'B', severity: 'low', derived_from: ['LAW-X-1', 'REGULATION-Y-1'] },
10
- { id: 'REQUIREMENT-C-1', name: 'C' }, // internal-only, no law
11
- ],
12
- assertions: [
13
- { id: 'ASSERTION-2', about: 'REQUIREMENT-A-1', subject: 'PRODUCT-M-1', status: 'compliant' },
14
- { id: 'ASSERTION-1', about: 'REQUIREMENT-A-1', subject: 'CAPABILITY-V2', status: 'under_review' },
15
- { id: 'ASSERTION-3', about: 'REQUIREMENT-B-1', subject: 'PRODUCT-M-1', status: 'partial' },
16
- ],
17
- };
18
-
19
- describe('buildComplianceIndex', () => {
20
- const idx = buildComplianceIndex(input);
21
- it('indexes requirements by the laws they derive from', () => {
22
- expect(idx.requirementsByLaw.get('LAW-X-1')?.map(r => r.id)).toEqual(['REQUIREMENT-A-1', 'REQUIREMENT-B-1']);
23
- expect(idx.requirementsByLaw.get('REGULATION-Y-1')?.map(r => r.id)).toEqual(['REQUIREMENT-B-1']);
24
- expect(idx.requirementsByLaw.has('LAW-NONE-1')).toBe(false);
25
- });
26
- it('indexes assertions by requirement and by subject', () => {
27
- expect(idx.assertionsByRequirement.get('REQUIREMENT-A-1')?.map(a => a.id).sort()).toEqual(['ASSERTION-1', 'ASSERTION-2']);
28
- expect(idx.assertionsBySubject.get('PRODUCT-M-1')?.map(a => a.id).sort()).toEqual(['ASSERTION-2', 'ASSERTION-3']);
29
- });
30
- });
31
-
32
- describe('buildLawTree', () => {
33
- const idx = buildComplianceIndex(input);
34
- it('lists requirements derived from the law, each with its id-sorted assertions', () => {
35
- const tree = buildLawTree('LAW-X-1', idx);
36
- expect(tree.requirements.map(r => r.requirement.id)).toEqual(['REQUIREMENT-A-1', 'REQUIREMENT-B-1']);
37
- expect(tree.requirements[0].assertions.map(a => a.id)).toEqual(['ASSERTION-1', 'ASSERTION-2']);
38
- expect(tree.requirements[0].assertions.map(a => a.status)).toEqual(['under_review', 'compliant']);
39
- });
40
- it('returns an empty tree for an unknown law', () => {
41
- expect(buildLawTree('LAW-NONE-1', idx).requirements).toEqual([]);
42
- });
43
- });
44
-
45
- describe('buildProductView', () => {
46
- const idx = buildComplianceIndex(input);
47
- it('lists the requirements the product is asserted against, with status, requirement-id-sorted', () => {
48
- const view = buildProductView('PRODUCT-M-1', idx);
49
- expect(view.requirements.map(r => r.requirement.id)).toEqual(['REQUIREMENT-A-1', 'REQUIREMENT-B-1']);
50
- expect(view.requirements.map(r => r.assertion.status)).toEqual(['compliant', 'partial']);
51
- expect(view.requirements[0].requirement.name).toBe('A');
52
- });
53
- it('falls back to the id as name when the requirement is not in the scan (dangling about)', () => {
54
- const idx2 = buildComplianceIndex({
55
- requirements: [],
56
- assertions: [{ id: 'ASSERTION-9', about: 'REQUIREMENT-GONE-1', subject: 'PRODUCT-M-1', status: 'n_a' }],
57
- });
58
- const view = buildProductView('PRODUCT-M-1', idx2);
59
- expect(view.requirements[0].requirement).toEqual({ id: 'REQUIREMENT-GONE-1', name: 'REQUIREMENT-GONE-1' });
60
- });
61
- it('returns an empty view for a product with no assertions', () => {
62
- expect(buildProductView('PRODUCT-NONE-1', idx).requirements).toEqual([]);
63
- });
64
- });
@@ -1,200 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { buildComplianceMatrix, filterComplianceMatrix } from '../build.js';
3
- import type { ComplianceMatrixInput } from '../types.js';
4
-
5
- function input(over: Partial<ComplianceMatrixInput> = {}): ComplianceMatrixInput {
6
- return {
7
- products: [
8
- { id: 'PRODUCT-ECOMM-1', name: 'E-Commerce' },
9
- { id: 'PRODUCT-SUPPORT-1', name: 'Support' },
10
- ],
11
- requirements: [
12
- { id: 'REQUIREMENT-DATA-ERASURE-1', name: 'Erasure', severity: 'high' },
13
- { id: 'REQUIREMENT-AUDIT-LOG-RETENTION-1', name: 'Audit logs', severity: 'medium' },
14
- ],
15
- assertions: [
16
- { id: 'ASSERTION-1', about: 'REQUIREMENT-DATA-ERASURE-1', subject: 'PRODUCT-ECOMM-1', status: 'compliant' },
17
- ],
18
- ...over,
19
- };
20
- }
21
-
22
- describe('buildComplianceMatrix', () => {
23
- it('sorts products as rows and requirements as columns by id', () => {
24
- const m = buildComplianceMatrix(input());
25
- expect(m.products.map(p => p.id)).toEqual(['PRODUCT-ECOMM-1', 'PRODUCT-SUPPORT-1']);
26
- expect(m.requirements.map(r => r.id)).toEqual([
27
- 'REQUIREMENT-AUDIT-LOG-RETENTION-1',
28
- 'REQUIREMENT-DATA-ERASURE-1',
29
- ]);
30
- });
31
-
32
- it('places an assertion status in the (product, requirement) cell and gaps elsewhere', () => {
33
- const m = buildComplianceMatrix(input());
34
- // row 0 = ECOMM; col 1 = DATA-ERASURE (after the sort)
35
- expect(m.cells[0][1]).toMatchObject({ status: 'compliant', assertionId: 'ASSERTION-1' });
36
- expect(m.cells[0][0].status).toBeUndefined(); // ECOMM × AUDIT-LOG → gap
37
- expect(m.cells[1][1].status).toBeUndefined(); // SUPPORT × DATA-ERASURE → gap
38
- expect(m.summary).toMatchObject({ products: 2, requirements: 2, assertions: 1, gaps: 3 });
39
- });
40
-
41
- it('adds a product-typed assertion subject with no product file as an unresolved row', () => {
42
- const m = buildComplianceMatrix(input({
43
- assertions: [
44
- { id: 'A1', about: 'REQUIREMENT-DATA-ERASURE-1', subject: 'PRODUCT-MOBILE-1', status: 'partial' },
45
- ],
46
- }));
47
- const mobile = m.products.find(p => p.id === 'PRODUCT-MOBILE-1');
48
- expect(mobile).toMatchObject({ unresolved: true });
49
- const col = m.requirements.findIndex(r => r.id === 'REQUIREMENT-DATA-ERASURE-1');
50
- const row = m.products.findIndex(p => p.id === 'PRODUCT-MOBILE-1');
51
- expect(m.cells[row][col].status).toBe('partial');
52
- });
53
-
54
- it('ignores assertions whose subject is not a PRODUCT', () => {
55
- const m = buildComplianceMatrix(input({
56
- assertions: [
57
- { id: 'A1', about: 'REQUIREMENT-DATA-ERASURE-1', subject: 'CAPABILITY-V2', status: 'compliant' },
58
- { id: 'A2', about: 'REQUIREMENT-DATA-ERASURE-1', subject: 'PROCESS-X-1', status: 'partial' },
59
- ],
60
- }));
61
- expect(m.summary.assertions).toBe(0);
62
- expect(m.products.map(p => p.id)).toEqual(['PRODUCT-ECOMM-1', 'PRODUCT-SUPPORT-1']);
63
- });
64
- });
65
-
66
- describe('buildComplianceMatrix — jurisdiction resolution (F16)', () => {
67
- it('resolves Requirement.jurisdictions from derived_from → codex', () => {
68
- const m = buildComplianceMatrix(input({
69
- requirements: [
70
- { id: 'REQUIREMENT-DATA-ERASURE-1', name: 'Erasure', severity: 'high',
71
- derived_from: ['LAW-PERSONAL-DATA-2017-1'] },
72
- { id: 'REQUIREMENT-AUDIT-LOG-RETENTION-1', name: 'Audit logs', severity: 'medium',
73
- derived_from: ['LAW-AUDIT-2020-1', 'LAW-PERSONAL-DATA-2017-1'] },
74
- ],
75
- codex: [
76
- { id: 'LAW-PERSONAL-DATA-2017-1', jurisdiction: 'ge' },
77
- { id: 'LAW-AUDIT-2020-1', jurisdiction: 'eu' },
78
- ],
79
- }));
80
- const erasure = m.requirements.find(r => r.id === 'REQUIREMENT-DATA-ERASURE-1')!;
81
- const audit = m.requirements.find(r => r.id === 'REQUIREMENT-AUDIT-LOG-RETENTION-1')!;
82
- expect(erasure.jurisdictions).toEqual(['ge']);
83
- // Sorted, deduplicated union.
84
- expect(audit.jurisdictions).toEqual(['eu', 'ge']);
85
- });
86
-
87
- it('leaves jurisdictions undefined when no codex source resolves', () => {
88
- const m = buildComplianceMatrix(input({
89
- requirements: [
90
- { id: 'REQUIREMENT-INTERNAL-1', name: 'Internal', severity: 'low' },
91
- { id: 'REQUIREMENT-DANGLING-1', name: 'Dangling', severity: 'low',
92
- derived_from: ['LAW-MISSING-1'] },
93
- ],
94
- codex: [{ id: 'LAW-OTHER-1', jurisdiction: 'us' }],
95
- }));
96
- expect(m.requirements.find(r => r.id === 'REQUIREMENT-INTERNAL-1')!.jurisdictions).toBeUndefined();
97
- expect(m.requirements.find(r => r.id === 'REQUIREMENT-DANGLING-1')!.jurisdictions).toBeUndefined();
98
- });
99
-
100
- it('ignores codex entries with no jurisdiction (e.g. internal POLICY)', () => {
101
- const m = buildComplianceMatrix(input({
102
- requirements: [
103
- { id: 'REQUIREMENT-DATA-ERASURE-1', name: 'Erasure', severity: 'high',
104
- derived_from: ['POLICY-INTERNAL-1'] },
105
- ],
106
- codex: [{ id: 'POLICY-INTERNAL-1' }],
107
- }));
108
- expect(m.requirements[0].jurisdictions).toBeUndefined();
109
- });
110
-
111
- it('works with no codex input (backwards-compatible)', () => {
112
- const m = buildComplianceMatrix(input({
113
- requirements: [
114
- { id: 'REQUIREMENT-DATA-ERASURE-1', name: 'Erasure', severity: 'high',
115
- derived_from: ['LAW-PERSONAL-DATA-2017-1'] },
116
- ],
117
- }));
118
- expect(m.requirements[0].jurisdictions).toBeUndefined();
119
- });
120
- });
121
-
122
- describe('filterComplianceMatrix', () => {
123
- it('trims requirement columns by severity', () => {
124
- const m = buildComplianceMatrix(input());
125
- const f = filterComplianceMatrix(m, { severities: ['high'] });
126
- expect(f.requirements.map(r => r.id)).toEqual(['REQUIREMENT-DATA-ERASURE-1']);
127
- expect(f.cells[0]).toHaveLength(1);
128
- expect(f.cells[0][0]).toMatchObject({ status: 'compliant' });
129
- });
130
-
131
- it('blanks cells whose status is filtered out, preserving the grid shape', () => {
132
- const m = buildComplianceMatrix(input());
133
- const f = filterComplianceMatrix(m, { statuses: ['non_compliant'] });
134
- // The compliant cell is now hidden (treated as a gap); columns unchanged.
135
- expect(f.requirements).toHaveLength(2);
136
- expect(f.cells[0][1].status).toBeUndefined();
137
- expect(f.summary.assertions).toBe(0);
138
- });
139
-
140
- it('is a no-op when no filter dimension is set', () => {
141
- const m = buildComplianceMatrix(input());
142
- const f = filterComplianceMatrix(m, {});
143
- expect(f.summary).toEqual(m.summary);
144
- });
145
-
146
- it('keeps only columns whose resolved jurisdiction is in the filter (F16)', () => {
147
- const m = buildComplianceMatrix(input({
148
- requirements: [
149
- { id: 'REQUIREMENT-DATA-ERASURE-1', name: 'Erasure', severity: 'high',
150
- derived_from: ['LAW-PERSONAL-DATA-2017-1'] },
151
- { id: 'REQUIREMENT-AUDIT-LOG-RETENTION-1', name: 'Audit logs', severity: 'medium',
152
- derived_from: ['LAW-AUDIT-2020-1'] },
153
- ],
154
- codex: [
155
- { id: 'LAW-PERSONAL-DATA-2017-1', jurisdiction: 'ge' },
156
- { id: 'LAW-AUDIT-2020-1', jurisdiction: 'eu' },
157
- ],
158
- }));
159
- const f = filterComplianceMatrix(m, { jurisdictions: ['ge'] });
160
- expect(f.requirements.map(r => r.id)).toEqual(['REQUIREMENT-DATA-ERASURE-1']);
161
- expect(f.cells[0]).toHaveLength(1);
162
- });
163
-
164
- it('drops requirements with no resolved jurisdiction when the filter is active', () => {
165
- const m = buildComplianceMatrix(input({
166
- requirements: [
167
- { id: 'REQUIREMENT-DATA-ERASURE-1', name: 'Erasure', severity: 'high',
168
- derived_from: ['LAW-PERSONAL-DATA-2017-1'] },
169
- { id: 'REQUIREMENT-INTERNAL-1', name: 'Internal', severity: 'low' },
170
- ],
171
- codex: [{ id: 'LAW-PERSONAL-DATA-2017-1', jurisdiction: 'ge' }],
172
- }));
173
- const f = filterComplianceMatrix(m, { jurisdictions: ['ge'] });
174
- expect(f.requirements.map(r => r.id)).toEqual(['REQUIREMENT-DATA-ERASURE-1']);
175
- });
176
-
177
- it('combines jurisdiction filter with severity (intersection)', () => {
178
- const m = buildComplianceMatrix(input({
179
- requirements: [
180
- { id: 'REQUIREMENT-DATA-ERASURE-1', name: 'Erasure', severity: 'high',
181
- derived_from: ['LAW-PERSONAL-DATA-2017-1'] },
182
- { id: 'REQUIREMENT-DATA-PORTABILITY-1', name: 'Portability', severity: 'medium',
183
- derived_from: ['LAW-PERSONAL-DATA-2017-1'] },
184
- ],
185
- codex: [{ id: 'LAW-PERSONAL-DATA-2017-1', jurisdiction: 'ge' }],
186
- }));
187
- const f = filterComplianceMatrix(m, { jurisdictions: ['ge'], severities: ['high'] });
188
- expect(f.requirements.map(r => r.id)).toEqual(['REQUIREMENT-DATA-ERASURE-1']);
189
- });
190
-
191
- it('empty jurisdiction array is treated as no-filter on that dimension', () => {
192
- const m = buildComplianceMatrix(input({
193
- requirements: [
194
- { id: 'REQUIREMENT-INTERNAL-1', name: 'Internal', severity: 'low' },
195
- ],
196
- }));
197
- const f = filterComplianceMatrix(m, { jurisdictions: [] });
198
- expect(f.requirements).toHaveLength(1);
199
- });
200
- });
@@ -1,57 +0,0 @@
1
- // Conformance test — the compliance matrix on the acme_corp worked examples
2
- // (mirrored under tests/fixtures/notation-corpus/product, tests/fixtures/notation-corpus/requirement, tests/fixtures/notation-corpus/assertion).
3
- // Pins the #84 Phase 2 acceptance: the matrix renders correctly and gaps are
4
- // obvious.
5
-
6
- import { describe, it, expect } from 'vitest';
7
- import { readdirSync, readFileSync } from 'node:fs';
8
- import { fileURLToPath } from 'node:url';
9
- import path from 'node:path';
10
- import yaml from 'js-yaml';
11
- import { buildComplianceMatrix } from '../build.js';
12
- import type { MatrixAssertionRef, MatrixProduct, MatrixRequirement } from '../types.js';
13
-
14
- const examples = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../../tests/fixtures/notation-corpus');
15
- function loadAll(dir: string): Record<string, unknown>[] {
16
- const full = path.join(examples, dir);
17
- return readdirSync(full)
18
- .filter(f => f.endsWith('.yaml'))
19
- .map(f => yaml.load(readFileSync(path.join(full, f), 'utf-8')) as Record<string, unknown>);
20
- }
21
-
22
- describe('compliance matrix — acme_corp worked examples', () => {
23
- const products: MatrixProduct[] = loadAll('product').map(p => ({ id: String(p.id), name: String(p.name) }));
24
- const requirements: MatrixRequirement[] = loadAll('requirement').map(r => ({
25
- id: String(r.id), name: String(r.name), severity: r.severity as string | undefined,
26
- }));
27
- const assertions: MatrixAssertionRef[] = loadAll('assertion').map(a => ({
28
- id: String(a.id), about: String(a.about), subject: String(a.subject),
29
- status: a.status as MatrixAssertionRef['status'],
30
- assessed_at: a.assessed_at as string | undefined,
31
- next_review_at: a.next_review_at as string | undefined,
32
- }));
33
-
34
- const m = buildComplianceMatrix({ products, requirements, assertions });
35
-
36
- it('rows = the two product files plus the dangling PRODUCT-MOBILE-1 subject', () => {
37
- expect(m.products.map(p => p.id)).toEqual([
38
- 'PRODUCT-ECOMM-1', 'PRODUCT-MOBILE-1', 'PRODUCT-SUPPORT-1',
39
- ]);
40
- expect(m.products.find(p => p.id === 'PRODUCT-MOBILE-1')?.unresolved).toBe(true);
41
- });
42
-
43
- it('columns = the two requirements', () => {
44
- expect(m.requirements.map(r => r.id)).toEqual([
45
- 'REQUIREMENT-AUDIT-LOG-RETENTION-1', 'REQUIREMENT-DATA-ERASURE-1',
46
- ]);
47
- });
48
-
49
- it('the only product-subject assertion (mobile → data-erasure) is compliant; everything else is a gap', () => {
50
- const row = m.products.findIndex(p => p.id === 'PRODUCT-MOBILE-1');
51
- const col = m.requirements.findIndex(r => r.id === 'REQUIREMENT-DATA-ERASURE-1');
52
- expect(m.cells[row][col]).toMatchObject({ status: 'compliant', assertionId: 'ASSERTION-MOBILE-DATA-ERASURE-1' });
53
- // 3 products × 2 requirements = 6 cells; 1 filled → 5 gaps. The CRM
54
- // (capability) and onboarding (process) assertions are not in the matrix.
55
- expect(m.summary).toMatchObject({ products: 3, requirements: 2, assertions: 1, gaps: 5 });
56
- });
57
- });