@transitrix/diagrams 1.6.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/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__/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/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 +6 -4
- package/dist/compliance/index.js +3 -2
- 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 +2 -1
- package/dist/goals/GoalNode.js +7 -2
- package/dist/goals/GoalTreeView.d.ts +3 -1
- package/dist/goals/GoalTreeView.js +31 -14
- package/dist/goals/__tests__/GoalTreeView.test.js +41 -0
- package/dist/goals/__tests__/mutations.test.js +39 -0
- package/dist/goals/__tests__/parse-canonical.test.js +2 -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/types.d.ts +2 -0
- 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 +1 -1
- 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__/view-resolution.test.ts +80 -0
- package/src/compliance/canon-catalog.ts +76 -0
- package/src/compliance/coverage-metric.ts +50 -0
- package/src/compliance/impact.ts +67 -1
- package/src/compliance/index.ts +10 -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 +8 -1
- package/src/goals/GoalTreeView.tsx +61 -27
- package/src/goals/__tests__/GoalTreeView.test.tsx +48 -0
- package/src/goals/__tests__/mutations.test.ts +42 -0
- package/src/goals/__tests__/parse-canonical.test.ts +2 -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/types.ts +2 -0
- 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
|
@@ -26,4 +26,9 @@ export interface CanonicalGoalsResult extends ValidationResult {
|
|
|
26
26
|
/** On success, the internal-form GoalTree derived from the canonical input. */
|
|
27
27
|
parsed?: GoalTree;
|
|
28
28
|
}
|
|
29
|
+
/** Display id for previews — canonical `GOAL-…` when present, else internal numeric id. */
|
|
30
|
+
export declare function displayGoalId(goal: {
|
|
31
|
+
id: number;
|
|
32
|
+
canonical_id?: string;
|
|
33
|
+
}): string;
|
|
29
34
|
export declare function parseCanonicalGoals(input: unknown): CanonicalGoalsResult;
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
*/
|
|
23
23
|
const GOAL_ID_RE = /^GOAL(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
24
24
|
const GOALS_DOC_ID_RE = /^GOALS(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
25
|
+
/** Display id for previews — canonical `GOAL-…` when present, else internal numeric id. */
|
|
26
|
+
export function displayGoalId(goal) {
|
|
27
|
+
return goal.canonical_id ?? String(goal.id);
|
|
28
|
+
}
|
|
25
29
|
function isNonEmptyString(v) {
|
|
26
30
|
return typeof v === 'string' && v.trim().length > 0;
|
|
27
31
|
}
|
|
@@ -240,6 +244,7 @@ export function parseCanonicalGoals(input) {
|
|
|
240
244
|
const parentId = isNonEmptyString(parent) && idToInternal.has(parent) ? idToInternal.get(parent) : 0;
|
|
241
245
|
return {
|
|
242
246
|
id: idToInternal.get(o['id']),
|
|
247
|
+
canonical_id: o['id'],
|
|
243
248
|
name: o['name'],
|
|
244
249
|
type: o['type'],
|
|
245
250
|
level: o['level'],
|
package/dist/goals/types.d.ts
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
// referential integrity, atomicity, ID uniqueness, policy — the checks that the
|
|
5
5
|
// methodology's Python `.validators/lint.py` owns today. This converges those
|
|
6
6
|
// checks onto the shared TypeScript model so there is a single validation
|
|
7
|
-
// runtime (methodology ADR
|
|
8
|
-
//
|
|
9
|
-
// `docs/decisions/2026-06-11-validation-runtime-convergence.md`).
|
|
7
|
+
// runtime (methodology ADR "Validation Two-Axis Model"; Studio decision
|
|
8
|
+
// "Validation Runtime Convergence").
|
|
10
9
|
//
|
|
11
10
|
// The finding shape is deliberately minimal — `{ scope, id, message }`. The
|
|
12
11
|
// richer `target` / `category` reporting taxonomy is explicitly DEFERRED per the
|
|
@@ -58,8 +58,22 @@ describe('renderGoalsSvg', () => {
|
|
|
58
58
|
expect(svg).toContain('width="0"');
|
|
59
59
|
expect(svg).toContain('height="0"');
|
|
60
60
|
});
|
|
61
|
-
it('
|
|
62
|
-
const
|
|
63
|
-
|
|
61
|
+
it('shows canonical goal ids in node labels when present', () => {
|
|
62
|
+
const tree = {
|
|
63
|
+
goal_types: [{ name: 'Strategy', level: 0 }],
|
|
64
|
+
goals: [
|
|
65
|
+
{
|
|
66
|
+
id: 1,
|
|
67
|
+
canonical_id: 'GOAL-REVENUE-1',
|
|
68
|
+
name: 'Triple revenue',
|
|
69
|
+
type: 'Strategy',
|
|
70
|
+
level: 0,
|
|
71
|
+
parent_id: 0,
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
};
|
|
75
|
+
const svg = renderGoalsSvg(tree);
|
|
76
|
+
expect(svg).toContain('GOAL-REVENUE-1');
|
|
77
|
+
expect(svg).not.toMatch(/>\s*1\s*</);
|
|
64
78
|
});
|
|
65
79
|
});
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* Step 4 will follow the same shape for the remaining ten notations.
|
|
12
12
|
*/
|
|
13
13
|
import { layoutGoalTree } from '../goals/layout.js';
|
|
14
|
+
import { displayGoalId } from '../goals/parse-canonical.js';
|
|
14
15
|
import { horizontalCubicEdgePath, DEFAULT_EDGE_CURVATURE } from '../edge-path.js';
|
|
15
16
|
import { generateSvgEmbedCss } from '../theme/index.js';
|
|
16
17
|
import { escXml } from './render-util.js';
|
|
@@ -102,7 +103,7 @@ export function renderGoalsLayoutSvg(layout, options = {}) {
|
|
|
102
103
|
const typeY = twoLines ? y + 43 : y + 35;
|
|
103
104
|
const idY = twoLines ? y + 59 : y + 55;
|
|
104
105
|
const typeLabel = n.data.type ?? '';
|
|
105
|
-
const idText =
|
|
106
|
+
const idText = displayGoalId(n.data);
|
|
106
107
|
return `<g>
|
|
107
108
|
<rect class="diagram-node level-${level}" x="${x}" y="${y}" width="${n.width}" height="${n.height}" rx="${ENTITY_NODE_RX}"/>
|
|
108
109
|
<text class="text-primary" x="${x + n.width / 2}" y="${nameY1}" text-anchor="middle" dominant-baseline="central">${escXml(line1)}</text>${twoLines ? `
|
package/package.json
CHANGED
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { emptyCanon } from '../classify.js';
|
|
4
|
+
import { catalogFromMap } from '../canon-catalog.js';
|
|
5
|
+
import { collectImpactViewResolutionFindings } from '../impact.js';
|
|
6
|
+
import { collectCoverageViewResolutionFindings } from '../coverage-metric.js';
|
|
7
|
+
import type { ImpactViewConfig } from '../impact.js';
|
|
8
|
+
import type { CoverageMetricConfig } from '../coverage-metric.js';
|
|
9
|
+
|
|
10
|
+
const catalog = catalogFromMap(
|
|
11
|
+
new Map([
|
|
12
|
+
['PRODUCT-ECOMM-1', 'PRODUCT'],
|
|
13
|
+
['REQUIREMENT-GDPR-1', 'REQUIREMENT'],
|
|
14
|
+
['LAW-GDPR-1', 'LAW'],
|
|
15
|
+
]),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const complianceCanon = emptyCanon();
|
|
19
|
+
complianceCanon.products.push({ id: 'PRODUCT-ECOMM-1', name: 'E-Commerce' });
|
|
20
|
+
complianceCanon.requirements.push({ id: 'REQUIREMENT-GDPR-1', name: 'GDPR req' });
|
|
21
|
+
complianceCanon.codex.push({ id: 'LAW-GDPR-1', name: 'GDPR' });
|
|
22
|
+
|
|
23
|
+
describe('collectImpactViewResolutionFindings', () => {
|
|
24
|
+
const base: ImpactViewConfig = {
|
|
25
|
+
id: 'test-impact',
|
|
26
|
+
name: 'Test',
|
|
27
|
+
subjects: { products: ['PRODUCT-ECOMM-1'], processes: [], capabilities: [] },
|
|
28
|
+
obligations: { filter: { derived_from_codex: ['LAW-GDPR-1'] } },
|
|
29
|
+
status_display: { show: ['compliant'] },
|
|
30
|
+
empty_cells: {},
|
|
31
|
+
order_rows_by: 'id',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
it('passes when subjects and regimes resolve', () => {
|
|
35
|
+
expect(collectImpactViewResolutionFindings(base, catalog, complianceCanon)).toEqual([]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('flags unresolved subjects and regimes', () => {
|
|
39
|
+
const findings = collectImpactViewResolutionFindings(
|
|
40
|
+
{
|
|
41
|
+
...base,
|
|
42
|
+
subjects: { products: ['PRODUCT-MISSING-1'], processes: [], capabilities: [] },
|
|
43
|
+
obligations: { include: ['REQUIREMENT-MISSING-1'], filter: { derived_from_codex: ['LAW-MISSING-1'] } },
|
|
44
|
+
},
|
|
45
|
+
catalog,
|
|
46
|
+
complianceCanon,
|
|
47
|
+
);
|
|
48
|
+
expect(findings.some((f) => f.code === 'COMPIMP-REF' && f.message.includes('PRODUCT-MISSING-1'))).toBe(true);
|
|
49
|
+
expect(findings.some((f) => f.message.includes('REQUIREMENT-MISSING-1'))).toBe(true);
|
|
50
|
+
expect(findings.some((f) => f.message.includes('LAW-MISSING-1'))).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('collectCoverageViewResolutionFindings', () => {
|
|
55
|
+
const base: CoverageMetricConfig = {
|
|
56
|
+
id: 'test-coverage',
|
|
57
|
+
name: 'Test',
|
|
58
|
+
thresholds: { green: 0.9, amber: 0.7 },
|
|
59
|
+
subjects: { products: ['PRODUCT-ECOMM-1'] },
|
|
60
|
+
regimes: { include: ['LAW-GDPR-1'] },
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
it('passes when products and regimes resolve', () => {
|
|
64
|
+
expect(collectCoverageViewResolutionFindings(base, catalog, complianceCanon)).toEqual([]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('flags unresolved product and regime refs', () => {
|
|
68
|
+
const findings = collectCoverageViewResolutionFindings(
|
|
69
|
+
{
|
|
70
|
+
...base,
|
|
71
|
+
subjects: { products: ['PRODUCT-MISSING-1'] },
|
|
72
|
+
regimes: { include: ['LAW-MISSING-1'] },
|
|
73
|
+
},
|
|
74
|
+
catalog,
|
|
75
|
+
complianceCanon,
|
|
76
|
+
);
|
|
77
|
+
expect(findings.some((f) => f.code === 'COVMET-REF')).toBe(true);
|
|
78
|
+
expect(findings).toHaveLength(2);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// CanonCatalog builder — repo-scope cross-reference resolution (#518 Phase C3).
|
|
2
|
+
//
|
|
3
|
+
// Scans admitted YAML documents and builds the `{ typeOf }` catalogue that
|
|
4
|
+
// `validateRequirement` / `validateAssertion` accept for REQ-002 and
|
|
5
|
+
// ASSERT-002..005 resolution.
|
|
6
|
+
|
|
7
|
+
import { typeOfId, type CanonCatalog } from '../typed-id.js';
|
|
8
|
+
import { emptyCanon, ingestComplianceDoc, type ComplianceCanon } from './classify.js';
|
|
9
|
+
|
|
10
|
+
export interface ScannedYamlDoc {
|
|
11
|
+
path: string;
|
|
12
|
+
data: unknown;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ComplianceScanResult {
|
|
16
|
+
complianceCanon: ComplianceCanon;
|
|
17
|
+
catalog: CanonCatalog;
|
|
18
|
+
/** First path where each admitted id was seen (for gap-dashboard warnings). */
|
|
19
|
+
pathById: Map<string, string>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function strId(doc: unknown): string | undefined {
|
|
23
|
+
if (doc === null || typeof doc !== 'object' || Array.isArray(doc)) return undefined;
|
|
24
|
+
const id = (doc as Record<string, unknown>).id;
|
|
25
|
+
return typeof id === 'string' && id.trim() !== '' ? id.trim() : undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Admit one parsed document into the id → TYPE map. */
|
|
29
|
+
export function admitDocumentToCatalog(map: Map<string, string>, doc: unknown): string | undefined {
|
|
30
|
+
const id = strId(doc);
|
|
31
|
+
if (!id) return undefined;
|
|
32
|
+
|
|
33
|
+
const fromPrefix = typeOfId(id);
|
|
34
|
+
if (fromPrefix) {
|
|
35
|
+
map.set(id, fromPrefix);
|
|
36
|
+
return id;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (doc !== null && typeof doc === 'object' && !Array.isArray(doc)) {
|
|
40
|
+
const d = doc as Record<string, unknown>;
|
|
41
|
+
if (d.zone === 'codex') {
|
|
42
|
+
const explicit = typeof d.type === 'string' ? d.type.trim().toUpperCase() : undefined;
|
|
43
|
+
if (explicit) {
|
|
44
|
+
map.set(id, explicit);
|
|
45
|
+
return id;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Build a read-only `CanonCatalog` from a populated id → TYPE map. */
|
|
53
|
+
export function catalogFromMap(map: Map<string, string>): CanonCatalog {
|
|
54
|
+
return { typeOf: (id: string) => map.get(id) };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Ingest compliance projections and admit cross-reference targets from a batch
|
|
58
|
+
* of already-parsed YAML documents (no IO). */
|
|
59
|
+
export function buildComplianceScan(docs: ScannedYamlDoc[]): ComplianceScanResult {
|
|
60
|
+
const complianceCanon = emptyCanon();
|
|
61
|
+
const catalogMap = new Map<string, string>();
|
|
62
|
+
const pathById = new Map<string, string>();
|
|
63
|
+
|
|
64
|
+
for (const { path, data } of docs) {
|
|
65
|
+
const ingested = ingestComplianceDoc(complianceCanon, data);
|
|
66
|
+
if (ingested) pathById.set(ingested, path);
|
|
67
|
+
const admitted = admitDocumentToCatalog(catalogMap, data);
|
|
68
|
+
if (admitted && !pathById.has(admitted)) pathById.set(admitted, path);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
complianceCanon,
|
|
73
|
+
catalog: catalogFromMap(catalogMap),
|
|
74
|
+
pathById,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import type { AssertionStatus } from '../assertion/types.js';
|
|
9
9
|
import type { ComplianceCanon } from './classify.js';
|
|
10
10
|
import { buildComplianceIndex } from './reverse-index.js';
|
|
11
|
+
import type { CanonCatalog } from '../typed-id.js';
|
|
11
12
|
import type { IndexAssertion } from './types.js';
|
|
12
13
|
|
|
13
14
|
// ── Config types ─────────────────────────────────────────────────────────────
|
|
@@ -93,6 +94,55 @@ export interface CoverageMatrix {
|
|
|
93
94
|
thresholds: CoverageMetricThresholds;
|
|
94
95
|
}
|
|
95
96
|
|
|
97
|
+
/** Repo-scope cross-reference finding for a coverage-metric view (#518 C3). */
|
|
98
|
+
export interface CoverageViewFinding {
|
|
99
|
+
code: string;
|
|
100
|
+
severity: 'error' | 'warning';
|
|
101
|
+
message: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Repo-scope cross-reference checks for a parsed coverage-metric view config.
|
|
106
|
+
* Surfaces unresolved product and regime ids before `buildCoverageMatrix` runs.
|
|
107
|
+
*/
|
|
108
|
+
export function collectCoverageViewResolutionFindings(
|
|
109
|
+
config: CoverageMetricConfig,
|
|
110
|
+
catalog: CanonCatalog,
|
|
111
|
+
complianceCanon: ComplianceCanon,
|
|
112
|
+
): CoverageViewFinding[] {
|
|
113
|
+
const findings: CoverageViewFinding[] = [];
|
|
114
|
+
const codexIds = new Set(complianceCanon.codex.map((c) => c.id));
|
|
115
|
+
|
|
116
|
+
for (const id of config.subjects?.products ?? []) {
|
|
117
|
+
const t = catalog.typeOf(id);
|
|
118
|
+
if (t === undefined) {
|
|
119
|
+
findings.push({
|
|
120
|
+
code: 'COVMET-REF',
|
|
121
|
+
severity: 'error',
|
|
122
|
+
message: `subjects.products: "${id}" does not resolve to an admitted artefact.`,
|
|
123
|
+
});
|
|
124
|
+
} else if (t !== 'PRODUCT') {
|
|
125
|
+
findings.push({
|
|
126
|
+
code: 'COVMET-REF',
|
|
127
|
+
severity: 'error',
|
|
128
|
+
message: `subjects.products: "${id}" resolves to ${t}, not PRODUCT.`,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
for (const id of config.regimes?.include ?? []) {
|
|
134
|
+
if (!codexIds.has(id)) {
|
|
135
|
+
findings.push({
|
|
136
|
+
code: 'COVMET-REF',
|
|
137
|
+
severity: 'error',
|
|
138
|
+
message: `regimes.include: "${id}" does not resolve to an admitted codex artefact.`,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return findings;
|
|
144
|
+
}
|
|
145
|
+
|
|
96
146
|
// ── Parser ───────────────────────────────────────────────────────────────────
|
|
97
147
|
|
|
98
148
|
function parseRegimes(raw: Record<string, unknown>): { regimes?: CoverageMetricRegimes; warnings: string[] } {
|