@transitrix/diagrams 1.5.0 → 1.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/capability-map/CapabilityCardNode.d.ts +19 -0
- package/dist/capability-map/CapabilityCardNode.js +66 -0
- package/dist/capability-map/CapabilityMapView.d.ts +59 -0
- package/dist/capability-map/CapabilityMapView.js +204 -0
- package/dist/capability-map/CapabilityRootNode.d.ts +12 -0
- package/dist/capability-map/CapabilityRootNode.js +23 -0
- package/dist/capability-map/__tests__/CapabilityMapView.test.d.ts +1 -0
- package/dist/capability-map/__tests__/CapabilityMapView.test.js +217 -0
- package/dist/capability-map/__tests__/address.test.d.ts +1 -0
- package/dist/capability-map/__tests__/address.test.js +49 -0
- package/dist/capability-map/__tests__/dsm-layout.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-layout.test.js +46 -0
- package/dist/capability-map/__tests__/dsm-mutations.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-mutations.test.js +125 -0
- package/dist/capability-map/__tests__/dsm-validate.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-validate.test.js +56 -0
- package/dist/capability-map/address.d.ts +12 -0
- package/dist/capability-map/address.js +48 -0
- package/dist/capability-map/dsm-layout.d.ts +9 -0
- package/dist/capability-map/dsm-layout.js +125 -0
- package/dist/capability-map/dsm-mutations.d.ts +28 -0
- package/dist/capability-map/dsm-mutations.js +196 -0
- package/dist/capability-map/dsm-schema.d.ts +71 -0
- package/dist/capability-map/dsm-schema.js +14 -0
- package/dist/capability-map/dsm-theme.d.ts +20 -0
- package/dist/capability-map/dsm-theme.js +36 -0
- package/dist/capability-map/dsm-validate.d.ts +2 -0
- package/dist/capability-map/dsm-validate.js +93 -0
- package/dist/capability-map/index.d.ts +9 -0
- package/dist/capability-map/index.js +6 -0
- package/dist/codex/__tests__/example.test.d.ts +1 -0
- package/dist/codex/__tests__/example.test.js +33 -0
- package/dist/codex/__tests__/validate.test.d.ts +1 -0
- package/dist/codex/__tests__/validate.test.js +68 -0
- package/dist/codex/index.d.ts +4 -0
- package/dist/codex/index.js +2 -0
- package/dist/codex/types.d.ts +7 -0
- package/dist/codex/types.js +8 -0
- package/dist/codex/validate.d.ts +11 -0
- package/dist/codex/validate.js +103 -0
- package/dist/compliance/__tests__/canon-catalog.test.d.ts +1 -0
- package/dist/compliance/__tests__/canon-catalog.test.js +60 -0
- package/dist/compliance/__tests__/trace.test.d.ts +1 -0
- package/dist/compliance/__tests__/trace.test.js +144 -0
- package/dist/compliance/__tests__/view-resolution.test.d.ts +1 -0
- package/dist/compliance/__tests__/view-resolution.test.js +59 -0
- package/dist/compliance/canon-catalog.d.ts +19 -0
- package/dist/compliance/canon-catalog.js +59 -0
- package/dist/compliance/classify.js +7 -1
- package/dist/compliance/coverage-metric.d.ts +12 -0
- package/dist/compliance/coverage-metric.js +35 -0
- package/dist/compliance/impact.d.ts +7 -1
- package/dist/compliance/impact.js +53 -0
- package/dist/compliance/index.d.ts +8 -5
- package/dist/compliance/index.js +4 -2
- package/dist/compliance/reverse-index.js +4 -1
- package/dist/compliance/trace.d.ts +26 -0
- package/dist/compliance/trace.js +89 -0
- package/dist/compliance/types.d.ts +94 -1
- package/dist/constraint/__tests__/example.test.d.ts +1 -0
- package/dist/constraint/__tests__/example.test.js +14 -0
- package/dist/constraint/__tests__/validate.test.d.ts +1 -0
- package/dist/constraint/__tests__/validate.test.js +58 -0
- package/dist/constraint/index.d.ts +4 -0
- package/dist/constraint/index.js +2 -0
- package/dist/constraint/types.d.ts +4 -0
- package/dist/constraint/types.js +2 -0
- package/dist/constraint/validate.d.ts +7 -0
- package/dist/constraint/validate.js +115 -0
- package/dist/fgca/__tests__/parse-canonical.test.js +31 -0
- package/dist/fgca/parse-canonical.d.ts +1 -1
- package/dist/fgca/parse-canonical.js +18 -4
- package/dist/goals/GoalNode.d.ts +19 -0
- package/dist/goals/GoalNode.js +96 -0
- package/dist/goals/GoalTreeView.d.ts +59 -0
- package/dist/goals/GoalTreeView.js +245 -0
- package/dist/goals/__tests__/GoalTreeView.test.d.ts +1 -0
- package/dist/goals/__tests__/GoalTreeView.test.js +337 -0
- package/dist/goals/__tests__/mutations.test.js +39 -0
- package/dist/goals/__tests__/parse-canonical.test.js +2 -0
- package/dist/goals/index.d.ts +3 -0
- package/dist/goals/index.js +1 -0
- package/dist/goals/layout.js +2 -1
- package/dist/goals/mutations.js +6 -6
- package/dist/goals/parse-canonical.d.ts +5 -0
- package/dist/goals/parse-canonical.js +5 -0
- package/dist/goals/theme.d.ts +22 -0
- package/dist/goals/theme.js +32 -0
- package/dist/goals/types.d.ts +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/repo-validate/types.js +2 -3
- package/dist/webview/__tests__/render-goals.test.js +17 -3
- package/dist/webview/render-goals.js +2 -1
- package/package.json +4 -1
- package/src/capability-map/CapabilityCardNode.tsx +146 -0
- package/src/capability-map/CapabilityMapView.tsx +331 -0
- package/src/capability-map/CapabilityRootNode.tsx +38 -0
- package/src/capability-map/__tests__/CapabilityMapView.test.tsx +232 -0
- package/src/capability-map/__tests__/address.test.ts +59 -0
- package/src/capability-map/__tests__/dsm-layout.test.ts +52 -0
- package/src/capability-map/__tests__/dsm-mutations.test.ts +141 -0
- package/src/capability-map/__tests__/dsm-validate.test.ts +65 -0
- package/src/capability-map/address.ts +48 -0
- package/src/capability-map/dsm-layout.ts +142 -0
- package/src/capability-map/dsm-mutations.ts +208 -0
- package/src/capability-map/dsm-schema.ts +80 -0
- package/src/capability-map/dsm-theme.ts +53 -0
- package/src/capability-map/dsm-validate.ts +103 -0
- package/src/capability-map/index.ts +35 -0
- package/src/codex/__tests__/example.test.ts +40 -0
- package/src/codex/__tests__/validate.test.ts +84 -0
- package/src/codex/index.ts +4 -0
- package/src/codex/types.ts +13 -0
- package/src/codex/validate.ts +125 -0
- package/src/compliance/__tests__/canon-catalog.test.ts +68 -0
- package/src/compliance/__tests__/trace.test.ts +157 -0
- package/src/compliance/__tests__/view-resolution.test.ts +80 -0
- package/src/compliance/canon-catalog.ts +76 -0
- package/src/compliance/classify.ts +7 -1
- package/src/compliance/coverage-metric.ts +50 -0
- package/src/compliance/impact.ts +67 -1
- package/src/compliance/index.ts +16 -1
- package/src/compliance/reverse-index.ts +3 -1
- package/src/compliance/trace.ts +118 -0
- package/src/compliance/types.ts +101 -1
- package/src/constraint/__tests__/example.test.ts +19 -0
- package/src/constraint/__tests__/validate.test.ts +68 -0
- package/src/constraint/index.ts +4 -0
- package/src/constraint/types.ts +5 -0
- package/src/constraint/validate.ts +131 -0
- package/src/fgca/__tests__/parse-canonical.test.ts +34 -0
- package/src/fgca/parse-canonical.ts +17 -4
- package/src/goals/GoalNode.tsx +219 -0
- package/src/goals/GoalTreeView.tsx +384 -0
- package/src/goals/__tests__/GoalTreeView.test.tsx +361 -0
- package/src/goals/__tests__/mutations.test.ts +42 -0
- package/src/goals/__tests__/parse-canonical.test.ts +2 -0
- package/src/goals/index.ts +4 -0
- package/src/goals/layout.ts +2 -1
- package/src/goals/mutations.ts +6 -6
- package/src/goals/parse-canonical.ts +6 -0
- package/src/goals/theme.ts +54 -0
- package/src/goals/types.ts +2 -0
- package/src/index.ts +29 -1
- package/src/repo-validate/types.ts +2 -3
- package/src/webview/__tests__/render-goals.test.ts +17 -3
- package/src/webview/render-goals.ts +2 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the DSM-migration capability map (docs/extraction/capability-map.md).
|
|
3
|
+
*
|
|
4
|
+
* Distinct from `./types.ts` (`CapabilityNode`/`CapabilityMapFile`), which is
|
|
5
|
+
* Transitrix's own native `*.capability-map.transitrix.yaml` notation — a
|
|
6
|
+
* nested-children tree, statically rendered to SVG. This module is a
|
|
7
|
+
* separate, flat, address-triple data model matching DSM's internal
|
|
8
|
+
* capability editor, for the interactive `CapabilityMapView` component. The
|
|
9
|
+
* two coexist in this folder by design (see the address-helper/component
|
|
10
|
+
* deliverables in the extraction spec); only the validator function name
|
|
11
|
+
* collided, so it's `validateCapabilityMapData` here, not
|
|
12
|
+
* `validateCapabilityMap` (already taken by `./validate.ts`).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export interface MaturitySnapshot {
|
|
16
|
+
date: string;
|
|
17
|
+
level: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Capability {
|
|
21
|
+
id: number;
|
|
22
|
+
name: string;
|
|
23
|
+
/** 'X.Y.Z' triple. X=0 or backlog=true means "not on the diagram". */
|
|
24
|
+
address: string;
|
|
25
|
+
backlog?: boolean;
|
|
26
|
+
description?: string;
|
|
27
|
+
maturity?: MaturitySnapshot[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface CapabilityMap {
|
|
31
|
+
organisation: string;
|
|
32
|
+
set_id: string;
|
|
33
|
+
capabilities: Capability[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type {
|
|
37
|
+
ValidationError,
|
|
38
|
+
ValidationWarning,
|
|
39
|
+
ValidationResult,
|
|
40
|
+
} from '../validation-types.js';
|
|
41
|
+
|
|
42
|
+
import type { ValidationError } from '../validation-types.js';
|
|
43
|
+
|
|
44
|
+
export interface MutationResult<T> {
|
|
45
|
+
ok: boolean;
|
|
46
|
+
result?: T;
|
|
47
|
+
error?: ValidationError;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface LayoutOptions {
|
|
51
|
+
rankdir?: 'LR' | 'TB';
|
|
52
|
+
nodeWidth?: number;
|
|
53
|
+
nodeHeight?: number;
|
|
54
|
+
rankSep?: number;
|
|
55
|
+
nodeSep?: number;
|
|
56
|
+
hideCollapsed?: number[];
|
|
57
|
+
organisationLabel?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface LaidOutNode {
|
|
61
|
+
id: number;
|
|
62
|
+
x: number;
|
|
63
|
+
y: number;
|
|
64
|
+
width: number;
|
|
65
|
+
height: number;
|
|
66
|
+
data: Capability | null;
|
|
67
|
+
hasHiddenChildren: boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface LaidOutEdge {
|
|
71
|
+
source: number | 'root';
|
|
72
|
+
target: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface CapabilityMapLayout {
|
|
76
|
+
rootNode: LaidOutNode;
|
|
77
|
+
nodes: LaidOutNode[];
|
|
78
|
+
edges: LaidOutEdge[];
|
|
79
|
+
bounds: { x: number; y: number; width: number; height: number };
|
|
80
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Theme tokens for CapabilityMapView — same host-agnostic-prop pattern as
|
|
2
|
+
* the goals module's ThemeTokens (see ../goals/theme.ts). */
|
|
3
|
+
export interface ThemeTokens {
|
|
4
|
+
cardFill?: string;
|
|
5
|
+
cardBorderColor?: string;
|
|
6
|
+
cardBorderWidth?: number;
|
|
7
|
+
cardTextColor?: string;
|
|
8
|
+
cardMetaColor?: string;
|
|
9
|
+
edgeColor?: string;
|
|
10
|
+
edgeWidth?: number;
|
|
11
|
+
dropTargetBorderColor?: string;
|
|
12
|
+
rootFill?: string;
|
|
13
|
+
rootTextColor?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Default 1..5 maturity-dot colour scale — overridable via the
|
|
17
|
+
* `maturityColours` prop (spec §6.2), which is separate from ThemeTokens
|
|
18
|
+
* since it's keyed by maturity level, not a fixed named token. */
|
|
19
|
+
export const DEFAULT_MATURITY_COLOURS: Record<number, string> = {
|
|
20
|
+
1: '#ef4444',
|
|
21
|
+
2: '#f97316',
|
|
22
|
+
3: '#eab308',
|
|
23
|
+
4: '#84cc16',
|
|
24
|
+
5: '#22c55e',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const DEFAULT_THEME: Required<ThemeTokens> = {
|
|
28
|
+
cardFill: '#eff6ff',
|
|
29
|
+
cardBorderColor: '#94a3b8',
|
|
30
|
+
cardBorderWidth: 1,
|
|
31
|
+
cardTextColor: '#0f172a',
|
|
32
|
+
cardMetaColor: '#64748b',
|
|
33
|
+
edgeColor: '#94a3b8',
|
|
34
|
+
edgeWidth: 1.5,
|
|
35
|
+
dropTargetBorderColor: '#2563eb',
|
|
36
|
+
rootFill: '#e2e8f0',
|
|
37
|
+
rootTextColor: '#0f172a',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export function resolveTheme(theme?: ThemeTokens): Required<ThemeTokens> {
|
|
41
|
+
return {
|
|
42
|
+
cardFill: theme?.cardFill ?? DEFAULT_THEME.cardFill,
|
|
43
|
+
cardBorderColor: theme?.cardBorderColor ?? DEFAULT_THEME.cardBorderColor,
|
|
44
|
+
cardBorderWidth: theme?.cardBorderWidth ?? DEFAULT_THEME.cardBorderWidth,
|
|
45
|
+
cardTextColor: theme?.cardTextColor ?? DEFAULT_THEME.cardTextColor,
|
|
46
|
+
cardMetaColor: theme?.cardMetaColor ?? DEFAULT_THEME.cardMetaColor,
|
|
47
|
+
edgeColor: theme?.edgeColor ?? DEFAULT_THEME.edgeColor,
|
|
48
|
+
edgeWidth: theme?.edgeWidth ?? DEFAULT_THEME.edgeWidth,
|
|
49
|
+
dropTargetBorderColor: theme?.dropTargetBorderColor ?? DEFAULT_THEME.dropTargetBorderColor,
|
|
50
|
+
rootFill: theme?.rootFill ?? DEFAULT_THEME.rootFill,
|
|
51
|
+
rootTextColor: theme?.rootTextColor ?? DEFAULT_THEME.rootTextColor,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { CapabilityMap, ValidationResult, ValidationError, ValidationWarning } from './dsm-schema.js';
|
|
2
|
+
|
|
3
|
+
/** Parses an address string loosely enough to tell "wrong shape"
|
|
4
|
+
* (INVALID_ADDRESS_FORMAT) apart from "right shape, too many levels"
|
|
5
|
+
* (MAX_DEPTH_EXCEEDED, e.g. '1.2.3.4') — a strict 3-segment regex would
|
|
6
|
+
* reject both identically and lose that distinction. */
|
|
7
|
+
function parseLoose(address: string): { triple: [number, number, number] } | { tooDeep: true } | null {
|
|
8
|
+
const parts = address.trim().split('.');
|
|
9
|
+
if (parts.length < 3 || !parts.every((p) => /^\d+$/.test(p))) return null;
|
|
10
|
+
if (parts.length > 3) return { tooDeep: true };
|
|
11
|
+
return { triple: [Number(parts[0]), Number(parts[1]), Number(parts[2])] };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function validateCapabilityMapData(input: unknown): ValidationResult {
|
|
15
|
+
const errors: ValidationError[] = [];
|
|
16
|
+
const warnings: ValidationWarning[] = [];
|
|
17
|
+
|
|
18
|
+
if (!input || typeof input !== 'object') {
|
|
19
|
+
return { valid: false, errors: [{ code: 'SCHEMA_INVALID', message: 'Input must be an object' }], warnings: [] };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const raw = input as Record<string, unknown>;
|
|
23
|
+
if (!Array.isArray(raw.capabilities)) {
|
|
24
|
+
errors.push({ code: 'SCHEMA_INVALID', message: 'capabilities must be an array', path: 'capabilities' });
|
|
25
|
+
return { valid: false, errors, warnings };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const map = raw as unknown as CapabilityMap;
|
|
29
|
+
const idSet = new Set<number>();
|
|
30
|
+
const addressToId = new Map<string, number>();
|
|
31
|
+
const onDiagram = new Map<number, [number, number, number]>();
|
|
32
|
+
|
|
33
|
+
for (let i = 0; i < map.capabilities.length; i++) {
|
|
34
|
+
const c = map.capabilities[i] as unknown;
|
|
35
|
+
const path = `capabilities[${i}]`;
|
|
36
|
+
|
|
37
|
+
if (!c || typeof c !== 'object') {
|
|
38
|
+
errors.push({ code: 'SCHEMA_INVALID', message: 'capability entry must be an object', path });
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const cap = c as { id?: unknown; name?: unknown; address?: unknown; backlog?: unknown; maturity?: unknown };
|
|
42
|
+
|
|
43
|
+
if (typeof cap.id !== 'number') {
|
|
44
|
+
errors.push({ code: 'SCHEMA_INVALID', message: 'capability id must be a number', path });
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (idSet.has(cap.id)) {
|
|
48
|
+
errors.push({ code: 'DUPLICATE_ID', message: `Duplicate capability id: ${cap.id}`, path });
|
|
49
|
+
} else {
|
|
50
|
+
idSet.add(cap.id);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!cap.name || typeof cap.name !== 'string' || cap.name.trim() === '') {
|
|
54
|
+
errors.push({ code: 'EMPTY_NAME', message: `Capability ${cap.id} has empty name`, path });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (typeof cap.address !== 'string') {
|
|
58
|
+
errors.push({ code: 'INVALID_ADDRESS_FORMAT', message: `Capability ${cap.id} address must be a string`, path });
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const parsed = parseLoose(cap.address);
|
|
62
|
+
if (parsed === null) {
|
|
63
|
+
errors.push({ code: 'INVALID_ADDRESS_FORMAT', message: `Capability ${cap.id} address "${cap.address}" is not in 'X.Y.Z' form`, path });
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if ('tooDeep' in parsed) {
|
|
67
|
+
errors.push({ code: 'MAX_DEPTH_EXCEEDED', message: `Capability ${cap.id} address "${cap.address}" has more than 3 levels`, path });
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const triple = parsed.triple;
|
|
71
|
+
const isBacklog = cap.backlog === true || triple[0] === 0;
|
|
72
|
+
|
|
73
|
+
if (!isBacklog) {
|
|
74
|
+
if (addressToId.has(cap.address)) {
|
|
75
|
+
errors.push({ code: 'DUPLICATE_ADDRESS', message: `Duplicate address "${cap.address}" (capability ${cap.id})`, path });
|
|
76
|
+
} else {
|
|
77
|
+
addressToId.set(cap.address, cap.id);
|
|
78
|
+
}
|
|
79
|
+
onDiagram.set(cap.id, triple);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (Array.isArray(cap.maturity)) {
|
|
83
|
+
for (const snap of cap.maturity as unknown[]) {
|
|
84
|
+
const level = (snap as { level?: unknown } | null)?.level;
|
|
85
|
+
if (typeof level === 'number' && (level < 1 || level > 5)) {
|
|
86
|
+
warnings.push({ code: 'INVALID_MATURITY_LEVEL', message: `Capability ${cap.id} has maturity level ${level} outside 1..5`, path });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (errors.length > 0) return { valid: false, errors, warnings };
|
|
93
|
+
|
|
94
|
+
for (const [id, [x, y, z]] of onDiagram) {
|
|
95
|
+
if (z !== 0 && !addressToId.has(`${x}.${y}.0`)) {
|
|
96
|
+
warnings.push({ code: 'MISSING_PARENT_BY_ADDRESS', message: `Capability ${id} (${x}.${y}.${z}) has no L2 parent at ${x}.${y}.0` });
|
|
97
|
+
} else if (y !== 0 && z === 0 && !addressToId.has(`${x}.0.0`)) {
|
|
98
|
+
warnings.push({ code: 'MISSING_PARENT_BY_ADDRESS', message: `Capability ${id} (${x}.${y}.0) has no L1 parent at ${x}.0.0` });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return { valid: errors.length === 0, errors, warnings };
|
|
103
|
+
}
|
|
@@ -17,3 +17,38 @@ export { layoutCapabilityTree, TREE_NODE_WIDTH, TREE_NODE_HEIGHT, TREE_RANK_SEP,
|
|
|
17
17
|
|
|
18
18
|
export type { RenderCapabilityTreeOptions } from './render-capability-tree.js';
|
|
19
19
|
export { renderCapabilityTreeSvg } from './render-capability-tree.js';
|
|
20
|
+
|
|
21
|
+
// ── DSM-migration capability map (docs/extraction/capability-map.md) ───────
|
|
22
|
+
// A separate, flat, address-triple data model from CapabilityNode above —
|
|
23
|
+
// see dsm-schema.ts for why the two coexist in this folder. Named
|
|
24
|
+
// `validateCapabilityMapData` rather than `validateCapabilityMap` because
|
|
25
|
+
// that name is already taken by the native-notation validator on line 8.
|
|
26
|
+
|
|
27
|
+
export type {
|
|
28
|
+
Capability,
|
|
29
|
+
CapabilityMap,
|
|
30
|
+
MaturitySnapshot,
|
|
31
|
+
MutationResult,
|
|
32
|
+
LayoutOptions,
|
|
33
|
+
LaidOutNode,
|
|
34
|
+
LaidOutEdge,
|
|
35
|
+
CapabilityMapLayout,
|
|
36
|
+
} from './dsm-schema.js';
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
parseAddress,
|
|
40
|
+
formatAddress,
|
|
41
|
+
getLevel,
|
|
42
|
+
getParentAddress,
|
|
43
|
+
getFirstFreeAddress,
|
|
44
|
+
isAddressTaken,
|
|
45
|
+
} from './address.js';
|
|
46
|
+
|
|
47
|
+
export { validateCapabilityMapData } from './dsm-validate.js';
|
|
48
|
+
export { layoutCapabilityMap } from './dsm-layout.js';
|
|
49
|
+
export { reparent, addChild, deleteWithDescendants, moveBranchToBacklog, restoreFromBacklog, normaliseAddresses } from './dsm-mutations.js';
|
|
50
|
+
|
|
51
|
+
export { CapabilityMapView } from './CapabilityMapView.js';
|
|
52
|
+
export type { CapabilityMapViewProps, CapabilityMapChange } from './CapabilityMapView.js';
|
|
53
|
+
export type { ThemeTokens } from './dsm-theme.js';
|
|
54
|
+
export { DEFAULT_MATURITY_COLOURS } from './dsm-theme.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Conformance test for CODEX worked examples under
|
|
2
|
+
// `tests/fixtures/notation-corpus/codex/` — pins #518 Phase C2 corpus signal.
|
|
3
|
+
|
|
4
|
+
import { describe, it, expect } from 'vitest';
|
|
5
|
+
import { readFileSync, readdirSync } from 'node:fs';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import yaml from 'js-yaml';
|
|
9
|
+
import { validateCodex, folderJurisdictionFromPath } from '../validate.js';
|
|
10
|
+
|
|
11
|
+
const corpusRoot = path.resolve(
|
|
12
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
13
|
+
'../../../../../tests/fixtures/notation-corpus/codex',
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
function codexFixturePaths(): Array<{ rel: string; folderJurisdiction?: string }> {
|
|
17
|
+
const out: Array<{ rel: string; folderJurisdiction?: string }> = [];
|
|
18
|
+
for (const zone of ['external/EU', 'internal']) {
|
|
19
|
+
const dir = path.join(corpusRoot, zone);
|
|
20
|
+
for (const f of readdirSync(dir).filter((x) => x.endsWith('.yaml'))) {
|
|
21
|
+
const rel = path.join('codex', zone, f).replace(/\\/g, '/');
|
|
22
|
+
out.push({
|
|
23
|
+
rel,
|
|
24
|
+
folderJurisdiction: folderJurisdictionFromPath(rel),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('codex worked examples (notation-corpus)', () => {
|
|
32
|
+
for (const { rel, folderJurisdiction } of codexFixturePaths()) {
|
|
33
|
+
it(`validates ${rel} without error`, () => {
|
|
34
|
+
const data = yaml.load(readFileSync(path.join(corpusRoot, rel.replace(/^codex\//, '')), 'utf-8'));
|
|
35
|
+
const v = validateCodex(data, { folderJurisdiction });
|
|
36
|
+
expect(v.valid, JSON.stringify(v.errors)).toBe(true);
|
|
37
|
+
expect(v.errors).toHaveLength(0);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
validateCodex,
|
|
4
|
+
isCodexDoc,
|
|
5
|
+
folderJurisdictionFromPath,
|
|
6
|
+
} from '../validate.js';
|
|
7
|
+
|
|
8
|
+
const VALID_EXTERNAL = {
|
|
9
|
+
zone: 'codex',
|
|
10
|
+
id: 'LAW-GDPR-1',
|
|
11
|
+
name: 'General Data Protection Regulation',
|
|
12
|
+
type: 'LAW',
|
|
13
|
+
jurisdiction: 'eu',
|
|
14
|
+
effective_date: '2018-05-25',
|
|
15
|
+
admitted_at: '2026-06-01',
|
|
16
|
+
admitted_by: 'legal.team',
|
|
17
|
+
gate_checks: { uniqueness: 'pass' },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const VALID_INTERNAL = {
|
|
21
|
+
zone: 'codex',
|
|
22
|
+
id: 'INTERNAL_STANDARD-coding-conventions-1',
|
|
23
|
+
name: 'Engineering Coding Conventions',
|
|
24
|
+
type: 'INTERNAL_STANDARD',
|
|
25
|
+
issuing_authority: 'VP Engineering',
|
|
26
|
+
effective_date: '2026-01-01',
|
|
27
|
+
admitted_at: '2026-05-27',
|
|
28
|
+
admitted_by: 'vp.engineering',
|
|
29
|
+
gate_checks: { source_authority: 'VP Engineering' },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe('validateCodex', () => {
|
|
33
|
+
it('accepts a valid external artefact', () => {
|
|
34
|
+
const r = validateCodex(VALID_EXTERNAL, { folderJurisdiction: 'eu' });
|
|
35
|
+
expect(r.valid, JSON.stringify(r.errors)).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('accepts a valid internal artefact', () => {
|
|
39
|
+
expect(validateCodex(VALID_INTERNAL).valid).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('CODEX-001 rejects non-mapping input', () => {
|
|
43
|
+
expect(validateCodex(null).errors.some((e) => e.code === 'CODEX-001')).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('CODEX-001 rejects wrong zone', () => {
|
|
47
|
+
const r = validateCodex({ ...VALID_EXTERNAL, zone: 'canon' });
|
|
48
|
+
expect(r.errors.some((e) => e.code === 'CODEX-001' && e.path === 'zone')).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('CODEX-002 rejects type/id prefix mismatch', () => {
|
|
52
|
+
const r = validateCodex({ ...VALID_EXTERNAL, type: 'REGULATION' });
|
|
53
|
+
expect(r.errors.some((e) => e.code === 'CODEX-002')).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('CODEX-003 requires jurisdiction on external artefacts', () => {
|
|
57
|
+
const r = validateCodex({ ...VALID_EXTERNAL, jurisdiction: '' });
|
|
58
|
+
expect(r.errors.some((e) => e.code === 'CODEX-003' && e.path === 'jurisdiction')).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('CODEX-005 enforces folder jurisdiction match', () => {
|
|
62
|
+
const r = validateCodex(VALID_EXTERNAL, { folderJurisdiction: 'ge' });
|
|
63
|
+
expect(r.errors.some((e) => e.code === 'CODEX-005')).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('CODEX-004 requires issuing_authority on internal artefacts', () => {
|
|
67
|
+
const r = validateCodex({ ...VALID_INTERNAL, issuing_authority: '' });
|
|
68
|
+
expect(r.errors.some((e) => e.code === 'CODEX-004')).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('isCodexDoc', () => {
|
|
73
|
+
it('detects zone: codex', () => {
|
|
74
|
+
expect(isCodexDoc({ zone: 'codex', id: 'LAW-1' })).toBe(true);
|
|
75
|
+
expect(isCodexDoc({ zone: 'canon' })).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('folderJurisdictionFromPath', () => {
|
|
80
|
+
it('parses codex/external/<jurisdiction>/ paths', () => {
|
|
81
|
+
expect(folderJurisdictionFromPath('codex/external/eu/LAW-GDPR-1.yaml')).toBe('eu');
|
|
82
|
+
expect(folderJurisdictionFromPath('codex/internal/POLICY-1.yaml')).toBeUndefined();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CODEX_ARTEFACT_TYPES, EXTERNAL_CODEX_TYPES, INTERNAL_CODEX_TYPES } from './types.js';
|
|
2
|
+
export type { CodexArtefactType } from './types.js';
|
|
3
|
+
export { validateCodex, isCodexDoc, folderJurisdictionFromPath } from './validate.js';
|
|
4
|
+
export type { CodexValidateOptions } from './validate.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Codex artefact — external laws/regulations and internal policies/standards.
|
|
2
|
+
// Schema: methodology notations/elements/14-codex.md §3–§4.
|
|
3
|
+
|
|
4
|
+
/** TYPE prefixes admitted in the codex zone (REQ-003 / 14-codex.md). */
|
|
5
|
+
export const CODEX_ARTEFACT_TYPES = ['LAW', 'REGULATION', 'POLICY', 'INTERNAL_STANDARD'] as const;
|
|
6
|
+
|
|
7
|
+
export type CodexArtefactType = (typeof CODEX_ARTEFACT_TYPES)[number];
|
|
8
|
+
|
|
9
|
+
/** External codex artefacts (codex/external/<jurisdiction>/). */
|
|
10
|
+
export const EXTERNAL_CODEX_TYPES: readonly CodexArtefactType[] = ['LAW', 'REGULATION'];
|
|
11
|
+
|
|
12
|
+
/** Internal codex artefacts (codex/internal/). */
|
|
13
|
+
export const INTERNAL_CODEX_TYPES: readonly CodexArtefactType[] = ['POLICY', 'INTERNAL_STANDARD'];
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// CODEX validator — methodology notations/elements/14-codex.md §4.
|
|
2
|
+
//
|
|
3
|
+
// CODEX-001 — shape, zone, id grammar, admission envelope.
|
|
4
|
+
// CODEX-002 — `type` field matches the id TYPE prefix when present.
|
|
5
|
+
// CODEX-003 — external artefact frontmatter (jurisdiction, effective_date).
|
|
6
|
+
// CODEX-004 — internal artefact frontmatter (issuing_authority, effective_date).
|
|
7
|
+
// CODEX-005 — jurisdiction must match the parent folder under codex/external/
|
|
8
|
+
// (when `folderJurisdiction` is supplied by the repo sweep).
|
|
9
|
+
|
|
10
|
+
import type { ValidationError, ValidationWarning, ValidationResult } from '../validation-types.js';
|
|
11
|
+
import { isCanonicalId, typeOfId } from '../typed-id.js';
|
|
12
|
+
import {
|
|
13
|
+
CODEX_ARTEFACT_TYPES,
|
|
14
|
+
EXTERNAL_CODEX_TYPES,
|
|
15
|
+
INTERNAL_CODEX_TYPES,
|
|
16
|
+
type CodexArtefactType,
|
|
17
|
+
} from './types.js';
|
|
18
|
+
|
|
19
|
+
export interface CodexValidateOptions {
|
|
20
|
+
/** Lowercased jurisdiction folder segment from `codex/external/<jurisdiction>/`. */
|
|
21
|
+
folderJurisdiction?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isCodexType(type: string | null): type is CodexArtefactType {
|
|
25
|
+
return type !== null && (CODEX_ARTEFACT_TYPES as readonly string[]).includes(type);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function normalizeType(value: unknown): string | undefined {
|
|
29
|
+
if (typeof value !== 'string' || value.trim() === '') return undefined;
|
|
30
|
+
return value.trim().toUpperCase();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function validateCodex(input: unknown, options: CodexValidateOptions = {}): ValidationResult {
|
|
34
|
+
const errors: ValidationError[] = [];
|
|
35
|
+
const warnings: ValidationWarning[] = [];
|
|
36
|
+
|
|
37
|
+
if (input === null || typeof input !== 'object' || Array.isArray(input)) {
|
|
38
|
+
errors.push({ code: 'CODEX-001', message: 'Codex artefact must be a YAML mapping.' });
|
|
39
|
+
return { valid: false, errors, warnings };
|
|
40
|
+
}
|
|
41
|
+
const c = input as Record<string, unknown>;
|
|
42
|
+
|
|
43
|
+
if (c.zone !== 'codex') {
|
|
44
|
+
errors.push({ code: 'CODEX-001', message: 'zone must be the fixed value "codex".', path: 'zone' });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const idType = typeOfId(c.id);
|
|
48
|
+
if (!isCanonicalId(c.id) || !isCodexType(idType)) {
|
|
49
|
+
errors.push({
|
|
50
|
+
code: 'CODEX-001',
|
|
51
|
+
message: `id "${String(c.id)}" must be a typed codex id (LAW, REGULATION, POLICY, or INTERNAL_STANDARD).`,
|
|
52
|
+
path: 'id',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (typeof c.name !== 'string' || c.name.trim() === '') {
|
|
57
|
+
errors.push({ code: 'CODEX-001', message: 'name is required.', path: 'name' });
|
|
58
|
+
}
|
|
59
|
+
for (const field of ['admitted_at', 'admitted_by'] as const) {
|
|
60
|
+
const v = c[field];
|
|
61
|
+
if (typeof v !== 'string' || v.trim() === '') {
|
|
62
|
+
errors.push({ code: 'CODEX-001', message: `${field} is required.`, path: field });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (c.gate_checks === null || typeof c.gate_checks !== 'object' || Array.isArray(c.gate_checks)) {
|
|
66
|
+
errors.push({ code: 'CODEX-001', message: 'gate_checks is required and must be a mapping.', path: 'gate_checks' });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const declaredType = normalizeType(c.type);
|
|
70
|
+
if (declaredType !== undefined && idType && declaredType !== idType) {
|
|
71
|
+
errors.push({
|
|
72
|
+
code: 'CODEX-002',
|
|
73
|
+
message: `type "${String(c.type)}" does not match the id TYPE prefix "${idType}".`,
|
|
74
|
+
path: 'type',
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const artefactType = (declaredType ?? idType) as CodexArtefactType | null;
|
|
79
|
+
|
|
80
|
+
if (artefactType && (EXTERNAL_CODEX_TYPES as readonly string[]).includes(artefactType)) {
|
|
81
|
+
const jurisdiction = typeof c.jurisdiction === 'string' ? c.jurisdiction.trim() : '';
|
|
82
|
+
if (!jurisdiction) {
|
|
83
|
+
errors.push({ code: 'CODEX-003', message: 'jurisdiction is required for external codex artefacts.', path: 'jurisdiction' });
|
|
84
|
+
} else if (options.folderJurisdiction && jurisdiction.toLowerCase() !== options.folderJurisdiction.toLowerCase()) {
|
|
85
|
+
errors.push({
|
|
86
|
+
code: 'CODEX-005',
|
|
87
|
+
message: `jurisdiction "${jurisdiction}" must match the parent folder "${options.folderJurisdiction}" (CODEX-001).`,
|
|
88
|
+
path: 'jurisdiction',
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (typeof c.effective_date !== 'string' || c.effective_date.trim() === '') {
|
|
92
|
+
errors.push({ code: 'CODEX-003', message: 'effective_date is required for external codex artefacts.', path: 'effective_date' });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (artefactType && (INTERNAL_CODEX_TYPES as readonly string[]).includes(artefactType)) {
|
|
97
|
+
if (typeof c.issuing_authority !== 'string' || c.issuing_authority.trim() === '') {
|
|
98
|
+
errors.push({
|
|
99
|
+
code: 'CODEX-004',
|
|
100
|
+
message: 'issuing_authority is required for internal codex artefacts.',
|
|
101
|
+
path: 'issuing_authority',
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (typeof c.effective_date !== 'string' || c.effective_date.trim() === '') {
|
|
105
|
+
errors.push({ code: 'CODEX-004', message: 'effective_date is required for internal codex artefacts.', path: 'effective_date' });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return { valid: errors.length === 0, errors, warnings };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** True when a parsed document is a codex-zone artefact candidate. */
|
|
113
|
+
export function isCodexDoc(data: unknown): boolean {
|
|
114
|
+
if (data === null || typeof data !== 'object' || Array.isArray(data)) return false;
|
|
115
|
+
return (data as Record<string, unknown>).zone === 'codex';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Infer codex folder jurisdiction from a repo-relative path such as
|
|
119
|
+
* `codex/external/eu/LAW-GDPR-1.yaml` → `eu`. */
|
|
120
|
+
export function folderJurisdictionFromPath(filePath: string): string | undefined {
|
|
121
|
+
const parts = filePath.replace(/\\/g, '/').toLowerCase().split('/');
|
|
122
|
+
const extIdx = parts.indexOf('external');
|
|
123
|
+
if (extIdx < 0 || extIdx + 1 >= parts.length) return undefined;
|
|
124
|
+
return parts[extIdx + 1] || undefined;
|
|
125
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
admitDocumentToCatalog,
|
|
5
|
+
buildComplianceScan,
|
|
6
|
+
catalogFromMap,
|
|
7
|
+
} from '../canon-catalog.js';
|
|
8
|
+
|
|
9
|
+
describe('buildComplianceScan', () => {
|
|
10
|
+
it('admits codex, requirement, and assertion ids into the catalogue', () => {
|
|
11
|
+
const docs = [
|
|
12
|
+
{
|
|
13
|
+
path: 'codex/external/ge/LAW-PERSONAL-DATA-2017-1.yaml',
|
|
14
|
+
data: {
|
|
15
|
+
zone: 'codex',
|
|
16
|
+
id: 'LAW-PERSONAL-DATA-2017-1',
|
|
17
|
+
name: 'Law',
|
|
18
|
+
type: 'LAW',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
path: 'canon/elements/01_motivation/requirements/REQUIREMENT-DATA-ERASURE-1.yaml',
|
|
23
|
+
data: {
|
|
24
|
+
notation: 'requirement',
|
|
25
|
+
id: 'REQUIREMENT-DATA-ERASURE-1',
|
|
26
|
+
name: 'Erasure',
|
|
27
|
+
derived_from: ['LAW-PERSONAL-DATA-2017-1'],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
path: 'canon/elements/02_business/products/PRODUCT-MOBILE-1.yaml',
|
|
32
|
+
data: { notation: 'product', id: 'PRODUCT-MOBILE-1', name: 'Mobile' },
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
path: 'canon/assertions/ASSERTION-MOBILE-DATA-ERASURE-1.yaml',
|
|
36
|
+
data: {
|
|
37
|
+
notation: 'assertion',
|
|
38
|
+
id: 'ASSERTION-MOBILE-DATA-ERASURE-1',
|
|
39
|
+
about: 'REQUIREMENT-DATA-ERASURE-1',
|
|
40
|
+
subject: 'PRODUCT-MOBILE-1',
|
|
41
|
+
status: 'compliant',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const { catalog, complianceCanon, pathById } = buildComplianceScan(docs);
|
|
47
|
+
expect(catalog.typeOf('LAW-PERSONAL-DATA-2017-1')).toBe('LAW');
|
|
48
|
+
expect(catalog.typeOf('REQUIREMENT-DATA-ERASURE-1')).toBe('REQUIREMENT');
|
|
49
|
+
expect(catalog.typeOf('PRODUCT-MOBILE-1')).toBe('PRODUCT');
|
|
50
|
+
expect(complianceCanon.requirements).toHaveLength(1);
|
|
51
|
+
expect(complianceCanon.assertions).toHaveLength(1);
|
|
52
|
+
expect(complianceCanon.codex).toHaveLength(1);
|
|
53
|
+
expect(pathById.get('REQUIREMENT-DATA-ERASURE-1')).toContain('requirements/');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('admitDocumentToCatalog', () => {
|
|
58
|
+
it('uses explicit codex type when the id prefix is ambiguous', () => {
|
|
59
|
+
const map = new Map<string, string>();
|
|
60
|
+
admitDocumentToCatalog(map, {
|
|
61
|
+
zone: 'codex',
|
|
62
|
+
id: 'INTERNAL_STANDARD-coding-conventions-1',
|
|
63
|
+
type: 'INTERNAL_STANDARD',
|
|
64
|
+
});
|
|
65
|
+
const catalog = catalogFromMap(map);
|
|
66
|
+
expect(catalog.typeOf('INTERNAL_STANDARD-coding-conventions-1')).toBe('INTERNAL_STANDARD');
|
|
67
|
+
});
|
|
68
|
+
});
|