@principal-ai/subsystems-core 0.51.4 → 0.51.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/README.md +21 -6
- package/dist/audit/boundary.d.ts +104 -0
- package/dist/audit/boundary.d.ts.map +1 -0
- package/dist/audit/boundary.js +363 -0
- package/dist/audit/boundary.js.map +1 -0
- package/dist/audit/c4.d.ts +41 -0
- package/dist/audit/c4.d.ts.map +1 -0
- package/dist/audit/c4.js +41 -0
- package/dist/audit/c4.js.map +1 -0
- package/dist/audit/engine.d.ts +135 -0
- package/dist/audit/engine.d.ts.map +1 -0
- package/dist/audit/engine.js +828 -0
- package/dist/audit/engine.js.map +1 -0
- package/dist/audit/fixes.d.ts +80 -0
- package/dist/audit/fixes.d.ts.map +1 -0
- package/dist/audit/fixes.js +162 -0
- package/dist/audit/fixes.js.map +1 -0
- package/dist/audit/hash.d.ts +25 -0
- package/dist/audit/hash.d.ts.map +1 -0
- package/dist/audit/hash.js +53 -0
- package/dist/audit/hash.js.map +1 -0
- package/dist/audit/index.d.ts +11 -1
- package/dist/audit/index.d.ts.map +1 -1
- package/dist/audit/index.js +37 -3
- package/dist/audit/index.js.map +1 -1
- package/dist/audit/local-graphify.d.ts +75 -0
- package/dist/audit/local-graphify.d.ts.map +1 -0
- package/dist/audit/local-graphify.js +283 -0
- package/dist/audit/local-graphify.js.map +1 -0
- package/dist/audit/paths.d.ts +16 -0
- package/dist/audit/paths.d.ts.map +1 -0
- package/dist/audit/paths.js +31 -0
- package/dist/audit/paths.js.map +1 -0
- package/dist/audit/pure.d.ts +18 -0
- package/dist/audit/pure.d.ts.map +1 -0
- package/dist/audit/pure.js +50 -0
- package/dist/audit/pure.js.map +1 -0
- package/dist/audit/report-logic.d.ts +17 -0
- package/dist/audit/report-logic.d.ts.map +1 -0
- package/dist/audit/report-logic.js +206 -0
- package/dist/audit/report-logic.js.map +1 -0
- package/dist/audit/report.d.ts +136 -0
- package/dist/audit/report.d.ts.map +1 -0
- package/dist/audit/report.js +3 -0
- package/dist/audit/report.js.map +1 -0
- package/dist/audit/trail.d.ts +29 -0
- package/dist/audit/trail.d.ts.map +1 -0
- package/dist/audit/trail.js +59 -0
- package/dist/audit/trail.js.map +1 -0
- package/dist/audit/verification.d.ts +98 -0
- package/dist/audit/verification.d.ts.map +1 -0
- package/dist/audit/verification.js +11 -0
- package/dist/audit/verification.js.map +1 -0
- package/dist/audit/verify/component.d.ts +68 -0
- package/dist/audit/verify/component.d.ts.map +1 -0
- package/dist/audit/verify/component.js +500 -0
- package/dist/audit/verify/component.js.map +1 -0
- package/dist/audit/verify/declarations.d.ts +58 -0
- package/dist/audit/verify/declarations.d.ts.map +1 -0
- package/dist/audit/verify/declarations.js +227 -0
- package/dist/audit/verify/declarations.js.map +1 -0
- package/dist/audit/verify/grammar.d.ts +12 -0
- package/dist/audit/verify/grammar.d.ts.map +1 -0
- package/dist/audit/verify/grammar.js +57 -0
- package/dist/audit/verify/grammar.js.map +1 -0
- package/dist/audit/verify/index.d.ts +12 -0
- package/dist/audit/verify/index.d.ts.map +1 -0
- package/dist/audit/verify/index.js +31 -0
- package/dist/audit/verify/index.js.map +1 -0
- package/dist/audit/verify/parser.d.ts +19 -0
- package/dist/audit/verify/parser.d.ts.map +1 -0
- package/dist/audit/verify/parser.js +122 -0
- package/dist/audit/verify/parser.js.map +1 -0
- package/dist/audit/verify/span.d.ts +49 -0
- package/dist/audit/verify/span.d.ts.map +1 -0
- package/dist/audit/verify/span.js +377 -0
- package/dist/audit/verify/span.js.map +1 -0
- package/dist/graphify/anchor.d.ts +45 -0
- package/dist/graphify/anchor.d.ts.map +1 -0
- package/dist/graphify/anchor.js +179 -0
- package/dist/graphify/anchor.js.map +1 -0
- package/dist/graphify/consolidated.d.ts +259 -0
- package/dist/graphify/consolidated.d.ts.map +1 -0
- package/dist/graphify/consolidated.js +12 -0
- package/dist/graphify/consolidated.js.map +1 -0
- package/dist/graphify/construct.d.ts +41 -0
- package/dist/graphify/construct.d.ts.map +1 -0
- package/dist/graphify/construct.js +106 -0
- package/dist/graphify/construct.js.map +1 -0
- package/dist/graphify/ids.d.ts +19 -0
- package/dist/graphify/ids.d.ts.map +1 -0
- package/dist/graphify/ids.js +53 -0
- package/dist/graphify/ids.js.map +1 -0
- package/dist/graphify/index.d.ts +16 -0
- package/dist/graphify/index.d.ts.map +1 -0
- package/dist/graphify/index.js +32 -0
- package/dist/graphify/index.js.map +1 -0
- package/dist/graphify/resolve.d.ts +48 -0
- package/dist/graphify/resolve.d.ts.map +1 -0
- package/dist/graphify/resolve.js +89 -0
- package/dist/graphify/resolve.js.map +1 -0
- package/dist/graphify/signature.d.ts +87 -0
- package/dist/graphify/signature.d.ts.map +1 -0
- package/dist/graphify/signature.js +282 -0
- package/dist/graphify/signature.js.map +1 -0
- package/dist/graphify/types.d.ts +141 -0
- package/dist/graphify/types.d.ts.map +1 -0
- package/dist/graphify/types.js +9 -0
- package/dist/graphify/types.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +2 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +3 -1
- package/dist/node.js.map +1 -1
- package/dist/storage/topic-share.d.ts +57 -0
- package/dist/storage/topic-share.d.ts.map +1 -0
- package/dist/storage/topic-share.js +55 -0
- package/dist/storage/topic-share.js.map +1 -0
- package/package.json +16 -2
- package/src/audit/boundary.ts +447 -0
- package/src/audit/c4.ts +70 -0
- package/src/audit/engine.ts +1058 -0
- package/src/audit/fixes.ts +192 -0
- package/src/audit/hash.ts +58 -0
- package/src/audit/index.ts +33 -8
- package/src/audit/local-graphify.test.ts +163 -0
- package/src/audit/local-graphify.ts +354 -0
- package/src/audit/paths.ts +25 -0
- package/src/audit/pure.ts +91 -0
- package/src/audit/report-logic.test.ts +145 -0
- package/src/audit/report-logic.ts +245 -0
- package/src/audit/report.ts +203 -0
- package/src/audit/trail.ts +77 -0
- package/src/audit/verification.ts +104 -0
- package/src/audit/verify/component.ts +760 -0
- package/src/audit/verify/declarations.ts +284 -0
- package/src/audit/verify/grammar.ts +57 -0
- package/src/audit/verify/index.ts +41 -0
- package/src/audit/verify/parser.ts +124 -0
- package/src/audit/verify/span.ts +478 -0
- package/src/graphify/anchor.ts +206 -0
- package/src/graphify/consolidated.ts +298 -0
- package/src/graphify/construct.ts +153 -0
- package/src/graphify/ids.ts +48 -0
- package/src/graphify/index.ts +16 -0
- package/src/graphify/resolve.ts +115 -0
- package/src/graphify/signature.ts +354 -0
- package/src/graphify/types.ts +164 -0
- package/src/index.ts +5 -3
- package/src/node.ts +2 -0
- package/src/storage/topic-share.test.ts +71 -0
- package/src/storage/topic-share.ts +91 -0
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boundary (process / module) audit helpers — membership for frames.
|
|
3
|
+
* Mechanical checks only; no Graphify.
|
|
4
|
+
*
|
|
5
|
+
* Soft rule: module≠file and process-nest disagreement are gaps (never hard
|
|
6
|
+
* fails). Module without a file anchor on a grounded component is an issue.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { SubsystemComponent } from '../types/subsystem-model'
|
|
10
|
+
import { getSubsystemProcessRegions } from '../types/subsystem-model'
|
|
11
|
+
import type { C4AuditElement } from './c4'
|
|
12
|
+
import { verifyProcessBoundaries } from './c4'
|
|
13
|
+
import { purlRepoKey } from './paths'
|
|
14
|
+
|
|
15
|
+
export type BoundaryCheckKind =
|
|
16
|
+
| 'module_file'
|
|
17
|
+
| 'process_nest'
|
|
18
|
+
| 'process_claim'
|
|
19
|
+
| 'process_container'
|
|
20
|
+
| 'skipped'
|
|
21
|
+
|
|
22
|
+
export type BoundaryCheckVerdict = 'ok' | 'issue' | 'gap' | 'skipped'
|
|
23
|
+
|
|
24
|
+
export interface BoundaryComponentCheck {
|
|
25
|
+
componentAlias: string
|
|
26
|
+
componentName?: string
|
|
27
|
+
kind: BoundaryCheckKind
|
|
28
|
+
module?: string
|
|
29
|
+
file?: string
|
|
30
|
+
process?: string
|
|
31
|
+
verdict: BoundaryCheckVerdict
|
|
32
|
+
note?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface BoundaryAuditFinding {
|
|
36
|
+
kind:
|
|
37
|
+
| 'boundary_module_file_mismatch'
|
|
38
|
+
| 'boundary_process_nest_disagree'
|
|
39
|
+
| 'boundary_process_missing'
|
|
40
|
+
| 'boundary_process_unassigned'
|
|
41
|
+
| 'boundary_process_proposed'
|
|
42
|
+
| 'boundary_process_rejected'
|
|
43
|
+
| 'boundary_process_unbacked'
|
|
44
|
+
severity: 'error' | 'info'
|
|
45
|
+
componentAlias?: string
|
|
46
|
+
componentName?: string
|
|
47
|
+
/** Module key when the finding is about a multi-member module group. */
|
|
48
|
+
moduleKey?: string
|
|
49
|
+
/** Process key when the finding is about a process boundary as a whole. */
|
|
50
|
+
processKey?: string
|
|
51
|
+
message: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface BoundaryAuditResult {
|
|
55
|
+
checks: BoundaryComponentCheck[]
|
|
56
|
+
findings: BoundaryAuditFinding[]
|
|
57
|
+
summary: {
|
|
58
|
+
/** Components with a non-empty module claim. */
|
|
59
|
+
modulesClaimed: number
|
|
60
|
+
moduleFileOk: number
|
|
61
|
+
moduleFileMismatch: number
|
|
62
|
+
/** Multi-member module groups inspected for process nest. */
|
|
63
|
+
processNestsChecked: number
|
|
64
|
+
processNestOk: number
|
|
65
|
+
processNestDisagree: number
|
|
66
|
+
/** Runtime-executing components that must state a deployment unit. */
|
|
67
|
+
processRequired: number
|
|
68
|
+
processClaimed: number
|
|
69
|
+
processMissing: number
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Normalize path-ish strings for module/file comparison. */
|
|
74
|
+
export function normalizeBoundaryPath(p: string): string {
|
|
75
|
+
return p.trim().replace(/\\/g, '/').replace(/^\.\//, '')
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* True when `module` is the file itself or a directory prefix of it
|
|
80
|
+
* (sensible parent path for a frame).
|
|
81
|
+
*/
|
|
82
|
+
export function moduleAgreesWithFile(module: string, file: string): boolean {
|
|
83
|
+
const m = normalizeBoundaryPath(module)
|
|
84
|
+
const f = normalizeBoundaryPath(file)
|
|
85
|
+
if (!m || !f) return false
|
|
86
|
+
if (m === f) return true
|
|
87
|
+
const prefix = m.endsWith('/') ? m : `${m}/`
|
|
88
|
+
return f.startsWith(prefix)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function isUngrounded(c: SubsystemComponent): boolean {
|
|
92
|
+
return c.construct === 'external'
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Constructs that must state a deployment unit (`process`).
|
|
97
|
+
*
|
|
98
|
+
* Required — runtime-executing declarations. A reader needs `process` to know
|
|
99
|
+
* where the code actually runs: function, class, custom_entity.
|
|
100
|
+
*
|
|
101
|
+
* Allowed but not required — type-only declarations are erased at compile
|
|
102
|
+
* time, and a shared type is often legitimately reachable from several
|
|
103
|
+
* processes at once.
|
|
104
|
+
*
|
|
105
|
+
* Not enforced — `external` is third-party (no owner in this repo); `store`
|
|
106
|
+
* is a state container rather than a deployment unit.
|
|
107
|
+
*/
|
|
108
|
+
const PROCESS_REQUIRED_CONSTRUCTS: ReadonlySet<string> = new Set([
|
|
109
|
+
'function',
|
|
110
|
+
'class',
|
|
111
|
+
'custom_entity',
|
|
112
|
+
])
|
|
113
|
+
|
|
114
|
+
/** True when this component must carry a `process` claim. */
|
|
115
|
+
export function requiresProcess(c: SubsystemComponent): boolean {
|
|
116
|
+
if (isUngrounded(c)) return false
|
|
117
|
+
return PROCESS_REQUIRED_CONSTRUCTS.has(c.construct ?? '')
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Audit process/module membership fields on components.
|
|
122
|
+
*
|
|
123
|
+
* `augmentedModuleAliases` — component aliases with an accepted
|
|
124
|
+
* module-boundary augmentation confirming an intentional module≠file
|
|
125
|
+
* grouping.
|
|
126
|
+
*/
|
|
127
|
+
export function auditBoundaryFields(
|
|
128
|
+
components: readonly SubsystemComponent[],
|
|
129
|
+
opts?: { augmentedModuleAliases?: ReadonlySet<string> },
|
|
130
|
+
): BoundaryAuditResult {
|
|
131
|
+
const checks: BoundaryComponentCheck[] = []
|
|
132
|
+
const findings: BoundaryAuditFinding[] = []
|
|
133
|
+
const augmented = opts?.augmentedModuleAliases
|
|
134
|
+
|
|
135
|
+
let modulesClaimed = 0
|
|
136
|
+
let moduleFileOk = 0
|
|
137
|
+
let moduleFileMismatch = 0
|
|
138
|
+
let processNestsChecked = 0
|
|
139
|
+
let processNestOk = 0
|
|
140
|
+
let processNestDisagree = 0
|
|
141
|
+
let processRequired = 0
|
|
142
|
+
let processClaimed = 0
|
|
143
|
+
let processMissing = 0
|
|
144
|
+
|
|
145
|
+
const byModule = new Map<string, SubsystemComponent[]>()
|
|
146
|
+
|
|
147
|
+
for (const c of components) {
|
|
148
|
+
const moduleRaw = c.module?.trim() ?? ''
|
|
149
|
+
const fileRaw = c.file?.trim() ?? ''
|
|
150
|
+
const processRaw = c.process?.trim() ?? ''
|
|
151
|
+
|
|
152
|
+
/*
|
|
153
|
+
* Dynamic topology, independent of module. A runtime-executing component
|
|
154
|
+
* must name its deployment unit whether or not it sits in a module group.
|
|
155
|
+
* Types are exempt but may still claim one.
|
|
156
|
+
*/
|
|
157
|
+
if (requiresProcess(c)) {
|
|
158
|
+
processRequired++
|
|
159
|
+
if (processRaw) {
|
|
160
|
+
processClaimed++
|
|
161
|
+
checks.push({
|
|
162
|
+
componentAlias: c.alias,
|
|
163
|
+
componentName: c.name,
|
|
164
|
+
kind: 'process_claim',
|
|
165
|
+
process: processRaw,
|
|
166
|
+
verdict: 'ok',
|
|
167
|
+
note: `process claimed (${processRaw})`,
|
|
168
|
+
})
|
|
169
|
+
} else {
|
|
170
|
+
processMissing++
|
|
171
|
+
const note = `${c.construct ?? 'component'} claims no process — no deployment unit stated`
|
|
172
|
+
checks.push({
|
|
173
|
+
componentAlias: c.alias,
|
|
174
|
+
componentName: c.name,
|
|
175
|
+
kind: 'process_claim',
|
|
176
|
+
verdict: 'gap',
|
|
177
|
+
note,
|
|
178
|
+
})
|
|
179
|
+
findings.push({
|
|
180
|
+
kind: 'boundary_process_missing',
|
|
181
|
+
severity: 'info',
|
|
182
|
+
componentAlias: c.alias,
|
|
183
|
+
componentName: c.name,
|
|
184
|
+
message: note,
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (!moduleRaw) continue
|
|
190
|
+
|
|
191
|
+
modulesClaimed++
|
|
192
|
+
const modNorm = normalizeBoundaryPath(moduleRaw)
|
|
193
|
+
const members = byModule.get(modNorm) ?? []
|
|
194
|
+
members.push(c)
|
|
195
|
+
byModule.set(modNorm, members)
|
|
196
|
+
|
|
197
|
+
if (!fileRaw) {
|
|
198
|
+
// A grounded component with a module but no file is rejected at input.
|
|
199
|
+
// Externals carry no file by design, so they are skipped rather than
|
|
200
|
+
// flagged.
|
|
201
|
+
if (isUngrounded(c)) {
|
|
202
|
+
checks.push({
|
|
203
|
+
componentAlias: c.alias,
|
|
204
|
+
componentName: c.name,
|
|
205
|
+
kind: 'module_file',
|
|
206
|
+
module: moduleRaw,
|
|
207
|
+
file: '',
|
|
208
|
+
process: processRaw || undefined,
|
|
209
|
+
verdict: 'skipped',
|
|
210
|
+
note: 'module on external — no file required',
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
continue
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (moduleAgreesWithFile(moduleRaw, fileRaw)) {
|
|
217
|
+
moduleFileOk++
|
|
218
|
+
checks.push({
|
|
219
|
+
componentAlias: c.alias,
|
|
220
|
+
componentName: c.name,
|
|
221
|
+
kind: 'module_file',
|
|
222
|
+
module: moduleRaw,
|
|
223
|
+
file: fileRaw,
|
|
224
|
+
process: processRaw || undefined,
|
|
225
|
+
verdict: 'ok',
|
|
226
|
+
note: 'module matches file (or is a path prefix)',
|
|
227
|
+
})
|
|
228
|
+
continue
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (augmented?.has(c.alias)) {
|
|
232
|
+
moduleFileOk++
|
|
233
|
+
checks.push({
|
|
234
|
+
componentAlias: c.alias,
|
|
235
|
+
componentName: c.name,
|
|
236
|
+
kind: 'module_file',
|
|
237
|
+
module: moduleRaw,
|
|
238
|
+
file: fileRaw,
|
|
239
|
+
process: processRaw || undefined,
|
|
240
|
+
verdict: 'ok',
|
|
241
|
+
note: 'module≠file confirmed (augmented)',
|
|
242
|
+
})
|
|
243
|
+
continue
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
moduleFileMismatch++
|
|
247
|
+
const note = `module ${JSON.stringify(moduleRaw)} does not match file ${JSON.stringify(fileRaw)} (and is not a path prefix)`
|
|
248
|
+
checks.push({
|
|
249
|
+
componentAlias: c.alias,
|
|
250
|
+
componentName: c.name,
|
|
251
|
+
kind: 'module_file',
|
|
252
|
+
module: moduleRaw,
|
|
253
|
+
file: fileRaw,
|
|
254
|
+
process: processRaw || undefined,
|
|
255
|
+
verdict: 'gap',
|
|
256
|
+
note,
|
|
257
|
+
})
|
|
258
|
+
findings.push({
|
|
259
|
+
kind: 'boundary_module_file_mismatch',
|
|
260
|
+
severity: 'info',
|
|
261
|
+
componentAlias: c.alias,
|
|
262
|
+
componentName: c.name,
|
|
263
|
+
moduleKey: modNorm,
|
|
264
|
+
message: note,
|
|
265
|
+
})
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
for (const [moduleKey, members] of byModule) {
|
|
269
|
+
if (members.length < 2) continue
|
|
270
|
+
processNestsChecked++
|
|
271
|
+
const processes = new Set<string>()
|
|
272
|
+
for (const m of members) {
|
|
273
|
+
const p = m.process?.trim()
|
|
274
|
+
if (p) processes.add(p)
|
|
275
|
+
}
|
|
276
|
+
// Empty process on some members is fine for nest; disagreement is
|
|
277
|
+
// two+ distinct non-empty process values among members.
|
|
278
|
+
if (processes.size <= 1) {
|
|
279
|
+
processNestOk++
|
|
280
|
+
for (const m of members) {
|
|
281
|
+
checks.push({
|
|
282
|
+
componentAlias: m.alias,
|
|
283
|
+
componentName: m.name,
|
|
284
|
+
kind: 'process_nest',
|
|
285
|
+
module: moduleKey,
|
|
286
|
+
process: m.process?.trim() || undefined,
|
|
287
|
+
verdict: 'ok',
|
|
288
|
+
note:
|
|
289
|
+
processes.size === 1
|
|
290
|
+
? `module nest agrees under process ${JSON.stringify([...processes][0])}`
|
|
291
|
+
: 'multi-member module with no process claims — nest n/a',
|
|
292
|
+
})
|
|
293
|
+
}
|
|
294
|
+
continue
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
processNestDisagree++
|
|
298
|
+
const list = [...processes].sort().map((p) => JSON.stringify(p)).join(', ')
|
|
299
|
+
const note = `module ${JSON.stringify(moduleKey)} members claim different processes: ${list}`
|
|
300
|
+
for (const m of members) {
|
|
301
|
+
checks.push({
|
|
302
|
+
componentAlias: m.alias,
|
|
303
|
+
componentName: m.name,
|
|
304
|
+
kind: 'process_nest',
|
|
305
|
+
module: moduleKey,
|
|
306
|
+
process: m.process?.trim() || undefined,
|
|
307
|
+
verdict: 'gap',
|
|
308
|
+
note,
|
|
309
|
+
})
|
|
310
|
+
findings.push({
|
|
311
|
+
kind: 'boundary_process_nest_disagree',
|
|
312
|
+
severity: 'info',
|
|
313
|
+
componentAlias: m.alias,
|
|
314
|
+
componentName: m.name,
|
|
315
|
+
moduleKey,
|
|
316
|
+
message: note,
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
checks,
|
|
323
|
+
findings,
|
|
324
|
+
summary: {
|
|
325
|
+
modulesClaimed,
|
|
326
|
+
moduleFileOk,
|
|
327
|
+
moduleFileMismatch,
|
|
328
|
+
processNestsChecked,
|
|
329
|
+
processNestOk,
|
|
330
|
+
processNestDisagree,
|
|
331
|
+
processRequired,
|
|
332
|
+
processClaimed,
|
|
333
|
+
processMissing,
|
|
334
|
+
},
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Which runtime components have NO verified key to assign a process from —
|
|
340
|
+
* a required process claim whose repo's element set holds no accepted
|
|
341
|
+
* container. Pure over its inputs.
|
|
342
|
+
*/
|
|
343
|
+
export function auditProcessBacking(
|
|
344
|
+
components: readonly SubsystemComponent[],
|
|
345
|
+
sets: ReadonlyMap<string, readonly C4AuditElement[]>,
|
|
346
|
+
): BoundaryAuditFinding[] {
|
|
347
|
+
const findings: BoundaryAuditFinding[] = []
|
|
348
|
+
for (const c of components) {
|
|
349
|
+
if (!requiresProcess(c)) continue
|
|
350
|
+
if (c.process?.trim()) continue
|
|
351
|
+
const repoKey = purlRepoKey(c.purl)
|
|
352
|
+
const set = repoKey ? sets.get(repoKey) : undefined
|
|
353
|
+
const hasBackableKey = (set ?? []).some(
|
|
354
|
+
(e) => e.kind === 'container' && e.state === 'accepted' && e.process?.trim(),
|
|
355
|
+
)
|
|
356
|
+
if (hasBackableKey) continue
|
|
357
|
+
findings.push({
|
|
358
|
+
kind: 'boundary_process_unbacked',
|
|
359
|
+
severity: 'info',
|
|
360
|
+
componentAlias: c.alias,
|
|
361
|
+
componentName: c.name,
|
|
362
|
+
message: `${c.construct ?? 'component'} ${JSON.stringify(c.alias)} claims no process and no accepted container exists to assign it from — accept a container for this boundary first (container-verifier).`,
|
|
363
|
+
})
|
|
364
|
+
}
|
|
365
|
+
return findings
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* One finding per claim-less component. The verification pass reports every
|
|
370
|
+
* claim-less runtime component as `boundary_process_missing`; the backing pass
|
|
371
|
+
* reports the subset with no accepted container as `boundary_process_unbacked`.
|
|
372
|
+
* This drops the missing finding for any component the backing pass already
|
|
373
|
+
* named as unbacked — missing survives only for backed gaps.
|
|
374
|
+
*
|
|
375
|
+
* Pure over its inputs; returns a new array.
|
|
376
|
+
*/
|
|
377
|
+
export function dropUnbackedMissing<
|
|
378
|
+
F extends { kind: string; componentAlias?: string | null },
|
|
379
|
+
>(findings: readonly F[]): F[] {
|
|
380
|
+
const unbackedAliases = new Set(
|
|
381
|
+
findings
|
|
382
|
+
.filter(
|
|
383
|
+
(f) => f.kind === 'boundary_process_unbacked' && f.componentAlias != null,
|
|
384
|
+
)
|
|
385
|
+
.map((f) => f.componentAlias as string),
|
|
386
|
+
)
|
|
387
|
+
if (unbackedAliases.size === 0) return [...findings]
|
|
388
|
+
return findings.filter(
|
|
389
|
+
(f) =>
|
|
390
|
+
!(
|
|
391
|
+
f.kind === 'boundary_process_missing' &&
|
|
392
|
+
f.componentAlias != null &&
|
|
393
|
+
unbackedAliases.has(f.componentAlias)
|
|
394
|
+
),
|
|
395
|
+
)
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Process-boundary verification against the C4 element store — the same read
|
|
400
|
+
* the renderer's issues list does. One finding per boundary that is NOT
|
|
401
|
+
* verified; `verified` reports nothing.
|
|
402
|
+
*
|
|
403
|
+
* Each finding carries a backing `process_container` check per member alias
|
|
404
|
+
* (verdict `gap` when unverified), so the lane tallies see the same state the
|
|
405
|
+
* issues list shows.
|
|
406
|
+
*
|
|
407
|
+
* Pure over its inputs; the caller reads the element set(s) from disk.
|
|
408
|
+
*/
|
|
409
|
+
export function auditProcessVerification(
|
|
410
|
+
components: readonly SubsystemComponent[],
|
|
411
|
+
elements: readonly C4AuditElement[],
|
|
412
|
+
): { checks: BoundaryComponentCheck[]; findings: BoundaryAuditFinding[] } {
|
|
413
|
+
const rollup = getSubsystemProcessRegions({ components })
|
|
414
|
+
const statuses = verifyProcessBoundaries({ rollup, elements })
|
|
415
|
+
const nameByAlias = new Map(components.map((c) => [c.alias, c.name]))
|
|
416
|
+
const checks: BoundaryComponentCheck[] = []
|
|
417
|
+
const findings: BoundaryAuditFinding[] = []
|
|
418
|
+
for (const { key, status, memberAliases, element } of statuses) {
|
|
419
|
+
const verified = status === 'verified'
|
|
420
|
+
for (const alias of memberAliases) {
|
|
421
|
+
checks.push({
|
|
422
|
+
componentAlias: alias,
|
|
423
|
+
componentName: nameByAlias.get(alias),
|
|
424
|
+
kind: 'process_container',
|
|
425
|
+
process: key,
|
|
426
|
+
verdict: verified ? 'ok' : 'gap',
|
|
427
|
+
note: verified
|
|
428
|
+
? `boundary ${JSON.stringify(key)} verified by container ${JSON.stringify(element?.label ?? element?.id ?? key)}`
|
|
429
|
+
: `boundary ${JSON.stringify(key)} has no accepted container (${status})`,
|
|
430
|
+
})
|
|
431
|
+
}
|
|
432
|
+
if (verified) continue
|
|
433
|
+
const label = element?.label ?? key
|
|
434
|
+
findings.push({
|
|
435
|
+
kind: `boundary_process_${status}`,
|
|
436
|
+
severity: 'info',
|
|
437
|
+
processKey: key,
|
|
438
|
+
message:
|
|
439
|
+
status === 'unassigned'
|
|
440
|
+
? `No C4 container claims the process boundary ${JSON.stringify(key)} yet — a container-verifier run would assess it.`
|
|
441
|
+
: status === 'proposed'
|
|
442
|
+
? `Container ${JSON.stringify(label)} claims the process boundary ${JSON.stringify(key)} and awaits a decision.`
|
|
443
|
+
: `Container ${JSON.stringify(label)} was rejected for the process boundary ${JSON.stringify(key)} — it stays unclaimed until a container is accepted.`,
|
|
444
|
+
})
|
|
445
|
+
}
|
|
446
|
+
return { checks, findings }
|
|
447
|
+
}
|
package/src/audit/c4.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal C4 read-side used by the audit engine.
|
|
3
|
+
*
|
|
4
|
+
* The full C4 model lives in the viewer package. The audit only needs to read
|
|
5
|
+
* a container's `process` claim and review state, so it takes a structural
|
|
6
|
+
* element shape here instead of depending on the renderer.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type C4AuditElementState = 'proposed' | 'accepted' | 'rejected'
|
|
10
|
+
|
|
11
|
+
export interface C4AuditElement {
|
|
12
|
+
id: string
|
|
13
|
+
kind: string
|
|
14
|
+
state: C4AuditElementState
|
|
15
|
+
process?: string
|
|
16
|
+
label?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type C4ProcessVerification =
|
|
20
|
+
| 'unassigned'
|
|
21
|
+
| 'proposed'
|
|
22
|
+
| 'rejected'
|
|
23
|
+
| 'verified'
|
|
24
|
+
|
|
25
|
+
export interface C4ProcessBoundaryStatus {
|
|
26
|
+
/** The `process` key, e.g. `principal-studio/host`. */
|
|
27
|
+
key: string
|
|
28
|
+
/** Aliases carrying this key in the model, when the caller supplied them. */
|
|
29
|
+
memberAliases: string[]
|
|
30
|
+
status: C4ProcessVerification
|
|
31
|
+
/** The container whose state decided the status. Absent when `unassigned`. */
|
|
32
|
+
element?: C4AuditElement
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Read a process boundary's verification off its container assignment.
|
|
37
|
+
*
|
|
38
|
+
* The claimant is the container whose `process` equals the boundary's key —
|
|
39
|
+
* a plain string match. When several containers claim one key, the decided one
|
|
40
|
+
* wins: accepted over rejected over proposed, so one reviewer's yes outranks
|
|
41
|
+
* another's no. Pure.
|
|
42
|
+
*/
|
|
43
|
+
export function verifyProcessBoundaries(options: {
|
|
44
|
+
rollup: ReadonlyArray<{ key: string; memberAliases?: readonly string[] }>
|
|
45
|
+
elements: readonly C4AuditElement[]
|
|
46
|
+
}): C4ProcessBoundaryStatus[] {
|
|
47
|
+
const byKey = new Map<string, C4AuditElement[]>()
|
|
48
|
+
for (const element of options.elements) {
|
|
49
|
+
if (element.kind !== 'container' || !element.process) continue
|
|
50
|
+
const list = byKey.get(element.process) ?? []
|
|
51
|
+
list.push(element)
|
|
52
|
+
byKey.set(element.process, list)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const precedence = { accepted: 0, rejected: 1, proposed: 2 } as const
|
|
56
|
+
return options.rollup.map(({ key, memberAliases }) => {
|
|
57
|
+
const aliases = [...(memberAliases ?? [])]
|
|
58
|
+
const claimants = byKey.get(key) ?? []
|
|
59
|
+
if (claimants.length === 0) {
|
|
60
|
+
return { key, memberAliases: aliases, status: 'unassigned' as const }
|
|
61
|
+
}
|
|
62
|
+
const decided = [...claimants].sort(
|
|
63
|
+
(a, b) =>
|
|
64
|
+
precedence[a.state] - precedence[b.state] || a.id.localeCompare(b.id),
|
|
65
|
+
)[0]!
|
|
66
|
+
const status =
|
|
67
|
+
decided.state === 'accepted' ? ('verified' as const) : decided.state
|
|
68
|
+
return { key, memberAliases: aliases, status, element: decided }
|
|
69
|
+
})
|
|
70
|
+
}
|