@transitrix/diagrams 1.8.6 → 1.8.8

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 (251) hide show
  1. package/dist/fgca/index.js +10 -10
  2. package/dist/fgca/layout.js +1 -1
  3. package/dist/fgca/nodeTypes.js +4 -4
  4. package/dist/index.js +33 -33
  5. package/package.json +8 -2
  6. package/dist/__tests__/edge-path.test.d.ts +0 -1
  7. package/dist/__tests__/edge-path.test.js +0 -55
  8. package/dist/__tests__/node-size-presets.test.d.ts +0 -1
  9. package/dist/__tests__/node-size-presets.test.js +0 -30
  10. package/dist/__tests__/scope.test.d.ts +0 -1
  11. package/dist/__tests__/scope.test.js +0 -23
  12. package/dist/__tests__/yaml-normalize.test.d.ts +0 -1
  13. package/dist/__tests__/yaml-normalize.test.js +0 -148
  14. package/dist/activities/__tests__/cpm.test.d.ts +0 -1
  15. package/dist/activities/__tests__/cpm.test.js +0 -146
  16. package/dist/activities/__tests__/gantt.test.d.ts +0 -1
  17. package/dist/activities/__tests__/gantt.test.js +0 -263
  18. package/dist/activities/__tests__/layout.test.d.ts +0 -1
  19. package/dist/activities/__tests__/layout.test.js +0 -98
  20. package/dist/activities/__tests__/validate.test.d.ts +0 -1
  21. package/dist/activities/__tests__/validate.test.js +0 -397
  22. package/dist/activity-card/__tests__/example.test.d.ts +0 -1
  23. package/dist/activity-card/__tests__/example.test.js +0 -73
  24. package/dist/activity-card/__tests__/layout.test.d.ts +0 -1
  25. package/dist/activity-card/__tests__/layout.test.js +0 -141
  26. package/dist/activity-card/__tests__/resolver.test.d.ts +0 -1
  27. package/dist/activity-card/__tests__/resolver.test.js +0 -325
  28. package/dist/activity-card/__tests__/validate.test.d.ts +0 -1
  29. package/dist/activity-card/__tests__/validate.test.js +0 -149
  30. package/dist/actor/__tests__/validate.test.d.ts +0 -1
  31. package/dist/actor/__tests__/validate.test.js +0 -95
  32. package/dist/applications/__tests__/validate.test.d.ts +0 -1
  33. package/dist/applications/__tests__/validate.test.js +0 -223
  34. package/dist/assertion/__tests__/example.test.d.ts +0 -1
  35. package/dist/assertion/__tests__/example.test.js +0 -32
  36. package/dist/assertion/__tests__/validate.test.d.ts +0 -1
  37. package/dist/assertion/__tests__/validate.test.js +0 -130
  38. package/dist/blocks/__tests__/layout.test.d.ts +0 -1
  39. package/dist/blocks/__tests__/layout.test.js +0 -153
  40. package/dist/blocks/__tests__/validate.test.d.ts +0 -1
  41. package/dist/blocks/__tests__/validate.test.js +0 -235
  42. package/dist/business-service/__tests__/validate.test.d.ts +0 -1
  43. package/dist/business-service/__tests__/validate.test.js +0 -135
  44. package/dist/capability-map/__tests__/CapabilityMapView.test.d.ts +0 -1
  45. package/dist/capability-map/__tests__/CapabilityMapView.test.js +0 -217
  46. package/dist/capability-map/__tests__/address.test.d.ts +0 -1
  47. package/dist/capability-map/__tests__/address.test.js +0 -49
  48. package/dist/capability-map/__tests__/dsm-layout.test.d.ts +0 -1
  49. package/dist/capability-map/__tests__/dsm-layout.test.js +0 -46
  50. package/dist/capability-map/__tests__/dsm-mutations.test.d.ts +0 -1
  51. package/dist/capability-map/__tests__/dsm-mutations.test.js +0 -125
  52. package/dist/capability-map/__tests__/dsm-validate.test.d.ts +0 -1
  53. package/dist/capability-map/__tests__/dsm-validate.test.js +0 -56
  54. package/dist/capability-map/__tests__/validate.test.d.ts +0 -1
  55. package/dist/capability-map/__tests__/validate.test.js +0 -212
  56. package/dist/change/__tests__/validate.test.d.ts +0 -1
  57. package/dist/change/__tests__/validate.test.js +0 -79
  58. package/dist/codex/__tests__/example.test.d.ts +0 -1
  59. package/dist/codex/__tests__/example.test.js +0 -33
  60. package/dist/codex/__tests__/validate.test.d.ts +0 -1
  61. package/dist/codex/__tests__/validate.test.js +0 -68
  62. package/dist/compliance/__tests__/canon-catalog.test.d.ts +0 -1
  63. package/dist/compliance/__tests__/canon-catalog.test.js +0 -60
  64. package/dist/compliance/__tests__/classify.test.d.ts +0 -1
  65. package/dist/compliance/__tests__/classify.test.js +0 -58
  66. package/dist/compliance/__tests__/confidence.test.d.ts +0 -1
  67. package/dist/compliance/__tests__/confidence.test.js +0 -78
  68. package/dist/compliance/__tests__/coverage-metric.test.d.ts +0 -1
  69. package/dist/compliance/__tests__/coverage-metric.test.js +0 -264
  70. package/dist/compliance/__tests__/demo-scenario.test.d.ts +0 -1
  71. package/dist/compliance/__tests__/demo-scenario.test.js +0 -226
  72. package/dist/compliance/__tests__/example.test.d.ts +0 -1
  73. package/dist/compliance/__tests__/example.test.js +0 -51
  74. package/dist/compliance/__tests__/gap-report.test.d.ts +0 -1
  75. package/dist/compliance/__tests__/gap-report.test.js +0 -113
  76. package/dist/compliance/__tests__/html.test.d.ts +0 -1
  77. package/dist/compliance/__tests__/html.test.js +0 -122
  78. package/dist/compliance/__tests__/impact.test.d.ts +0 -1
  79. package/dist/compliance/__tests__/impact.test.js +0 -913
  80. package/dist/compliance/__tests__/markdown.test.d.ts +0 -1
  81. package/dist/compliance/__tests__/markdown.test.js +0 -85
  82. package/dist/compliance/__tests__/trace.test.d.ts +0 -1
  83. package/dist/compliance/__tests__/trace.test.js +0 -144
  84. package/dist/compliance/__tests__/view-resolution.test.d.ts +0 -1
  85. package/dist/compliance/__tests__/view-resolution.test.js +0 -59
  86. package/dist/compliance/__tests__/views.test.d.ts +0 -1
  87. package/dist/compliance/__tests__/views.test.js +0 -59
  88. package/dist/compliance-matrix/__tests__/build.test.d.ts +0 -1
  89. package/dist/compliance-matrix/__tests__/build.test.js +0 -183
  90. package/dist/compliance-matrix/__tests__/example.test.d.ts +0 -1
  91. package/dist/compliance-matrix/__tests__/example.test.js +0 -49
  92. package/dist/confidence/__tests__/score.test.d.ts +0 -1
  93. package/dist/confidence/__tests__/score.test.js +0 -188
  94. package/dist/constraint/__tests__/example.test.d.ts +0 -1
  95. package/dist/constraint/__tests__/example.test.js +0 -14
  96. package/dist/constraint/__tests__/validate.test.d.ts +0 -1
  97. package/dist/constraint/__tests__/validate.test.js +0 -58
  98. package/dist/factor/__tests__/validate.test.d.ts +0 -1
  99. package/dist/factor/__tests__/validate.test.js +0 -112
  100. package/dist/fgca/__tests__/chain-table.test.d.ts +0 -1
  101. package/dist/fgca/__tests__/chain-table.test.js +0 -158
  102. package/dist/fgca/__tests__/layout.test.d.ts +0 -1
  103. package/dist/fgca/__tests__/layout.test.js +0 -140
  104. package/dist/fgca/__tests__/parse-canonical.test.d.ts +0 -1
  105. package/dist/fgca/__tests__/parse-canonical.test.js +0 -268
  106. package/dist/fgca/__tests__/preview-layout.test.d.ts +0 -1
  107. package/dist/fgca/__tests__/preview-layout.test.js +0 -106
  108. package/dist/fgca/__tests__/resolver.test.d.ts +0 -1
  109. package/dist/fgca/__tests__/resolver.test.js +0 -185
  110. package/dist/fgca/__tests__/validate.test.d.ts +0 -1
  111. package/dist/fgca/__tests__/validate.test.js +0 -125
  112. package/dist/goals/__tests__/GoalTreeView.test.d.ts +0 -1
  113. package/dist/goals/__tests__/GoalTreeView.test.js +0 -337
  114. package/dist/goals/__tests__/layout.test.d.ts +0 -1
  115. package/dist/goals/__tests__/layout.test.js +0 -153
  116. package/dist/goals/__tests__/mutations.test.d.ts +0 -1
  117. package/dist/goals/__tests__/mutations.test.js +0 -134
  118. package/dist/goals/__tests__/parse-canonical.test.d.ts +0 -1
  119. package/dist/goals/__tests__/parse-canonical.test.js +0 -131
  120. package/dist/goals/__tests__/validate.test.d.ts +0 -1
  121. package/dist/goals/__tests__/validate.test.js +0 -183
  122. package/dist/integration/__tests__/validate.test.d.ts +0 -1
  123. package/dist/integration/__tests__/validate.test.js +0 -169
  124. package/dist/location/__tests__/validate.test.d.ts +0 -1
  125. package/dist/location/__tests__/validate.test.js +0 -107
  126. package/dist/node/__tests__/validate.test.d.ts +0 -1
  127. package/dist/node/__tests__/validate.test.js +0 -100
  128. package/dist/process-blueprint/__tests__/compliance-lane.test.d.ts +0 -1
  129. package/dist/process-blueprint/__tests__/compliance-lane.test.js +0 -272
  130. package/dist/process-blueprint/__tests__/layout.test.d.ts +0 -1
  131. package/dist/process-blueprint/__tests__/layout.test.js +0 -196
  132. package/dist/process-blueprint/__tests__/validate.test.d.ts +0 -1
  133. package/dist/process-blueprint/__tests__/validate.test.js +0 -280
  134. package/dist/process-map/__tests__/validate.test.d.ts +0 -1
  135. package/dist/process-map/__tests__/validate.test.js +0 -199
  136. package/dist/products/__tests__/validate.test.d.ts +0 -1
  137. package/dist/products/__tests__/validate.test.js +0 -210
  138. package/dist/repo-validate/__tests__/validate-repo.test.d.ts +0 -1
  139. package/dist/repo-validate/__tests__/validate-repo.test.js +0 -576
  140. package/dist/requirement/__tests__/example.test.d.ts +0 -1
  141. package/dist/requirement/__tests__/example.test.js +0 -21
  142. package/dist/requirement/__tests__/validate.test.d.ts +0 -1
  143. package/dist/requirement/__tests__/validate.test.js +0 -80
  144. package/dist/scenarios/__tests__/validate.test.d.ts +0 -1
  145. package/dist/scenarios/__tests__/validate.test.js +0 -183
  146. package/dist/stakeholder/__tests__/validate.test.d.ts +0 -1
  147. package/dist/stakeholder/__tests__/validate.test.js +0 -88
  148. package/dist/target-state/__tests__/validate.test.d.ts +0 -1
  149. package/dist/target-state/__tests__/validate.test.js +0 -78
  150. package/dist/technology-service/__tests__/validate.test.d.ts +0 -1
  151. package/dist/technology-service/__tests__/validate.test.js +0 -121
  152. package/dist/theme/__tests__/tokens.test.d.ts +0 -1
  153. package/dist/theme/__tests__/tokens.test.js +0 -159
  154. package/dist/webview/__tests__/entity-text-layout.test.d.ts +0 -1
  155. package/dist/webview/__tests__/entity-text-layout.test.js +0 -155
  156. package/dist/webview/__tests__/entry-notations.test.d.ts +0 -1
  157. package/dist/webview/__tests__/entry-notations.test.js +0 -62
  158. package/dist/webview/__tests__/entry.test.d.ts +0 -1
  159. package/dist/webview/__tests__/entry.test.js +0 -56
  160. package/dist/webview/__tests__/render-activities.test.d.ts +0 -1
  161. package/dist/webview/__tests__/render-activities.test.js +0 -91
  162. package/dist/webview/__tests__/render-blocks.test.d.ts +0 -1
  163. package/dist/webview/__tests__/render-blocks.test.js +0 -175
  164. package/dist/webview/__tests__/render-goals.test.d.ts +0 -1
  165. package/dist/webview/__tests__/render-goals.test.js +0 -120
  166. package/dist/webview/__tests__/render-process.test.d.ts +0 -1
  167. package/dist/webview/__tests__/render-process.test.js +0 -463
  168. package/dist/webview/__tests__/render-util.test.d.ts +0 -1
  169. package/dist/webview/__tests__/render-util.test.js +0 -54
  170. package/src/__tests__/edge-path.test.ts +0 -67
  171. package/src/__tests__/node-size-presets.test.ts +0 -50
  172. package/src/__tests__/scope.test.ts +0 -27
  173. package/src/__tests__/yaml-normalize.test.ts +0 -158
  174. package/src/activities/__tests__/cpm.test.ts +0 -164
  175. package/src/activities/__tests__/gantt.test.ts +0 -290
  176. package/src/activities/__tests__/layout.test.ts +0 -112
  177. package/src/activities/__tests__/validate.test.ts +0 -446
  178. package/src/activity-card/__tests__/example.test.ts +0 -83
  179. package/src/activity-card/__tests__/layout.test.ts +0 -162
  180. package/src/activity-card/__tests__/resolver.test.ts +0 -357
  181. package/src/activity-card/__tests__/validate.test.ts +0 -167
  182. package/src/actor/__tests__/validate.test.ts +0 -114
  183. package/src/applications/__tests__/validate.test.ts +0 -256
  184. package/src/assertion/__tests__/example.test.ts +0 -37
  185. package/src/assertion/__tests__/validate.test.ts +0 -142
  186. package/src/blocks/__tests__/layout.test.ts +0 -169
  187. package/src/blocks/__tests__/validate.test.ts +0 -260
  188. package/src/business-service/__tests__/validate.test.ts +0 -160
  189. package/src/capability-map/__tests__/CapabilityMapView.test.tsx +0 -232
  190. package/src/capability-map/__tests__/address.test.ts +0 -59
  191. package/src/capability-map/__tests__/dsm-layout.test.ts +0 -52
  192. package/src/capability-map/__tests__/dsm-mutations.test.ts +0 -141
  193. package/src/capability-map/__tests__/dsm-validate.test.ts +0 -65
  194. package/src/capability-map/__tests__/validate.test.ts +0 -238
  195. package/src/change/__tests__/validate.test.ts +0 -97
  196. package/src/codex/__tests__/example.test.ts +0 -40
  197. package/src/codex/__tests__/validate.test.ts +0 -84
  198. package/src/compliance/__tests__/canon-catalog.test.ts +0 -68
  199. package/src/compliance/__tests__/classify.test.ts +0 -64
  200. package/src/compliance/__tests__/confidence.test.ts +0 -98
  201. package/src/compliance/__tests__/coverage-metric.test.ts +0 -300
  202. package/src/compliance/__tests__/demo-scenario.test.ts +0 -273
  203. package/src/compliance/__tests__/example.test.ts +0 -57
  204. package/src/compliance/__tests__/gap-report.test.ts +0 -129
  205. package/src/compliance/__tests__/html.test.ts +0 -142
  206. package/src/compliance/__tests__/impact.test.ts +0 -1060
  207. package/src/compliance/__tests__/markdown.test.ts +0 -95
  208. package/src/compliance/__tests__/trace.test.ts +0 -157
  209. package/src/compliance/__tests__/view-resolution.test.ts +0 -80
  210. package/src/compliance/__tests__/views.test.ts +0 -64
  211. package/src/compliance-matrix/__tests__/build.test.ts +0 -200
  212. package/src/compliance-matrix/__tests__/example.test.ts +0 -57
  213. package/src/confidence/__tests__/score.test.ts +0 -254
  214. package/src/constraint/__tests__/example.test.ts +0 -19
  215. package/src/constraint/__tests__/validate.test.ts +0 -68
  216. package/src/factor/__tests__/validate.test.ts +0 -133
  217. package/src/fgca/__tests__/chain-table.test.ts +0 -172
  218. package/src/fgca/__tests__/layout.test.ts +0 -179
  219. package/src/fgca/__tests__/parse-canonical.test.ts +0 -296
  220. package/src/fgca/__tests__/preview-layout.test.ts +0 -124
  221. package/src/fgca/__tests__/resolver.test.ts +0 -209
  222. package/src/fgca/__tests__/validate.test.ts +0 -142
  223. package/src/goals/__tests__/GoalTreeView.test.tsx +0 -361
  224. package/src/goals/__tests__/layout.test.ts +0 -175
  225. package/src/goals/__tests__/mutations.test.ts +0 -153
  226. package/src/goals/__tests__/parse-canonical.test.ts +0 -147
  227. package/src/goals/__tests__/validate.test.ts +0 -202
  228. package/src/integration/__tests__/validate.test.ts +0 -203
  229. package/src/location/__tests__/validate.test.ts +0 -127
  230. package/src/node/__tests__/validate.test.ts +0 -118
  231. package/src/process-blueprint/__tests__/compliance-lane.test.ts +0 -320
  232. package/src/process-blueprint/__tests__/layout.test.ts +0 -240
  233. package/src/process-blueprint/__tests__/validate.test.ts +0 -310
  234. package/src/process-map/__tests__/validate.test.ts +0 -223
  235. package/src/products/__tests__/validate.test.ts +0 -239
  236. package/src/repo-validate/__tests__/validate-repo.test.ts +0 -699
  237. package/src/requirement/__tests__/example.test.ts +0 -24
  238. package/src/requirement/__tests__/validate.test.ts +0 -96
  239. package/src/scenarios/__tests__/validate.test.ts +0 -209
  240. package/src/stakeholder/__tests__/validate.test.ts +0 -105
  241. package/src/target-state/__tests__/validate.test.ts +0 -95
  242. package/src/technology-service/__tests__/validate.test.ts +0 -143
  243. package/src/theme/__tests__/tokens.test.ts +0 -185
  244. package/src/webview/__tests__/entity-text-layout.test.ts +0 -182
  245. package/src/webview/__tests__/entry-notations.test.ts +0 -77
  246. package/src/webview/__tests__/entry.test.ts +0 -64
  247. package/src/webview/__tests__/render-activities.test.ts +0 -100
  248. package/src/webview/__tests__/render-blocks.test.ts +0 -206
  249. package/src/webview/__tests__/render-goals.test.ts +0 -128
  250. package/src/webview/__tests__/render-process.test.ts +0 -538
  251. package/src/webview/__tests__/render-util.test.ts +0 -66
