archctx-contracts 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fixtures/invalid/projection-result-applied-incomplete-coverage.json +3 -3
- package/fixtures/valid/archctx-capabilities.json +2 -2
- package/fixtures/valid/flow-selector-check.json +1 -1
- package/fixtures/valid/product-version-manifest.json +5 -11
- package/fixtures/valid/projection-manifest.json +1 -1
- package/fixtures/valid/projection-result.json +3 -3
- package/package.json +4 -1
- package/schemas/repo/refactor-decision.schema.json +283 -37
- package/schemas/runtime/archctx-capabilities.schema.json +144 -20
- package/schemas/runtime/architecture-debt-delta.schema.json +58 -19
- package/schemas/runtime/architecture-debt.schema.json +42 -42
- package/schemas/runtime/architecture-event.schema.json +1 -1
- package/schemas/runtime/architecture-history.schema.json +354 -0
- package/schemas/runtime/capability-dependencies.schema.json +266 -59
- package/schemas/runtime/cli-check.schema.json +197 -0
- package/schemas/runtime/cli-help.schema.json +28 -0
- package/schemas/runtime/dependency-constraint-evaluation.schema.json +67 -68
- package/schemas/runtime/docs-anchors.schema.json +250 -67
- package/schemas/runtime/doctor-code-facts.schema.json +49 -0
- package/schemas/runtime/evidence-binding.schema.json +1 -1
- package/schemas/runtime/flow-selector-check.schema.json +179 -46
- package/schemas/runtime/hook-debt-checkpoint.schema.json +12 -12
- package/schemas/runtime/index-seed.schema.json +56 -0
- package/schemas/runtime/path-context.schema.json +108 -0
- package/schemas/runtime/product-version-manifest.schema.json +142 -54
- package/schemas/runtime/projection-apply-readback.schema.json +2 -2
- package/schemas/runtime/projection-apply-recovery.schema.json +1 -1
- package/schemas/runtime/projection-result.schema.json +1 -1
- package/schemas/runtime/projection-slice.schema.json +34 -34
- package/schemas/runtime/recommendation-v3.schema.json +372 -1
- package/schemas/runtime/ref-impact-batch-request.schema.json +20 -7
- package/schemas/runtime/ref-impact-batch.schema.json +83 -13
- package/schemas/runtime/ref-impact.schema.json +68 -61
- package/schemas/runtime/refactor-scan-v2.schema.json +434 -0
- package/schemas/runtime/refactor-simulate.schema.json +505 -0
- package/schemas/runtime/refactor-verify-v2.schema.json +172 -0
- package/schemas/runtime/resolve-path.schema.json +69 -0
- package/schemas/runtime/runtime-recommendation-show.schema.json +531 -2
- package/schemas/runtime/runtime-refactor-scan.schema.json +498 -2
- package/schemas/runtime/runtime-verify.schema.json +274 -56
- package/schemas/runtime/state-machine-check.schema.json +357 -89
- package/schemas/runtime/structural-observation-payload.schema.json +372 -1
- package/schemas/runtime/sync-check.schema.json +65 -0
- package/src/architecture-debt.ts +125 -38
- package/src/architecture-history.ts +168 -42
- package/src/architecture.ts +100 -0
- package/src/cli-read.ts +228 -0
- package/src/docs-anchors.ts +105 -50
- package/src/explorer-occurrence-ports.ts +175 -0
- package/src/explorer-query-ports.ts +270 -0
- package/src/failure.ts +3 -0
- package/src/index-seed.ts +42 -0
- package/src/index.ts +5 -0
- package/src/ledger-records.ts +262 -0
- package/src/ledger.ts +27 -566
- package/src/ownership-dependencies.ts +115 -5
- package/src/ports.ts +12 -543
- package/src/product-version.ts +75 -56
- package/src/projection-apply-types.ts +216 -0
- package/src/projection-apply-validators.ts +355 -0
- package/src/projection-capabilities.ts +181 -0
- package/src/projection-constants.ts +317 -0
- package/src/projection-manifest-types.ts +298 -0
- package/src/projection-manifest.ts +12 -299
- package/src/projection-recovery-validators.ts +229 -0
- package/src/projection-request-validators.ts +326 -0
- package/src/projection-types.ts +365 -0
- package/src/projection-validation-helpers.ts +15 -0
- package/src/projection.ts +7 -1689
- package/src/ref-impact.ts +225 -33
- package/src/refactor-constants.ts +213 -0
- package/src/refactor-decision-validators.ts +350 -0
- package/src/refactor-evidence-types.ts +286 -0
- package/src/refactor-observation-validators.ts +359 -0
- package/src/refactor-resolution-validators.ts +229 -0
- package/src/refactor-snapshot-validators.ts +368 -0
- package/src/refactor-types.ts +270 -0
- package/src/refactor-v2.ts +389 -0
- package/src/refactor-validation-helpers.ts +195 -0
- package/src/refactor.ts +7 -1849
- package/src/review-guards.ts +3 -23
- package/src/runtime-verify.ts +87 -0
- package/src/schema-kit.ts +183 -0
- package/src/schema-registry.ts +73 -0
- package/src/schema.ts +0 -4
- package/src/state-machine-schemas.ts +192 -0
- package/src/state-machine-types.ts +188 -0
- package/src/state-machine.ts +9 -189
- package/fixtures/boundary/agent-job-expired.json +0 -33
- package/fixtures/invalid/adapter-fidelity-reverse-sync.json +0 -9
- package/fixtures/invalid/agent-job-direct-mutation.json +0 -32
- package/fixtures/invalid/cloud-egress-envelope-private-field.json +0 -12
- package/fixtures/invalid/investigation-report-direct-mutation.json +0 -38
- package/fixtures/invalid/investigation-report-missing-proposed-delta.json +0 -19
- package/fixtures/invalid/notification-event-code-field.json +0 -11
- package/fixtures/valid/adapter-fidelity.json +0 -9
- package/fixtures/valid/agent-job.json +0 -33
- package/fixtures/valid/architecture-candidate-delta-policy.json +0 -45
- package/fixtures/valid/architecture-candidate-delta.json +0 -188
- package/fixtures/valid/chatgpt-ga-tool.json +0 -9
- package/fixtures/valid/cloud-egress-envelope.json +0 -11
- package/fixtures/valid/entitlement.json +0 -12
- package/fixtures/valid/investigation-report.json +0 -38
- package/fixtures/valid/likec4-mapping.json +0 -14
- package/fixtures/valid/notification-event.json +0 -10
- package/fixtures/valid/notification-provider.json +0 -12
- package/fixtures/valid/structurizr-mapping.json +0 -15
- package/schemas/cloud/cloud-egress-envelope.schema.json +0 -19
- package/schemas/cloud/entitlement.schema.json +0 -24
- package/schemas/integrations/adapter-fidelity.schema.json +0 -21
- package/schemas/integrations/chatgpt-ga-tool.schema.json +0 -25
- package/schemas/integrations/likec4-mapping.schema.json +0 -32
- package/schemas/integrations/structurizr-mapping.schema.json +0 -33
- package/schemas/runtime/agent-job.schema.json +0 -63
- package/schemas/runtime/architecture-candidate-delta-policy.schema.json +0 -129
- package/schemas/runtime/architecture-candidate-delta.schema.json +0 -386
- package/schemas/runtime/investigation-report.schema.json +0 -119
- package/schemas/runtime/notification-event.schema.json +0 -18
- package/schemas/runtime/notification-provider.schema.json +0 -26
|
@@ -1,153 +1,21 @@
|
|
|
1
|
-
import type { ProjectionTargetFormat, ProjectionTargetOwnership, ProjectionTargetScopeKind, ProjectionTargetType } from "./ledger";
|
|
1
|
+
import type { ProjectionTargetFormat, ProjectionTargetOwnership, ProjectionTargetScopeKind, ProjectionTargetType } from "./ledger-records";
|
|
2
2
|
import {
|
|
3
3
|
ARCHITECTURE_DOCS_RENDERER_VERSION,
|
|
4
4
|
PROJECTION_REQUEST_SCHEMA_VERSION,
|
|
5
5
|
ARCHITECTURE_SEMANTIC_FACETS,
|
|
6
|
-
isArchitectureCapabilityProofStatus,
|
|
7
|
-
type ArchitectureCapabilityProofStatusV1,
|
|
8
|
-
type ArchitectureDigestSetV2,
|
|
9
|
-
type ArchitectureSemanticFacet,
|
|
10
6
|
type Sha256Digest
|
|
11
|
-
} from "./projection";
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* header line leaves the file byte-identical. Header lines change only on a protocol upgrade, the
|
|
22
|
-
* one Git-visible anchor is `semanticBaseline.modelDigest`, and every other line belongs to one
|
|
23
|
-
* capability or one target. Two pull requests that touch different capabilities therefore rewrite
|
|
24
|
-
* disjoint lines. The global digests a run still needs (flow proof, projection) are computed from
|
|
25
|
-
* the rows when the manifest is read (`architectureDocsProjectionManifestDigests`).
|
|
26
|
-
*
|
|
27
|
-
* A `v1`, `v2` or `v3` manifest is read only for its `schemaVersion` and refused with
|
|
28
|
-
* `projection-manifest-upgrade-required`; nothing else in it is read.
|
|
29
|
-
*/
|
|
30
|
-
export const ARCHITECTURE_DOCS_PROJECTION_MANIFEST_SCHEMA_VERSION = "archcontext.architecture-docs-projection-manifest/v4" as const;
|
|
31
|
-
/** Manifest versions earlier releases wrote. Only their `schemaVersion` is read, to refuse them. */
|
|
32
|
-
export const SUPERSEDED_ARCHITECTURE_DOCS_PROJECTION_MANIFEST_SCHEMA_VERSIONS = [
|
|
33
|
-
"archcontext.architecture-docs-projection-manifest/v1",
|
|
34
|
-
"archcontext.architecture-docs-projection-manifest/v2",
|
|
35
|
-
"archcontext.architecture-docs-projection-manifest/v3"
|
|
36
|
-
] as const;
|
|
37
|
-
/**
|
|
38
|
-
* The one-time re-baseline an operator runs after the migration preconditions in the runbook are
|
|
39
|
-
* met. The profile comes from the repository, not from a superseded manifest, so the command names
|
|
40
|
-
* both supported profiles instead of guessing.
|
|
41
|
-
*/
|
|
42
|
-
export const ARCHITECTURE_DOCS_PROJECTION_MANIFEST_UPGRADE_COMMAND = "archctx docs apply --approved --profile <default|repo-harness/v1>" as const;
|
|
43
|
-
/** The operator runbook that pairs a re-baseline with its prerequisites (model restoration, upgrade path, receipt drain). */
|
|
44
|
-
export const ARCHITECTURE_DOCS_PROJECTION_MANIFEST_MIGRATION_GUIDE = "docs/runbooks/architecture-documentation-projections.md" as const;
|
|
45
|
-
/** The reason code of a refused superseded manifest; the operator re-baselines once with `archctx docs apply --approved`. */
|
|
46
|
-
export const PROJECTION_MANIFEST_UPGRADE_REQUIRED = "projection-manifest-upgrade-required" as const;
|
|
47
|
-
/** The reason code of a current-format manifest that fails its contract; restore it from Git. */
|
|
48
|
-
export const PROJECTION_MANIFEST_INVALID = "projection-manifest-invalid" as const;
|
|
49
|
-
/** The reason code of a declared source footprint that no entity-summary or topology target documents. */
|
|
50
|
-
export const PROJECTION_FOOTPRINT_UNCOVERED = "projection-footprint-uncovered" as const;
|
|
51
|
-
export const ARCHITECTURE_DOCS_PROJECTION_PROVENANCE_SCHEMA_VERSION = "archcontext.architecture-docs-projection-provenance/v3" as const;
|
|
52
|
-
export const ARCHITECTURE_DOCS_LAYOUT_VERSION_V1 = "archcontext.docs-layout/v1" as const;
|
|
53
|
-
export const ARCHITECTURE_SEMANTIC_STATE_SCHEMA_VERSION = "archcontext.architecture-semantic-state/v1" as const;
|
|
54
|
-
export const ARCHITECTURE_DOCS_PROJECTION_PROFILES = ["default", "repo-harness/v1"] as const;
|
|
55
|
-
|
|
56
|
-
export type ArchitectureDocsProjectionProfile = (typeof ARCHITECTURE_DOCS_PROJECTION_PROFILES)[number];
|
|
57
|
-
|
|
58
|
-
export interface ArchitectureCapabilitySemanticStateV1 {
|
|
59
|
-
capabilityId: string;
|
|
60
|
-
memberNodeIds: string[];
|
|
61
|
-
semanticFingerprint: string;
|
|
62
|
-
flowProofFingerprint: string;
|
|
63
|
-
proofStatus: ArchitectureCapabilityProofStatusV1;
|
|
64
|
-
facets: Record<ArchitectureSemanticFacet, string>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface ArchitectureSemanticStateV1 {
|
|
68
|
-
schemaVersion: typeof ARCHITECTURE_SEMANTIC_STATE_SCHEMA_VERSION;
|
|
69
|
-
capabilities: ArchitectureCapabilitySemanticStateV1[];
|
|
70
|
-
semanticFingerprint: string;
|
|
71
|
-
flowProofFingerprint: string;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* The inputs besides the model that the flow proofs of one projection were compiled from, per
|
|
76
|
-
* capability. Committed acceptance compares the manifest's value with a fresh measurement: a
|
|
77
|
-
* capability whose proof moved while its semantic fingerprint held is explained by the journaled
|
|
78
|
-
* model only when its selector-evidence digest and the renderer are unchanged (ADR-0056 §5).
|
|
79
|
-
*/
|
|
80
|
-
export interface ArchitectureProjectionProofEvidenceV2 {
|
|
81
|
-
rendererVersion: string;
|
|
82
|
-
/** Per capability: digest of the proof-relevant selector evidence its flows cite. */
|
|
83
|
-
selectorEvidenceDigests: Record<string, string>;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Projection provenance of one run. Runtime only: receipts, recovery bindings and envelopes carry
|
|
88
|
-
* it, the committed manifest does not (#327). It records machine-independent values only: content
|
|
89
|
-
* digests of the model and the declared sources, plus renderer, layout and CodeGraph versions.
|
|
90
|
-
* HEAD, the full-worktree digest, the CodeGraph evidence digest, the indexed-worktree digest and
|
|
91
|
-
* the CodeGraph status are runtime snapshot facts (#277).
|
|
92
|
-
*/
|
|
93
|
-
export interface ArchitectureDocumentationProjectionProvenanceV3 {
|
|
94
|
-
schemaVersion: typeof ARCHITECTURE_DOCS_PROJECTION_PROVENANCE_SCHEMA_VERSION;
|
|
95
|
-
sourceTreeDigest: string;
|
|
96
|
-
modelDigest: string;
|
|
97
|
-
projectionInputDigest: string;
|
|
98
|
-
rendererVersion: typeof ARCHITECTURE_DOCS_RENDERER_VERSION;
|
|
99
|
-
layoutVersion: typeof ARCHITECTURE_DOCS_LAYOUT_VERSION_V1;
|
|
100
|
-
/** Reproducible CodeGraph identity only: package name and version (#266, #277). */
|
|
101
|
-
generatedFrom: ArchitectureDocsProjectionGeneratedFromV1;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export type ArchitectureDocsProjectionGeneratedFromV1 = {
|
|
105
|
-
codeGraphPackage: string;
|
|
106
|
-
codeGraphVersion: string;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* One target row of the committed manifest, keyed by `targetId`. The targetId and the renderer
|
|
111
|
-
* version are not repeated in the row: the key and the manifest header carry them. A row records
|
|
112
|
-
* no source state; its `outputDigest` is the target's freshness identity (ADR-0056 §1).
|
|
113
|
-
*/
|
|
114
|
-
export interface ArchitectureDocsProjectionManifestTargetV4 {
|
|
115
|
-
type: ProjectionTargetType;
|
|
116
|
-
scope: { kind: ProjectionTargetScopeKind; id?: string; entityKind?: string };
|
|
117
|
-
path: string;
|
|
118
|
-
ownership: ProjectionTargetOwnership;
|
|
119
|
-
format: ProjectionTargetFormat;
|
|
120
|
-
/** `digestJson({ targetId, body })` of the generated body: the region of a `mixed` target, the whole file of a `generated` one. */
|
|
121
|
-
outputDigest: string;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/** One capability of the committed semantic baseline. */
|
|
125
|
-
export interface ArchitectureDocsProjectionManifestCapabilityV4 extends ArchitectureCapabilitySemanticStateV1 {
|
|
126
|
-
/** Digest of the proof-relevant selector evidence for the selectors this capability's flows cite. */
|
|
127
|
-
selectorEvidenceDigest: string;
|
|
128
|
-
}
|
|
7
|
+
} from "./projection-constants";
|
|
8
|
+
import { isArchitectureCapabilityProofStatus } from "./projection-apply-validators";
|
|
9
|
+
import { isRepoRelativePosixPath } from "./schema";
|
|
10
|
+
import {
|
|
11
|
+
ARCHITECTURE_DOCS_LAYOUT_VERSION_V1,
|
|
12
|
+
ARCHITECTURE_DOCS_PROJECTION_MANIFEST_SCHEMA_VERSION,
|
|
13
|
+
ARCHITECTURE_DOCS_PROJECTION_PROFILES,
|
|
14
|
+
ARCHITECTURE_DOCS_PROJECTION_PROVENANCE_SCHEMA_VERSION,
|
|
15
|
+
isSupersededArchitectureDocsProjectionManifestSchemaVersion
|
|
16
|
+
} from "./projection-manifest-types";
|
|
129
17
|
|
|
130
|
-
export
|
|
131
|
-
schemaVersion: typeof ARCHITECTURE_DOCS_PROJECTION_MANIFEST_SCHEMA_VERSION;
|
|
132
|
-
/**
|
|
133
|
-
* The renderer that wrote this manifest. Any renderer is readable: a renderer bump re-renders
|
|
134
|
-
* the owned outputs (drift reports them stale) and the per-capability proof check compares it.
|
|
135
|
-
*/
|
|
136
|
-
rendererVersion: string;
|
|
137
|
-
/** Optional repository-declared engine floors; preserved by every render. */
|
|
138
|
-
minimumRendererVersion?: string;
|
|
139
|
-
minimumProtocolVersion?: string;
|
|
140
|
-
profile: ArchitectureDocsProjectionProfile;
|
|
141
|
-
layoutVersion: typeof ARCHITECTURE_DOCS_LAYOUT_VERSION_V1;
|
|
142
|
-
generatedFrom: ArchitectureDocsProjectionGeneratedFromV1;
|
|
143
|
-
semanticBaseline: {
|
|
144
|
-
/** The one Git-visible anchor: the digest of the model this baseline was compiled from. */
|
|
145
|
-
modelDigest: string;
|
|
146
|
-
/** Sorted and unique by capabilityId. */
|
|
147
|
-
capabilities: ArchitectureDocsProjectionManifestCapabilityV4[];
|
|
148
|
-
};
|
|
149
|
-
targets: Record<string, ArchitectureDocsProjectionManifestTargetV4>;
|
|
150
|
-
}
|
|
18
|
+
export * from "./projection-manifest-types";
|
|
151
19
|
|
|
152
20
|
const SHA256 = /^sha256:[a-f0-9]{64}$/;
|
|
153
21
|
const TARGET_TYPES: Record<ProjectionTargetType, true> = {
|
|
@@ -163,11 +31,6 @@ const TARGET_TYPES: Record<ProjectionTargetType, true> = {
|
|
|
163
31
|
"architecture-history": true,
|
|
164
32
|
"agent-context": true
|
|
165
33
|
};
|
|
166
|
-
/** The whole-model targets that render the runtime topology (ADR-0049); they document its nodes' footprints. */
|
|
167
|
-
export const RUNTIME_TOPOLOGY_TARGET_TYPES = ["diagram-runtime-topology", "runtime-topology-summary"] as const satisfies readonly ProjectionTargetType[];
|
|
168
|
-
export function isRuntimeTopologyTargetType(type: unknown): type is (typeof RUNTIME_TOPOLOGY_TARGET_TYPES)[number] {
|
|
169
|
-
return typeof type === "string" && (RUNTIME_TOPOLOGY_TARGET_TYPES as readonly string[]).includes(type);
|
|
170
|
-
}
|
|
171
34
|
const SCOPE_KINDS: Record<ProjectionTargetScopeKind, true> = { repository: true, entity: true, relation: true, decision: true, diagram: true };
|
|
172
35
|
const OWNERSHIPS: Record<ProjectionTargetOwnership, true> = { generated: true, mixed: true };
|
|
173
36
|
const FORMATS: Record<ProjectionTargetFormat, true> = { markdown: true, mermaid: true, "structurizr-json": true, likec4: true };
|
|
@@ -235,125 +98,6 @@ export function architectureDocsProjectionManifestSchemaVersion(body: string): s
|
|
|
235
98
|
return typeof schemaVersion === "string" ? schemaVersion : undefined;
|
|
236
99
|
}
|
|
237
100
|
|
|
238
|
-
/** True for a manifest version an earlier release wrote; such a manifest is refused, never read. */
|
|
239
|
-
export function isSupersededArchitectureDocsProjectionManifestSchemaVersion(schemaVersion: string | undefined): boolean {
|
|
240
|
-
return (SUPERSEDED_ARCHITECTURE_DOCS_PROJECTION_MANIFEST_SCHEMA_VERSIONS as readonly (string | undefined)[]).includes(schemaVersion);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* The committed byte layout. JSON, with one rule beyond `JSON.stringify`: every value that one
|
|
245
|
-
* capability or one target owns sits on lines no other capability or target shares, and an
|
|
246
|
-
* unchanged line separates the lines of any two owners. Git merges two branches that touch
|
|
247
|
-
* different owners without a conflict, because a merge conflicts on adjacent changed lines too.
|
|
248
|
-
*
|
|
249
|
-
* - Header lines (`schemaVersion`, `rendererVersion`, `profile`, `layoutVersion`, `generatedFrom`)
|
|
250
|
-
* change only on a protocol upgrade.
|
|
251
|
-
* - `semanticBaseline.modelDigest` is the one shared line a model change rewrites; two concurrent
|
|
252
|
-
* model changes conflict there, as they should.
|
|
253
|
-
* - Each capability entry is indented JSON and starts with its own `capabilityId` line.
|
|
254
|
-
* - Each target row is one line, after a line holding its `targetId` key, in canonical key order.
|
|
255
|
-
*/
|
|
256
|
-
export function serializeArchitectureDocsProjectionManifest(manifest: ArchitectureDocsProjectionManifestV4): string {
|
|
257
|
-
const capabilities = [...manifest.semanticBaseline.capabilities]
|
|
258
|
-
.sort((left, right) => compareStrings(left.capabilityId, right.capabilityId))
|
|
259
|
-
.map(canonicalCapability);
|
|
260
|
-
const capabilityBlock = JSON.stringify(capabilities, null, 2).split("\n").map((line, index) => index === 0 ? line : ` ${line}`).join("\n");
|
|
261
|
-
const targetIds = Object.keys(manifest.targets).sort(compareStrings);
|
|
262
|
-
const targetLines = targetIds.length === 0
|
|
263
|
-
? [" \"targets\": {}"]
|
|
264
|
-
: [
|
|
265
|
-
" \"targets\": {",
|
|
266
|
-
...targetIds.flatMap((targetId, index) => [
|
|
267
|
-
` ${JSON.stringify(targetId)}:`,
|
|
268
|
-
` ${JSON.stringify(canonicalTargetRow(manifest.targets[targetId]!))}${index === targetIds.length - 1 ? "" : ","}`
|
|
269
|
-
]),
|
|
270
|
-
" }"
|
|
271
|
-
];
|
|
272
|
-
return [
|
|
273
|
-
"{",
|
|
274
|
-
` "schemaVersion": ${JSON.stringify(manifest.schemaVersion)},`,
|
|
275
|
-
` "rendererVersion": ${JSON.stringify(manifest.rendererVersion)},`,
|
|
276
|
-
...(manifest.minimumRendererVersion === undefined ? [] : [` "minimumRendererVersion": ${JSON.stringify(manifest.minimumRendererVersion)},`]),
|
|
277
|
-
...(manifest.minimumProtocolVersion === undefined ? [] : [` "minimumProtocolVersion": ${JSON.stringify(manifest.minimumProtocolVersion)},`]),
|
|
278
|
-
` "profile": ${JSON.stringify(manifest.profile)},`,
|
|
279
|
-
` "layoutVersion": ${JSON.stringify(manifest.layoutVersion)},`,
|
|
280
|
-
` "generatedFrom": ${JSON.stringify({ codeGraphPackage: manifest.generatedFrom.codeGraphPackage, codeGraphVersion: manifest.generatedFrom.codeGraphVersion })},`,
|
|
281
|
-
" \"semanticBaseline\": {",
|
|
282
|
-
` "modelDigest": ${JSON.stringify(manifest.semanticBaseline.modelDigest)},`,
|
|
283
|
-
` "capabilities": ${capabilityBlock}`,
|
|
284
|
-
" },",
|
|
285
|
-
...targetLines,
|
|
286
|
-
"}",
|
|
287
|
-
""
|
|
288
|
-
].join("\n");
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/** The runtime semantic state the baseline records: capability entries without their evidence, plus the two aggregates. */
|
|
292
|
-
export function architectureDocsProjectionManifestSemanticState(manifest: ArchitectureDocsProjectionManifestV4): ArchitectureSemanticStateV1 {
|
|
293
|
-
return architectureSemanticStateFromCapabilities(manifest.semanticBaseline.capabilities.map(({ selectorEvidenceDigest: _selectorEvidenceDigest, ...capability }) => capability));
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Assembles a semantic state from its capability entries. The two aggregates are a function of
|
|
298
|
-
* the entries, so the committed manifest records only the entries and every reader recomputes them.
|
|
299
|
-
*/
|
|
300
|
-
export function architectureSemanticStateFromCapabilities(capabilities: readonly ArchitectureCapabilitySemanticStateV1[]): ArchitectureSemanticStateV1 {
|
|
301
|
-
const sorted = [...capabilities].sort((left, right) => compareStrings(left.capabilityId, right.capabilityId));
|
|
302
|
-
return {
|
|
303
|
-
schemaVersion: ARCHITECTURE_SEMANTIC_STATE_SCHEMA_VERSION,
|
|
304
|
-
capabilities: sorted,
|
|
305
|
-
semanticFingerprint: digestJson(sorted.map(({ capabilityId, semanticFingerprint }) => ({ capabilityId, semanticFingerprint })) as unknown as Json),
|
|
306
|
-
flowProofFingerprint: digestJson(sorted.map(({ capabilityId, flowProofFingerprint }) => ({ capabilityId, flowProofFingerprint })) as unknown as Json)
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/** The proof evidence the baseline was compiled from, as `ArchitectureProjectionProofEvidenceV2`. */
|
|
311
|
-
export function architectureDocsProjectionManifestProofEvidence(manifest: ArchitectureDocsProjectionManifestV4): ArchitectureProjectionProofEvidenceV2 {
|
|
312
|
-
return {
|
|
313
|
-
rendererVersion: manifest.rendererVersion,
|
|
314
|
-
selectorEvidenceDigests: Object.fromEntries(manifest.semanticBaseline.capabilities.map((capability) => [capability.capabilityId, capability.selectorEvidenceDigest]))
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* The declared source tree digest of runtime provenance: the digest of every node's footprint
|
|
320
|
-
* digest, by node id. It binds the CodeGraph index and the expected snapshot to the measured tree
|
|
321
|
-
* and is never committed (ADR-0056 §4).
|
|
322
|
-
*/
|
|
323
|
-
export function architectureSourceTreeDigest(footprintDigests: Readonly<Record<string, string>>): Sha256Digest {
|
|
324
|
-
return digestJson({
|
|
325
|
-
schemaVersion: "archcontext.architecture-source-stamps/v1",
|
|
326
|
-
stamps: Object.keys(footprintDigests).sort(compareStrings).map((nodeId) => ({ nodeId, digest: footprintDigests[nodeId]! }))
|
|
327
|
-
} as unknown as Json) as Sha256Digest;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/** The projection digest: renderer, profile and every target's output digest. */
|
|
331
|
-
export function architectureProjectionOutputsDigest(input: {
|
|
332
|
-
rendererVersion: string;
|
|
333
|
-
profile: string;
|
|
334
|
-
outputDigests: Readonly<Record<string, string>>;
|
|
335
|
-
}): Sha256Digest {
|
|
336
|
-
return digestJson({
|
|
337
|
-
schemaVersion: "archcontext.architecture-projection-outputs/v1",
|
|
338
|
-
rendererVersion: input.rendererVersion,
|
|
339
|
-
profile: input.profile,
|
|
340
|
-
outputs: Object.keys(input.outputDigests).sort(compareStrings).map((targetId) => ({ targetId, outputDigest: input.outputDigests[targetId]! }))
|
|
341
|
-
} as unknown as Json) as Sha256Digest;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/** The global digests of a committed manifest, computed from its rows at read time. */
|
|
345
|
-
export function architectureDocsProjectionManifestDigests(manifest: ArchitectureDocsProjectionManifestV4): ArchitectureDigestSetV2 {
|
|
346
|
-
return {
|
|
347
|
-
modelDigest: manifest.semanticBaseline.modelDigest as Sha256Digest,
|
|
348
|
-
flowProofDigest: architectureDocsProjectionManifestSemanticState(manifest).flowProofFingerprint as Sha256Digest,
|
|
349
|
-
projectionDigest: architectureProjectionOutputsDigest({
|
|
350
|
-
rendererVersion: manifest.rendererVersion,
|
|
351
|
-
profile: manifest.profile,
|
|
352
|
-
outputDigests: Object.fromEntries(Object.entries(manifest.targets).map(([targetId, row]) => [targetId, row.outputDigest]))
|
|
353
|
-
})
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
|
|
357
101
|
export function architectureDocsProjectionProvenanceIssues(value: unknown, prefix = "provenance"): string[] {
|
|
358
102
|
const provenance = record(value);
|
|
359
103
|
if (!provenance) return [`${prefix} must be an object`];
|
|
@@ -410,33 +154,6 @@ function generatedFromIssues(value: unknown, prefix: string): string[] {
|
|
|
410
154
|
return issues;
|
|
411
155
|
}
|
|
412
156
|
|
|
413
|
-
function canonicalCapability(capability: ArchitectureDocsProjectionManifestCapabilityV4): ArchitectureDocsProjectionManifestCapabilityV4 {
|
|
414
|
-
return {
|
|
415
|
-
capabilityId: capability.capabilityId,
|
|
416
|
-
memberNodeIds: [...capability.memberNodeIds],
|
|
417
|
-
semanticFingerprint: capability.semanticFingerprint,
|
|
418
|
-
flowProofFingerprint: capability.flowProofFingerprint,
|
|
419
|
-
proofStatus: { p1: capability.proofStatus.p1, p2: capability.proofStatus.p2 },
|
|
420
|
-
facets: Object.fromEntries(Object.keys(capability.facets).sort(compareStrings).map((facet) => [facet, capability.facets[facet as ArchitectureSemanticFacet]])) as Record<ArchitectureSemanticFacet, string>,
|
|
421
|
-
selectorEvidenceDigest: capability.selectorEvidenceDigest
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
function canonicalTargetRow(row: ArchitectureDocsProjectionManifestTargetV4): ArchitectureDocsProjectionManifestTargetV4 {
|
|
426
|
-
return {
|
|
427
|
-
type: row.type,
|
|
428
|
-
scope: {
|
|
429
|
-
kind: row.scope.kind,
|
|
430
|
-
...(row.scope.id !== undefined ? { id: row.scope.id } : {}),
|
|
431
|
-
...(row.scope.entityKind !== undefined ? { entityKind: row.scope.entityKind } : {})
|
|
432
|
-
},
|
|
433
|
-
path: row.path,
|
|
434
|
-
ownership: row.ownership,
|
|
435
|
-
format: row.format,
|
|
436
|
-
outputDigest: row.outputDigest
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
|
|
440
157
|
function manifestTargetIssues(value: unknown, prefix: string): string[] {
|
|
441
158
|
const target = record(value);
|
|
442
159
|
if (!target) return [`${prefix} must be an object`];
|
|
@@ -484,10 +201,6 @@ function isSortedUniqueStrings(values: readonly unknown[]): boolean {
|
|
|
484
201
|
return values.every((value, index) => typeof value === "string" && (index === 0 || (values[index - 1] as string) < value));
|
|
485
202
|
}
|
|
486
203
|
|
|
487
|
-
function compareStrings(left: string, right: string): number {
|
|
488
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
204
|
function versionNumber(value: unknown, family: string): number | undefined {
|
|
492
205
|
if (typeof value !== "string" || !value.startsWith(family)) return undefined;
|
|
493
206
|
const suffix = value.slice(family.length);
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PROJECTION_APPLY_READBACK_RESULT_SCHEMA_VERSION,
|
|
3
|
+
PROJECTION_APPLY_RECEIPT_SCHEMA_VERSION,
|
|
4
|
+
PROJECTION_APPLY_RECOVERY_BINDING_SCHEMA_VERSION,
|
|
5
|
+
PROJECTION_APPLY_RECOVERY_INTENT_SCHEMA_VERSION,
|
|
6
|
+
PROJECTION_APPLY_RECOVERY_PROOF_SCHEMA_VERSION,
|
|
7
|
+
PROJECTION_APPLY_RECOVERY_RESULT_SCHEMA_VERSION,
|
|
8
|
+
type Sha256Digest
|
|
9
|
+
} from "./projection-constants";
|
|
10
|
+
import type { ArchitectureDigestSetV2, ProjectionRequestV1 } from "./projection-types";
|
|
11
|
+
import type {
|
|
12
|
+
ProjectionApplyReadbackResultV2,
|
|
13
|
+
ProjectionApplyReceiptV1,
|
|
14
|
+
ProjectionApplyRecoveryBindingV2,
|
|
15
|
+
ProjectionApplyRecoveryIntentV1,
|
|
16
|
+
ProjectionApplyRecoveryProofV2,
|
|
17
|
+
ProjectionApplyRecoveryResultV2
|
|
18
|
+
} from "./projection-apply-types";
|
|
19
|
+
import {
|
|
20
|
+
architectureRefreshSignalInvariantIssues,
|
|
21
|
+
createProjectionApplyIdentity,
|
|
22
|
+
projectionApplyReadbackRequestInvariantIssues,
|
|
23
|
+
projectionResultInvariantIssues
|
|
24
|
+
} from "./projection-apply-validators";
|
|
25
|
+
import { SHA256_DIGEST, sortedUniqueIssues } from "./projection-validation-helpers";
|
|
26
|
+
import { digestJson, type Json } from "./schema";
|
|
27
|
+
|
|
28
|
+
export function projectionApplyReceiptInvariantIssues(input: ProjectionApplyReceiptV1): string[] {
|
|
29
|
+
const identity = createProjectionApplyIdentity({
|
|
30
|
+
repositoryId: input.identity.repositoryId,
|
|
31
|
+
workspaceId: input.identity.workspaceId,
|
|
32
|
+
acceptedChange: input.identity.acceptedChange,
|
|
33
|
+
changeSetId: input.identity.semanticCommit.changeSetId,
|
|
34
|
+
idempotencyKey: input.identity.semanticCommit.idempotencyKey,
|
|
35
|
+
files: input.result.files,
|
|
36
|
+
refreshSignals: input.result.refreshSignals
|
|
37
|
+
});
|
|
38
|
+
const issues = projectionResultInvariantIssues(input.result);
|
|
39
|
+
if (digestJson(identity as unknown as Json) !== digestJson(input.identity as unknown as Json)) {
|
|
40
|
+
issues.push("projection apply identity must bind the committed files and original refresh signals");
|
|
41
|
+
}
|
|
42
|
+
if (input.result.status !== "applied") issues.push("projection apply receipt result status must be applied");
|
|
43
|
+
// A partial projection is never accepted, so no receipt ever records one.
|
|
44
|
+
if (input.result.coverage !== undefined) issues.push("projection apply receipt result must cover every target");
|
|
45
|
+
if (digestJson(input.result.applyReceipt as unknown as Json) !== digestJson(input.identity as unknown as Json)) {
|
|
46
|
+
issues.push("projection apply receipt result must carry the same apply identity");
|
|
47
|
+
}
|
|
48
|
+
if (input.recovery) issues.push(...projectionApplyRecoveryBindingInvariantIssues(input.recovery, input));
|
|
49
|
+
return issues;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function projectionApplyRecoveryBindingInvariantIssues(
|
|
53
|
+
binding: ProjectionApplyRecoveryBindingV2,
|
|
54
|
+
receipt?: ProjectionApplyReceiptV1
|
|
55
|
+
): string[] {
|
|
56
|
+
const issues = [
|
|
57
|
+
...sortedUniqueIssues("recovery.targets", binding.targets),
|
|
58
|
+
...sortedUniqueIssues("recovery.changedPaths", binding.changedPaths)
|
|
59
|
+
];
|
|
60
|
+
if (binding.schemaVersion !== PROJECTION_APPLY_RECOVERY_BINDING_SCHEMA_VERSION) {
|
|
61
|
+
issues.push("recovery schemaVersion is invalid");
|
|
62
|
+
}
|
|
63
|
+
if (binding.targets.length === 0) issues.push("recovery targets must contain at least one projection target");
|
|
64
|
+
if (binding.requestDigest !== undefined && !SHA256_DIGEST.test(binding.requestDigest)) issues.push("recovery requestDigest must be a SHA-256 digest");
|
|
65
|
+
if (receipt) {
|
|
66
|
+
if (binding.receiptDigest !== receipt.result.receiptDigest) {
|
|
67
|
+
issues.push("recovery receiptDigest must match the committed result receiptDigest");
|
|
68
|
+
}
|
|
69
|
+
if (binding.originalExpectedSnapshot.repositoryId !== receipt.result.inputSnapshot.repositoryId
|
|
70
|
+
|| binding.originalExpectedSnapshot.workspaceId !== receipt.result.inputSnapshot.workspaceId
|
|
71
|
+
|| binding.originalExpectedSnapshot.headSha !== receipt.result.inputSnapshot.headSha
|
|
72
|
+
|| binding.originalExpectedSnapshot.worktreeDigest !== receipt.result.inputSnapshot.worktreeDigest) {
|
|
73
|
+
issues.push("recovery originalExpectedSnapshot must match the committed input snapshot");
|
|
74
|
+
}
|
|
75
|
+
if (binding.rendererVersion !== receipt.result.outputSnapshot.rendererVersion
|
|
76
|
+
|| binding.layoutVersion !== receipt.result.outputSnapshot.layoutVersion
|
|
77
|
+
|| digestJson(binding.generatedFrom as unknown as Json) !== digestJson(receipt.result.outputSnapshot.generatedFrom as unknown as Json)) {
|
|
78
|
+
issues.push("recovery renderer, layout, and CodeGraph provenance must match the committed output snapshot");
|
|
79
|
+
}
|
|
80
|
+
const expectedDigests = projectionApplyReceiptResultingDigests(receipt);
|
|
81
|
+
if (!expectedDigests || digestJson(binding.expectedResultingDigests as unknown as Json) !== digestJson(expectedDigests as unknown as Json)) {
|
|
82
|
+
issues.push("recovery expectedResultingDigests must match committed refresh signals");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return issues;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function projectionApplyReadbackResultDigest(input: Omit<ProjectionApplyReadbackResultV2, "readbackDigest">): Sha256Digest {
|
|
89
|
+
return digestJson(input as unknown as Json) as Sha256Digest;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function projectionApplyReadbackResultInvariantIssues(
|
|
93
|
+
input: ProjectionApplyReadbackResultV2,
|
|
94
|
+
request?: ProjectionRequestV1
|
|
95
|
+
): string[] {
|
|
96
|
+
const issues = projectionApplyReceiptInvariantIssues(input.receipt);
|
|
97
|
+
const { readbackDigest, ...body } = input;
|
|
98
|
+
if (input.schemaVersion !== PROJECTION_APPLY_READBACK_RESULT_SCHEMA_VERSION) issues.push("readback schemaVersion is invalid");
|
|
99
|
+
if (projectionApplyReadbackResultDigest(body) !== readbackDigest) issues.push("readbackDigest must bind the complete readback result");
|
|
100
|
+
if (!/^[a-zA-Z0-9_.:-]+$/.test(input.requestId)) issues.push("readback requestId is invalid");
|
|
101
|
+
for (const value of [input.requestDigest, input.current.ownedOutputDigest, input.current.fixedPointDigest]) {
|
|
102
|
+
if (!/^sha256:[a-f0-9]{64}$/.test(value)) issues.push("readback digest is invalid");
|
|
103
|
+
}
|
|
104
|
+
const receipt = input.receipt;
|
|
105
|
+
if (receipt.schemaVersion !== PROJECTION_APPLY_RECEIPT_SCHEMA_VERSION) issues.push("readback receipt schemaVersion is invalid");
|
|
106
|
+
const binding = receipt.recovery;
|
|
107
|
+
if (!binding) return [...issues, "committed receipt lacks its original recovery binding"];
|
|
108
|
+
for (const field of ["repositoryId", "workspaceId", "headSha", "worktreeDigest"] as const) {
|
|
109
|
+
if (input.current.snapshot[field] !== binding.originalExpectedSnapshot[field]) issues.push(`readback current ${field} differs from approval`);
|
|
110
|
+
}
|
|
111
|
+
if (input.current.snapshot.generatedFrom.codeGraphStatus !== "ready"
|
|
112
|
+
|| input.current.snapshot.rendererVersion !== binding.rendererVersion
|
|
113
|
+
|| input.current.snapshot.layoutVersion !== binding.layoutVersion
|
|
114
|
+
|| input.current.snapshot.projectionInputDigest !== receipt.result.outputSnapshot.projectionInputDigest
|
|
115
|
+
|| input.current.snapshot.codeGraphDigest !== receipt.result.outputSnapshot.codeGraphDigest
|
|
116
|
+
|| digestJson(input.current.snapshot.generatedFrom as unknown as Json) !== digestJson(binding.generatedFrom as unknown as Json)
|
|
117
|
+
|| digestJson(input.current.resultingDigests as unknown as Json) !== digestJson(binding.expectedResultingDigests as unknown as Json)
|
|
118
|
+
|| input.current.ownedOutputDigest !== binding.ownedOutputDigest) {
|
|
119
|
+
issues.push("readback current state differs from committed recovery binding");
|
|
120
|
+
}
|
|
121
|
+
if (input.requestId !== receipt.result.requestId) issues.push("readback requestId differs from committed request");
|
|
122
|
+
if (request) {
|
|
123
|
+
issues.push(...projectionApplyReadbackRequestInvariantIssues(request));
|
|
124
|
+
if (input.requestDigest !== digestJson(request as unknown as Json) || input.requestId !== request.requestId) issues.push("readback request identity mismatch");
|
|
125
|
+
if (digestJson(request.expected as unknown as Json) !== digestJson(binding.originalExpectedSnapshot as unknown as Json)
|
|
126
|
+
|| digestJson(request.acceptedChange as unknown as Json) !== digestJson(receipt.identity.acceptedChange as unknown as Json)
|
|
127
|
+
|| digestJson(request.targets as unknown as Json) !== digestJson(binding.targets as unknown as Json)
|
|
128
|
+
|| digestJson(request.changedPaths as unknown as Json) !== digestJson(binding.changedPaths as unknown as Json)) {
|
|
129
|
+
issues.push("readback request differs from committed approval binding");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return issues;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function projectionApplyRecoveryIntentInvariantIssues(input: ProjectionApplyRecoveryIntentV1): string[] {
|
|
136
|
+
const issues: string[] = [];
|
|
137
|
+
if (input.schemaVersion !== PROJECTION_APPLY_RECOVERY_INTENT_SCHEMA_VERSION) issues.push("recovery intent schemaVersion is invalid");
|
|
138
|
+
if (!/^[a-zA-Z0-9_.:-]+$/.test(input.requestId)) issues.push("recovery intent requestId must use the stable identifier character set");
|
|
139
|
+
if (input.profile !== "repo-harness/v1") issues.push("recovery intent profile is invalid");
|
|
140
|
+
for (const field of ["lookupKey", "applyId"] as const) {
|
|
141
|
+
if (!/^sha256:[a-f0-9]{64}$/.test(input.receipt[field])) issues.push(`recovery intent receipt.${field} must be a SHA-256 digest`);
|
|
142
|
+
}
|
|
143
|
+
return issues;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function projectionApplyRecoveryProofDigest(input: Omit<ProjectionApplyRecoveryProofV2, "proofDigest" | "deliveryStatus">): Sha256Digest {
|
|
147
|
+
return digestJson(input as unknown as Json) as Sha256Digest;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function projectionApplyRecoveryProofInvariantIssues(input: ProjectionApplyRecoveryProofV2): string[] {
|
|
151
|
+
const issues = [
|
|
152
|
+
...sortedUniqueIssues("acceptedChange.reasonCodes", input.acceptedChange.reasonCodes),
|
|
153
|
+
...sortedUniqueIssues("acceptedChange.affectedNodeIds", input.acceptedChange.affectedNodeIds)
|
|
154
|
+
];
|
|
155
|
+
if (input.schemaVersion !== PROJECTION_APPLY_RECOVERY_PROOF_SCHEMA_VERSION) issues.push("recovery proof schemaVersion is invalid");
|
|
156
|
+
if (!/^[a-zA-Z0-9_.:-]+$/.test(input.requestId)) issues.push("recovery proof requestId must use the stable identifier character set");
|
|
157
|
+
if (input.current.snapshot.generatedFrom.codeGraphStatus !== "ready") issues.push("recovery proof requires a ready current CodeGraph snapshot");
|
|
158
|
+
const { proofDigest: _proofDigest, deliveryStatus: _deliveryStatus, ...payload } = input;
|
|
159
|
+
if (projectionApplyRecoveryProofDigest(payload) !== input.proofDigest) {
|
|
160
|
+
issues.push("recovery proofDigest must bind the semantic proof payload");
|
|
161
|
+
}
|
|
162
|
+
return issues;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function projectionApplyRecoveryResultInvariantIssues(input: ProjectionApplyRecoveryResultV2): string[] {
|
|
166
|
+
const issues = [
|
|
167
|
+
...projectionApplyRecoveryProofInvariantIssues(input.proof),
|
|
168
|
+
...input.refreshSignals.flatMap((signal, index) => architectureRefreshSignalInvariantIssues(signal, `refreshSignals[${index}]`)),
|
|
169
|
+
...sortedUniqueIssues("refreshSignals.signalId", input.refreshSignals.map((signal) => signal.signalId))
|
|
170
|
+
];
|
|
171
|
+
if (input.schemaVersion !== PROJECTION_APPLY_RECOVERY_RESULT_SCHEMA_VERSION) {
|
|
172
|
+
issues.push("recovery result schemaVersion is invalid");
|
|
173
|
+
}
|
|
174
|
+
if (input.proof.deliveryStatus === "already-delivered" && input.refreshSignals.length > 0) {
|
|
175
|
+
issues.push("already-delivered recovery result cannot repeat refreshSignals");
|
|
176
|
+
}
|
|
177
|
+
for (const [index, signal] of input.refreshSignals.entries()) {
|
|
178
|
+
const prefix = `refreshSignals[${index}]`;
|
|
179
|
+
if (signal.projectionReceiptDigest !== input.proof.receipt.receiptDigest) {
|
|
180
|
+
issues.push(`${prefix}.projectionReceiptDigest must match recovery proof receiptDigest`);
|
|
181
|
+
}
|
|
182
|
+
if (digestJson(signal.acceptedChange as unknown as Json) !== digestJson(input.proof.acceptedChange as unknown as Json)) {
|
|
183
|
+
issues.push(`${prefix}.acceptedChange must match recovery proof approval`);
|
|
184
|
+
}
|
|
185
|
+
if (digestJson(signal.resultingDigests as unknown as Json) !== digestJson(input.proof.expectedResultingDigests as unknown as Json)) {
|
|
186
|
+
issues.push(`${prefix}.resultingDigests must match recovery proof`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return issues;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** The durable store uses this before delivery; it can validate immutable bindings but not re-render the current projection. */
|
|
193
|
+
export function projectionApplyRecoveryProofReceiptInvariantIssues(
|
|
194
|
+
proof: ProjectionApplyRecoveryProofV2,
|
|
195
|
+
receipt: ProjectionApplyReceiptV1
|
|
196
|
+
): string[] {
|
|
197
|
+
const issues = [
|
|
198
|
+
...projectionApplyRecoveryProofInvariantIssues(proof),
|
|
199
|
+
...projectionApplyReceiptInvariantIssues(receipt)
|
|
200
|
+
];
|
|
201
|
+
const binding = receipt.recovery;
|
|
202
|
+
if (!binding) return [...issues, "committed projection receipt does not support semantic recovery"];
|
|
203
|
+
if (proof.receipt.lookupKey !== receipt.identity.lookupKey
|
|
204
|
+
|| proof.receipt.applyId !== receipt.identity.applyId
|
|
205
|
+
|| proof.receipt.receiptDigest !== receipt.result.receiptDigest) {
|
|
206
|
+
issues.push("recovery proof receipt identity must match the committed receipt");
|
|
207
|
+
}
|
|
208
|
+
if (digestJson(proof.acceptedChange as unknown as Json) !== digestJson(receipt.identity.acceptedChange as unknown as Json)
|
|
209
|
+
|| digestJson(proof.expectedResultingDigests as unknown as Json) !== digestJson(binding.expectedResultingDigests as unknown as Json)) {
|
|
210
|
+
issues.push("recovery proof approval binding must match the committed receipt");
|
|
211
|
+
}
|
|
212
|
+
if (digestJson(proof.current.resultingDigests as unknown as Json) !== digestJson(binding.expectedResultingDigests as unknown as Json)
|
|
213
|
+
|| proof.current.ownedOutputDigest !== binding.ownedOutputDigest
|
|
214
|
+
|| proof.current.snapshot.rendererVersion !== binding.rendererVersion
|
|
215
|
+
|| proof.current.snapshot.layoutVersion !== binding.layoutVersion
|
|
216
|
+
|| digestJson(proof.current.snapshot.generatedFrom as unknown as Json) !== digestJson(binding.generatedFrom as unknown as Json)) {
|
|
217
|
+
issues.push("recovery proof current state must match the committed recovery binding");
|
|
218
|
+
}
|
|
219
|
+
return issues;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function projectionApplyReceiptResultingDigests(receipt: ProjectionApplyReceiptV1): ArchitectureDigestSetV2 | undefined {
|
|
223
|
+
const signals = receipt.result.refreshSignals;
|
|
224
|
+
if (signals.length === 0) return undefined;
|
|
225
|
+
const [first] = signals;
|
|
226
|
+
return signals.every((signal) => digestJson(signal.resultingDigests as unknown as Json) === digestJson(first.resultingDigests as unknown as Json))
|
|
227
|
+
? first.resultingDigests
|
|
228
|
+
: undefined;
|
|
229
|
+
}
|