@beehexa/hexasync-template-validate 2608.7.4
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/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/validate/buildValidationModel.d.ts +31 -0
- package/dist/validate/buildValidationModel.d.ts.map +1 -0
- package/dist/validate/buildValidationModel.js +68 -0
- package/dist/validate/buildValidationModel.js.map +1 -0
- package/dist/validate/context.d.ts +97 -0
- package/dist/validate/context.d.ts.map +1 -0
- package/dist/validate/context.js +90 -0
- package/dist/validate/context.js.map +1 -0
- package/dist/validate/contextFromGraph.d.ts +60 -0
- package/dist/validate/contextFromGraph.d.ts.map +1 -0
- package/dist/validate/contextFromGraph.js +77 -0
- package/dist/validate/contextFromGraph.js.map +1 -0
- package/dist/validate/harvestPullerTaskIds.d.ts +60 -0
- package/dist/validate/harvestPullerTaskIds.d.ts.map +1 -0
- package/dist/validate/harvestPullerTaskIds.js +115 -0
- package/dist/validate/harvestPullerTaskIds.js.map +1 -0
- package/dist/validate/model.d.ts +14 -0
- package/dist/validate/model.d.ts.map +1 -0
- package/dist/validate/model.js +92 -0
- package/dist/validate/model.js.map +1 -0
- package/dist/validate/registry.d.ts +20 -0
- package/dist/validate/registry.d.ts.map +1 -0
- package/dist/validate/registry.js +58 -0
- package/dist/validate/registry.js.map +1 -0
- package/dist/validate/rule.d.ts +18 -0
- package/dist/validate/rule.d.ts.map +1 -0
- package/dist/validate/rule.js +2 -0
- package/dist/validate/rule.js.map +1 -0
- package/dist/validate/ruleCatalog.d.ts +22 -0
- package/dist/validate/ruleCatalog.d.ts.map +1 -0
- package/dist/validate/ruleCatalog.js +263 -0
- package/dist/validate/ruleCatalog.js.map +1 -0
- package/dist/validate/rules/dependencyIntegrity.d.ts +60 -0
- package/dist/validate/rules/dependencyIntegrity.d.ts.map +1 -0
- package/dist/validate/rules/dependencyIntegrity.js +296 -0
- package/dist/validate/rules/dependencyIntegrity.js.map +1 -0
- package/dist/validate/rules/duplicates.d.ts +23 -0
- package/dist/validate/rules/duplicates.d.ts.map +1 -0
- package/dist/validate/rules/duplicates.js +321 -0
- package/dist/validate/rules/duplicates.js.map +1 -0
- package/dist/validate/rules/flow.d.ts +41 -0
- package/dist/validate/rules/flow.d.ts.map +1 -0
- package/dist/validate/rules/flow.js +559 -0
- package/dist/validate/rules/flow.js.map +1 -0
- package/dist/validate/rules/overwriteLoss.d.ts +23 -0
- package/dist/validate/rules/overwriteLoss.d.ts.map +1 -0
- package/dist/validate/rules/overwriteLoss.js +40 -0
- package/dist/validate/rules/overwriteLoss.js.map +1 -0
- package/dist/validate/rules/pullerKind.d.ts +3 -0
- package/dist/validate/rules/pullerKind.d.ts.map +1 -0
- package/dist/validate/rules/pullerKind.js +83 -0
- package/dist/validate/rules/pullerKind.js.map +1 -0
- package/dist/validate/rules/reference.d.ts +44 -0
- package/dist/validate/rules/reference.d.ts.map +1 -0
- package/dist/validate/rules/reference.js +370 -0
- package/dist/validate/rules/reference.js.map +1 -0
- package/dist/validate/rules/referenceKind.d.ts +25 -0
- package/dist/validate/rules/referenceKind.d.ts.map +1 -0
- package/dist/validate/rules/referenceKind.js +230 -0
- package/dist/validate/rules/referenceKind.js.map +1 -0
- package/dist/validate/rules/retiredType.d.ts +142 -0
- package/dist/validate/rules/retiredType.d.ts.map +1 -0
- package/dist/validate/rules/retiredType.js +228 -0
- package/dist/validate/rules/retiredType.js.map +1 -0
- package/dist/validate/rules/tables.d.ts +8 -0
- package/dist/validate/rules/tables.d.ts.map +1 -0
- package/dist/validate/rules/tables.js +116 -0
- package/dist/validate/rules/tables.js.map +1 -0
- package/dist/validate/rules/variableDrift.d.ts +63 -0
- package/dist/validate/rules/variableDrift.d.ts.map +1 -0
- package/dist/validate/rules/variableDrift.js +132 -0
- package/dist/validate/rules/variableDrift.js.map +1 -0
- package/dist/validate/rules/variables.d.ts +12 -0
- package/dist/validate/rules/variables.d.ts.map +1 -0
- package/dist/validate/rules/variables.js +207 -0
- package/dist/validate/rules/variables.js.map +1 -0
- package/dist/validate/sourceLocator.d.ts +32 -0
- package/dist/validate/sourceLocator.d.ts.map +1 -0
- package/dist/validate/sourceLocator.js +166 -0
- package/dist/validate/sourceLocator.js.map +1 -0
- package/package.json +32 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
export const RULE_CATALOG = {
|
|
2
|
+
// REF — reference integrity (profile-local edges only).
|
|
3
|
+
'REF-1': {
|
|
4
|
+
title: 'Association puller does not exist',
|
|
5
|
+
what: 'An objectAssociation names a `puller.id` that is not defined in `pullers[]`. Not flagged when the task is fed by a DIRECT_INDEX / data-insertion step in another puller or pusher — such a task is populated without a puller of its own.',
|
|
6
|
+
consequence: 'The object is never pulled — its inbound sync silently does nothing.',
|
|
7
|
+
},
|
|
8
|
+
'REF-2': {
|
|
9
|
+
title: 'Association pusher does not exist',
|
|
10
|
+
what: 'An objectAssociation names a `pusher.id` that is not defined in `pushers[]`.',
|
|
11
|
+
consequence: 'The object is never pushed — its outbound sync silently does nothing.',
|
|
12
|
+
},
|
|
13
|
+
'REF-3': {
|
|
14
|
+
title: 'Association table does not exist',
|
|
15
|
+
what: 'An objectAssociation names a `table.id` that is not defined in `tables[]`.',
|
|
16
|
+
consequence: 'The object has no backing table to read from or write to.',
|
|
17
|
+
},
|
|
18
|
+
'REF-5': {
|
|
19
|
+
title: 'Transformations/validations keyed to a missing object',
|
|
20
|
+
what: 'A `transformations`/`validations` map is keyed by an object id that is not in `objects[]`.',
|
|
21
|
+
consequence: 'Those transformations/validations are silently never applied.',
|
|
22
|
+
},
|
|
23
|
+
'REF-6': {
|
|
24
|
+
title: 'Dependency points at a missing object',
|
|
25
|
+
what: 'A `dependencies[]` entry `objectId`/`dependedOn` references an object not in `objects[]`.',
|
|
26
|
+
consequence: 'The dependency edge is silently ignored, so ordering is not enforced.',
|
|
27
|
+
},
|
|
28
|
+
'REF-7': {
|
|
29
|
+
title: 'Metric references a missing group',
|
|
30
|
+
what: 'A metric `groups[]` entry names a metric-group key defined neither at top level nor under any object.',
|
|
31
|
+
consequence: 'The metric is ungrouped and will not display under its intended group.',
|
|
32
|
+
},
|
|
33
|
+
'REF-9': {
|
|
34
|
+
title: 'Webhook target points at a missing object',
|
|
35
|
+
what: 'A webhook `targets[].objectIds` entry references an object not in `objects[]`.',
|
|
36
|
+
consequence: 'The webhook target is silently dead — inbound events go nowhere.',
|
|
37
|
+
},
|
|
38
|
+
'REF-13': {
|
|
39
|
+
title: 'Step references a missing object',
|
|
40
|
+
what: 'A step (`data.objectId(s)` / `arguments.object_id`) references an object not in `objects[]`.',
|
|
41
|
+
consequence: 'The step no-ops or errors at runtime.',
|
|
42
|
+
},
|
|
43
|
+
'REF-15': {
|
|
44
|
+
title: 'Startup task targets a missing object',
|
|
45
|
+
what: 'A `startupTasks[]` scheduler `entityId`/`targetId` (when object-typed) references an object not in `objects[]`.',
|
|
46
|
+
consequence: 'The scheduled task targets nothing and never runs meaningfully.',
|
|
47
|
+
},
|
|
48
|
+
'REF-16': {
|
|
49
|
+
title: 'New-kind puller step targets a missing task',
|
|
50
|
+
what: 'A new-kind puller `SAVE_TASK_DATA` / `UPDATE_TASK_DATA_STATUS` step names a static `data.taskId` that is neither an object id nor a declared objectAssociation task.',
|
|
51
|
+
consequence: 'The puller writes into a task that does not exist — the data is silently dropped.',
|
|
52
|
+
},
|
|
53
|
+
'REF-K1': {
|
|
54
|
+
title: 'Reference points at nothing',
|
|
55
|
+
what: 'A property the reference registry recognises — `pullerId`, `tableId`, `connectionId`, a discriminated `entityId`/`targetId`, and the rest — names an id that the project does not declare in the collection that property points into.',
|
|
56
|
+
consequence: 'The reference resolves to nothing at runtime: the step, association or schedule silently does nothing.',
|
|
57
|
+
},
|
|
58
|
+
'REF-K2': {
|
|
59
|
+
title: 'Reference points at the wrong KIND of thing',
|
|
60
|
+
what: 'The named id exists, but in a different collection from the one the property points into — a `pullerId` naming a pusher, for example. The target collection comes from the reference registry, which discriminates `entityId`/`targetId` on their sibling `entityType`/`targetType`.',
|
|
61
|
+
consequence: 'The worker looks the id up in the collection the property implies and finds nothing, so the reference is dead even though the id exists somewhere.',
|
|
62
|
+
},
|
|
63
|
+
// DUP — duplicate ids/keys.
|
|
64
|
+
'DUP-1': {
|
|
65
|
+
title: 'Two component identities resolve to one id',
|
|
66
|
+
what: 'Two different keys in the same collection — typically two `**Variable**` names bound to the same value — produce the same id once variables are substituted.',
|
|
67
|
+
consequence: 'Both entries reach `output.yaml` under one id. When their content matches, the duplicate is merely redundant; when it differs, HexaSync keeps one and the other declaration is silently discarded.',
|
|
68
|
+
},
|
|
69
|
+
'DUP-3': {
|
|
70
|
+
title: 'Duplicate step key in a workflow',
|
|
71
|
+
what: 'Two steps in the same workflow (pullSteps/pushSteps/…) share the same `key`.',
|
|
72
|
+
consequence: 'Step routing (`next`) is nondeterministic — the wrong step may run.',
|
|
73
|
+
},
|
|
74
|
+
'DUP-4': {
|
|
75
|
+
title: 'Duplicate nested id',
|
|
76
|
+
what: 'Two nested items (metric / transformation / validation) share the same id within their group.',
|
|
77
|
+
consequence: 'One silently shadows the other; the intended item may never execute.',
|
|
78
|
+
},
|
|
79
|
+
'DUP-5': {
|
|
80
|
+
title: 'Step key reused across step-lists',
|
|
81
|
+
what: "The same step `key` appears in more than one of a puller's or pusher's step-lists combined (beforePullSteps/pullSteps/afterPullSteps/finalSteps/steps/onErrorSteps). NOT applied across a webhook's targets: a target is its own execution scope, so the same key in two targets is legitimate.",
|
|
82
|
+
consequence: 'The workflow engine keys `_outputs` and resolves `next` by a GLOBAL step key within the entity — a cross-list collision makes output reads and routing ambiguous.',
|
|
83
|
+
},
|
|
84
|
+
// DEP — the shape of the dependency graph.
|
|
85
|
+
'DEP-1': {
|
|
86
|
+
title: 'Circular dependency between tasks',
|
|
87
|
+
what: 'Tasks depend on each other in a loop via `dependencies[].objectId`/`dependedOn`. A task depending on ITSELF is excluded — that is an ordinary self-join for a parent/child hierarchy.',
|
|
88
|
+
consequence: 'There is no order in which every task in the chain can be satisfied: each waits on the next and the last waits back on the first.',
|
|
89
|
+
},
|
|
90
|
+
// COL — column references.
|
|
91
|
+
'COL-1': {
|
|
92
|
+
title: 'Dependency join key is not a declared column',
|
|
93
|
+
what: "A `dependencies[].data.keys` entry names a column that the task's backing table does not declare. Worker-managed `__`-prefixed names are not checked, and a task whose association or table cannot be resolved is left to REF-3/REF-5.",
|
|
94
|
+
consequence: 'The join matches nothing, so the dependency never resolves and the depending task is held back with no error to read.',
|
|
95
|
+
},
|
|
96
|
+
// OVW — inherited components dropped by a wholesale overwrite.
|
|
97
|
+
'OVW-1': {
|
|
98
|
+
title: 'Wholesale array overwrite dropped inherited components',
|
|
99
|
+
what: 'A file replaces an entire inherited component array because its own items declare no `id`, so the merge cannot match them element-by-element.',
|
|
100
|
+
consequence: 'Every inherited component that array held is absent from the composed output, with nothing left to point at — no `!` removal and no dangling reference. Give the override items their `id` to merge onto the inherited components instead.',
|
|
101
|
+
},
|
|
102
|
+
// DRIFT — a copied family that no longer matches its source.
|
|
103
|
+
'DRIFT-1': {
|
|
104
|
+
title: 'Copied variable family has partly drifted',
|
|
105
|
+
what: "A variable family copied from a component library matches the library for some of its ids and not others — e.g. `_Task_Id` and `_Table_Id` are still the library's while `_Puller_Id` was regenerated.",
|
|
106
|
+
consequence: "Part of the copy still points at the library's entities and part at this project's own. A family is normally all-shared (a second project using the same entities) or all-regenerated (an independent deployment); a mixture is a half-finished job.",
|
|
107
|
+
},
|
|
108
|
+
// PLK — puller kind (legacy vs new-kind).
|
|
109
|
+
'PLK-1': {
|
|
110
|
+
title: 'Legacy (old-kind) puller',
|
|
111
|
+
what: 'A puller uses the old-kind shape (pullSteps/responseFilters) rather than the new-kind `steps` workflow.',
|
|
112
|
+
consequence: 'Still supported, but misses the generic `_inputs`/`_outputs`/`__this` context, errors-as-data, and onErrorSteps/finalSteps — migrate per the Worker > Puller Workflow guide.',
|
|
113
|
+
},
|
|
114
|
+
'PLK-2': {
|
|
115
|
+
title: 'New-kind puller carries legacy fields',
|
|
116
|
+
what: 'A new-kind puller (has `steps`) also declares a legacy field (responseFilters/beforePullSteps/pullSteps/afterPullSteps).',
|
|
117
|
+
consequence: 'The two shapes are mutually exclusive; the legacy fields are ignored on the steps path and signal a half-migrated puller — remove them.',
|
|
118
|
+
},
|
|
119
|
+
// TBL — table & column integrity.
|
|
120
|
+
'TBL-1': {
|
|
121
|
+
title: 'Table has no SOURCE_ID column',
|
|
122
|
+
what: 'A synced object’s backing table has no column in the `SOURCE_ID` index group.',
|
|
123
|
+
consequence: 'The worker cannot identify source rows — upserts fail or duplicate.',
|
|
124
|
+
},
|
|
125
|
+
'TBL-2': {
|
|
126
|
+
title: 'Table has more than one SOURCE_ID column',
|
|
127
|
+
what: 'A synced object’s backing table declares multiple `SOURCE_ID` columns.',
|
|
128
|
+
consequence: 'The source-row identity is ambiguous — reconciliation is undefined.',
|
|
129
|
+
},
|
|
130
|
+
'TBL-3': {
|
|
131
|
+
title: 'Table has no KEYS column',
|
|
132
|
+
what: 'A synced object’s backing table has no column in the `KEYS` index group.',
|
|
133
|
+
consequence: 'The table has no primary key for change tracking / dedup.',
|
|
134
|
+
},
|
|
135
|
+
'TBL-4': {
|
|
136
|
+
title: 'SOURCE_ID column is not also a KEYS column',
|
|
137
|
+
what: 'The single `SOURCE_ID` column is not also part of the `KEYS` group.',
|
|
138
|
+
consequence: 'Source identity is not part of the key — rows can collide or duplicate.',
|
|
139
|
+
},
|
|
140
|
+
'TBL-5': {
|
|
141
|
+
title: 'Column uses an undeclared index group',
|
|
142
|
+
what: 'A column lists an `indexGroups` value that is neither reserved nor declared in the table’s `indexGroups`.',
|
|
143
|
+
consequence: 'The worker throws `KeyNotFoundException` building the table context.',
|
|
144
|
+
},
|
|
145
|
+
'TBL-6': {
|
|
146
|
+
title: 'Declared index group is unused',
|
|
147
|
+
what: 'A table declares an index group that no column references.',
|
|
148
|
+
consequence: 'Dead configuration — usually a typo or a leftover after refactoring.',
|
|
149
|
+
},
|
|
150
|
+
'TBL-7': {
|
|
151
|
+
title: 'Column name is not a safe SQL identifier',
|
|
152
|
+
what: 'A column name does not match `^[a-z0-9_]{1,63}$` (lowercase / digits / underscore).',
|
|
153
|
+
consequence: 'Produces an invalid or case-folded SQL identifier — the column breaks at DDL time.',
|
|
154
|
+
},
|
|
155
|
+
// VAR — variable hygiene.
|
|
156
|
+
'VAR-1': {
|
|
157
|
+
title: 'Unresolved token in the output',
|
|
158
|
+
what: 'A `**token**` survived into the composed output (a value or field) because a variable was missing or misspelled.',
|
|
159
|
+
consequence: 'The value is never substituted; an unresolved token in an id can stop the profile loading.',
|
|
160
|
+
},
|
|
161
|
+
'VAR-2': {
|
|
162
|
+
title: 'Malformed variable key',
|
|
163
|
+
what: 'A declared variable key does not match the `**Name**` pattern (double-star-wrapped identifier).',
|
|
164
|
+
consequence: 'The key is never substituted anywhere — the variable is effectively dead.',
|
|
165
|
+
},
|
|
166
|
+
'VAR-4': {
|
|
167
|
+
title: 'Variables in this file are never substituted',
|
|
168
|
+
what: 'A `variables.yaml` was found by the component glob rather than declared, so its keys never reach the substitution pool.',
|
|
169
|
+
consequence: "Every token that file was meant to define ships to core.api as a literal `**Token**`, behind a green compose. Declare the file as a `type: local` external, or move its keys into the project's root `variables.yaml`.",
|
|
170
|
+
},
|
|
171
|
+
'VAR-3': {
|
|
172
|
+
title: 'Declared variable never referenced',
|
|
173
|
+
what: 'A well-formed variable is declared but referenced nowhere in the profile.',
|
|
174
|
+
consequence: 'Dead declaration — harmless, but usually a leftover or a typo in the reference.',
|
|
175
|
+
},
|
|
176
|
+
// FLOW — workflow graph integrity.
|
|
177
|
+
'FLOW-3': {
|
|
178
|
+
title: 'Orphan (unreachable) step',
|
|
179
|
+
what: 'A step is never reached from the workflow entry via any `next` edge (and its routing is not dynamic).',
|
|
180
|
+
consequence: 'The step never executes — dead logic in the workflow.',
|
|
181
|
+
},
|
|
182
|
+
'FLOW-4': {
|
|
183
|
+
title: 'Dangling next edge',
|
|
184
|
+
what: 'A step’s `next` points at a step key that does not exist in the workflow.',
|
|
185
|
+
consequence: 'Execution falls off the end of the graph — the workflow stops early.',
|
|
186
|
+
},
|
|
187
|
+
'FLOW-5': {
|
|
188
|
+
title: 'Cycle in the workflow graph',
|
|
189
|
+
what: 'The `next` edges form a cycle, so the workflow can loop back on itself.',
|
|
190
|
+
consequence: 'The workflow can never terminate along that path.',
|
|
191
|
+
},
|
|
192
|
+
'FLOW-6': {
|
|
193
|
+
title: 'Empty SWITCH / incomplete branch',
|
|
194
|
+
what: 'A SWITCH step has no branches; an IF step routes nowhere at all; or a conditional ' +
|
|
195
|
+
'`next: { if, then, else }` is missing one of the three the schema requires. A `next`, `then` or ' +
|
|
196
|
+
'`else` that is a STRING is a step key and needs nothing further — only the object form is a branch.',
|
|
197
|
+
consequence: 'The branch step has nowhere to route — execution stalls or errors.',
|
|
198
|
+
},
|
|
199
|
+
'FLOW-7': {
|
|
200
|
+
title: 'New-kind puller: misplaced sweep / bad Exception reference',
|
|
201
|
+
what: 'A removal-recipe `UPDATE_TASK_DATA_STATUS` (statusToAdd includes Removed) sits in `finalSteps`, or an Exception step `fromStep` names no existing step.',
|
|
202
|
+
consequence: 'A partial run sweeps un-pulled pages as removed, or the exception handler never binds to its source step.',
|
|
203
|
+
},
|
|
204
|
+
// RET — component types the platform has retired (Story 1.10). Last, matching FAMILY_ORDER.
|
|
205
|
+
'RET-1': {
|
|
206
|
+
title: 'Retired component type',
|
|
207
|
+
what: 'The project declares a `schemas` or `reports` component. Both types are retired: a Task (an `objects[]` entry) with `type: REFERENCE` replaces Schema. Report has no documented successor yet.',
|
|
208
|
+
consequence: 'Still composes today, so this is a warning and the build succeeds — but the type will stop being supported. Migrate Schema components to `type: REFERENCE` Tasks; ask the platform team about Report.',
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Family order for the appendix; unknown families sort last, alphabetically.
|
|
213
|
+
*
|
|
214
|
+
* EVERY family is listed, which it was not before. The comparator gives an unlisted family index `99`, so
|
|
215
|
+
* appending `RET` to a five-entry list put it AHEAD of `PLK`, `DEP` and `OVW` — the opposite of the "RET last"
|
|
216
|
+
* intent — and left those three interleaved by rule NUMBER alone, which is why `PLK-1, DEP-1, OVW-1, PLK-2`
|
|
217
|
+
* came out in that order. Both were pre-existing for the unlisted families; adding `RET` is what made the
|
|
218
|
+
* docstring's promise visibly false. Found by the Story 1.10 review.
|
|
219
|
+
*
|
|
220
|
+
* `RET` is last deliberately: a deprecation notice is the least urgent thing in a report.
|
|
221
|
+
*
|
|
222
|
+
* Its own entry here is REDUNDANT, and kept on purpose. Now that every other family is named, `RET` would fall
|
|
223
|
+
* to index `99` and land last anyway — mutation-checked: deleting the `'RET'` line changes no test. What fixes
|
|
224
|
+
* the order is naming the OTHERS. It stays listed so the array reads as the complete, intentional order rather
|
|
225
|
+
* than a list that happens to omit one, and so retiring a twelfth family does not silently jump ahead of it.
|
|
226
|
+
*/
|
|
227
|
+
const FAMILY_ORDER = [
|
|
228
|
+
'REF',
|
|
229
|
+
'DUP',
|
|
230
|
+
'TBL',
|
|
231
|
+
'VAR',
|
|
232
|
+
'FLOW',
|
|
233
|
+
'DRIFT',
|
|
234
|
+
'COL',
|
|
235
|
+
'DEP',
|
|
236
|
+
'OVW',
|
|
237
|
+
'PLK',
|
|
238
|
+
'RET',
|
|
239
|
+
];
|
|
240
|
+
/** The catalog entries for the given rule ids, deduped and sorted by family then number.
|
|
241
|
+
* Rule ids with no catalog entry are skipped (never invents documentation). */
|
|
242
|
+
export function ruleDocsFor(ruleIds) {
|
|
243
|
+
const present = new Set();
|
|
244
|
+
for (const id of ruleIds)
|
|
245
|
+
if (RULE_CATALOG[id])
|
|
246
|
+
present.add(id);
|
|
247
|
+
return [...present]
|
|
248
|
+
.sort((a, b) => {
|
|
249
|
+
const [fa, na] = splitRuleId(a);
|
|
250
|
+
const [fb, nb] = splitRuleId(b);
|
|
251
|
+
const oa = FAMILY_ORDER.indexOf(fa);
|
|
252
|
+
const ob = FAMILY_ORDER.indexOf(fb);
|
|
253
|
+
if (oa !== ob)
|
|
254
|
+
return (oa < 0 ? 99 : oa) - (ob < 0 ? 99 : ob) || fa.localeCompare(fb);
|
|
255
|
+
return na - nb;
|
|
256
|
+
})
|
|
257
|
+
.map((ruleId) => ({ ruleId, doc: RULE_CATALOG[ruleId] }));
|
|
258
|
+
}
|
|
259
|
+
function splitRuleId(id) {
|
|
260
|
+
const m = /^([A-Za-z]+)-(\d+)$/.exec(id);
|
|
261
|
+
return m ? [m[1], Number(m[2])] : [id, 0];
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=ruleCatalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ruleCatalog.js","sourceRoot":"","sources":["../../src/validate/ruleCatalog.ts"],"names":[],"mappings":"AAeA,MAAM,CAAC,MAAM,YAAY,GAA4B;IACnD,wDAAwD;IACxD,OAAO,EAAE;QACP,KAAK,EAAE,mCAAmC;QAC1C,IAAI,EAAE,2OAA2O;QACjP,WAAW,EACT,sEAAsE;KACzE;IACD,OAAO,EAAE;QACP,KAAK,EAAE,mCAAmC;QAC1C,IAAI,EAAE,8EAA8E;QACpF,WAAW,EACT,uEAAuE;KAC1E;IACD,OAAO,EAAE;QACP,KAAK,EAAE,kCAAkC;QACzC,IAAI,EAAE,4EAA4E;QAClF,WAAW,EAAE,2DAA2D;KACzE;IACD,OAAO,EAAE;QACP,KAAK,EAAE,uDAAuD;QAC9D,IAAI,EAAE,4FAA4F;QAClG,WAAW,EACT,+DAA+D;KAClE;IACD,OAAO,EAAE;QACP,KAAK,EAAE,uCAAuC;QAC9C,IAAI,EAAE,2FAA2F;QACjG,WAAW,EACT,uEAAuE;KAC1E;IACD,OAAO,EAAE;QACP,KAAK,EAAE,mCAAmC;QAC1C,IAAI,EAAE,uGAAuG;QAC7G,WAAW,EACT,wEAAwE;KAC3E;IAC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AAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integrity of the `dependencies[]` graph (Phase 2 Story 1.9, FR-56).
|
|
3
|
+
*
|
|
4
|
+
* Two of the classes AC 1 names, and both live here because both read `dependencies[]`:
|
|
5
|
+
*
|
|
6
|
+
* - **DEP-1, a circular dependency.** `REF-6` already checks that each edge's endpoints exist; the
|
|
7
|
+
* SHAPE of the graph they form was never examined.
|
|
8
|
+
* - **COL-1, an invalid column reference.** `data.keys` maps a column on the depending task's table
|
|
9
|
+
* to one on the depended-on task's table. It is the corpus's only statically checkable column
|
|
10
|
+
* reference — everything else lives inside `filterSql`, and parsing SQL to find columns is a
|
|
11
|
+
* different project with a much worse failure mode.
|
|
12
|
+
*
|
|
13
|
+
* Both were measured before being written, and both measurements changed the design.
|
|
14
|
+
*/
|
|
15
|
+
import type { ValidationRule } from '../rule.js';
|
|
16
|
+
/**
|
|
17
|
+
* DEP-1 — a cycle in the dependency graph.
|
|
18
|
+
*
|
|
19
|
+
* **Self-dependencies are excluded, and that is the whole of the measurement.** 51 cycles exist in the
|
|
20
|
+
* corpus and 45 of them are `A -> A`: a task depending on itself is a SELF-JOIN, the ordinary way a
|
|
21
|
+
* parent/child hierarchy is resolved within one task — `LEFT JOIN variants root_v ON root_v.id =
|
|
22
|
+
* v.packsize_root_id`. Reporting those would make the rule wrong about 88% of what it found.
|
|
23
|
+
*
|
|
24
|
+
* What remains is 8 cycles across 7 projects, and they are real. `hapas` has *Sales Order Payments
|
|
25
|
+
* depends on Sales Orders* and *Sales Orders depends on Sales Order Payments*, both `nullable: false`
|
|
26
|
+
* with `constraints: [synced]` — a mutual readiness requirement where neither side can be satisfied
|
|
27
|
+
* first.
|
|
28
|
+
*
|
|
29
|
+
* The finding states the CYCLE and stops there. Whether the worker deadlocks, retries or breaks the
|
|
30
|
+
* tie is runtime behaviour this rule does not know, and asserting it would be the NFR-1 violation the
|
|
31
|
+
* two-surface architecture exists to prevent. `high` rather than `critical` for the same reason.
|
|
32
|
+
*
|
|
33
|
+
* Iterative rather than recursive: a corpus dependency graph is small, but the guard costs nothing and
|
|
34
|
+
* a stack overflow inside a rule is swallowed by `runValidation` — it would disable the rule
|
|
35
|
+
* SILENTLY, which is the worst way for this to fail.
|
|
36
|
+
*/
|
|
37
|
+
export declare const dependencyCycleRule: ValidationRule;
|
|
38
|
+
/**
|
|
39
|
+
* COL-1 — a dependency's `data.keys` names a column the table does not declare.
|
|
40
|
+
*
|
|
41
|
+
* `keys: { customer_id: id }` on a dependency from Sales Orders to Customers means "join my
|
|
42
|
+
* `customer_id` to their `id`". Both sides are column names on the respective tasks' tables, reachable
|
|
43
|
+
* through `objectAssociations[taskId].table.id` → `tables[].columns`.
|
|
44
|
+
*
|
|
45
|
+
* Two exclusions, both from measurement, and each one is the difference between a usable rule and an
|
|
46
|
+
* unusable one:
|
|
47
|
+
*
|
|
48
|
+
* - **`__`-prefixed names are never checked.** `__id`, `__source_id`, `__destination_id` are managed
|
|
49
|
+
* by the worker and are not declared in `columns`: of 119,575 authored column keys in the corpus,
|
|
50
|
+
* exactly 2 begin with `__`, against thousands of references to them. Without this exclusion 17 of
|
|
51
|
+
* 25 findings were these, all false.
|
|
52
|
+
* - **An unresolvable chain reports nothing.** When the task has no association, or the association's
|
|
53
|
+
* table does not exist, or the table declares no columns, this rule is silent — 18 of 208 key
|
|
54
|
+
* references are in that state, and every one of them is already `REF-3`/`REF-5`'s finding. Two
|
|
55
|
+
* rules reporting one defect makes the panel look twice as bad as the project is.
|
|
56
|
+
*
|
|
57
|
+
* What survives: 12 of 190 resolvable references, across 5 projects.
|
|
58
|
+
*/
|
|
59
|
+
export declare const dependencyColumnRule: ValidationRule;
|
|
60
|
+
//# sourceMappingURL=dependencyIntegrity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependencyIntegrity.d.ts","sourceRoot":"","sources":["../../../src/validate/rules/dependencyIntegrity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAsBjD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,mBAAmB,EAAE,cAkJjC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,oBAAoB,EAAE,cA6GlC,CAAC"}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { isDynamic, isRefEmpty, makeTokenResolver } from './reference.js';
|
|
2
|
+
function arr(cnf, key) {
|
|
3
|
+
const value = cnf?.[key];
|
|
4
|
+
return Array.isArray(value) ? value : [];
|
|
5
|
+
}
|
|
6
|
+
/** A usable, statically-known identifier, or undefined. */
|
|
7
|
+
function idish(raw, resolve) {
|
|
8
|
+
if (raw === null || raw === undefined || isRefEmpty(raw) || isDynamic(raw))
|
|
9
|
+
return undefined;
|
|
10
|
+
if (typeof raw !== 'string' && typeof raw !== 'number')
|
|
11
|
+
return undefined;
|
|
12
|
+
const resolved = resolve(String(raw));
|
|
13
|
+
return resolved === '' ? undefined : resolved;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* DEP-1 — a cycle in the dependency graph.
|
|
17
|
+
*
|
|
18
|
+
* **Self-dependencies are excluded, and that is the whole of the measurement.** 51 cycles exist in the
|
|
19
|
+
* corpus and 45 of them are `A -> A`: a task depending on itself is a SELF-JOIN, the ordinary way a
|
|
20
|
+
* parent/child hierarchy is resolved within one task — `LEFT JOIN variants root_v ON root_v.id =
|
|
21
|
+
* v.packsize_root_id`. Reporting those would make the rule wrong about 88% of what it found.
|
|
22
|
+
*
|
|
23
|
+
* What remains is 8 cycles across 7 projects, and they are real. `hapas` has *Sales Order Payments
|
|
24
|
+
* depends on Sales Orders* and *Sales Orders depends on Sales Order Payments*, both `nullable: false`
|
|
25
|
+
* with `constraints: [synced]` — a mutual readiness requirement where neither side can be satisfied
|
|
26
|
+
* first.
|
|
27
|
+
*
|
|
28
|
+
* The finding states the CYCLE and stops there. Whether the worker deadlocks, retries or breaks the
|
|
29
|
+
* tie is runtime behaviour this rule does not know, and asserting it would be the NFR-1 violation the
|
|
30
|
+
* two-surface architecture exists to prevent. `high` rather than `critical` for the same reason.
|
|
31
|
+
*
|
|
32
|
+
* Iterative rather than recursive: a corpus dependency graph is small, but the guard costs nothing and
|
|
33
|
+
* a stack overflow inside a rule is swallowed by `runValidation` — it would disable the rule
|
|
34
|
+
* SILENTLY, which is the worst way for this to fail.
|
|
35
|
+
*/
|
|
36
|
+
export const dependencyCycleRule = {
|
|
37
|
+
id: 'DEP',
|
|
38
|
+
family: 'DEP',
|
|
39
|
+
run(ctx) {
|
|
40
|
+
const cnf = ctx.tokenForm;
|
|
41
|
+
if (!cnf || typeof cnf !== 'object')
|
|
42
|
+
return [];
|
|
43
|
+
const resolve = makeTokenResolver(ctx.variables);
|
|
44
|
+
/** from -> to, deduped. Self-edges are never added: they are self-joins, not cycles. */
|
|
45
|
+
const edges = new Map();
|
|
46
|
+
/**
|
|
47
|
+
* `from→to` -> the id of the DEPENDENCY that declared it, and the file it lives in.
|
|
48
|
+
*
|
|
49
|
+
* Kept because a finding has to name something the graph can place. Reporting the cycle against a
|
|
50
|
+
* TASK id under `parentKey: 'dependencies'` cannot resolve — a task is not a dependency — so the
|
|
51
|
+
* lookup fell through to `main.yaml` and sent the developer to a file containing neither edge.
|
|
52
|
+
* Found by the Epic 1 review, by probing the panel rather than by reading the rule.
|
|
53
|
+
*/
|
|
54
|
+
const declaredBy = new Map();
|
|
55
|
+
/**
|
|
56
|
+
* resolved task id -> the TOKEN form first seen for it.
|
|
57
|
+
*
|
|
58
|
+
* Detection has to compare RESOLVED ids, because two token names can alias to one task. Display
|
|
59
|
+
* and attribution have to use the TOKEN form, because that is what the file contains and what the
|
|
60
|
+
* component→source-file map is keyed by. Keeping both is the only way to have each.
|
|
61
|
+
*/
|
|
62
|
+
const tokenFor = new Map();
|
|
63
|
+
for (const dependency of arr(cnf, 'dependencies')) {
|
|
64
|
+
const rawFrom = dependency?.objectId;
|
|
65
|
+
const rawTo = dependency?.dependedOn;
|
|
66
|
+
const from = idish(rawFrom, resolve);
|
|
67
|
+
const to = idish(rawTo, resolve);
|
|
68
|
+
if (!from || !to || from === to)
|
|
69
|
+
continue;
|
|
70
|
+
if (!tokenFor.has(from))
|
|
71
|
+
tokenFor.set(from, String(rawFrom));
|
|
72
|
+
if (!tokenFor.has(to))
|
|
73
|
+
tokenFor.set(to, String(rawTo));
|
|
74
|
+
const targets = edges.get(from) ?? new Set();
|
|
75
|
+
targets.add(to);
|
|
76
|
+
edges.set(from, targets);
|
|
77
|
+
const edgeKey = `${from}→${to}`;
|
|
78
|
+
// The dependency's own id in TOKEN form. Emitting the resolved GUID made attribution fail on
|
|
79
|
+
// every project that drives ids from variables — which is nearly all of them: the component→file
|
|
80
|
+
// map is keyed by the id as AUTHORED, so a resolved id never matched and the finding fell through
|
|
81
|
+
// to main.yaml. Found by the Epic 1 review, in the CLI report rather than in a test.
|
|
82
|
+
const declaredId = dependency?.id;
|
|
83
|
+
if (declaredId !== undefined &&
|
|
84
|
+
declaredId !== null &&
|
|
85
|
+
!isDynamic(declaredId) &&
|
|
86
|
+
!isRefEmpty(declaredId) &&
|
|
87
|
+
!declaredBy.has(edgeKey)) {
|
|
88
|
+
declaredBy.set(edgeKey, { id: String(declaredId) });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (edges.size === 0)
|
|
92
|
+
return [];
|
|
93
|
+
// Deterministic traversal order, so the same project always yields the same cycle in the same
|
|
94
|
+
// rotation. A finding that changes shape between runs looks like a new problem each time.
|
|
95
|
+
const roots = [...edges.keys()].sort();
|
|
96
|
+
// GREY = on the current path, BLACK = fully explored. Absent = not yet visited.
|
|
97
|
+
const GREY = 1;
|
|
98
|
+
const BLACK = 2;
|
|
99
|
+
const colour = new Map();
|
|
100
|
+
/** Cycles as a canonical key, so one cycle reached from two roots is reported once. */
|
|
101
|
+
const cycles = new Map();
|
|
102
|
+
for (const root of roots) {
|
|
103
|
+
if (colour.get(root) !== undefined)
|
|
104
|
+
continue;
|
|
105
|
+
// An explicit stack of (node, iterator over its targets), which is the iterative equivalent of
|
|
106
|
+
// colouring on entry and clearing on exit.
|
|
107
|
+
const stack = [
|
|
108
|
+
{ node: root, next: [...(edges.get(root) ?? [])].sort(), at: 0 },
|
|
109
|
+
];
|
|
110
|
+
colour.set(root, GREY);
|
|
111
|
+
const path = [root];
|
|
112
|
+
while (stack.length > 0) {
|
|
113
|
+
const top = stack[stack.length - 1];
|
|
114
|
+
if (top.at >= top.next.length) {
|
|
115
|
+
colour.set(top.node, BLACK);
|
|
116
|
+
stack.pop();
|
|
117
|
+
path.pop();
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const target = top.next[top.at];
|
|
121
|
+
top.at += 1;
|
|
122
|
+
if (colour.get(target) === GREY) {
|
|
123
|
+
// Back edge: the cycle is the path from `target` onwards.
|
|
124
|
+
const loop = path.slice(path.indexOf(target));
|
|
125
|
+
// Canonical: rotate so the smallest id leads, so the same cycle found from a different
|
|
126
|
+
// entry point produces the same key and is not reported twice.
|
|
127
|
+
const smallest = loop.indexOf([...loop].sort()[0]);
|
|
128
|
+
const rotated = [...loop.slice(smallest), ...loop.slice(0, smallest)];
|
|
129
|
+
cycles.set(rotated.join('→'), rotated);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (colour.get(target) === BLACK)
|
|
133
|
+
continue;
|
|
134
|
+
colour.set(target, GREY);
|
|
135
|
+
path.push(target);
|
|
136
|
+
stack.push({
|
|
137
|
+
node: target,
|
|
138
|
+
next: [...(edges.get(target) ?? [])].sort(),
|
|
139
|
+
at: 0,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const issues = [];
|
|
144
|
+
for (const loop of [...cycles.keys()]
|
|
145
|
+
.sort()
|
|
146
|
+
.map((key) => cycles.get(key))) {
|
|
147
|
+
// Token form in the message too, because a developer reading it has the FILE open and the file
|
|
148
|
+
// says `**SapoProductVariant**`, not a GUID.
|
|
149
|
+
const named = loop.map((id) => tokenFor.get(id) ?? id);
|
|
150
|
+
const chain = [...named, named[0]].join(' → ');
|
|
151
|
+
// The dependency that CLOSES the loop — the last edge back to the start. It is both the
|
|
152
|
+
// actionable one (deleting it breaks the cycle) and, unlike a task id, a `dependencies`
|
|
153
|
+
// component the graph can place in a file.
|
|
154
|
+
//
|
|
155
|
+
// The first version named `loop[0]`, a TASK id, under `parentKey: 'dependencies'`. A task is not
|
|
156
|
+
// a dependency, so the lookup never matched and every DEP-1 finding fell through to the
|
|
157
|
+
// project's `main.yaml` — sending the developer to a file containing neither edge. Found by the
|
|
158
|
+
// Epic 1 review by probing the panel, not by reading the rule.
|
|
159
|
+
const closing = declaredBy.get(`${loop[loop.length - 1]}→${loop[0]}`);
|
|
160
|
+
issues.push({
|
|
161
|
+
ruleId: 'DEP-1',
|
|
162
|
+
family: 'DEP',
|
|
163
|
+
// Not `critical`: the runtime's response to a cycle is not something this rule knows.
|
|
164
|
+
severity: 'high',
|
|
165
|
+
parentKey: 'dependencies',
|
|
166
|
+
// Falling back to the task id keeps a finding for an id-less dependency rather than dropping
|
|
167
|
+
// it: it lands on main.yaml, which is worse than exact and better than silent.
|
|
168
|
+
idOrKey: closing?.id ?? named[0],
|
|
169
|
+
message: `these tasks depend on each other in a cycle: ${chain}`,
|
|
170
|
+
why: 'each task in the chain declares that it depends on the next, and the last depends back on ' +
|
|
171
|
+
'the first, so there is no order in which they can all be satisfied. A task depending on ' +
|
|
172
|
+
'ITSELF is excluded — that is an ordinary self-join for a parent/child hierarchy — and this ' +
|
|
173
|
+
'is a genuine loop between distinct tasks.',
|
|
174
|
+
locateValue: closing?.id ?? named[0],
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return issues;
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* COL-1 — a dependency's `data.keys` names a column the table does not declare.
|
|
182
|
+
*
|
|
183
|
+
* `keys: { customer_id: id }` on a dependency from Sales Orders to Customers means "join my
|
|
184
|
+
* `customer_id` to their `id`". Both sides are column names on the respective tasks' tables, reachable
|
|
185
|
+
* through `objectAssociations[taskId].table.id` → `tables[].columns`.
|
|
186
|
+
*
|
|
187
|
+
* Two exclusions, both from measurement, and each one is the difference between a usable rule and an
|
|
188
|
+
* unusable one:
|
|
189
|
+
*
|
|
190
|
+
* - **`__`-prefixed names are never checked.** `__id`, `__source_id`, `__destination_id` are managed
|
|
191
|
+
* by the worker and are not declared in `columns`: of 119,575 authored column keys in the corpus,
|
|
192
|
+
* exactly 2 begin with `__`, against thousands of references to them. Without this exclusion 17 of
|
|
193
|
+
* 25 findings were these, all false.
|
|
194
|
+
* - **An unresolvable chain reports nothing.** When the task has no association, or the association's
|
|
195
|
+
* table does not exist, or the table declares no columns, this rule is silent — 18 of 208 key
|
|
196
|
+
* references are in that state, and every one of them is already `REF-3`/`REF-5`'s finding. Two
|
|
197
|
+
* rules reporting one defect makes the panel look twice as bad as the project is.
|
|
198
|
+
*
|
|
199
|
+
* What survives: 12 of 190 resolvable references, across 5 projects.
|
|
200
|
+
*/
|
|
201
|
+
export const dependencyColumnRule = {
|
|
202
|
+
id: 'COL',
|
|
203
|
+
family: 'COL',
|
|
204
|
+
run(ctx) {
|
|
205
|
+
const cnf = ctx.tokenForm;
|
|
206
|
+
if (!cnf || typeof cnf !== 'object')
|
|
207
|
+
return [];
|
|
208
|
+
const resolve = makeTokenResolver(ctx.variables);
|
|
209
|
+
const associations = cnf.objectAssociations &&
|
|
210
|
+
typeof cnf.objectAssociations === 'object' &&
|
|
211
|
+
!Array.isArray(cnf.objectAssociations)
|
|
212
|
+
? cnf.objectAssociations
|
|
213
|
+
: {};
|
|
214
|
+
// Resolved association key -> its entry, and resolved table id -> its declared column names.
|
|
215
|
+
const associationOf = new Map();
|
|
216
|
+
for (const [key, entry] of Object.entries(associations)) {
|
|
217
|
+
const resolved = idish(key, resolve);
|
|
218
|
+
if (resolved && !associationOf.has(resolved))
|
|
219
|
+
associationOf.set(resolved, entry);
|
|
220
|
+
}
|
|
221
|
+
const columnsOfTable = new Map();
|
|
222
|
+
for (const table of arr(cnf, 'tables')) {
|
|
223
|
+
const id = idish(table?.id ?? table?.key, resolve);
|
|
224
|
+
if (!id)
|
|
225
|
+
continue;
|
|
226
|
+
const columns = table?.columns;
|
|
227
|
+
if (!columns || typeof columns !== 'object' || Array.isArray(columns))
|
|
228
|
+
continue;
|
|
229
|
+
if (columnsOfTable.has(id))
|
|
230
|
+
continue;
|
|
231
|
+
columnsOfTable.set(id, new Set(Object.keys(columns)));
|
|
232
|
+
}
|
|
233
|
+
/** The declared columns of a task's backing table, or undefined when the chain breaks. */
|
|
234
|
+
const columnsOfTask = (taskId) => {
|
|
235
|
+
const tableId = idish(associationOf.get(taskId)?.table?.id, resolve);
|
|
236
|
+
if (!tableId)
|
|
237
|
+
return undefined;
|
|
238
|
+
return columnsOfTable.get(tableId);
|
|
239
|
+
};
|
|
240
|
+
const issues = [];
|
|
241
|
+
for (const dependency of arr(cnf, 'dependencies')) {
|
|
242
|
+
const keys = dependency?.data?.keys;
|
|
243
|
+
if (!keys || typeof keys !== 'object' || Array.isArray(keys))
|
|
244
|
+
continue;
|
|
245
|
+
const from = idish(dependency?.objectId, resolve);
|
|
246
|
+
const to = idish(dependency?.dependedOn, resolve);
|
|
247
|
+
if (!from || !to)
|
|
248
|
+
continue;
|
|
249
|
+
const fromColumns = columnsOfTask(from);
|
|
250
|
+
const toColumns = columnsOfTask(to);
|
|
251
|
+
if (!fromColumns || !toColumns)
|
|
252
|
+
continue;
|
|
253
|
+
// TOKEN form, for the same reason as DEP-1: the component→source-file map is keyed by the id as
|
|
254
|
+
// authored, so a resolved GUID never matches and the finding lands on main.yaml.
|
|
255
|
+
const rawDependencyId = dependency?.id;
|
|
256
|
+
const dependencyId = rawDependencyId !== undefined &&
|
|
257
|
+
rawDependencyId !== null &&
|
|
258
|
+
!isDynamic(rawDependencyId) &&
|
|
259
|
+
!isRefEmpty(rawDependencyId)
|
|
260
|
+
? String(rawDependencyId)
|
|
261
|
+
: String(dependency?.objectId ?? from);
|
|
262
|
+
const report = (column, side, available) => {
|
|
263
|
+
issues.push({
|
|
264
|
+
ruleId: 'COL-1',
|
|
265
|
+
family: 'COL',
|
|
266
|
+
// The join silently matches nothing, so the dependency never resolves — but the table may
|
|
267
|
+
// simply be declared elsewhere in a way this cannot see, hence `high` and not `critical`.
|
|
268
|
+
severity: 'high',
|
|
269
|
+
parentKey: 'dependencies',
|
|
270
|
+
idOrKey: dependencyId,
|
|
271
|
+
message: `the join key "${column}" is not a column of the ${side} task's table ` +
|
|
272
|
+
`(it declares ${available.size} column(s))`,
|
|
273
|
+
why: "a dependency joins on named columns of the two tasks' backing tables. A name that is " +
|
|
274
|
+
'not declared matches nothing, so the dependency never resolves and the depending task ' +
|
|
275
|
+
'is held back with no error to read. Worker-managed `__`-prefixed columns are not ' +
|
|
276
|
+
'checked — they are never declared.',
|
|
277
|
+
locateValue: column,
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
for (const [left, right] of Object.entries(keys)) {
|
|
281
|
+
if (!left.startsWith('__') && !fromColumns.has(left)) {
|
|
282
|
+
report(left, 'depending', fromColumns);
|
|
283
|
+
}
|
|
284
|
+
if (typeof right === 'string' &&
|
|
285
|
+
right &&
|
|
286
|
+
!right.startsWith('__') &&
|
|
287
|
+
!isDynamic(right) &&
|
|
288
|
+
!toColumns.has(right)) {
|
|
289
|
+
report(right, 'depended-on', toColumns);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return issues;
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
//# sourceMappingURL=dependencyIntegrity.js.map
|