@principal-ai/subsystems-core 0.52.0 → 0.53.1
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 +30 -2
- 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 +865 -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/graphify-provider.d.ts +51 -0
- package/dist/audit/graphify-provider.d.ts.map +1 -0
- package/dist/audit/graphify-provider.js +36 -0
- package/dist/audit/graphify-provider.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 +12 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/index.js +40 -0
- package/dist/audit/index.js.map +1 -0
- 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 +140 -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 +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/infra/c4.d.ts +59 -0
- package/dist/infra/c4.d.ts.map +1 -0
- package/dist/infra/c4.js +106 -0
- package/dist/infra/c4.js.map +1 -0
- package/dist/infra/index.d.ts +17 -0
- package/dist/infra/index.d.ts.map +1 -0
- package/dist/infra/index.js +30 -0
- package/dist/infra/index.js.map +1 -0
- package/dist/infra/jsonc.d.ts +10 -0
- package/dist/infra/jsonc.d.ts.map +1 -0
- package/dist/infra/jsonc.js +77 -0
- package/dist/infra/jsonc.js.map +1 -0
- package/dist/infra/observe.d.ts +102 -0
- package/dist/infra/observe.d.ts.map +1 -0
- package/dist/infra/observe.js +347 -0
- package/dist/infra/observe.js.map +1 -0
- package/dist/infra/terraform.d.ts +41 -0
- package/dist/infra/terraform.d.ts.map +1 -0
- package/dist/infra/terraform.js +208 -0
- package/dist/infra/terraform.js.map +1 -0
- package/dist/infra/types.d.ts +107 -0
- package/dist/infra/types.d.ts.map +1 -0
- package/dist/infra/types.js +47 -0
- package/dist/infra/types.js.map +1 -0
- package/dist/infra/wrangler.d.ts +32 -0
- package/dist/infra/wrangler.d.ts.map +1 -0
- package/dist/infra/wrangler.js +177 -0
- package/dist/infra/wrangler.js.map +1 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +4 -1
- package/dist/node.js.map +1 -1
- package/dist/storage/topic-reference-links.d.ts +3 -3
- package/dist/storage/topic-reference-links.d.ts.map +1 -1
- package/dist/storage/topic-reference-links.js +23 -8
- package/dist/storage/topic-reference-links.js.map +1 -1
- package/dist/storage/topic-share.d.ts +69 -0
- package/dist/storage/topic-share.d.ts.map +1 -0
- package/dist/storage/topic-share.js +67 -0
- package/dist/storage/topic-share.js.map +1 -0
- package/dist/storage/topic-types.d.ts +5 -1
- package/dist/storage/topic-types.d.ts.map +1 -1
- package/dist/types/subsystem-model.d.ts +59 -0
- package/dist/types/subsystem-model.d.ts.map +1 -1
- package/dist/types/subsystem-model.js +50 -1
- package/dist/types/subsystem-model.js.map +1 -1
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +25 -2
- package/dist/validation.js.map +1 -1
- package/package.json +22 -2
- package/schemas/subsystem-model.schema.json +35 -19
- package/src/audit/boundary.ts +447 -0
- package/src/audit/c4.ts +70 -0
- package/src/audit/engine.ts +1099 -0
- package/src/audit/fixes.ts +192 -0
- package/src/audit/graphify-provider.test.ts +58 -0
- package/src/audit/graphify-provider.ts +77 -0
- package/src/audit/hash.ts +58 -0
- package/src/audit/index.ts +34 -0
- 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 +207 -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 +11 -0
- package/src/infra/c4.ts +146 -0
- package/src/infra/index.ts +36 -0
- package/src/infra/infra.test.ts +360 -0
- package/src/infra/jsonc.ts +70 -0
- package/src/infra/observe.test.ts +202 -0
- package/src/infra/observe.ts +451 -0
- package/src/infra/terraform.ts +251 -0
- package/src/infra/types.ts +136 -0
- package/src/infra/wrangler.ts +203 -0
- package/src/node.ts +3 -0
- package/src/storage/topic-reference-links.test.ts +7 -1
- package/src/storage/topic-reference-links.ts +24 -8
- package/src/storage/topic-share.test.ts +91 -0
- package/src/storage/topic-share.ts +118 -0
- package/src/storage/topic-types.ts +3 -1
- package/src/storage/topicStore.test.ts +1 -0
- package/src/types/subsystem-model.test.ts +52 -2
- package/src/types/subsystem-model.ts +104 -0
- package/src/validation.test.ts +71 -7
- package/src/validation.ts +27 -2
|
@@ -96,6 +96,7 @@ describe('CRUD', () => {
|
|
|
96
96
|
const store = makeStore();
|
|
97
97
|
const references: TopicReference[] = [
|
|
98
98
|
{ kind: 'c4-sketch', sketchId: 'c4s-1-abc' },
|
|
99
|
+
{ kind: 'drawing', drawingId: 'drawing-1' },
|
|
99
100
|
{ kind: 'topic', topicId: 'topic-related' },
|
|
100
101
|
];
|
|
101
102
|
const created = await store.createTopic({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
|
-
import { toPortableDocument } from "./subsystem-model";
|
|
4
|
+
import { isUnbuiltComponent, isUnbuiltStep, proposalAction, stepProposalAction, toPortableDocument } from "./subsystem-model";
|
|
5
5
|
|
|
6
6
|
const schema = JSON.parse(
|
|
7
7
|
readFileSync(
|
|
@@ -10,7 +10,7 @@ const schema = JSON.parse(
|
|
|
10
10
|
),
|
|
11
11
|
) as {
|
|
12
12
|
properties: Record<string, unknown>;
|
|
13
|
-
$defs: Record<string, { properties?: Record<string, unknown
|
|
13
|
+
$defs: Record<string, { properties?: Record<string, unknown>; enum?: string[] }>;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
describe("toPortableDocument", () => {
|
|
@@ -25,6 +25,17 @@ describe("toPortableDocument", () => {
|
|
|
25
25
|
expect(portable.verifiedAtCommits).toEqual({ "pkg:github/a/b": "def" });
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
+
test("keeps the description / notes split", () => {
|
|
29
|
+
const portable = toPortableDocument({
|
|
30
|
+
title: "t",
|
|
31
|
+
components: [],
|
|
32
|
+
description: "Short blurb.",
|
|
33
|
+
notes: "## Extended\n\nLonger context.",
|
|
34
|
+
} as unknown as Parameters<typeof toPortableDocument>[0]);
|
|
35
|
+
expect(portable.description).toBe("Short blurb.");
|
|
36
|
+
expect(portable.notes).toBe("## Extended\n\nLonger context.");
|
|
37
|
+
});
|
|
38
|
+
|
|
28
39
|
test("still drops store metadata", () => {
|
|
29
40
|
const portable = toPortableDocument({
|
|
30
41
|
title: "t",
|
|
@@ -46,6 +57,12 @@ describe("subsystem-model schema", () => {
|
|
|
46
57
|
expect(schema.properties.verifiedAtCommits).toBeDefined();
|
|
47
58
|
});
|
|
48
59
|
|
|
60
|
+
test("caps the short description and declares extended notes", () => {
|
|
61
|
+
const description = schema.properties.description as { maxLength?: number };
|
|
62
|
+
expect(description.maxLength).toBe(200);
|
|
63
|
+
expect(schema.properties.notes).toBeDefined();
|
|
64
|
+
});
|
|
65
|
+
|
|
49
66
|
test("declares a content-addressed source span", () => {
|
|
50
67
|
// The identity primitive: start + end + content hash. Replaces the old
|
|
51
68
|
// start-line-only `declarationRef`.
|
|
@@ -65,6 +82,39 @@ describe("subsystem-model schema", () => {
|
|
|
65
82
|
expect(schema.$defs.trailStep?.properties?.target).toBeDefined();
|
|
66
83
|
});
|
|
67
84
|
|
|
85
|
+
test("components and trail steps carry a lifecycle status", () => {
|
|
86
|
+
expect(schema.$defs.status?.enum).toEqual(["built", "proposed-add", "proposed-change", "proposed-remove"]);
|
|
87
|
+
const component = Object.values(schema.$defs).find(
|
|
88
|
+
(d) => (d as { properties?: { alias?: unknown } }).properties?.alias,
|
|
89
|
+
) as { properties: Record<string, unknown> };
|
|
90
|
+
expect(component.properties.status).toBeDefined();
|
|
91
|
+
expect(schema.$defs.trailStep?.properties?.status).toBeDefined();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("a step's proposal follows its own status, then its ends", () => {
|
|
95
|
+
const byAlias = new Map([
|
|
96
|
+
["a", {}],
|
|
97
|
+
["new", { status: "proposed-add" as const }],
|
|
98
|
+
["going", { status: "proposed-remove" as const }],
|
|
99
|
+
["changing", { status: "proposed-change" as const }],
|
|
100
|
+
]);
|
|
101
|
+
expect(proposalAction(byAlias.get("new"))).toBe("add");
|
|
102
|
+
expect(proposalAction(byAlias.get("a"))).toBeUndefined();
|
|
103
|
+
expect(isUnbuiltComponent(byAlias.get("new"))).toBe(true);
|
|
104
|
+
// Changing or going away is still built.
|
|
105
|
+
expect(isUnbuiltComponent(byAlias.get("going"))).toBe(false);
|
|
106
|
+
expect(isUnbuiltComponent(byAlias.get("changing"))).toBe(false);
|
|
107
|
+
|
|
108
|
+
expect(stepProposalAction({ from: "a", to: "a" }, byAlias)).toBeUndefined();
|
|
109
|
+
expect(stepProposalAction({ from: "a", to: "new" }, byAlias)).toBe("add");
|
|
110
|
+
expect(stepProposalAction({ from: "going", to: "a" }, byAlias)).toBe("remove");
|
|
111
|
+
expect(stepProposalAction({ from: "a", to: "changing" }, byAlias)).toBeUndefined();
|
|
112
|
+
expect(stepProposalAction({ from: "a", to: "a", status: "proposed-remove" }, byAlias)).toBe("remove");
|
|
113
|
+
// Only an added step is unbuilt.
|
|
114
|
+
expect(isUnbuiltStep({ from: "a", to: "new" }, byAlias)).toBe(true);
|
|
115
|
+
expect(isUnbuiltStep({ from: "going", to: "a" }, byAlias)).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
68
118
|
test("a store declares its own value type", () => {
|
|
69
119
|
// `additionalProperties: false` on the store declaration, so the field
|
|
70
120
|
// has to be declared here or every typed store would be rejected.
|
|
@@ -299,6 +299,78 @@ export type SubsystemConstructDeclaration =
|
|
|
299
299
|
| SubsystemStoreDeclaration
|
|
300
300
|
| SubsystemCustomEntityDeclaration;
|
|
301
301
|
|
|
302
|
+
/**
|
|
303
|
+
* Where a claim is in its life. Absent means `built`: the code exists, nothing
|
|
304
|
+
* is planned for it, and the claim is verified against it. The `proposed-*`
|
|
305
|
+
* values name what a proposal would do:
|
|
306
|
+
*
|
|
307
|
+
* - `proposed-add` — planned, not built. The claim keeps its real `construct`
|
|
308
|
+
* (and `role`, `declaration`, …) so it draws as the thing it will be, but
|
|
309
|
+
* there is no source yet, so verification skips it.
|
|
310
|
+
* - `proposed-change` — built, and planned to change. Still verified.
|
|
311
|
+
* - `proposed-remove` — built, and planned to go. Still verified until it does.
|
|
312
|
+
*/
|
|
313
|
+
export type SubsystemLifecycleStatus =
|
|
314
|
+
| 'built'
|
|
315
|
+
| 'proposed-add'
|
|
316
|
+
| 'proposed-change'
|
|
317
|
+
| 'proposed-remove';
|
|
318
|
+
|
|
319
|
+
/** What a proposal would do to a claim. */
|
|
320
|
+
export type SubsystemProposalAction = 'add' | 'change' | 'remove';
|
|
321
|
+
|
|
322
|
+
/** The action a claim's `status` proposes, or undefined when it is plainly built. */
|
|
323
|
+
export function proposalAction(
|
|
324
|
+
claim: { status?: SubsystemLifecycleStatus } | undefined,
|
|
325
|
+
): SubsystemProposalAction | undefined {
|
|
326
|
+
switch (claim?.status) {
|
|
327
|
+
case 'proposed-add':
|
|
328
|
+
return 'add';
|
|
329
|
+
case 'proposed-change':
|
|
330
|
+
return 'change';
|
|
331
|
+
case 'proposed-remove':
|
|
332
|
+
return 'remove';
|
|
333
|
+
default:
|
|
334
|
+
return undefined;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** True when the component is planned but not built — there is no source to check. */
|
|
339
|
+
export function isUnbuiltComponent(
|
|
340
|
+
component: Pick<SubsystemComponent, 'status'> | undefined,
|
|
341
|
+
): boolean {
|
|
342
|
+
return proposalAction(component) === 'add';
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* What a proposal would do to a trail step. The step says so itself, or it
|
|
347
|
+
* follows from its ends: a seam into or out of a component that is not built
|
|
348
|
+
* cannot exist yet (`add`), and one touching a component that is going away
|
|
349
|
+
* goes with it (`remove`). A component that merely changes leaves its seams be.
|
|
350
|
+
*/
|
|
351
|
+
export function stepProposalAction(
|
|
352
|
+
step: Pick<SubsystemTrailStep, 'from' | 'to' | 'status'>,
|
|
353
|
+
componentByAlias: ReadonlyMap<string, Pick<SubsystemComponent, 'status'>>,
|
|
354
|
+
): SubsystemProposalAction | undefined {
|
|
355
|
+
const own = proposalAction(step);
|
|
356
|
+
if (own) return own;
|
|
357
|
+
const ends = [
|
|
358
|
+
proposalAction(componentByAlias.get(step.from)),
|
|
359
|
+
proposalAction(componentByAlias.get(step.to)),
|
|
360
|
+
];
|
|
361
|
+
if (ends.includes('add')) return 'add';
|
|
362
|
+
if (ends.includes('remove')) return 'remove';
|
|
363
|
+
return undefined;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** True when a trail step is planned but not built — nothing in the code to check. */
|
|
367
|
+
export function isUnbuiltStep(
|
|
368
|
+
step: Pick<SubsystemTrailStep, 'from' | 'to' | 'status'>,
|
|
369
|
+
componentByAlias: ReadonlyMap<string, Pick<SubsystemComponent, 'status'>>,
|
|
370
|
+
): boolean {
|
|
371
|
+
return stepProposalAction(step, componentByAlias) === 'add';
|
|
372
|
+
}
|
|
373
|
+
|
|
302
374
|
/** A component node — the named unit, construct-tagged. */
|
|
303
375
|
export interface SubsystemComponent {
|
|
304
376
|
/**
|
|
@@ -324,6 +396,14 @@ export interface SubsystemComponent {
|
|
|
324
396
|
logo?: string;
|
|
325
397
|
purpose?: string;
|
|
326
398
|
role?: SubsystemComponentRole;
|
|
399
|
+
/**
|
|
400
|
+
* Lifecycle of the claim; absent means `built`. `proposed-add` is planned
|
|
401
|
+
* work: `file` and `symbol` say where it is meant to live (either may be
|
|
402
|
+
* empty), and verification skips it. `proposed-change` and `proposed-remove`
|
|
403
|
+
* mark a built component a proposal would alter or delete; both stay
|
|
404
|
+
* verified. Drop the field once the proposal lands.
|
|
405
|
+
*/
|
|
406
|
+
status?: SubsystemLifecycleStatus;
|
|
327
407
|
/**
|
|
328
408
|
* The claim was real but its source is gone — deleted or renamed upstream.
|
|
329
409
|
* Verification skips source checks so a model carrying deprecations is no
|
|
@@ -475,6 +555,15 @@ export interface SubsystemTrailStep {
|
|
|
475
555
|
* mechanism + filename fallback.
|
|
476
556
|
*/
|
|
477
557
|
symbol: string;
|
|
558
|
+
/**
|
|
559
|
+
* Lifecycle of the seam; absent means `built`. Mark a step `proposed-add`
|
|
560
|
+
* for a planned seam between two built components, `proposed-remove` for one
|
|
561
|
+
* a proposal would cut. A step that touches a `proposed-add` component is
|
|
562
|
+
* itself an addition without saying so (and one touching a `proposed-remove`
|
|
563
|
+
* component a removal). Verification skips added steps, and an added `calls`
|
|
564
|
+
* step need not carry a `site`.
|
|
565
|
+
*/
|
|
566
|
+
status?: SubsystemLifecycleStatus;
|
|
478
567
|
/**
|
|
479
568
|
* Free-text note anchored to this step's site line. Optional — informative
|
|
480
569
|
* only, never verified against source; viewers surface it via the codeview's
|
|
@@ -502,6 +591,9 @@ export interface SubsystemTrail {
|
|
|
502
591
|
*/
|
|
503
592
|
export type PurlCommit = string;
|
|
504
593
|
|
|
594
|
+
/** Maximum length of a model's authored description (short sidebar blurb). */
|
|
595
|
+
export const SUBSYSTEM_MODEL_DESCRIPTION_MAX = 200;
|
|
596
|
+
|
|
505
597
|
export interface SubsystemModelDocument {
|
|
506
598
|
/**
|
|
507
599
|
* Optional pointer to the JSON Schema that describes this file. Lets editors
|
|
@@ -510,7 +602,18 @@ export interface SubsystemModelDocument {
|
|
|
510
602
|
$schema?: string;
|
|
511
603
|
|
|
512
604
|
title: string;
|
|
605
|
+
/**
|
|
606
|
+
* Short description shown at the top of a model's sidebar. At most
|
|
607
|
+
* {@link SUBSYSTEM_MODEL_DESCRIPTION_MAX} characters; hosts reject longer
|
|
608
|
+
* values and point authors at `notes` instead.
|
|
609
|
+
*/
|
|
513
610
|
description?: string;
|
|
611
|
+
/**
|
|
612
|
+
* Extended Markdown notes about the model. The sidebar shows the short
|
|
613
|
+
* `description` (or a clamped preview of these notes when it is absent);
|
|
614
|
+
* `More` opens the full document in an Overview overlay.
|
|
615
|
+
*/
|
|
616
|
+
notes?: string;
|
|
514
617
|
components: SubsystemComponent[];
|
|
515
618
|
/** Runtime trails (ordered steps with sites). */
|
|
516
619
|
trails?: SubsystemTrail[];
|
|
@@ -570,6 +673,7 @@ export function toPortableDocument(
|
|
|
570
673
|
};
|
|
571
674
|
if (doc.$schema) out.$schema = doc.$schema;
|
|
572
675
|
if (doc.description) out.description = doc.description;
|
|
676
|
+
if (doc.notes) out.notes = doc.notes;
|
|
573
677
|
if (doc.trails) out.trails = doc.trails;
|
|
574
678
|
if (doc.createdAtCommits) out.createdAtCommits = doc.createdAtCommits;
|
|
575
679
|
if (doc.verifiedAtCommits) out.verifiedAtCommits = doc.verifiedAtCommits;
|
package/src/validation.test.ts
CHANGED
|
@@ -32,7 +32,7 @@ describe('validateSubsystemModelCrossField', () => {
|
|
|
32
32
|
{
|
|
33
33
|
id: 'w1',
|
|
34
34
|
title: 'flow',
|
|
35
|
-
steps: [{ from: 'a', to: 'b', mechanism: '
|
|
35
|
+
steps: [{ from: 'a', to: 'b', mechanism: 'uses', file: 'src/a.ts', purl: 'pkg:github/acme/app#src/a.ts', symbol: 'a' }],
|
|
36
36
|
},
|
|
37
37
|
],
|
|
38
38
|
});
|
|
@@ -55,7 +55,7 @@ describe('validateSubsystemModelCrossField', () => {
|
|
|
55
55
|
{
|
|
56
56
|
id: 'w1',
|
|
57
57
|
title: 'flow',
|
|
58
|
-
steps: [{ from: 'ghost', to: 'a', mechanism: '
|
|
58
|
+
steps: [{ from: 'ghost', to: 'a', mechanism: 'uses', file: 'src/a.ts', purl: 'pkg:github/acme/app#src/a.ts', symbol: 'ghost' }],
|
|
59
59
|
},
|
|
60
60
|
],
|
|
61
61
|
}),
|
|
@@ -72,7 +72,7 @@ describe('validateSubsystemModelCrossField', () => {
|
|
|
72
72
|
{
|
|
73
73
|
id: 'w1',
|
|
74
74
|
title: 'flow',
|
|
75
|
-
steps: [{ from: 'a', to: 'a', mechanism: '
|
|
75
|
+
steps: [{ from: 'a', to: 'a', mechanism: 'uses', file: 'src/a.ts', purl: 'pkg:github/acme/app#src/other.ts', symbol: 'a' }],
|
|
76
76
|
},
|
|
77
77
|
],
|
|
78
78
|
}),
|
|
@@ -126,7 +126,7 @@ describe('validateSubsystemModelCrossField', () => {
|
|
|
126
126
|
{
|
|
127
127
|
from: 'a',
|
|
128
128
|
to: 'b',
|
|
129
|
-
mechanism: '
|
|
129
|
+
mechanism: 'uses',
|
|
130
130
|
file: 'src/a.ts',
|
|
131
131
|
purl: 'pkg:github/acme/app#src/a.ts',
|
|
132
132
|
symbol: 'a',
|
|
@@ -219,7 +219,7 @@ describe('validateSubsystemModelCrossField', () => {
|
|
|
219
219
|
{
|
|
220
220
|
from: 'a',
|
|
221
221
|
to: 'a',
|
|
222
|
-
mechanism: '
|
|
222
|
+
mechanism: 'uses',
|
|
223
223
|
file: 'packages/react/node_modules/@pierre/diffs/dist/index.js',
|
|
224
224
|
purl: 'pkg:npm/@pierre/diffs#packages/react/node_modules/@pierre/diffs/dist/index.js',
|
|
225
225
|
symbol: 'a',
|
|
@@ -250,7 +250,7 @@ describe('validateSubsystemModelCrossField', () => {
|
|
|
250
250
|
{
|
|
251
251
|
from: 'a',
|
|
252
252
|
to: 'a',
|
|
253
|
-
mechanism: '
|
|
253
|
+
mechanism: 'uses',
|
|
254
254
|
file: 'src/a.ts',
|
|
255
255
|
purl: 'pkg:github/acme/app#src/a.ts',
|
|
256
256
|
symbol: 'a',
|
|
@@ -280,7 +280,7 @@ describe('validateSubsystemModelCrossField', () => {
|
|
|
280
280
|
{
|
|
281
281
|
from: 'a',
|
|
282
282
|
to: 'a',
|
|
283
|
-
mechanism: '
|
|
283
|
+
mechanism: 'uses',
|
|
284
284
|
file: 'src/a.ts',
|
|
285
285
|
purl: 'pkg:github/acme/app#src/a.ts',
|
|
286
286
|
symbol: 'a',
|
|
@@ -296,4 +296,68 @@ describe('validateSubsystemModelCrossField', () => {
|
|
|
296
296
|
expect(problems[0]!.message).toContain('precedes startLine');
|
|
297
297
|
expect(problems[1]!.path).toBe('/trails/0/steps/0/span');
|
|
298
298
|
});
|
|
299
|
+
|
|
300
|
+
test('a built calls step needs a site; a proposed one does not', () => {
|
|
301
|
+
const step = {
|
|
302
|
+
from: 'a',
|
|
303
|
+
to: 'b',
|
|
304
|
+
mechanism: 'calls' as const,
|
|
305
|
+
file: 'src/a.ts',
|
|
306
|
+
purl: 'pkg:github/acme/app#src/a.ts',
|
|
307
|
+
symbol: 'a',
|
|
308
|
+
};
|
|
309
|
+
const trails = (extra: object = {}) => [{ id: 'w1', title: 'flow', steps: [{ ...step, ...extra }] }];
|
|
310
|
+
|
|
311
|
+
const built = validateSubsystemModelCrossField(
|
|
312
|
+
doc({ components: [comp('a'), comp('b')], trails: trails() }),
|
|
313
|
+
);
|
|
314
|
+
expect(built.map((p) => p.path)).toEqual(['/trails/0/steps/0/site']);
|
|
315
|
+
|
|
316
|
+
// The step says so itself.
|
|
317
|
+
expect(
|
|
318
|
+
validateSubsystemModelCrossField(
|
|
319
|
+
doc({ components: [comp('a'), comp('b')], trails: trails({ status: 'proposed-add' }) }),
|
|
320
|
+
),
|
|
321
|
+
).toEqual([]);
|
|
322
|
+
// Or it reaches a proposed component.
|
|
323
|
+
expect(
|
|
324
|
+
validateSubsystemModelCrossField(
|
|
325
|
+
doc({
|
|
326
|
+
components: [comp('a'), comp('b', { status: 'proposed-add', file: '' })],
|
|
327
|
+
trails: trails(),
|
|
328
|
+
}),
|
|
329
|
+
),
|
|
330
|
+
).toEqual([]);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test('a proposed component may claim a module without a file', () => {
|
|
334
|
+
expect(
|
|
335
|
+
validateSubsystemModelCrossField(
|
|
336
|
+
doc({ components: [comp('a', { status: 'proposed-add', file: '', module: 'src/search.ts' })] }),
|
|
337
|
+
),
|
|
338
|
+
).toEqual([]);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
test('a component proposed for change or removal is still built: it needs its file and site', () => {
|
|
342
|
+
const problems = validateSubsystemModelCrossField(
|
|
343
|
+
doc({
|
|
344
|
+
components: [comp('a'), comp('b', { status: 'proposed-remove', file: '', module: 'src/b.ts' })],
|
|
345
|
+
trails: [
|
|
346
|
+
{
|
|
347
|
+
id: 'w1',
|
|
348
|
+
title: 'flow',
|
|
349
|
+
steps: [{ from: 'a', to: 'b', mechanism: 'calls', file: 'src/a.ts', purl: 'pkg:github/acme/app#src/a.ts', symbol: 'a' }],
|
|
350
|
+
},
|
|
351
|
+
],
|
|
352
|
+
}),
|
|
353
|
+
);
|
|
354
|
+
expect(problems.map((p) => p.path).sort()).toEqual(['/components/1/module', '/trails/0/steps/0/site']);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
test('flags a component that is both proposed and deprecated', () => {
|
|
358
|
+
const problems = validateSubsystemModelCrossField(
|
|
359
|
+
doc({ components: [comp('a', { status: 'proposed-add', deprecated: true })] }),
|
|
360
|
+
);
|
|
361
|
+
expect(problems.map((p) => p.path)).toEqual(['/components/0/status']);
|
|
362
|
+
});
|
|
299
363
|
});
|
package/src/validation.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* Pure and dependency-free (browser-safe) — no JSON Schema validator here.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
import { isUnbuiltStep } from './types/subsystem-model';
|
|
14
15
|
import type {
|
|
15
16
|
SubsystemModelDocument,
|
|
16
17
|
SubsystemComponent,
|
|
@@ -27,8 +28,9 @@ export interface SubsystemValidationProblem {
|
|
|
27
28
|
function isUngrounded(c: SubsystemComponent): boolean {
|
|
28
29
|
// Deprecated components are exempt: the file is a historical pointer to
|
|
29
30
|
// source that is gone, so it cannot resolve and its absence is not an
|
|
30
|
-
// inconsistency.
|
|
31
|
-
|
|
31
|
+
// inconsistency. Components proposed for addition are exempt too: the file says where
|
|
32
|
+
// the code is meant to live, and may be empty until that is decided.
|
|
33
|
+
return c.construct === 'external' || c.deprecated === true || c.status === 'proposed-add';
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
/**
|
|
@@ -113,6 +115,14 @@ export function validateSubsystemModelCrossField(
|
|
|
113
115
|
message: `component ${JSON.stringify(c.alias)}: file ${JSON.stringify(file)} points into node_modules — installed artifacts are not part of the repo and cannot be verified. Model the dependency as construct "external" with purl "pkg:npm/<package>" and no file, or anchor the claim to the package's real source.`,
|
|
114
116
|
});
|
|
115
117
|
}
|
|
118
|
+
// Proposed for addition is "not built yet"; deprecated is "was built, now
|
|
119
|
+
// gone". A component cannot be both.
|
|
120
|
+
if (c.status === 'proposed-add' && c.deprecated === true) {
|
|
121
|
+
problems.push({
|
|
122
|
+
path: `/components/${i}/status`,
|
|
123
|
+
message: `component ${JSON.stringify(c.alias)}: status "proposed-add" and deprecated cannot both be set — a component that is not built has no source to have been removed.`,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
116
126
|
const spanProblem = spanRangeProblem(
|
|
117
127
|
c.declarationSpan,
|
|
118
128
|
`/components/${i}/declarationSpan`,
|
|
@@ -121,8 +131,23 @@ export function validateSubsystemModelCrossField(
|
|
|
121
131
|
if (spanProblem) problems.push(spanProblem);
|
|
122
132
|
});
|
|
123
133
|
|
|
134
|
+
const componentByAlias = new Map(components.map((c) => [c.alias, c]));
|
|
124
135
|
trails.forEach((w: SubsystemTrail, ti) => {
|
|
125
136
|
(w.steps ?? []).forEach((step, si) => {
|
|
137
|
+
// A built calls step claims the site is the caller frame, so it must
|
|
138
|
+
// carry the enclosing site construct. A proposed step has no caller
|
|
139
|
+
// frame yet. (The schema cannot tell: a step is also proposed when
|
|
140
|
+
// either end is.)
|
|
141
|
+
if (
|
|
142
|
+
step.mechanism === 'calls' &&
|
|
143
|
+
!step.site &&
|
|
144
|
+
!isUnbuiltStep(step, componentByAlias)
|
|
145
|
+
) {
|
|
146
|
+
problems.push({
|
|
147
|
+
path: `/trails/${ti}/steps/${si}/site`,
|
|
148
|
+
message: `trail ${JSON.stringify(w.id)}: step ${si} is a calls step with no site — add the enclosing caller declaration (symbol + span), or mark the step status "proposed-add" if the call is not built yet.`,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
126
151
|
if (!ids.has(step.from)) {
|
|
127
152
|
problems.push({
|
|
128
153
|
path: `/trails/${ti}/steps/${si}/from`,
|