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