@@ -1,188 +0,0 @@
1
- // Pins CONTRACT §11 — source-trust scale, freshness curve, element confidence,
2
- // view composite, unsourced handling, manifest decay resolution, A–D bands.
3
- import { describe, it, expect } from 'vitest';
4
- import { IMPLICIT_DECAY_DEFAULTS, composeView, confidenceBand, formatConfidenceHeader, freshness, resolveDecayParams, scoreElement, scoreView, sourceTrustWeight, } from '../score.js';
5
- const D = { fresh_days: 100, stale_days: 200, floor: 0.3 };
6
- describe('sourceTrustWeight (§11.2)', () => {
7
- it('matches the closed scale', () => {
8
- expect(sourceTrustWeight('authoritative')).toBe(1.0);
9
- expect(sourceTrustWeight('corroborated')).toBe(0.8);
10
- expect(sourceTrustWeight('single_source')).toBe(0.5);
11
- expect(sourceTrustWeight('unverified')).toBe(0.25);
12
- });
13
- });
14
- describe('freshness (§11.3)', () => {
15
- const today = '2026-06-05';
16
- it('returns 1.0 when age ≤ fresh_days', () => {
17
- expect(freshness('2026-05-01', today, D)).toBe(1.0);
18
- expect(freshness('2026-06-05', today, D)).toBe(1.0);
19
- });
20
- it('returns floor when age ≥ stale_days', () => {
21
- expect(freshness('2025-01-01', today, D)).toBeCloseTo(0.3, 10);
22
- const exactlyStale = '2025-11-17';
23
- expect(freshness(exactlyStale, today, { fresh_days: 100, stale_days: 200, floor: 0.3 })).toBeCloseTo(0.3, 10);
24
- });
25
- it('interpolates linearly between fresh_days and stale_days', () => {
26
- // midpoint: age 150 → 1.0 − (1.0 − 0.3) · (150 − 100) / (200 − 100) = 0.65
27
- const midAge = new Date(Date.UTC(2026, 5, 5));
28
- midAge.setUTCDate(midAge.getUTCDate() - 150);
29
- const iso = midAge.toISOString().slice(0, 10);
30
- expect(freshness(iso, today, D)).toBeCloseTo(0.65, 10);
31
- });
32
- it('clamps future-dated admitted_at to 1.0', () => {
33
- expect(freshness('2030-01-01', today, D)).toBe(1.0);
34
- });
35
- it('treats absent admitted_at as fully stale (returns floor)', () => {
36
- expect(freshness(undefined, today, D)).toBe(0.3);
37
- });
38
- it('treats unparseable admitted_at as fully stale', () => {
39
- expect(freshness('not-a-date', today, D)).toBe(0.3);
40
- expect(freshness('2026/06/05', today, D)).toBe(0.3);
41
- expect(freshness('2026-13-01', today, D)).toBe(0.3);
42
- });
43
- it('returns floor when stale_days <= fresh_days (degenerate config) and age exceeds fresh', () => {
44
- // age 365d for 2025-06-05; both branches collapse to floor.
45
- expect(freshness('2025-06-05', today, { fresh_days: 100, stale_days: 100, floor: 0.4 })).toBe(0.4);
46
- expect(freshness('2025-06-05', today, { fresh_days: 200, stale_days: 100, floor: 0.4 })).toBe(0.4);
47
- });
48
- });
49
- describe('resolveDecayParams (§11.3 + MANIFEST §2)', () => {
50
- const config = {
51
- defaults: { fresh_days: 180, stale_days: 730, floor: 0.3 },
52
- by_type: {
53
- CAPABILITY: { fresh_days: 365, stale_days: 1825 },
54
- APPLICATION: { fresh_days: 180, stale_days: 730 },
55
- },
56
- };
57
- it('uses by_type overrides and inherits missing fields from defaults', () => {
58
- // Pins the §11.3 example: CAPABILITY overrides fresh/stale but inherits floor=0.3.
59
- expect(resolveDecayParams('CAPABILITY', config)).toEqual({ fresh_days: 365, stale_days: 1825, floor: 0.3 });
60
- });
61
- it('falls back to defaults for an unknown TYPE', () => {
62
- expect(resolveDecayParams('PROCESS', config)).toEqual({ fresh_days: 180, stale_days: 730, floor: 0.3 });
63
- });
64
- it('falls back to §11.3 implicit defaults when the whole block is omitted', () => {
65
- expect(resolveDecayParams('CAPABILITY', undefined)).toEqual(IMPLICIT_DECAY_DEFAULTS);
66
- expect(resolveDecayParams('CAPABILITY', {})).toEqual(IMPLICIT_DECAY_DEFAULTS);
67
- });
68
- it('fills missing defaults fields from §11.3 implicit defaults', () => {
69
- const partial = { defaults: { floor: 0.5 } };
70
- expect(resolveDecayParams('PROCESS', partial)).toEqual({
71
- fresh_days: IMPLICIT_DECAY_DEFAULTS.fresh_days,
72
- stale_days: IMPLICIT_DECAY_DEFAULTS.stale_days,
73
- floor: 0.5,
74
- });
75
- });
76
- });
77
- describe('scoreElement (§11.4–11.5)', () => {
78
- const today = '2026-06-05';
79
- it('takes the max source-trust weight (§11.4): extra weak sources never subtract', () => {
80
- const score = scoreElement({ type: 'CAPABILITY', admitted_at: today, sources: ['unverified', 'authoritative', 'single_source'] }, today);
81
- expect(score.source_trust).toBe(1.0);
82
- expect(score.confidence).toBe(1.0);
83
- expect(score.sourced).toBe(true);
84
- });
85
- it('multiplies source_trust by freshness', () => {
86
- // §11.4 worked example: authoritative · floor.
87
- const score = scoreElement({ type: 'X', admitted_at: '2024-01-01', sources: ['authoritative'] }, today, { defaults: D });
88
- expect(score.source_trust).toBe(1.0);
89
- expect(score.freshness).toBeCloseTo(0.3, 10);
90
- expect(score.confidence).toBeCloseTo(0.3, 10);
91
- });
92
- it('marks unsourced elements at the unverified floor (§11.5) and sourced=false', () => {
93
- const undef = scoreElement({ type: 'X', admitted_at: today }, today);
94
- const empty = scoreElement({ type: 'X', admitted_at: today, sources: [] }, today);
95
- for (const score of [undef, empty]) {
96
- expect(score.source_trust).toBe(0.25);
97
- expect(score.sourced).toBe(false);
98
- expect(score.confidence).toBeCloseTo(0.25, 10);
99
- }
100
- });
101
- it('distinguishes unsourced (counted separately) from sourced-but-unverified', () => {
102
- const unsourced = scoreElement({ type: 'X', admitted_at: today }, today);
103
- const sourcedUnverified = scoreElement({ type: 'X', admitted_at: today, sources: ['unverified'] }, today);
104
- expect(unsourced.source_trust).toBe(sourcedUnverified.source_trust);
105
- expect(unsourced.sourced).toBe(false);
106
- expect(sourcedUnverified.sourced).toBe(true);
107
- });
108
- });
109
- describe('confidenceBand (§11.6)', () => {
110
- it('uses the documented thresholds', () => {
111
- expect(confidenceBand(1.0)).toBe('A');
112
- expect(confidenceBand(0.8)).toBe('A');
113
- expect(confidenceBand(0.79)).toBe('B');
114
- expect(confidenceBand(0.6)).toBe('B');
115
- expect(confidenceBand(0.59)).toBe('C');
116
- expect(confidenceBand(0.4)).toBe('C');
117
- expect(confidenceBand(0.39)).toBe('D');
118
- expect(confidenceBand(0)).toBe('D');
119
- });
120
- });
121
- describe('composeView (§11.6)', () => {
122
- it('headlines weakest link, reports mean and coverage', () => {
123
- const composite = composeView([
124
- { source_trust: 1.0, freshness: 1.0, confidence: 1.0, sourced: true },
125
- { source_trust: 0.5, freshness: 0.8, confidence: 0.4, sourced: true },
126
- { source_trust: 0.25, freshness: 1.0, confidence: 0.25, sourced: false },
127
- ]);
128
- expect(composite.weakest_link).toBeCloseTo(0.25, 10);
129
- expect(composite.band).toBe('D');
130
- expect(composite.mean).toBeCloseTo((1.0 + 0.4 + 0.25) / 3, 10);
131
- expect(composite.coverage).toBeCloseTo(2 / 3, 10);
132
- expect(composite.element_count).toBe(3);
133
- expect(composite.unsourced_count).toBe(1);
134
- });
135
- it('returns a degenerate composite (band D, counts 0) for an empty set', () => {
136
- const composite = composeView([]);
137
- expect(composite.element_count).toBe(0);
138
- expect(composite.weakest_link).toBe(0);
139
- expect(composite.mean).toBe(0);
140
- expect(composite.coverage).toBe(0);
141
- expect(composite.band).toBe('D');
142
- });
143
- });
144
- describe('scoreView end-to-end', () => {
145
- const today = '2026-06-05';
146
- it('composes weakest-link / mean / coverage / band from heterogenous elements', () => {
147
- const view = scoreView([
148
- // weakest link = 0.50 → band C
149
- { type: 'X', admitted_at: today, sources: ['authoritative'] }, // 1.00
150
- { type: 'X', admitted_at: today, sources: ['corroborated'] }, // 0.80
151
- { type: 'X', admitted_at: today, sources: ['single_source'] }, // 0.50
152
- { type: 'X', admitted_at: today, sources: ['corroborated'] }, // 0.80
153
- ], today);
154
- expect(view.composite.weakest_link).toBeCloseTo(0.5, 10);
155
- expect(view.composite.band).toBe('C');
156
- expect(view.composite.mean).toBeCloseTo((1.0 + 0.8 + 0.5 + 0.8) / 4, 10);
157
- expect(view.composite.coverage).toBe(1);
158
- expect(view.composite.unsourced_count).toBe(0);
159
- expect(view.today).toBe(today);
160
- });
161
- it('accepts Date for today and converts to ISO', () => {
162
- const view = scoreView([{ type: 'X', admitted_at: '2026-06-05', sources: ['authoritative'] }], new Date(Date.UTC(2026, 5, 5)));
163
- expect(view.today).toBe('2026-06-05');
164
- expect(view.composite.band).toBe('A');
165
- });
166
- it('reports band D and 0% coverage when every element is unsourced and fully stale', () => {
167
- const view = scoreView([
168
- { type: 'X' },
169
- { type: 'X' },
170
- ], '2026-06-05', { defaults: D });
171
- // unsourced (0.25) · freshness floor (0.3) = 0.075 → band D.
172
- expect(view.composite.coverage).toBe(0);
173
- expect(view.composite.unsourced_count).toBe(2);
174
- expect(view.composite.band).toBe('D');
175
- expect(view.composite.weakest_link).toBeCloseTo(0.075, 10);
176
- });
177
- });
178
- describe('formatConfidenceHeader (§11.6)', () => {
179
- it('renders the documented header shape', () => {
180
- const view = scoreView([{ type: 'X', admitted_at: '2026-06-05', sources: ['corroborated'] }], '2026-06-05');
181
- // corroborated (0.8) · freshness 1.0 = 0.80 → band A (A is ≥ 0.8).
182
- expect(formatConfidenceHeader(view)).toBe('Data confidence (as of 2026-06-05): A (weakest link) · 0.80 mean · 100% sourced');
183
- });
184
- it('returns an empty string for an empty composite', () => {
185
- const view = scoreView([], '2026-06-05');
186
- expect(formatConfidenceHeader(view)).toBe('');
187
- });
188
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,14 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { readFileSync } from 'node:fs';
3
- import { fileURLToPath } from 'node:url';
4
- import path from 'node:path';
5
- import yaml from 'js-yaml';
6
- import { validateConstraint } from '../validate.js';
7
- const dir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../../tests/fixtures/notation-corpus/constraint');
8
- describe('constraint worked example (notation-corpus)', () => {
9
- it('validates CONSTRAINT-GDPR-RESIDENCY-1.yaml without error', () => {
10
- const data = yaml.load(readFileSync(path.join(dir, 'CONSTRAINT-GDPR-RESIDENCY-1.yaml'), 'utf-8'));
11
- const v = validateConstraint(data);
12
- expect(v.valid, JSON.stringify(v.errors)).toBe(true);
13
- });
14
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,58 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { validateConstraint } from '../validate.js';
3
- function valid() {
4
- return {
5
- notation: 'constraint',
6
- id: 'CONSTRAINT-GDPR-RESIDENCY-1',
7
- name: 'EU customer personal data must be stored within EU/EEA jurisdictions',
8
- statement: 'Personal data of EU customers MUST NOT be persisted outside EU / EEA jurisdictions.',
9
- status: 'active',
10
- zone: 'canon',
11
- admitted_at: '2026-05-29',
12
- admitted_by: 'v.korobeinikov',
13
- gate_checks: { uniqueness: 'pass', consistency: 'pass', completeness: 'pass' },
14
- valid_from: '2018-05-25',
15
- valid_to: null,
16
- severity: 'mandatory',
17
- owner_role: 'ROLE-DPO-1',
18
- applies_to: ['APPLICATION-CRM-1'],
19
- };
20
- }
21
- const codes = (input, opts) => validateConstraint(input, opts).errors.map((e) => e.code);
22
- describe('validateConstraint — positive', () => {
23
- it('accepts a well-formed constraint', () => {
24
- const r = validateConstraint(valid());
25
- expect(r.valid, JSON.stringify(r.errors)).toBe(true);
26
- });
27
- });
28
- describe('validateConstraint — CONST-001', () => {
29
- it('flags missing required fields and wrong notation', () => {
30
- const r = valid();
31
- delete r.statement;
32
- expect(codes(r)).toContain('CONST-001');
33
- expect(codes({ ...valid(), notation: 'requirement' })).toContain('CONST-001');
34
- expect(codes({ ...valid(), id: 'CONSTRAINT-001' })).toContain('CONST-001');
35
- });
36
- });
37
- describe('validateConstraint — CONST-002/003', () => {
38
- it('flags invalid status and severity', () => {
39
- expect(codes({ ...valid(), status: 'enabled' })).toContain('CONST-002');
40
- expect(codes({ ...valid(), severity: 'critical' })).toContain('CONST-003');
41
- });
42
- });
43
- describe('validateConstraint — CONST-004/005 (catalog)', () => {
44
- it('flags unresolved applies_to and owner_role with catalog', () => {
45
- const catalog = { typeOf: () => undefined };
46
- expect(codes(valid(), { catalog })).toContain('CONST-004');
47
- expect(codes(valid(), { catalog })).toContain('CONST-005');
48
- });
49
- it('does not flag CONST-004 without catalog for well-formed applies_to', () => {
50
- expect(codes(valid())).not.toContain('CONST-004');
51
- });
52
- it('resolves applies_to when catalogue admits the target', () => {
53
- const catalog = {
54
- typeOf: (id) => (id === 'APPLICATION-CRM-1' ? 'APPLICATION' : id === 'ROLE-DPO-1' ? 'ROLE' : undefined),
55
- };
56
- expect(validateConstraint(valid(), { catalog }).valid).toBe(true);
57
- });
58
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,112 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { validateFactor } from '../validate.js';
3
- function validExternal() {
4
- return {
5
- notation: 'driver',
6
- id: 'FACTOR-EU-REG-1',
7
- name: 'EU regulatory window',
8
- type: 'external',
9
- category: 'legal',
10
- description: 'Standing external driver — the EU regulatory regime.',
11
- references_constraint: ['CONSTRAINT-GDPR-RESIDENCY-1'],
12
- zone: 'canon',
13
- admitted_at: '2026-05-29',
14
- admitted_by: 'v.korobeinikov',
15
- gate_checks: { uniqueness: 'pass', consistency: 'pass', completeness: 'pass' },
16
- valid_from: '2026-05-26',
17
- valid_to: null,
18
- };
19
- }
20
- function validInternal() {
21
- return {
22
- notation: 'driver',
23
- id: 'FACTOR-COMP-1',
24
- name: 'Support response time',
25
- type: 'internal',
26
- description: 'Standing internal driver.',
27
- zone: 'canon',
28
- admitted_at: '2026-05-29',
29
- admitted_by: 'v.korobeinikov',
30
- gate_checks: { uniqueness: 'pass', consistency: 'pass', completeness: 'pass' },
31
- valid_from: '2026-05-26',
32
- valid_to: null,
33
- };
34
- }
35
- const codes = (input, opts) => validateFactor(input, opts).errors.map(e => e.code);
36
- describe('validateFactor — positive', () => {
37
- it('accepts a well-formed external PESTLE factor', () => {
38
- const r = validateFactor(validExternal());
39
- expect(r.valid, JSON.stringify(r.errors)).toBe(true);
40
- });
41
- it('accepts a well-formed internal factor (no PESTLE category)', () => {
42
- expect(validateFactor(validInternal()).valid).toBe(true);
43
- });
44
- it('accepts a minimal factor with no optional fields', () => {
45
- const f = validInternal();
46
- delete f.type;
47
- delete f.description;
48
- expect(validateFactor(f).valid).toBe(true);
49
- });
50
- });
51
- describe('validateFactor — FACTOR-001 (shape / id grammar)', () => {
52
- it('flags a missing required envelope field', () => {
53
- const f = validExternal();
54
- delete f.admitted_by;
55
- expect(codes(f)).toContain('FACTOR-001');
56
- });
57
- it('flags an id that violates the grammar', () => {
58
- expect(codes({ ...validExternal(), id: 'FACTOR-EU-REG-001' })).toContain('FACTOR-001');
59
- expect(codes({ ...validExternal(), id: 'FAC-1' })).toContain('FACTOR-001');
60
- expect(codes({ ...validExternal(), id: 'factor-1' })).toContain('FACTOR-001');
61
- });
62
- it('flags a wrong notation tag and a non-canon zone', () => {
63
- expect(codes({ ...validExternal(), notation: 'factor' })).toContain('FACTOR-001');
64
- expect(codes({ ...validExternal(), zone: 'sandbox' })).toContain('FACTOR-001');
65
- });
66
- it('flags a missing valid_to key (distinct from a null value)', () => {
67
- const f = validExternal();
68
- delete f.valid_to;
69
- expect(codes(f)).toContain('FACTOR-001');
70
- });
71
- it('rejects a non-object', () => {
72
- expect(codes(null)).toEqual(['FACTOR-001']);
73
- expect(codes(['a'])).toEqual(['FACTOR-001']);
74
- });
75
- });
76
- describe('validateFactor — FACTOR-002 (type enum)', () => {
77
- it('flags a type value outside {external, internal}', () => {
78
- expect(codes({ ...validExternal(), type: 'driver' })).toContain('FACTOR-002');
79
- });
80
- });
81
- describe('validateFactor — FACTOR-003 (PESTLE category)', () => {
82
- it('flags a category outside PESTLE', () => {
83
- expect(codes({ ...validExternal(), category: 'cosmic' })).toContain('FACTOR-003');
84
- });
85
- it('flags PESTLE category on an internal factor', () => {
86
- const f = validInternal();
87
- f.category = 'legal';
88
- expect(codes(f)).toContain('FACTOR-003');
89
- });
90
- it('accepts each permitted PESTLE category on an external factor', () => {
91
- for (const cat of ['political', 'economic', 'social', 'technological', 'legal', 'environmental']) {
92
- const f = validExternal();
93
- f.category = cat;
94
- expect(codes(f)).not.toContain('FACTOR-003');
95
- }
96
- });
97
- });
98
- describe('validateFactor — FACTOR-004 (references_constraint)', () => {
99
- it('flags a malformed references_constraint entry', () => {
100
- expect(codes({ ...validExternal(), references_constraint: ['not an id'] })).toContain('FACTOR-004');
101
- });
102
- it('flags a references_constraint entry of the wrong TYPE', () => {
103
- expect(codes({ ...validExternal(), references_constraint: ['GOAL-X-1'] })).toContain('FACTOR-004');
104
- });
105
- it('flags an unresolved id when a catalog is supplied', () => {
106
- const catalog = { typeOf: () => undefined };
107
- expect(codes(validExternal(), { catalog })).toContain('FACTOR-004');
108
- });
109
- it('does not flag without a catalog for a well-formed CONSTRAINT id', () => {
110
- expect(codes(validExternal())).not.toContain('FACTOR-004');
111
- });
112
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,158 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { buildChainTable } from '../chain-table.js';
3
- // Renders a ChainTable to a compact text grid for readable assertions. Each
4
- // cell shows "label×rowSpan" (×1 omitted); a position covered by a span above
5
- // shows "·".
6
- function asGrid(t) {
7
- return t.rows.map(row => row.map(c => {
8
- if (c === null)
9
- return '·';
10
- const label = c.cell ? c.cell.label : '∅';
11
- return c.rowSpan > 1 ? `${label}×${c.rowSpan}` : label;
12
- }));
13
- }
14
- describe('buildChainTable — worked example (FGCA)', () => {
15
- // F1 → G1, G2 ; G1 → C1 → A1 ; G2 → C2 → A2, A3
16
- const doc = {
17
- factors: [{ id: 1, name: 'F1' }],
18
- goals: [
19
- { id: 10, name: 'G1', factor: [{ id: 1 }] },
20
- { id: 11, name: 'G2', factor: [{ id: 1 }] },
21
- ],
22
- changes: [
23
- { id: 20, name: 'C1', goal_id: 10, activity_ids: [30] },
24
- { id: 21, name: 'C2', goal_id: 11, activity_ids: [31, 32] },
25
- ],
26
- activities: [
27
- { id: 30, name: 'A1', goal_id: 10 },
28
- { id: 31, name: 'A2', goal_id: 11 },
29
- { id: 32, name: 'A3', goal_id: 11 },
30
- ],
31
- };
32
- it('produces the spec grid with F1 spanning 3 and G2/C2 spanning 2', () => {
33
- const t = buildChainTable(doc);
34
- expect(t.columns).toEqual(['driver', 'goal', 'change', 'activity']);
35
- expect(asGrid(t)).toEqual([
36
- ['F1×3', 'G1', 'C1', 'A1'],
37
- ['·', 'G2×2', 'C2×2', 'A2'],
38
- ['·', '·', '·', 'A3'],
39
- ]);
40
- });
41
- it('orders the merged cells with correct rowSpans on the model', () => {
42
- const t = buildChainTable(doc);
43
- // Factor cell spans all three rows.
44
- expect(t.rows[0][0]).toMatchObject({ rowSpan: 3, cell: { label: 'F1' } });
45
- // Covered positions are null (no <td> emitted).
46
- expect(t.rows[1][0]).toBeNull();
47
- expect(t.rows[2][1]).toBeNull();
48
- });
49
- });
50
- describe('buildChainTable — FGA (no Change column)', () => {
51
- // FGA links Goal → Activity directly via activity.goal_id; no changes.
52
- const doc = {
53
- factors: [{ id: 1, name: 'F1' }],
54
- goals: [{ id: 10, name: 'G1', factor: [{ id: 1 }] }],
55
- activities: [
56
- { id: 30, name: 'A1', goal_id: 10 },
57
- { id: 31, name: 'A2', goal_id: 10 },
58
- ],
59
- };
60
- it('emits three columns and merges Factor/Goal across the two activities', () => {
61
- const t = buildChainTable(doc, { hideChanges: true });
62
- expect(t.columns).toEqual(['driver', 'goal', 'activity']);
63
- expect(asGrid(t)).toEqual([
64
- ['F1×2', 'G1×2', 'A1'],
65
- ['·', '·', 'A2'],
66
- ]);
67
- });
68
- });
69
- describe('buildChainTable — missing downstream links (gaps stay visible)', () => {
70
- it('shows a factor with no goal, a goal with no change, and a change with no activity', () => {
71
- const doc = {
72
- factors: [
73
- { id: 1, name: 'F1' },
74
- { id: 2, name: 'F2' }, // no goals
75
- ],
76
- goals: [
77
- { id: 10, name: 'G1', factor: [{ id: 1 }] }, // no change, no activity
78
- { id: 11, name: 'G2', factor: [{ id: 1 }] }, // has a change with no activity
79
- ],
80
- changes: [{ id: 20, name: 'C1', goal_id: 11, activity_ids: [] }],
81
- activities: [],
82
- };
83
- const t = buildChainTable(doc);
84
- expect(asGrid(t)).toEqual([
85
- ['F1×2', 'G1', '∅', '∅'],
86
- ['·', 'G2', 'C1', '∅'],
87
- ['F2', '∅', '∅', '∅'],
88
- ]);
89
- });
90
- it('renders a change-less direct goal→activity path with an empty Change cell', () => {
91
- const doc = {
92
- factors: [{ id: 1, name: 'F1' }],
93
- goals: [{ id: 10, name: 'G1', factor: [{ id: 1 }] }],
94
- // activity bound straight to the goal, not covered by any change
95
- changes: [],
96
- activities: [{ id: 30, name: 'A1', goal_id: 10 }],
97
- };
98
- const t = buildChainTable(doc);
99
- expect(asGrid(t)).toEqual([['F1', 'G1', '∅', 'A1']]);
100
- });
101
- });
102
- describe('buildChainTable — orphans (broken refs are warnings, not errors)', () => {
103
- it('places a goal with a missing factor in a trailing empty-Factor row', () => {
104
- const doc = {
105
- factors: [{ id: 1, name: 'F1' }],
106
- goals: [
107
- { id: 10, name: 'G1', factor: [{ id: 1 }] },
108
- { id: 11, name: 'Gx', factor: [{ id: 99 }] }, // factor 99 does not exist
109
- { id: 12, name: 'Gy' }, // no factor at all
110
- ],
111
- changes: [{ id: 20, name: 'C1', goal_id: 10, activity_ids: [30] }],
112
- activities: [{ id: 30, name: 'A1', goal_id: 10 }],
113
- };
114
- const t = buildChainTable(doc);
115
- expect(asGrid(t)).toEqual([
116
- ['F1', 'G1', 'C1', 'A1'],
117
- ['∅×2', 'Gx', '∅', '∅'],
118
- ['·', 'Gy', '∅', '∅'],
119
- ]);
120
- });
121
- it('surfaces an unlinked activity as a trailing row with empty cells to its left', () => {
122
- const doc = {
123
- factors: [{ id: 1, name: 'F1' }],
124
- goals: [{ id: 10, name: 'G1', factor: [{ id: 1 }] }],
125
- changes: [{ id: 20, name: 'C1', goal_id: 10, activity_ids: [30] }],
126
- activities: [
127
- { id: 30, name: 'A1', goal_id: 10 },
128
- { id: 99, name: 'Aorphan' }, // no goal, no change
129
- ],
130
- };
131
- const t = buildChainTable(doc);
132
- expect(asGrid(t)).toEqual([
133
- ['F1', 'G1', 'C1', 'A1'],
134
- ['∅', '∅', '∅', 'Aorphan'],
135
- ]);
136
- });
137
- it('surfaces a change whose goal is missing as an empty Factor+Goal row', () => {
138
- const doc = {
139
- factors: [],
140
- goals: [],
141
- changes: [{ id: 20, name: 'Cx', goal_id: 999, activity_ids: [30] }],
142
- activities: [{ id: 30, name: 'A1' }],
143
- };
144
- const t = buildChainTable(doc);
145
- expect(asGrid(t)).toEqual([['∅', '∅', 'Cx', 'A1']]);
146
- });
147
- });
148
- describe('buildChainTable — name fallback', () => {
149
- it('falls back to the id when an element has an empty name', () => {
150
- const doc = {
151
- factors: [{ id: 7, name: '' }],
152
- goals: [],
153
- activities: [],
154
- };
155
- const t = buildChainTable(doc);
156
- expect(t.rows[0][0]?.cell?.label).toBe('7');
157
- });
158
- });
@@ -1 +0,0 @@
1
- export {};