@sdd-method/maintain-cli 0.0.0-stage → 0.1.0
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/LICENSE +201 -0
- package/NOTICE +17 -0
- package/README.md +6 -2
- package/dist/lib/adr-origin.js +59 -0
- package/dist/lib/agent-harness.js +28 -0
- package/dist/lib/briefing/index.js +13 -0
- package/dist/lib/briefing/render.js +123 -0
- package/dist/lib/briefing/variables.js +92 -0
- package/dist/lib/bundle.js +123 -0
- package/dist/lib/catalogue/aggregate.js +2404 -0
- package/dist/lib/catalogue/aggregation-manifest-loader.js +173 -0
- package/dist/lib/catalogue/application-archetype/expectations.js +119 -0
- package/dist/lib/catalogue/application-archetype/vocabulary.js +177 -0
- package/dist/lib/catalogue/archetype/maps/android.yaml +66 -0
- package/dist/lib/catalogue/archetype/maps/swiftui.yaml +58 -0
- package/dist/lib/catalogue/archetype/maps/uikit.yaml +48 -0
- package/dist/lib/catalogue/archetype/maps/web-generic.yaml +86 -0
- package/dist/lib/catalogue/archetype/openui-archetype-vocabulary.yaml +46 -0
- package/dist/lib/catalogue/archetype/resolver.js +103 -0
- package/dist/lib/catalogue/archetype/wireframe.js +418 -0
- package/dist/lib/catalogue/baseline-check.js +151 -0
- package/dist/lib/catalogue/build.js +1502 -0
- package/dist/lib/catalogue/builders/adr-supersedes.js +103 -0
- package/dist/lib/catalogue/builders/adrs.js +222 -0
- package/dist/lib/catalogue/builders/application-conformance-coverage.js +47 -0
- package/dist/lib/catalogue/builders/application-data-plane-bindings.js +115 -0
- package/dist/lib/catalogue/builders/c4-components.js +229 -0
- package/dist/lib/catalogue/builders/c4-containers.js +240 -0
- package/dist/lib/catalogue/builders/c4-entity-rollups.js +87 -0
- package/dist/lib/catalogue/builders/c4-external-systems.js +194 -0
- package/dist/lib/catalogue/builders/c4-l1-candidates.js +107 -0
- package/dist/lib/catalogue/builders/c4-systems.js +98 -0
- package/dist/lib/catalogue/builders/capabilities.js +488 -0
- package/dist/lib/catalogue/builders/capability-domain-model.js +74 -0
- package/dist/lib/catalogue/builders/capability-edges.js +256 -0
- package/dist/lib/catalogue/builders/capability-spec-walker.js +99 -0
- package/dist/lib/catalogue/builders/capability-spec.js +348 -0
- package/dist/lib/catalogue/builders/container-dependency.js +183 -0
- package/dist/lib/catalogue/builders/contracts.js +402 -0
- package/dist/lib/catalogue/builders/data-items.js +344 -0
- package/dist/lib/catalogue/builders/data-store-mapping.js +113 -0
- package/dist/lib/catalogue/builders/domain-models.js +175 -0
- package/dist/lib/catalogue/builders/domains.js +119 -0
- package/dist/lib/catalogue/builders/edge-label-merge.js +19 -0
- package/dist/lib/catalogue/builders/entities-manifest.js +160 -0
- package/dist/lib/catalogue/builders/entities-mermaid.js +189 -0
- package/dist/lib/catalogue/builders/entity-persistence.js +102 -0
- package/dist/lib/catalogue/builders/entity-slug.js +47 -0
- package/dist/lib/catalogue/builders/event-catalog-walker.js +186 -0
- package/dist/lib/catalogue/builders/event-edges.js +327 -0
- package/dist/lib/catalogue/builders/events.js +168 -0
- package/dist/lib/catalogue/builders/evidence-class.js +43 -0
- package/dist/lib/catalogue/builders/evidence-target-repo.js +67 -0
- package/dist/lib/catalogue/builders/external-system-exemption.js +120 -0
- package/dist/lib/catalogue/builders/feature-contract.js +77 -0
- package/dist/lib/catalogue/builders/feature-domain-model.js +50 -0
- package/dist/lib/catalogue/builders/feature-grounding-walker.js +254 -0
- package/dist/lib/catalogue/builders/feature-grounding.js +391 -0
- package/dist/lib/catalogue/builders/feature-groups.js +63 -0
- package/dist/lib/catalogue/builders/feature-subscription-channels.js +228 -0
- package/dist/lib/catalogue/builders/feature-tree-walker.js +295 -0
- package/dist/lib/catalogue/builders/features.js +300 -0
- package/dist/lib/catalogue/builders/glossary-xref.js +378 -0
- package/dist/lib/catalogue/builders/glossary.js +204 -0
- package/dist/lib/catalogue/builders/implementations.js +214 -0
- package/dist/lib/catalogue/builders/index.js +64 -0
- package/dist/lib/catalogue/builders/integration-components.js +344 -0
- package/dist/lib/catalogue/builders/integrations.js +181 -0
- package/dist/lib/catalogue/builders/persona-c4system.js +149 -0
- package/dist/lib/catalogue/builders/persona-container.js +133 -0
- package/dist/lib/catalogue/builders/persona-journey-edges.js +133 -0
- package/dist/lib/catalogue/builders/personas.js +152 -0
- package/dist/lib/catalogue/builders/product-edges.js +106 -0
- package/dist/lib/catalogue/builders/product-platform-dependencies.js +405 -0
- package/dist/lib/catalogue/builders/products.js +162 -0
- package/dist/lib/catalogue/builders/quality-scores.js +635 -0
- package/dist/lib/catalogue/builders/repo-capability-exemption.js +61 -0
- package/dist/lib/catalogue/builders/repo-dependency.js +127 -0
- package/dist/lib/catalogue/builders/repo-edges.js +340 -0
- package/dist/lib/catalogue/builders/repositories.js +458 -0
- package/dist/lib/catalogue/builders/scaffolds.js +197 -0
- package/dist/lib/catalogue/builders/screen-tree.js +222 -0
- package/dist/lib/catalogue/builders/screens.js +396 -0
- package/dist/lib/catalogue/builders/service-capability-exemption.js +63 -0
- package/dist/lib/catalogue/builders/service-contract-consumes.js +186 -0
- package/dist/lib/catalogue/builders/service-contract.js +74 -0
- package/dist/lib/catalogue/builders/service-entity-tables.js +187 -0
- package/dist/lib/catalogue/builders/services.js +232 -0
- package/dist/lib/catalogue/builders/system-external-dependency.js +115 -0
- package/dist/lib/catalogue/builders/user-journeys.js +253 -0
- package/dist/lib/catalogue/canonical-schema.yaml +4117 -0
- package/dist/lib/catalogue/cli-version.js +10 -0
- package/dist/lib/catalogue/contract-id.js +49 -0
- package/dist/lib/catalogue/contract-path-resolution.js +149 -0
- package/dist/lib/catalogue/coverage-predicates.js +603 -0
- package/dist/lib/catalogue/coverage-render.js +552 -0
- package/dist/lib/catalogue/coverage-run.js +115 -0
- package/dist/lib/catalogue/csv-reader.js +97 -0
- package/dist/lib/catalogue/csv-writer.js +96 -0
- package/dist/lib/catalogue/data-item-coverage.js +142 -0
- package/dist/lib/catalogue/data-plane-coherence.js +77 -0
- package/dist/lib/catalogue/ddl-generator.js +233 -0
- package/dist/lib/catalogue/dedupe-keyed-tables.js +0 -0
- package/dist/lib/catalogue/engine-validator.js +239 -0
- package/dist/lib/catalogue/ext-id.js +76 -0
- package/dist/lib/catalogue/feature-grounding-aliases-loader.js +65 -0
- package/dist/lib/catalogue/feature-repo-zero-resolution-summary.js +31 -0
- package/dist/lib/catalogue/finding-identity.js +183 -0
- package/dist/lib/catalogue/findings.js +46 -0
- package/dist/lib/catalogue/fk-validator.js +136 -0
- package/dist/lib/catalogue/freshness.js +69 -0
- package/dist/lib/catalogue/gate-checks.js +338 -0
- package/dist/lib/catalogue/graph-projection.js +346 -0
- package/dist/lib/catalogue/graph-run.js +64 -0
- package/dist/lib/catalogue/impact-run.js +228 -0
- package/dist/lib/catalogue/manifest-loader.js +435 -0
- package/dist/lib/catalogue/platform-scope.js +7 -0
- package/dist/lib/catalogue/population-checks.js +87 -0
- package/dist/lib/catalogue/relationship-semantics.js +66 -0
- package/dist/lib/catalogue/reverse-product-quality.js +99 -0
- package/dist/lib/catalogue/rubric-coverage-map.yaml +871 -0
- package/dist/lib/catalogue/runway-vocabulary-loader.js +56 -0
- package/dist/lib/catalogue/scaffold-delta.js +261 -0
- package/dist/lib/catalogue/schema-compat.js +52 -0
- package/dist/lib/catalogue/schema-loader.js +87 -0
- package/dist/lib/catalogue/scores-coverage.js +573 -0
- package/dist/lib/catalogue/screen-validation-loader.js +89 -0
- package/dist/lib/catalogue/service-architecture-parser.js +193 -0
- package/dist/lib/catalogue/service-contract-aliases-loader.js +109 -0
- package/dist/lib/catalogue/staleness-verdicts.js +345 -0
- package/dist/lib/catalogue/traceability-loader.js +350 -0
- package/dist/lib/catalogue/validate.js +200 -0
- package/dist/lib/catalogue/version.js +18 -0
- package/dist/lib/ci-binding/index.js +220 -0
- package/dist/lib/ci-binding/module.js +204 -0
- package/dist/lib/conformance/binding.js +70 -0
- package/dist/lib/context-pull/index.js +151 -0
- package/dist/lib/context-pull/resolve.js +70 -0
- package/dist/lib/generate-briefing/index.js +77 -0
- package/dist/lib/hooks-seed/copilot.js +167 -0
- package/dist/lib/hooks-seed/entries.js +47 -0
- package/dist/lib/hooks-seed/index.js +17 -0
- package/dist/lib/hooks-seed/lifecycle-mapping.js +28 -0
- package/dist/lib/hooks-seed/merge.js +128 -0
- package/dist/lib/hooks-seed/types.js +20 -0
- package/dist/lib/init/ci-workflow.js +98 -0
- package/dist/lib/list/discover.js +100 -0
- package/dist/lib/list/format.js +84 -0
- package/dist/lib/list/index.js +16 -0
- package/dist/lib/lock-file.js +437 -0
- package/dist/lib/mcp-seed/entries.js +14 -0
- package/dist/lib/mcp-seed/index.js +28 -0
- package/dist/lib/mcp-seed/merge.js +99 -0
- package/dist/lib/mcp-seed/types.js +13 -0
- package/dist/lib/pack/builder.js +303 -0
- package/dist/lib/pack/index.js +87 -0
- package/dist/lib/pack/leakage.js +144 -0
- package/dist/lib/pack/log.js +18 -0
- package/dist/lib/pack/publish-transform.js +233 -0
- package/dist/lib/pack/reference-closure.js +125 -0
- package/dist/lib/pack/schema.js +121 -0
- package/dist/lib/pack/seed.js +182 -0
- package/dist/lib/pack/validate.js +49 -0
- package/dist/lib/package-version.js +92 -0
- package/dist/lib/repo-kind.js +129 -0
- package/dist/lib/scripts.js +7 -0
- package/dist/lib/snapshot/catalogue-diff.js +219 -0
- package/dist/lib/snapshot/manifest.js +206 -0
- package/dist/lib/sync/adr-transitions.js +250 -0
- package/dist/lib/sync/apply.js +91 -0
- package/dist/lib/sync/briefing-merge.js +90 -0
- package/dist/lib/sync/bundle-cache.js +109 -0
- package/dist/lib/sync/bundle-source.js +61 -0
- package/dist/lib/sync/config.js +72 -0
- package/dist/lib/sync/copilot-hooks-merge.js +108 -0
- package/dist/lib/sync/diff.js +251 -0
- package/dist/lib/sync/index.js +818 -0
- package/dist/lib/sync/settings-merge.js +216 -0
- package/dist/lib/sync/yaml-block-merge.js +120 -0
- package/dist/lib/validate/aggregate.js +51 -0
- package/dist/lib/validate/bundle-coherence.js +74 -0
- package/dist/lib/validate/dispatch.js +243 -0
- package/dist/lib/validate/index.js +110 -0
- package/dist/lib/validate/plan.js +54 -0
- package/dist/lib/validate/runner.js +85 -0
- package/dist/lib/validate/yaml-parse.js +112 -0
- package/dist/maintain-bin.js +8 -0
- package/dist/maintain-program.js +91 -0
- package/dist/maintain-version.json +4 -0
- package/dist/verbs/catalogue-maintain.js +110 -0
- package/dist/verbs/catalogue-verify.js +114 -0
- package/dist/verbs/context.js +39 -0
- package/dist/verbs/generate-briefing.js +29 -0
- package/dist/verbs/list.js +45 -0
- package/dist/verbs/pack-build.js +31 -0
- package/dist/verbs/pack-validate.js +17 -0
- package/dist/verbs/path-option.js +25 -0
- package/dist/verbs/render.js +87 -0
- package/dist/verbs/sync.js +110 -0
- package/dist/verbs/validate.js +48 -0
- package/dist/verify-program.js +122 -0
- package/dist/verify-version.json +4 -0
- package/package.json +32 -4
- package/scripts/validate-app-dependencies.sh +664 -0
- package/scripts/validate-app-docs.sh +199 -0
- package/scripts/validate-integration-docs.sh +505 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema→DDL generator — M-ADR 0205 §4.3 (engine-evolution Phase A1).
|
|
3
|
+
*
|
|
4
|
+
* Emits, from the loaded canonical schema:
|
|
5
|
+
* (a) CREATE TABLE DDL for every declared catalogue, typed per the
|
|
6
|
+
* schema's column types; and
|
|
7
|
+
* (b) a deterministic list of constraint-violation queries (fk | pk |
|
|
8
|
+
* enum) whose row semantics mirror fk-validator.ts and
|
|
9
|
+
* enum-validator.ts EXACTLY — the Phase A2 dual-run comparison
|
|
10
|
+
* (old path vs engine path, count AND list) depends on that
|
|
11
|
+
* equivalence, so any semantic change here must change there too:
|
|
12
|
+
* - fk: a required (non-nullable, non-external) FK fails when
|
|
13
|
+
* empty; a non-empty value must resolve against the target
|
|
14
|
+
* catalogue's primary keys unless the FK is effective-external
|
|
15
|
+
* (declared `external`, or external for the build's profile via
|
|
16
|
+
* `externalForProfiles`) — mirroring FkValidationOptions.
|
|
17
|
+
* - pk: duplicate non-empty primary-key values.
|
|
18
|
+
* - enum: a non-empty (trimmed) bound-column value outside the
|
|
19
|
+
* bound enum's declared set. Emptiness is nullability's concern,
|
|
20
|
+
* not the enum's, exactly as in enum-validator.ts.
|
|
21
|
+
*
|
|
22
|
+
* Determinism per M-ADR 0205 §4.2: emission order is the schema's own
|
|
23
|
+
* declaration order; every query carries a total ORDER BY.
|
|
24
|
+
*
|
|
25
|
+
* Digest coupling per §4.3 is inherited, not re-implemented: this module
|
|
26
|
+
* reads the schema through loadCanonicalSchema, and the vendored copy it
|
|
27
|
+
* loads is guarded by canonical-schema-drift.test.ts.
|
|
28
|
+
*
|
|
29
|
+
* There is NO hand-maintained DDL anywhere: an unknown column type or a
|
|
30
|
+
* binding to an unknown enum throws at generation time — loud, never a
|
|
31
|
+
* silent fallback (the known*Ids.has() lesson).
|
|
32
|
+
*/
|
|
33
|
+
import { PLATFORM_STAMP_COLUMN, isPlatformScopedFk } from "./fk-validator.js";
|
|
34
|
+
/** Closed map from schema column types to engine column types. */
|
|
35
|
+
const TYPE_MAP = {
|
|
36
|
+
string: "VARCHAR",
|
|
37
|
+
int: "INTEGER",
|
|
38
|
+
integer: "INTEGER",
|
|
39
|
+
number: "DOUBLE",
|
|
40
|
+
date: "DATE",
|
|
41
|
+
boolean: "BOOLEAN",
|
|
42
|
+
};
|
|
43
|
+
/** Engine type for a schema column type; throws on an unmapped type. */
|
|
44
|
+
export function sqlType(catalogue, column, type) {
|
|
45
|
+
const mapped = TYPE_MAP[type];
|
|
46
|
+
if (!mapped) {
|
|
47
|
+
throw new Error(`ddl-generator: ${catalogue}.${column} declares unmapped column type "${type}" — extend TYPE_MAP deliberately, never default`);
|
|
48
|
+
}
|
|
49
|
+
return mapped;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The one definition of effective-external, shared with the engine
|
|
53
|
+
* validator so the three consumers (fk-validator.ts, the query generator,
|
|
54
|
+
* engine-validator.ts) cannot drift: declared `external`, or external for
|
|
55
|
+
* the build's profile via `externalForProfiles`.
|
|
56
|
+
*/
|
|
57
|
+
export function isEffectiveExternal(fk, options) {
|
|
58
|
+
return (fk.external ||
|
|
59
|
+
(options.profile !== undefined &&
|
|
60
|
+
(fk.externalForProfiles ?? []).includes(options.profile)));
|
|
61
|
+
}
|
|
62
|
+
function quote(identifier) {
|
|
63
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(identifier)) {
|
|
64
|
+
throw new Error(`ddl-generator: identifier "${identifier}" is outside the schema's naming form — refusing to interpolate it into SQL`);
|
|
65
|
+
}
|
|
66
|
+
return `"${identifier}"`;
|
|
67
|
+
}
|
|
68
|
+
function sqlStringLiteral(value) {
|
|
69
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* One CREATE TABLE statement per catalogue, in schema declaration order.
|
|
73
|
+
* Plain typed columns only: enforcement of PK/FK/enum semantics lives in
|
|
74
|
+
* the violation queries, whose findings-shaped output (never a load
|
|
75
|
+
* abort) is what the validators' exit contracts need.
|
|
76
|
+
*/
|
|
77
|
+
export function generateTableDdl(schema) {
|
|
78
|
+
return schema.catalogues.map((cat) => {
|
|
79
|
+
const cols = cat.columns
|
|
80
|
+
.map((c) => ` ${quote(c.name)} ${sqlType(cat.name, c.name, c.type)}`)
|
|
81
|
+
.join(",\n");
|
|
82
|
+
return `CREATE TABLE ${quote(cat.name)} (\n${cols}\n);`;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The violation-query set for a schema, mirroring the in-memory
|
|
87
|
+
* validators' semantics under the same options they take.
|
|
88
|
+
*/
|
|
89
|
+
export function generateConstraintQueries(schema, options = {}) {
|
|
90
|
+
const catalogueNames = new Set(schema.catalogues.map((c) => c.name));
|
|
91
|
+
const queries = [];
|
|
92
|
+
const catByName = new Map(schema.catalogues.map((c) => [c.name, c]));
|
|
93
|
+
for (const cat of schema.catalogues) {
|
|
94
|
+
queries.push(pkQuery(cat, options));
|
|
95
|
+
for (const fk of cat.foreignKeys) {
|
|
96
|
+
const [targetCat, targetCol] = fk.references.split(".");
|
|
97
|
+
if (!targetCat || !targetCol) {
|
|
98
|
+
throw new Error(`ddl-generator: malformed FK reference "${fk.references}" on ${cat.name}.${fk.column}`);
|
|
99
|
+
}
|
|
100
|
+
if (!catalogueNames.has(targetCat)) {
|
|
101
|
+
throw new Error(`ddl-generator: FK ${cat.name}.${fk.column} references unknown catalogue "${targetCat}"`);
|
|
102
|
+
}
|
|
103
|
+
if (!cat.columns.some((c) => c.name === fk.column)) {
|
|
104
|
+
throw new Error(`ddl-generator: FK column ${cat.name}.${fk.column} is not a declared column — the schema 3.1.3 vacuous-binding class`);
|
|
105
|
+
}
|
|
106
|
+
const effectiveExternal = isEffectiveExternal(fk, options);
|
|
107
|
+
// Mirrors fk-validator.ts exactly: the required-empty clause is keyed
|
|
108
|
+
// on the DECLARED external flag; the dangling clause is keyed on
|
|
109
|
+
// effective-external (unless the aggregator asks for internal
|
|
110
|
+
// treatment).
|
|
111
|
+
const checkEmpty = !fk.nullable && !fk.external;
|
|
112
|
+
const checkDangling = !effectiveExternal || options.treatExternalAsInternal === true;
|
|
113
|
+
if (!checkEmpty && !checkDangling)
|
|
114
|
+
continue;
|
|
115
|
+
const t = quote(cat.name);
|
|
116
|
+
const col = quote(fk.column);
|
|
117
|
+
const pk = quote(cat.primaryKey);
|
|
118
|
+
const clauses = [];
|
|
119
|
+
if (checkEmpty) {
|
|
120
|
+
clauses.push(`(t.${col} IS NULL OR t.${col} = '')`);
|
|
121
|
+
}
|
|
122
|
+
if (checkDangling) {
|
|
123
|
+
// M-ADR 0208 §4.4 (F-D): a platform-scoped target resolves on
|
|
124
|
+
// (platform_sdd_id, pk) — equal stamps, or either side unstamped.
|
|
125
|
+
// Mirrors fk-validator.ts's `resolved` predicate exactly.
|
|
126
|
+
const stamp = quote(PLATFORM_STAMP_COLUMN);
|
|
127
|
+
const scope = isPlatformScopedFk(cat, catByName.get(targetCat), options)
|
|
128
|
+
? ` AND (COALESCE(t.${stamp}, '') = '' OR COALESCE(r.${stamp}, '') = '' OR r.${stamp} = t.${stamp})`
|
|
129
|
+
: "";
|
|
130
|
+
clauses.push(`(t.${col} IS NOT NULL AND t.${col} <> '' AND NOT EXISTS (` +
|
|
131
|
+
`SELECT 1 FROM ${quote(targetCat)} r WHERE r.${quote(targetCol)} = t.${col}${scope}))`);
|
|
132
|
+
}
|
|
133
|
+
queries.push({
|
|
134
|
+
catalogue: cat.name,
|
|
135
|
+
kind: "fk",
|
|
136
|
+
column: fk.column,
|
|
137
|
+
target: fk.references,
|
|
138
|
+
sql: `SELECT t.${pk} AS row_pk, COALESCE(t.${col}, '') AS value FROM ${t} t ` +
|
|
139
|
+
`WHERE ${clauses.join(" OR ")} ORDER BY row_pk, value;`,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
for (const [column, enumRef] of Object.entries(cat.columnEnums)) {
|
|
143
|
+
const enumName = enumRef.replace(/^enums\./, "");
|
|
144
|
+
const enumDef = schema.enums[enumName];
|
|
145
|
+
if (!enumDef) {
|
|
146
|
+
throw new Error(`ddl-generator: ${cat.name}.${column} binds unknown enum "${enumRef}" — a binding that names no enum must not validate as vacuously true`);
|
|
147
|
+
}
|
|
148
|
+
if (!cat.columns.some((c) => c.name === column)) {
|
|
149
|
+
throw new Error(`ddl-generator: ${cat.name}.${column} binds a column the catalogue does not declare — the schema 3.1.3 vacuous-binding class`);
|
|
150
|
+
}
|
|
151
|
+
const allowed = enumDef.values
|
|
152
|
+
.map((v) => sqlStringLiteral(v.value))
|
|
153
|
+
.join(", ");
|
|
154
|
+
const t = quote(cat.name);
|
|
155
|
+
const col = quote(column);
|
|
156
|
+
const pk = quote(cat.primaryKey);
|
|
157
|
+
queries.push({
|
|
158
|
+
catalogue: cat.name,
|
|
159
|
+
kind: "enum",
|
|
160
|
+
column,
|
|
161
|
+
target: enumName,
|
|
162
|
+
sql:
|
|
163
|
+
// TRIM in the projection too: enum-validator.ts records the
|
|
164
|
+
// TRIMMED value in its violation objects, and A2's count-and-list
|
|
165
|
+
// parity compares those objects field-for-field.
|
|
166
|
+
`SELECT t.${pk} AS row_pk, TRIM(t.${col}) AS value FROM ${t} t ` +
|
|
167
|
+
`WHERE t.${col} IS NOT NULL AND TRIM(t.${col}) <> '' ` +
|
|
168
|
+
`AND TRIM(t.${col}) NOT IN (${allowed}) ORDER BY row_pk, value;`,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return queries;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Dangling-value queries for the FKs the main set SKIPS as
|
|
176
|
+
* effective-external — one query per skipped FK, returning the rows the
|
|
177
|
+
* in-memory path logs as `[finding] external` (unresolved non-empty
|
|
178
|
+
* values; resolution happens at aggregation). Empty when
|
|
179
|
+
* treatExternalAsInternal is set, exactly as the main set then skips
|
|
180
|
+
* nothing. Kept separate from generateConstraintQueries because these
|
|
181
|
+
* rows are FINDINGS, not failures — the exit contracts differ.
|
|
182
|
+
*/
|
|
183
|
+
export function generateExternalFindingQueries(schema, options = {}) {
|
|
184
|
+
if (options.treatExternalAsInternal === true)
|
|
185
|
+
return [];
|
|
186
|
+
const queries = [];
|
|
187
|
+
for (const cat of schema.catalogues) {
|
|
188
|
+
for (const fk of cat.foreignKeys) {
|
|
189
|
+
if (!isEffectiveExternal(fk, options))
|
|
190
|
+
continue;
|
|
191
|
+
const [targetCat, targetCol] = fk.references.split(".");
|
|
192
|
+
if (!targetCat || !targetCol) {
|
|
193
|
+
throw new Error(`ddl-generator: malformed FK reference "${fk.references}" on ${cat.name}.${fk.column}`);
|
|
194
|
+
}
|
|
195
|
+
const t = quote(cat.name);
|
|
196
|
+
const col = quote(fk.column);
|
|
197
|
+
const pk = quote(cat.primaryKey);
|
|
198
|
+
queries.push({
|
|
199
|
+
catalogue: cat.name,
|
|
200
|
+
kind: "fk",
|
|
201
|
+
column: fk.column,
|
|
202
|
+
target: fk.references,
|
|
203
|
+
sql: `SELECT t.${pk} AS row_pk, t.${col} AS value FROM ${t} t ` +
|
|
204
|
+
`WHERE t.${col} IS NOT NULL AND t.${col} <> '' AND NOT EXISTS (` +
|
|
205
|
+
`SELECT 1 FROM ${quote(targetCat)} r WHERE r.${quote(targetCol)} = t.${col}) ` +
|
|
206
|
+
`ORDER BY row_pk, value;`,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return queries;
|
|
211
|
+
}
|
|
212
|
+
function pkQuery(cat, options = {}) {
|
|
213
|
+
const t = quote(cat.name);
|
|
214
|
+
const pk = quote(cat.primaryKey);
|
|
215
|
+
// M-ADR 0208 §4.4 (F-D): for a platform-scoped catalogue the key is
|
|
216
|
+
// (platform_sdd_id, pk). n rows sharing a pk are distinct iff every one
|
|
217
|
+
// carries a stamp and the stamps are all different — an EMPTY stamp is
|
|
218
|
+
// unresolved, never a key, so it collides with everything. Mirrors
|
|
219
|
+
// aggregate.ts findDuplicatePrimaryKeys.
|
|
220
|
+
const scoped = isPlatformScopedFk(cat, cat, options);
|
|
221
|
+
const having = scoped
|
|
222
|
+
? `HAVING COUNT(*) > COUNT(DISTINCT NULLIF(${quote(PLATFORM_STAMP_COLUMN)}, ''))`
|
|
223
|
+
: `HAVING COUNT(*) > 1`;
|
|
224
|
+
return {
|
|
225
|
+
catalogue: cat.name,
|
|
226
|
+
kind: "pk",
|
|
227
|
+
column: cat.primaryKey,
|
|
228
|
+
sql: `SELECT ${pk} AS row_pk, COUNT(*) AS n FROM ${t} ` +
|
|
229
|
+
`WHERE ${pk} IS NOT NULL AND ${pk} <> '' ` +
|
|
230
|
+
`GROUP BY ${pk} ${having} ORDER BY row_pk;`,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=ddl-generator.js.map
|
|
Binary file
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine-path FK/PK/enum validation — M-ADR 0205 §4.4 (Phase A2).
|
|
3
|
+
*
|
|
4
|
+
* Runs the ddl-generator's queries on the embedded engine and returns
|
|
5
|
+
* results in the SAME shapes as fk-validator.ts / enum-validator.ts, so
|
|
6
|
+
* the parity harness can compare count AND list, field for field. The
|
|
7
|
+
* input is the same rowsByCatalogue map the in-memory validators take:
|
|
8
|
+
* A2 compares the two VALIDATION implementations on identical parsed
|
|
9
|
+
* input — CSV-read equivalence is deliberately out of this comparison's
|
|
10
|
+
* scope and belongs to the cutover evaluation.
|
|
11
|
+
*
|
|
12
|
+
* The engine package is a devDependency until cutover (M-ADR 0205 §4.1's
|
|
13
|
+
* no-fallback rule governs how it eventually ships). It is imported
|
|
14
|
+
* dynamically inside the entry function so merely loading this module
|
|
15
|
+
* never requires it: no production path imports the engine today, and an
|
|
16
|
+
* adopter install without the package only fails if something actually
|
|
17
|
+
* calls it — loudly.
|
|
18
|
+
*
|
|
19
|
+
* PK-duplicate detection has NO in-memory counterpart at validate time
|
|
20
|
+
* (builders dedupe at emission instead), so pkDuplicates is engine-only
|
|
21
|
+
* information: reported, never part of the parity claim — you cannot
|
|
22
|
+
* claim agreement with an instrument that does not exist.
|
|
23
|
+
*/
|
|
24
|
+
import { generateConstraintQueries, generateExternalFindingQueries, generateTableDdl, sqlType, } from "./ddl-generator.js";
|
|
25
|
+
const INSERT_CHUNK = 500;
|
|
26
|
+
function sqlStringLiteral(value) {
|
|
27
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* One loaded engine: schema DDL applied, every provided catalogue's rows
|
|
31
|
+
* inserted. Shared by the FK/PK/enum path and the coverage predicates so
|
|
32
|
+
* there is exactly one load semantics to reason about.
|
|
33
|
+
*/
|
|
34
|
+
export async function createEngineSession(schema, rowsByCatalogue) {
|
|
35
|
+
const { DuckDBInstance } = await import("@duckdb/node-api");
|
|
36
|
+
const instance = await DuckDBInstance.create(":memory:");
|
|
37
|
+
const conn = await instance.connect();
|
|
38
|
+
for (const ddl of generateTableDdl(schema)) {
|
|
39
|
+
await conn.run(ddl);
|
|
40
|
+
}
|
|
41
|
+
await loadRows(conn, schema, rowsByCatalogue);
|
|
42
|
+
return { conn, dispose: () => conn.disconnectSync() };
|
|
43
|
+
}
|
|
44
|
+
// @rule engine-fk-validation
|
|
45
|
+
export async function validateWithEngine(schema, rowsByCatalogue, options = {}) {
|
|
46
|
+
const session = await createEngineSession(schema, rowsByCatalogue);
|
|
47
|
+
const conn = session.conn;
|
|
48
|
+
try {
|
|
49
|
+
const typeNonconformances = await findTypeNonconformances(conn, schema, rowsByCatalogue);
|
|
50
|
+
const failures = [];
|
|
51
|
+
const enumViolations = [];
|
|
52
|
+
const pkDuplicates = [];
|
|
53
|
+
for (const q of generateConstraintQueries(schema, options)) {
|
|
54
|
+
const reader = await conn.runAndReadAll(q.sql);
|
|
55
|
+
for (const row of reader.getRows()) {
|
|
56
|
+
if (q.kind === "fk") {
|
|
57
|
+
failures.push({
|
|
58
|
+
catalogue: q.catalogue,
|
|
59
|
+
column: q.column,
|
|
60
|
+
referencingRow: String(row[0] ?? ""),
|
|
61
|
+
value: String(row[1] ?? ""),
|
|
62
|
+
target: q.target,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else if (q.kind === "enum") {
|
|
66
|
+
const enumDef = schema.enums[q.target];
|
|
67
|
+
enumViolations.push({
|
|
68
|
+
catalogue: q.catalogue,
|
|
69
|
+
column: q.column,
|
|
70
|
+
rowPk: row[0] === null || row[0] === undefined ? "<no-pk>" : String(row[0]),
|
|
71
|
+
value: String(row[1] ?? ""),
|
|
72
|
+
allowed: enumDef.values.map((v) => v.value).join(" | "),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
pkDuplicates.push({
|
|
77
|
+
catalogue: q.catalogue,
|
|
78
|
+
rowPk: String(row[0] ?? ""),
|
|
79
|
+
count: Number(row[1]),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const externalFindingDetails = [];
|
|
85
|
+
for (const q of generateExternalFindingQueries(schema, options)) {
|
|
86
|
+
const reader = await conn.runAndReadAll(q.sql);
|
|
87
|
+
for (const row of reader.getRows()) {
|
|
88
|
+
externalFindingDetails.push({
|
|
89
|
+
catalogue: q.catalogue,
|
|
90
|
+
column: q.column,
|
|
91
|
+
target: q.target,
|
|
92
|
+
rowPk: row[0] === null || row[0] === undefined ? "?" : String(row[0]),
|
|
93
|
+
value: String(row[1] ?? ""),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
fk: {
|
|
99
|
+
internalPass: failures.length === 0,
|
|
100
|
+
internalFailures: failures,
|
|
101
|
+
externalFindings: externalFindingDetails.length,
|
|
102
|
+
},
|
|
103
|
+
enums: { pass: enumViolations.length === 0, violations: enumViolations },
|
|
104
|
+
externalFindingDetails,
|
|
105
|
+
pkDuplicates,
|
|
106
|
+
typeNonconformances,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
session.dispose();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The A4 cutover surface: runs the engine validation and writes findings
|
|
115
|
+
* into the caller's FindingsLog with BYTE-IDENTICAL text to what
|
|
116
|
+
* fk-validator.ts / enum-validator.ts wrote — adopters' committed
|
|
117
|
+
* findings baselines hold those literal lines, so the text is a
|
|
118
|
+
* compatibility contract, not a style choice. Line ORDER within a
|
|
119
|
+
* category follows the engine's total ORDER BY (M-ADR 0205 §4.2) and may
|
|
120
|
+
* differ from the old file-order rendering; baselines compare by
|
|
121
|
+
* membership, so ordering is free — declared in the change-set anyway.
|
|
122
|
+
*/
|
|
123
|
+
export async function validateWithEngineToLog(schema, rowsByCatalogue, findings, options = {}, extras = {}) {
|
|
124
|
+
const logEnumFindings = extras.logEnumFindings !== false;
|
|
125
|
+
const res = await validateWithEngine(schema, rowsByCatalogue, options);
|
|
126
|
+
for (const d of res.externalFindingDetails) {
|
|
127
|
+
findings.add("external", `${d.catalogue}.${d.column} → ${d.target}=${d.value} ` +
|
|
128
|
+
`(referencing row pk=${d.rowPk}; resolves at aggregation)`);
|
|
129
|
+
}
|
|
130
|
+
if (logEnumFindings) {
|
|
131
|
+
const enumNameByCatalogueColumn = new Map();
|
|
132
|
+
for (const cat of schema.catalogues) {
|
|
133
|
+
for (const [column, enumRef] of Object.entries(cat.columnEnums)) {
|
|
134
|
+
enumNameByCatalogueColumn.set(`${cat.name}.${column}`, enumRef.replace(/^enums\./, ""));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
for (const v of res.enums.violations) {
|
|
138
|
+
const enumName = enumNameByCatalogueColumn.get(`${v.catalogue}.${v.column}`);
|
|
139
|
+
findings.add("divergence", `${v.catalogue}.${v.column}: row ${v.rowPk} value "${v.value}" is outside the bound enum ${enumName} (${v.allowed})`, "error");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { fk: res.fk, enums: res.enums };
|
|
143
|
+
}
|
|
144
|
+
async function loadRows(conn, schema, rowsByCatalogue) {
|
|
145
|
+
for (const cat of schema.catalogues) {
|
|
146
|
+
const rows = rowsByCatalogue.get(cat.name) ?? [];
|
|
147
|
+
if (rows.length === 0)
|
|
148
|
+
continue;
|
|
149
|
+
for (let i = 0; i < rows.length; i += INSERT_CHUNK) {
|
|
150
|
+
const chunk = rows.slice(i, i + INSERT_CHUNK);
|
|
151
|
+
const tuples = chunk
|
|
152
|
+
.map((row) => `(${cat.columns
|
|
153
|
+
.map((c) => literal(row[c.name], cat.name, c.name, c.type))
|
|
154
|
+
.join(", ")})`)
|
|
155
|
+
.join(",\n");
|
|
156
|
+
await conn.run(`INSERT INTO "${cat.name}" VALUES\n${tuples};`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Renders one cell. String columns keep the empty string AS an empty
|
|
162
|
+
* string — the in-memory validators' emptiness predicates see '' from the
|
|
163
|
+
* CSV reader, and the generated queries test both NULL and ''. Non-string
|
|
164
|
+
* columns TRY_CAST with '' becoming NULL: one uncastable cell must not
|
|
165
|
+
* abort a whole run (measured on a real estate: a prose value in a
|
|
166
|
+
* date-typed column), and the miss is not smoothed either —
|
|
167
|
+
* findTypeNonconformances re-derives every such cell with the engine's
|
|
168
|
+
* own cast semantics and reports it.
|
|
169
|
+
*/
|
|
170
|
+
function literal(value, catalogue, column, type) {
|
|
171
|
+
const s = value === null || value === undefined ? "" : String(value);
|
|
172
|
+
if (type === "string")
|
|
173
|
+
return sqlStringLiteral(s);
|
|
174
|
+
if (s === "")
|
|
175
|
+
return "NULL";
|
|
176
|
+
return `TRY_CAST(${sqlStringLiteral(s)} AS ${sqlType(catalogue, column, type)})`;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Exact engine-semantics detection of the cells TRY_CAST nulled: the
|
|
180
|
+
* distinct non-empty values of every typed column are re-checked with the
|
|
181
|
+
* SAME cast the load used — a JS re-implementation of the engine's parsers
|
|
182
|
+
* would be a second opinion pretending to be the first.
|
|
183
|
+
*/
|
|
184
|
+
async function findTypeNonconformances(conn, schema, rowsByCatalogue) {
|
|
185
|
+
const out = [];
|
|
186
|
+
for (const cat of schema.catalogues) {
|
|
187
|
+
const rows = rowsByCatalogue.get(cat.name) ?? [];
|
|
188
|
+
if (rows.length === 0)
|
|
189
|
+
continue;
|
|
190
|
+
for (const col of cat.columns) {
|
|
191
|
+
if (col.type === "string")
|
|
192
|
+
continue;
|
|
193
|
+
const counts = new Map();
|
|
194
|
+
for (const row of rows) {
|
|
195
|
+
const v = row[col.name];
|
|
196
|
+
const s = v === null || v === undefined ? "" : String(v);
|
|
197
|
+
if (s === "")
|
|
198
|
+
continue;
|
|
199
|
+
counts.set(s, (counts.get(s) ?? 0) + 1);
|
|
200
|
+
}
|
|
201
|
+
if (counts.size === 0)
|
|
202
|
+
continue;
|
|
203
|
+
const engineType = sqlType(cat.name, col.name, col.type);
|
|
204
|
+
const values = [...counts.keys()].sort();
|
|
205
|
+
const tuples = values.map((v) => `(${sqlStringLiteral(v)})`).join(", ");
|
|
206
|
+
const reader = await conn.runAndReadAll(`SELECT v FROM (VALUES ${tuples}) t(v) ` +
|
|
207
|
+
`WHERE TRY_CAST(v AS ${engineType}) IS NULL ORDER BY v;`);
|
|
208
|
+
for (const row of reader.getRows()) {
|
|
209
|
+
const value = String(row[0]);
|
|
210
|
+
out.push({
|
|
211
|
+
catalogue: cat.name,
|
|
212
|
+
column: col.name,
|
|
213
|
+
declaredType: col.type,
|
|
214
|
+
value,
|
|
215
|
+
rows: counts.get(value) ?? 0,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* The population a PASS was measured over, for the verdict line. An FK or enum
|
|
224
|
+
* PASS over zero rows is true of nothing (empty-set sweep, R2): the count makes
|
|
225
|
+
* the zero visible. The `PASS` token itself is kept for anything that greps it.
|
|
226
|
+
*/
|
|
227
|
+
export function validatedPopulation(rowsByCatalogue) {
|
|
228
|
+
let rows = 0;
|
|
229
|
+
let nonEmpty = 0;
|
|
230
|
+
for (const r of rowsByCatalogue.values()) {
|
|
231
|
+
rows += r.length;
|
|
232
|
+
if (r.length > 0)
|
|
233
|
+
nonEmpty += 1;
|
|
234
|
+
}
|
|
235
|
+
return rows === 0
|
|
236
|
+
? "0 rows — nothing was validated"
|
|
237
|
+
: `${rows} row(s) across ${nonEmpty} non-empty catalogue(s)`;
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=engine-validator.js.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// External-system row identity (schema 3.0.0) and the legacy-id migration
|
|
2
|
+
// map — M-ADR 0203 §4.2, completing M-ADR 0189 §4.2.
|
|
3
|
+
//
|
|
4
|
+
// From 3.0.0 a `c4_external_systems` row id derives from the DECLARED
|
|
5
|
+
// diagram entry id (`System_Ext(<entry-id>, …)`), not from a slug of the
|
|
6
|
+
// display name. The declared id is the identity the aggregator resolves
|
|
7
|
+
// (M-ADR 0189 §4.2); keying the row on anything else meant the row's own
|
|
8
|
+
// PK was label-keyed evidence — the exact identity class 0189 measured
|
|
9
|
+
// false-positiving at 14 of 15.
|
|
10
|
+
//
|
|
11
|
+
// The 2.x name-slug ids remain derivable from data every 2.30.0+ catalogue
|
|
12
|
+
// carries (`name`), so the old→new map is a build artefact, not an authored
|
|
13
|
+
// migration: `sdd-cli catalogue migration-map` emits it, and the exemption
|
|
14
|
+
// loader consults it during the cut window (an authored exemption keyed by
|
|
15
|
+
// a mapped old id is regenerable, NOT drift — the F30 rule at schema scale).
|
|
16
|
+
/**
|
|
17
|
+
* Normalise a declared diagram entry id to slug form. Camel humps split
|
|
18
|
+
* BEFORE lowercasing (the F11a rule, matching the aggregator's resolver):
|
|
19
|
+
* most SDD ids are hyphenated, and `bvfmGatewayFramework` must derive the
|
|
20
|
+
* same identity the adjudicator resolves for it (`bvfm-gateway-framework`).
|
|
21
|
+
*/
|
|
22
|
+
export function normaliseEntryId(entryId) {
|
|
23
|
+
return entryId
|
|
24
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
25
|
+
.toLowerCase()
|
|
26
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
27
|
+
.replace(/^-+|-+$/g, "");
|
|
28
|
+
}
|
|
29
|
+
/** The 3.0.0 row id for a declared diagram entry id, or "" when the entry id normalises to nothing. */
|
|
30
|
+
export function extIdFromEntryId(entryId) {
|
|
31
|
+
const slug = normaliseEntryId(entryId);
|
|
32
|
+
return slug === "" ? "" : `ext-${slug}`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The 2.x row id for a display name — the pre-3.0.0 derivation, kept
|
|
36
|
+
* VERBATIM (including the parenthetical strip) so the migration map
|
|
37
|
+
* reproduces exactly the ids the old builder minted.
|
|
38
|
+
*/
|
|
39
|
+
export function legacyExtIdFromName(name) {
|
|
40
|
+
const slug = name
|
|
41
|
+
.toLowerCase()
|
|
42
|
+
.replace(/\s*\([^)]+\)/g, "")
|
|
43
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
44
|
+
.replace(/^-+|-+$/g, "");
|
|
45
|
+
return slug === "" ? "" : `ext-${slug}`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* legacy (2.x, name-derived) id → the 3.0.0 ids it maps to, from built
|
|
49
|
+
* rows. Usually one; MORE than one means two distinct declared identities
|
|
50
|
+
* shared a display-name slug and were wrongly merged as one row under 2.x
|
|
51
|
+
* — the map surfaces the split rather than guessing (the consumer decides,
|
|
52
|
+
* loudly).
|
|
53
|
+
*/
|
|
54
|
+
export function buildLegacyExtIdMap(rows) {
|
|
55
|
+
const map = new Map();
|
|
56
|
+
for (const row of rows) {
|
|
57
|
+
const legacy = legacyExtIdFromName(String(row["name"] ?? ""));
|
|
58
|
+
if (legacy === "")
|
|
59
|
+
continue;
|
|
60
|
+
const current = String(row["id"] ?? "");
|
|
61
|
+
if (current === "" || legacy === current)
|
|
62
|
+
continue;
|
|
63
|
+
const ids = map.get(legacy);
|
|
64
|
+
if (ids) {
|
|
65
|
+
if (!ids.includes(current))
|
|
66
|
+
ids.push(current);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
map.set(legacy, [current]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const ids of map.values())
|
|
73
|
+
ids.sort((a, b) => a.localeCompare(b));
|
|
74
|
+
return map;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=ext-id.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loader for the optional `.sdd/feature-grounding-aliases.yaml` config
|
|
3
|
+
* per ADR 0143 (schema 2.5.0).
|
|
4
|
+
*
|
|
5
|
+
* Adopters use this map to translate display names in
|
|
6
|
+
* `feature-grounding.md` tables (class names, file basenames, route
|
|
7
|
+
* fragments) into canonical service / repo ids that resolve against
|
|
8
|
+
* `services.csv` and `repositories.csv`. Follows the same shape
|
|
9
|
+
* convention as the existing capability_service alias map.
|
|
10
|
+
*
|
|
11
|
+
* File shape:
|
|
12
|
+
*
|
|
13
|
+
* service_aliases:
|
|
14
|
+
* AuthHandler: example-service-api
|
|
15
|
+
* web-ui: example-web-ui
|
|
16
|
+
* repo_aliases:
|
|
17
|
+
* camera-bff: global-camera-bff
|
|
18
|
+
*
|
|
19
|
+
* Either block is optional. Empty / missing file = no aliases (every
|
|
20
|
+
* reference must resolve directly against the canonical id).
|
|
21
|
+
*/
|
|
22
|
+
import { readFile } from "node:fs/promises";
|
|
23
|
+
import { join } from "node:path";
|
|
24
|
+
import { parse as parseYaml } from "yaml";
|
|
25
|
+
const ALIASES_FILENAME = join(".sdd", "feature-grounding-aliases.yaml");
|
|
26
|
+
/**
|
|
27
|
+
* Load the optional alias map. Returns `null` when the file is absent
|
|
28
|
+
* — callers treat that as "no aliases, all references must resolve
|
|
29
|
+
* directly against the canonical id." Throws on malformed YAML.
|
|
30
|
+
*/
|
|
31
|
+
export async function loadFeatureGroundingAliases(sddPath) {
|
|
32
|
+
const full = join(sddPath, ALIASES_FILENAME);
|
|
33
|
+
let text;
|
|
34
|
+
try {
|
|
35
|
+
text = await readFile(full, "utf-8");
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
const code = err.code;
|
|
39
|
+
if (code === "ENOENT")
|
|
40
|
+
return null;
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
const raw = parseYaml(text);
|
|
44
|
+
if (raw === null || typeof raw !== "object") {
|
|
45
|
+
throw new Error(`${ALIASES_FILENAME}: expected a mapping at the document root`);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
serviceAliases: toStringMap(raw.service_aliases),
|
|
49
|
+
repoAliases: toStringMap(raw.repo_aliases),
|
|
50
|
+
relPath: ALIASES_FILENAME,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function toStringMap(raw) {
|
|
54
|
+
const out = new Map();
|
|
55
|
+
if (raw === null || raw === undefined)
|
|
56
|
+
return out;
|
|
57
|
+
if (typeof raw !== "object" || Array.isArray(raw))
|
|
58
|
+
return out;
|
|
59
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
60
|
+
if (typeof v === "string" && v !== "")
|
|
61
|
+
out.set(k, v);
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=feature-grounding-aliases-loader.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* feature_repo zero-resolution SUMMARY line (M-ADR 0143 §4.4), split against
|
|
3
|
+
* the final feature_repo table.
|
|
4
|
+
*
|
|
5
|
+
* A builder (feature-grounding: Evidence cell; capability-spec:
|
|
6
|
+
* Implementation cell) fires one per-row finding for every feature row whose
|
|
7
|
+
* cell is non-empty but resolves to zero repos. That measures the CELL. The
|
|
8
|
+
* feature may still be anchored by another surface — feature-tree
|
|
9
|
+
* `## Feature Services`, feature-spec, or the feature_service ⋈
|
|
10
|
+
* service_repo derivation — and only the build, holding the final
|
|
11
|
+
* feature_repo, can say so. The summary therefore states both numbers:
|
|
12
|
+
* how many rows fired, and how many of those fired on features that no
|
|
13
|
+
* surface anchors.
|
|
14
|
+
*
|
|
15
|
+
* Returns null when nothing fired: an absent line is the designed shape
|
|
16
|
+
* for zero (the per-row lines are absent too), and this keeps the finding
|
|
17
|
+
* surface identical to pre-1.20.2 in that case.
|
|
18
|
+
*/
|
|
19
|
+
export function zeroResolutionSummary(cellLabel, evidenceRows, firedFeatureIds, anchoredFeatures) {
|
|
20
|
+
if (firedFeatureIds.length === 0)
|
|
21
|
+
return null;
|
|
22
|
+
const distinctFired = new Set(firedFeatureIds);
|
|
23
|
+
const unanchoredFeatures = new Set([...distinctFired].filter((fid) => !anchoredFeatures.has(fid)));
|
|
24
|
+
const unanchoredRows = firedFeatureIds.filter((fid) => unanchoredFeatures.has(fid)).length;
|
|
25
|
+
const anchoredElsewhere = distinctFired.size - unanchoredFeatures.size;
|
|
26
|
+
return (`feature_repo: ${firedFeatureIds.length} of ${evidenceRows} feature rows with a non-empty ${cellLabel} cell resolved to zero repos, ` +
|
|
27
|
+
`of which ${unanchoredRows} on ${unanchoredFeatures.size} feature(s) with no anchor from ANY surface in the final feature_repo ` +
|
|
28
|
+
`(${anchoredElsewhere} of the ${distinctFired.size} named features are anchored by another surface — those rows are cell quality, not coverage) ` +
|
|
29
|
+
`(member tier; evidence→repo resolution coverage only — a resolved row is not thereby correct; M-ADR 0143 §4.4)`);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=feature-repo-zero-resolution-summary.js.map
|