@actuarial-ts/compliance 0.6.1 → 0.7.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/README.md +6 -2
- package/dist/diagnosticArtifactStream.d.ts +30 -0
- package/dist/diagnosticArtifactStream.d.ts.map +1 -0
- package/dist/diagnosticArtifactStream.js +128 -0
- package/dist/diagnosticArtifactStream.js.map +1 -0
- package/dist/diagnosticByteSource.d.ts +10 -0
- package/dist/diagnosticByteSource.d.ts.map +1 -0
- package/dist/diagnosticByteSource.js +70 -0
- package/dist/diagnosticByteSource.js.map +1 -0
- package/dist/diagnosticByteView.d.ts +3 -0
- package/dist/diagnosticByteView.d.ts.map +1 -0
- package/dist/diagnosticByteView.js +27 -0
- package/dist/diagnosticByteView.js.map +1 -0
- package/dist/diagnosticCompactRun.d.ts +43 -0
- package/dist/diagnosticCompactRun.d.ts.map +1 -0
- package/dist/diagnosticCompactRun.js +253 -0
- package/dist/diagnosticCompactRun.js.map +1 -0
- package/dist/diagnosticReplayFrames.d.ts +10 -0
- package/dist/diagnosticReplayFrames.d.ts.map +1 -0
- package/dist/diagnosticReplayFrames.js +99 -0
- package/dist/diagnosticReplayFrames.js.map +1 -0
- package/dist/diagnosticReplayProtocol.d.ts +17 -0
- package/dist/diagnosticReplayProtocol.d.ts.map +1 -0
- package/dist/diagnosticReplayProtocol.js +98 -0
- package/dist/diagnosticReplayProtocol.js.map +1 -0
- package/dist/diagnosticReplayReader.d.ts +41 -0
- package/dist/diagnosticReplayReader.d.ts.map +1 -0
- package/dist/diagnosticReplayReader.js +346 -0
- package/dist/diagnosticReplayReader.js.map +1 -0
- package/dist/diagnosticReplayValue.d.ts +34 -0
- package/dist/diagnosticReplayValue.d.ts.map +1 -0
- package/dist/diagnosticReplayValue.js +269 -0
- package/dist/diagnosticReplayValue.js.map +1 -0
- package/dist/diagnosticReplayWriter.d.ts +25 -0
- package/dist/diagnosticReplayWriter.d.ts.map +1 -0
- package/dist/diagnosticReplayWriter.js +148 -0
- package/dist/diagnosticReplayWriter.js.map +1 -0
- package/dist/diagnosticRun.d.ts.map +1 -1
- package/dist/diagnosticRun.js +1 -193
- package/dist/diagnosticRun.js.map +1 -1
- package/dist/diagnosticRunEvidence.d.ts +18 -0
- package/dist/diagnosticRunEvidence.d.ts.map +1 -0
- package/dist/diagnosticRunEvidence.js +195 -0
- package/dist/diagnosticRunEvidence.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/sha256Stream.d.ts +6 -0
- package/dist/sha256Stream.d.ts.map +1 -0
- package/dist/sha256Stream.js +103 -0
- package/dist/sha256Stream.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/src/diagnosticArtifactStream.ts +148 -0
- package/src/diagnosticByteSource.ts +82 -0
- package/src/diagnosticByteView.ts +27 -0
- package/src/diagnosticCompactRun.ts +462 -0
- package/src/diagnosticReplayFrames.ts +99 -0
- package/src/diagnosticReplayProtocol.ts +99 -0
- package/src/diagnosticReplayReader.ts +428 -0
- package/src/diagnosticReplayValue.ts +269 -0
- package/src/diagnosticReplayWriter.ts +190 -0
- package/src/diagnosticRun.ts +7 -373
- package/src/diagnosticRunEvidence.ts +391 -0
- package/src/index.ts +10 -0
- package/src/sha256Stream.ts +108 -0
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Documentation, judgment, provenance, and reproducibility primitives for actuarial-ts. The package is designed to support compliance work under applicable ASOPs; it neither determines compliance nor replaces the actuary’s review.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npm install @actuarial-ts/compliance@0.
|
|
6
|
+
npm install @actuarial-ts/compliance@0.7.0 @actuarial-ts/core@0.7.0 @actuarial-ts/data@0.7.0 @actuarial-ts/interchange@0.7.0
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
Node 20+, ESM.
|
|
@@ -59,7 +59,11 @@ Material host judgments worth recording in the assumption ledger include amount
|
|
|
59
59
|
|
|
60
60
|
The package also provides estimate metadata, assumption ledgers, ASOP No. 41 draft disclosure generation, ASOP No. 56 model cards, actual-versus-expected roll-forward, and canonical reproducibility bundles.
|
|
61
61
|
|
|
62
|
-
See the [formula catalog](https://github.com/yerromnitsuj/actng/blob/v0.
|
|
62
|
+
See the [formula catalog](https://github.com/yerromnitsuj/actng/blob/v0.7.0/docs/reference/diagnostic-formulas.md) and [migration guide](https://github.com/yerromnitsuj/actng/blob/v0.7.0/docs/migrations/0.6-generalized-diagnostics.md).
|
|
63
|
+
|
|
64
|
+
## Compact provenance and replay streams
|
|
65
|
+
|
|
66
|
+
Version 0.7.0 adds separately authenticated compact provenance and a versioned replay stream. They retain complete audit evidence while avoiding archive-sized identity objects/strings; this is not a dataset-capacity certification. In the source checkout, `docs/reference/diagnostic-replay-stream.md` describes the APIs, host resource limits, wire version, independent verification, and assurance boundaries; that reference document is not part of the npm package. Existing eager provenance and interchange BundleDoc APIs remain unchanged.
|
|
63
67
|
|
|
64
68
|
## License
|
|
65
69
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DiagnosticArtifactDigest } from "./diagnosticRun.js";
|
|
2
|
+
export interface DiagnosticArtifactStreamMetadata {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly scope: "input" | "preparation";
|
|
5
|
+
/** Optional completeness check; no digest handle is issued on truncation. */
|
|
6
|
+
readonly expectedByteLength?: number;
|
|
7
|
+
/** Caller-selected resource ceiling, at most Number.MAX_SAFE_INTEGER. */
|
|
8
|
+
readonly maximumByteLength?: number;
|
|
9
|
+
}
|
|
10
|
+
declare const computedArtifactDigestBrand: unique symbol;
|
|
11
|
+
export type ComputedDiagnosticArtifactDigest = Extract<DiagnosticArtifactDigest, {
|
|
12
|
+
assurance: "sdk-computed";
|
|
13
|
+
}> & {
|
|
14
|
+
readonly [computedArtifactDigestBrand]: true;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Hash the bytes actually received, retaining only a bounded chunk copy.
|
|
18
|
+
* The producer owns I/O. A completed handle means SDK-computed content digest,
|
|
19
|
+
* not source authenticity, a signature, or validation of an actuarial run.
|
|
20
|
+
* Shared buffers are refused; bytes are consumed before requesting the next
|
|
21
|
+
* chunk. A changing producer must be checked again against this digest on replay.
|
|
22
|
+
* Cancellation is cooperative between received chunks; the producer should use
|
|
23
|
+
* the same signal to cancel pending I/O. One synchronous chunk is not interrupted.
|
|
24
|
+
*/
|
|
25
|
+
export declare function digestDiagnosticArtifactChunks(metadata: DiagnosticArtifactStreamMetadata, chunks: AsyncIterable<Uint8Array> | Iterable<Uint8Array>, options?: {
|
|
26
|
+
readonly signal?: AbortSignal;
|
|
27
|
+
}): Promise<ComputedDiagnosticArtifactDigest>;
|
|
28
|
+
export declare function assertComputedDiagnosticArtifactDigest(value: unknown): asserts value is ComputedDiagnosticArtifactDigest;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=diagnosticArtifactStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnosticArtifactStream.d.ts","sourceRoot":"","sources":["../src/diagnosticArtifactStream.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAKnE,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAAC;IACxC,6EAA6E;IAC7E,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,yEAAyE;IACzE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACrC;AACD,OAAO,CAAC,MAAM,2BAA2B,EAAE,OAAO,MAAM,CAAC;AACzD,MAAM,MAAM,gCAAgC,GAAG,OAAO,CACpD,wBAAwB,EACxB;IAAE,SAAS,EAAE,cAAc,CAAA;CAAE,CAC9B,GAAG;IAAE,QAAQ,CAAC,CAAC,2BAA2B,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAiErD;;;;;;;;GAQG;AACH,wBAAsB,8BAA8B,CAClD,QAAQ,EAAE,gCAAgC,EAC1C,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,EACxD,OAAO,GAAE;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GAC9C,OAAO,CAAC,gCAAgC,CAAC,CAuC3C;AAED,wBAAgB,sCAAsC,CACpD,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,KAAK,IAAI,gCAAgC,CAGnD"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { diagnosticJsonPreflight, isDiagnosticPlainRecord, isDiagnosticToken, } from "@actuarial-ts/core";
|
|
2
|
+
import { ComplianceError } from "./errors.js";
|
|
3
|
+
import { createSha256 } from "./sha256Stream.js";
|
|
4
|
+
import { diagnosticByteView } from "./diagnosticByteView.js";
|
|
5
|
+
import { consumeDiagnosticByteSource } from "./diagnosticByteSource.js";
|
|
6
|
+
const computed = new WeakSet();
|
|
7
|
+
const signalAborted = Object.getOwnPropertyDescriptor(AbortSignal.prototype, "aborted").get;
|
|
8
|
+
const throwIfAborted = AbortSignal.prototype.throwIfAborted;
|
|
9
|
+
const COPY_SIZE = 65_536;
|
|
10
|
+
function invalid(message, path = "$") {
|
|
11
|
+
throw new ComplianceError("BAD_DIAGNOSTIC_RUN", message, path);
|
|
12
|
+
}
|
|
13
|
+
function ownedMetadata(value) {
|
|
14
|
+
// Read descriptors once. A Proxy must not pass validation with one property
|
|
15
|
+
// value and supply a different value when the final digest is assembled.
|
|
16
|
+
if (!isDiagnosticPlainRecord(value))
|
|
17
|
+
invalid("Artifact metadata must be a plain object");
|
|
18
|
+
const snapshot = Object.create(null);
|
|
19
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
20
|
+
if (typeof key !== "string")
|
|
21
|
+
invalid("Artifact metadata cannot have symbol keys");
|
|
22
|
+
const field = Object.getOwnPropertyDescriptor(value, key);
|
|
23
|
+
if (!field || !("value" in field) || !field.enumerable)
|
|
24
|
+
invalid("Artifact metadata must contain enumerable data properties", `$.${key}`);
|
|
25
|
+
snapshot[key] = field.value;
|
|
26
|
+
}
|
|
27
|
+
value = snapshot;
|
|
28
|
+
const issues = diagnosticJsonPreflight(value, "input");
|
|
29
|
+
if (issues.length)
|
|
30
|
+
invalid(issues[0].message, issues[0].path);
|
|
31
|
+
if (!isDiagnosticPlainRecord(value))
|
|
32
|
+
invalid("Artifact metadata must be a plain object");
|
|
33
|
+
for (const key of Object.keys(value))
|
|
34
|
+
if (!["id", "scope", "expectedByteLength", "maximumByteLength"].includes(key))
|
|
35
|
+
invalid("Unknown artifact metadata key", `$.${key}`);
|
|
36
|
+
if (!isDiagnosticToken(value.id))
|
|
37
|
+
invalid("Artifact ID must be a valid token", "$.id");
|
|
38
|
+
if (value.scope !== "input" && value.scope !== "preparation")
|
|
39
|
+
invalid("Artifact scope must be input or preparation", "$.scope");
|
|
40
|
+
for (const key of ["expectedByteLength", "maximumByteLength"])
|
|
41
|
+
if (value[key] !== undefined && (!Number.isSafeInteger(value[key]) || value[key] < 0))
|
|
42
|
+
invalid("Byte length must be a nonnegative safe integer", `$.${key}`);
|
|
43
|
+
const maximumByteLength = value.maximumByteLength ?? Number.MAX_SAFE_INTEGER;
|
|
44
|
+
if (value.expectedByteLength !== undefined && value.expectedByteLength > maximumByteLength)
|
|
45
|
+
invalid("Expected byte length exceeds the resource ceiling", "$.expectedByteLength");
|
|
46
|
+
return {
|
|
47
|
+
id: value.id,
|
|
48
|
+
scope: value.scope,
|
|
49
|
+
expectedByteLength: value.expectedByteLength,
|
|
50
|
+
maximumByteLength,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function cancellation(options) {
|
|
54
|
+
if (!isDiagnosticPlainRecord(options))
|
|
55
|
+
invalid("Artifact stream options must be a plain object");
|
|
56
|
+
for (const key of Reflect.ownKeys(options))
|
|
57
|
+
if (key !== "signal")
|
|
58
|
+
invalid("Unknown artifact stream option");
|
|
59
|
+
const field = Object.getOwnPropertyDescriptor(options, "signal");
|
|
60
|
+
if (field && (!("value" in field) || !field.enumerable))
|
|
61
|
+
invalid("Artifact signal must be supplied as a data property");
|
|
62
|
+
const signal = field?.value;
|
|
63
|
+
if (signal === undefined)
|
|
64
|
+
return () => { };
|
|
65
|
+
try {
|
|
66
|
+
signalAborted.call(signal);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
invalid("Artifact signal must be an AbortSignal");
|
|
70
|
+
}
|
|
71
|
+
// Capture the genuine signal and intrinsic method before any producer await.
|
|
72
|
+
return () => throwIfAborted.call(signal);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Hash the bytes actually received, retaining only a bounded chunk copy.
|
|
76
|
+
* The producer owns I/O. A completed handle means SDK-computed content digest,
|
|
77
|
+
* not source authenticity, a signature, or validation of an actuarial run.
|
|
78
|
+
* Shared buffers are refused; bytes are consumed before requesting the next
|
|
79
|
+
* chunk. A changing producer must be checked again against this digest on replay.
|
|
80
|
+
* Cancellation is cooperative between received chunks; the producer should use
|
|
81
|
+
* the same signal to cancel pending I/O. One synchronous chunk is not interrupted.
|
|
82
|
+
*/
|
|
83
|
+
export async function digestDiagnosticArtifactChunks(metadata, chunks, options = {}) {
|
|
84
|
+
const owned = ownedMetadata(metadata);
|
|
85
|
+
const checkCancellation = cancellation(options);
|
|
86
|
+
checkCancellation();
|
|
87
|
+
const hash = createSha256();
|
|
88
|
+
const copy = new Uint8Array(COPY_SIZE);
|
|
89
|
+
let byteLength = 0;
|
|
90
|
+
try {
|
|
91
|
+
for await (const chunk of consumeDiagnosticByteSource(chunks, checkCancellation)) {
|
|
92
|
+
checkCancellation();
|
|
93
|
+
const view = diagnosticByteView(chunk);
|
|
94
|
+
const size = view.byteLength;
|
|
95
|
+
if (!Number.isSafeInteger(byteLength + size) || byteLength + size > owned.maximumByteLength)
|
|
96
|
+
invalid("Artifact byte length exceeds the resource ceiling", "$.chunks");
|
|
97
|
+
if (owned.expectedByteLength !== undefined && byteLength + size > owned.expectedByteLength)
|
|
98
|
+
invalid("Artifact has more bytes than declared", "$.chunks");
|
|
99
|
+
for (let start = 0; start < size; start += COPY_SIZE) {
|
|
100
|
+
const length = Math.min(COPY_SIZE, size - start);
|
|
101
|
+
copy.set(new Uint8Array(view.buffer, view.byteOffset + start, length));
|
|
102
|
+
hash.update(copy.subarray(0, length));
|
|
103
|
+
}
|
|
104
|
+
byteLength += size;
|
|
105
|
+
}
|
|
106
|
+
checkCancellation();
|
|
107
|
+
if (owned.expectedByteLength !== undefined && byteLength !== owned.expectedByteLength)
|
|
108
|
+
invalid("Artifact ended before its declared byte length", "$.chunks");
|
|
109
|
+
const digest = Object.freeze({
|
|
110
|
+
id: owned.id,
|
|
111
|
+
scope: owned.scope,
|
|
112
|
+
assurance: "sdk-computed",
|
|
113
|
+
algorithm: "sha256",
|
|
114
|
+
value: hash.digest(),
|
|
115
|
+
byteLength,
|
|
116
|
+
});
|
|
117
|
+
computed.add(digest);
|
|
118
|
+
return digest;
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
copy.fill(0);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export function assertComputedDiagnosticArtifactDigest(value) {
|
|
125
|
+
if (value === null || typeof value !== "object" || !computed.has(value))
|
|
126
|
+
invalid("Value is not an authentic SDK-computed streamed artifact digest");
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=diagnosticArtifactStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnosticArtifactStream.js","sourceRoot":"","sources":["../src/diagnosticArtifactStream.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,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M,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YACxC,CAAC;YACD,UAAU,IAAI,IAAI,CAAC;QACrB,CAAC;QACD,iBAAiB,EAAE,CAAC;QACpB,IAAI,KAAK,CAAC,kBAAkB,KAAK,SAAS,IAAI,UAAU,KAAK,KAAK,CAAC,kBAAkB;YACnF,OAAO,CAAC,gDAAgD,EAAE,UAAU,CAAC,CAAC;QACxE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;YAC3B,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,SAAS,EAAE,cAAuB;YAClC,SAAS,EAAE,QAAiB;YAC5B,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;YACpB,UAAU;SACX,CAAqC,CAAC;QACvC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACrB,OAAO,MAAM,CAAC;IAChB,CAAC;YAAS,CAAC;QACT,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,UAAU,sCAAsC,CACpD,KAAc;IAEd,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC;QACrE,OAAO,CAAC,iEAAiE,CAAC,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type DiagnosticByteSource = Iterable<Uint8Array> | AsyncIterable<Uint8Array>;
|
|
2
|
+
/**
|
|
3
|
+
* Own one producer iterator through completion, cancellation or read failure.
|
|
4
|
+
* Unlike a bare for-await loop, a rejected next() also closes the producer.
|
|
5
|
+
* A cleanup failure never replaces the error that caused cleanup. Hosts should
|
|
6
|
+
* pass the same cancellation signal to pending I/O; checks cannot interrupt it.
|
|
7
|
+
*/
|
|
8
|
+
export declare function consumeDiagnosticByteSource(source: DiagnosticByteSource, checkCancellation?: () => void): AsyncGenerator<Uint8Array>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=diagnosticByteSource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnosticByteSource.d.ts","sourceRoot":"","sources":["../src/diagnosticByteSource.ts"],"names":[],"mappings":"AAAA,KAAK,oBAAoB,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;AAQ7E;;;;;GAKG;AACH,wBAAuB,2BAA2B,CAChD,MAAM,EAAE,oBAAoB,EAC5B,iBAAiB,GAAE,MAAM,IAAe,GACvC,cAAc,CAAC,UAAU,CAAC,CAgE5B"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
function isObject(value) {
|
|
2
|
+
return (value !== null && (typeof value === "object" || typeof value === "function"));
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Own one producer iterator through completion, cancellation or read failure.
|
|
6
|
+
* Unlike a bare for-await loop, a rejected next() also closes the producer.
|
|
7
|
+
* A cleanup failure never replaces the error that caused cleanup. Hosts should
|
|
8
|
+
* pass the same cancellation signal to pending I/O; checks cannot interrupt it.
|
|
9
|
+
*/
|
|
10
|
+
export async function* consumeDiagnosticByteSource(source, checkCancellation = () => { }) {
|
|
11
|
+
if (!isObject(source))
|
|
12
|
+
throw new TypeError("Diagnostic byte source must be iterable");
|
|
13
|
+
const iterable = source;
|
|
14
|
+
const asynchronous = iterable[Symbol.asyncIterator];
|
|
15
|
+
const method = asynchronous ?? iterable[Symbol.iterator];
|
|
16
|
+
if (typeof method !== "function")
|
|
17
|
+
throw new TypeError("Diagnostic byte source must provide an iterator method");
|
|
18
|
+
const iterator = Reflect.apply(method, source, []);
|
|
19
|
+
if (!isObject(iterator))
|
|
20
|
+
throw new TypeError("Diagnostic byte iterator must be an object");
|
|
21
|
+
const protocol = iterator;
|
|
22
|
+
let completed = false;
|
|
23
|
+
let failed = false;
|
|
24
|
+
try {
|
|
25
|
+
// Capture next once, as the iterator protocol does; never use a producer's
|
|
26
|
+
// potentially overwritten Function.call property.
|
|
27
|
+
const next = protocol.next;
|
|
28
|
+
if (typeof next !== "function")
|
|
29
|
+
throw new TypeError("Diagnostic byte iterator must provide next()");
|
|
30
|
+
for (;;) {
|
|
31
|
+
checkCancellation();
|
|
32
|
+
const result = await Reflect.apply(next, iterator, []);
|
|
33
|
+
if (!isObject(result))
|
|
34
|
+
throw new TypeError("Diagnostic byte read must return an iterator result");
|
|
35
|
+
const item = result;
|
|
36
|
+
completed = Boolean(item.done);
|
|
37
|
+
checkCancellation();
|
|
38
|
+
if (completed)
|
|
39
|
+
return;
|
|
40
|
+
// An async generator also observes a rejected value from a synchronous
|
|
41
|
+
// iterator here, so that failure follows the same cleanup path.
|
|
42
|
+
yield item.value;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
failed = true;
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
if (!completed) {
|
|
51
|
+
try {
|
|
52
|
+
// Read return only when closing, once, following normal iterator
|
|
53
|
+
// semantics. The generator's finally executes at most once.
|
|
54
|
+
const close = protocol.return;
|
|
55
|
+
if (close !== undefined && close !== null) {
|
|
56
|
+
if (typeof close !== "function")
|
|
57
|
+
throw new TypeError("Diagnostic byte iterator return must be a function");
|
|
58
|
+
const result = await Reflect.apply(close, iterator, []);
|
|
59
|
+
if (!isObject(result))
|
|
60
|
+
throw new TypeError("Diagnostic byte iterator return must return an iterator result");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (cleanupError) {
|
|
64
|
+
if (!failed)
|
|
65
|
+
throw cleanupError;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=diagnosticByteSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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,"file":"diagnosticByteView.d.ts","sourceRoot":"","sources":["../src/diagnosticByteView.ts"],"names":[],"mappings":"AAUA,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,CAe1E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ComplianceError } from "./errors.js";
|
|
2
|
+
const typedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
|
|
3
|
+
const byteLength = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteLength").get;
|
|
4
|
+
const byteOffset = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteOffset").get;
|
|
5
|
+
const bufferOf = Object.getOwnPropertyDescriptor(typedArrayPrototype, "buffer").get;
|
|
6
|
+
const arrayBufferLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength")
|
|
7
|
+
.get;
|
|
8
|
+
const resizable = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "resizable")?.get;
|
|
9
|
+
/** Borrow a synchronous intrinsic-only view; callers copy before yielding. */
|
|
10
|
+
export function diagnosticByteView(chunk) {
|
|
11
|
+
const fail = (message) => {
|
|
12
|
+
throw new ComplianceError("BAD_DIAGNOSTIC_RUN", message, "$.chunks");
|
|
13
|
+
};
|
|
14
|
+
if (!(chunk instanceof Uint8Array) || !ArrayBuffer.isView(chunk))
|
|
15
|
+
fail("Artifact chunks must be Uint8Array values");
|
|
16
|
+
const buffer = bufferOf.call(chunk);
|
|
17
|
+
try {
|
|
18
|
+
arrayBufferLength.call(buffer);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
fail("Shared artifact buffers cannot provide a stable byte snapshot");
|
|
22
|
+
}
|
|
23
|
+
if (resizable?.call(buffer))
|
|
24
|
+
fail("Resizable artifact buffers cannot provide a stable byte snapshot");
|
|
25
|
+
return new Uint8Array(buffer, byteOffset.call(chunk), byteLength.call(chunk));
|
|
26
|
+
}
|
|
27
|
+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,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,CAAC,+DAA+D,CAAC,CAAC;IACxE,CAAC;IACD,IAAI,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,kEAAkE,CAAC,CAAC;IAC3E,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type DiagnosticIdentityDocument } from "@actuarial-ts/core";
|
|
2
|
+
import { type CompletedCompactMetricDiagnosticsRun } from "@actuarial-ts/data";
|
|
3
|
+
import { type ComputedDiagnosticArtifactDigest } from "./diagnosticArtifactStream.js";
|
|
4
|
+
import type { DiagnosticArtifactDigest, DiagnosticPreparationLineage, DiagnosticRunIdentity, DiagnosticRunProvenance } from "./diagnosticRun.js";
|
|
5
|
+
/** Computed digests must be authentic completed byte-stream receipts, not JSON copies. */
|
|
6
|
+
export type CompactDiagnosticArtifactEvidence = ComputedDiagnosticArtifactDigest | Extract<DiagnosticArtifactDigest, {
|
|
7
|
+
assurance: "caller-declared";
|
|
8
|
+
}>;
|
|
9
|
+
export interface CreateCompactDiagnosticRunIdentityInput {
|
|
10
|
+
readonly completedRun: CompletedCompactMetricDiagnosticsRun;
|
|
11
|
+
readonly inputArtifacts: readonly CompactDiagnosticArtifactEvidence[];
|
|
12
|
+
readonly preparationArtifacts: readonly CompactDiagnosticArtifactEvidence[];
|
|
13
|
+
readonly preparationLineage: readonly DiagnosticPreparationLineage[];
|
|
14
|
+
}
|
|
15
|
+
declare const verifiedCompactDiagnosticRunProvenanceBrand: unique symbol;
|
|
16
|
+
/**
|
|
17
|
+
* Verified compact evidence, not a legacy provenance DTO or BundleDoc.
|
|
18
|
+
* Documents emit the complete legacy normalized manifest/result identity bytes.
|
|
19
|
+
* They retain immutable owners, not expanded identity arrays or source bytes.
|
|
20
|
+
* The provenance brand, not a structural document, establishes verification.
|
|
21
|
+
*/
|
|
22
|
+
export interface VerifiedCompactDiagnosticRunProvenance extends DiagnosticRunIdentity {
|
|
23
|
+
readonly [verifiedCompactDiagnosticRunProvenanceBrand]: true;
|
|
24
|
+
readonly definition: DiagnosticRunProvenance["definition"];
|
|
25
|
+
readonly inputArtifacts: readonly DiagnosticArtifactDigest[];
|
|
26
|
+
readonly preparationArtifacts: readonly DiagnosticArtifactDigest[];
|
|
27
|
+
readonly preparationLineage: readonly DiagnosticPreparationLineage[];
|
|
28
|
+
readonly preparationFingerprint: string;
|
|
29
|
+
readonly reviewFingerprint: string;
|
|
30
|
+
readonly manifestIdentityDocument: DiagnosticIdentityDocument;
|
|
31
|
+
readonly resultIdentityDocument: DiagnosticIdentityDocument;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Verify an authentic compact completed run and bind completed artifact digests.
|
|
35
|
+
* Synchronous: source bytes were consumed by digestDiagnosticArtifactChunks already.
|
|
36
|
+
* This deliberately replays review/math and compares every identity code unit.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createCompactDiagnosticRunIdentity(input: CreateCompactDiagnosticRunIdentityInput): VerifiedCompactDiagnosticRunProvenance;
|
|
39
|
+
export declare function assertVerifiedCompactDiagnosticRunProvenance(value: unknown): asserts value is VerifiedCompactDiagnosticRunProvenance;
|
|
40
|
+
/** Internal transport plumbing; deliberately not exported from the package index. */
|
|
41
|
+
export declare function getCompactDiagnosticRunOwner(provenance: VerifiedCompactDiagnosticRunProvenance): CompletedCompactMetricDiagnosticsRun;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=diagnosticCompactRun.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnosticCompactRun.d.ts","sourceRoot":"","sources":["../src/diagnosticCompactRun.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,KAAK,0BAA0B,EAChC,MAAM,o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,CAAC;CAC7D;AAuRD;;;;GAIG;AACH,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,uCAAuC,GAC7C,sCAAsC,CAyFxC;AAED,wBAAgB,4CAA4C,CAC1D,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,KAAK,IAAI,sCAAsC,CAGzD;AAED,qFAAqF;AACrF,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,sCAAsC,GACjD,oCAAoC,CAGtC"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { CORE_PACKAGE_VERSION, canonicalFnv1a64, compareDiagnosticIdentityDocuments, createDiagnosticIdentityArray, createDiagnosticIdentityObject, createDiagnosticIdentityValue, fingerprintDiagnosticIdentity, getCompactMetricDiagnosticsResultIdentityDocument, getCompactPreparedDiagnosticDataFingerprint, normalizeDiagnosticsFilterIdentity, runMetricDiagnosticsCompact, } from "@actuarial-ts/core";
|
|
2
|
+
import { DATA_PACKAGE_VERSION, assertCompletedCompactMetricDiagnosticsRun, getCompactDiagnosticReviewReceiptFingerprint, getCompactDiagnosticReviewReceiptIdentityDocument, reviewPreparedDiagnosticDataCompact, } from "@actuarial-ts/data";
|
|
3
|
+
import { assertComputedDiagnosticArtifactDigest, } from "./diagnosticArtifactStream.js";
|
|
4
|
+
import { plain, snapshotLineage, token, validateArtifactGraph, } from "./diagnosticRunEvidence.js";
|
|
5
|
+
import { ComplianceError } from "./errors.js";
|
|
6
|
+
import { COMPLIANCE_PACKAGE_VERSION } from "./version.js";
|
|
7
|
+
const verified = new WeakMap();
|
|
8
|
+
function bad(message, path) {
|
|
9
|
+
throw new ComplianceError("BAD_DIAGNOSTIC_RUN", message, path);
|
|
10
|
+
}
|
|
11
|
+
/** Snapshot boundary metadata without invoking getters or caller array methods. */
|
|
12
|
+
function record(value, allowed, path) {
|
|
13
|
+
if (!plain(value))
|
|
14
|
+
bad("Expected a plain metadata object", path);
|
|
15
|
+
const copy = Object.create(null);
|
|
16
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
17
|
+
if (typeof key !== "string" || !allowed.includes(key))
|
|
18
|
+
bad("Unknown metadata field", `${path}.${String(key)}`);
|
|
19
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
20
|
+
if (!descriptor || !descriptor.enumerable || !("value" in descriptor))
|
|
21
|
+
bad("Metadata fields must be enumerable data properties", `${path}.${key}`);
|
|
22
|
+
copy[key] = descriptor.value;
|
|
23
|
+
}
|
|
24
|
+
return copy;
|
|
25
|
+
}
|
|
26
|
+
function array(value, path) {
|
|
27
|
+
if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype)
|
|
28
|
+
bad("Expected a plain metadata array", path);
|
|
29
|
+
const length = Object.getOwnPropertyDescriptor(value, "length")?.value;
|
|
30
|
+
if (!Number.isSafeInteger(length) || length < 0)
|
|
31
|
+
bad("Invalid array length", path);
|
|
32
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
33
|
+
if (key === "length")
|
|
34
|
+
continue;
|
|
35
|
+
if (typeof key !== "string" ||
|
|
36
|
+
!/^(0|[1-9][0-9]*)$/.test(key) ||
|
|
37
|
+
Number(key) >= length)
|
|
38
|
+
bad("Unexpected array property", `${path}.${String(key)}`);
|
|
39
|
+
}
|
|
40
|
+
const copy = [];
|
|
41
|
+
for (let index = 0; index < length; index++) {
|
|
42
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
|
|
43
|
+
if (!descriptor || !descriptor.enumerable || !("value" in descriptor))
|
|
44
|
+
bad("Array items must be present data properties", `${path}[${index}]`);
|
|
45
|
+
copy.push(descriptor.value);
|
|
46
|
+
}
|
|
47
|
+
return copy;
|
|
48
|
+
}
|
|
49
|
+
function artifacts(value, scope, path) {
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
const result = array(value, path).map((raw, index) => {
|
|
52
|
+
const itemPath = `${path}[${index}]`;
|
|
53
|
+
const item = record(raw, ["id", "scope", "assurance", "algorithm", "value", "byteLength"], itemPath);
|
|
54
|
+
if (typeof item.id !== "string")
|
|
55
|
+
bad("Artifact id must be a string", `${itemPath}.id`);
|
|
56
|
+
token(item.id, `${itemPath}.id`);
|
|
57
|
+
if (seen.has(item.id))
|
|
58
|
+
bad("Artifact IDs must be unique", `${itemPath}.id`);
|
|
59
|
+
seen.add(item.id);
|
|
60
|
+
if (item.scope !== scope)
|
|
61
|
+
bad(`Artifact must have ${scope} scope`, `${itemPath}.scope`);
|
|
62
|
+
if (item.assurance === "sdk-computed") {
|
|
63
|
+
assertComputedDiagnosticArtifactDigest(raw);
|
|
64
|
+
return raw;
|
|
65
|
+
}
|
|
66
|
+
if (item.assurance !== "caller-declared")
|
|
67
|
+
bad("Unknown artifact assurance", `${itemPath}.assurance`);
|
|
68
|
+
if (Object.hasOwn(item, "byteLength"))
|
|
69
|
+
bad("Caller-declared evidence cannot claim a computed byte length", `${itemPath}.byteLength`);
|
|
70
|
+
if (typeof item.algorithm !== "string" || typeof item.value !== "string")
|
|
71
|
+
bad("Declared algorithm and value must be strings", itemPath);
|
|
72
|
+
token(item.algorithm, `${itemPath}.algorithm`);
|
|
73
|
+
token(item.value, `${itemPath}.value`);
|
|
74
|
+
return Object.freeze({
|
|
75
|
+
id: item.id,
|
|
76
|
+
scope,
|
|
77
|
+
assurance: "caller-declared",
|
|
78
|
+
algorithm: item.algorithm,
|
|
79
|
+
value: item.value,
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
return Object.freeze(result.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)));
|
|
83
|
+
}
|
|
84
|
+
function lineage(value) {
|
|
85
|
+
const copied = array(value, "$.preparationLineage").map((raw, index) => {
|
|
86
|
+
const path = `$.preparationLineage[${index}]`;
|
|
87
|
+
const item = record(raw, ["outputArtifactId", "inputArtifactIds", "transformationArtifactIds"], path);
|
|
88
|
+
return {
|
|
89
|
+
outputArtifactId: item.outputArtifactId,
|
|
90
|
+
inputArtifactIds: array(item.inputArtifactIds, `${path}.inputArtifactIds`),
|
|
91
|
+
transformationArtifactIds: array(item.transformationArtifactIds, `${path}.transformationArtifactIds`),
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
return Object.freeze(snapshotLineage(copied).map((edge) => Object.freeze({
|
|
95
|
+
outputArtifactId: edge.outputArtifactId,
|
|
96
|
+
inputArtifactIds: Object.freeze([...edge.inputArtifactIds]),
|
|
97
|
+
transformationArtifactIds: Object.freeze([
|
|
98
|
+
...edge.transformationArtifactIds,
|
|
99
|
+
]),
|
|
100
|
+
})));
|
|
101
|
+
}
|
|
102
|
+
function requireEqual(actual, expected, path) {
|
|
103
|
+
const comparison = compareDiagnosticIdentityDocuments(actual, expected);
|
|
104
|
+
if (!comparison.equal)
|
|
105
|
+
throw new ComplianceError("DIAGNOSTIC_MISMATCH", `Deterministic replay differs at canonical code-unit offset ${comparison.codeUnitOffset}`, path);
|
|
106
|
+
}
|
|
107
|
+
/** Replay before issuing authority; hashes never replace complete identity comparison. */
|
|
108
|
+
function rerunAndVerify(run) {
|
|
109
|
+
const review = reviewPreparedDiagnosticDataCompact({
|
|
110
|
+
prepared: run.prepared,
|
|
111
|
+
evidence: run.review.evidence,
|
|
112
|
+
});
|
|
113
|
+
requireEqual(getCompactDiagnosticReviewReceiptIdentityDocument(review), getCompactDiagnosticReviewReceiptIdentityDocument(run.review), "$.review");
|
|
114
|
+
const rerun = runMetricDiagnosticsCompact({
|
|
115
|
+
prepared: run.prepared,
|
|
116
|
+
groupMap: run.groupMap,
|
|
117
|
+
groupDimensions: run.groupDimensions,
|
|
118
|
+
});
|
|
119
|
+
requireEqual(getCompactMetricDiagnosticsResultIdentityDocument(rerun), getCompactMetricDiagnosticsResultIdentityDocument(run.result), "$.result");
|
|
120
|
+
const counts = review.evaluations.summary;
|
|
121
|
+
const effectiveCounts = {
|
|
122
|
+
pass: counts.pass,
|
|
123
|
+
warning: counts.warning,
|
|
124
|
+
fail: counts.fail,
|
|
125
|
+
"not-evaluated": counts.notEvaluated,
|
|
126
|
+
};
|
|
127
|
+
const statuses = ["pass", "warning", "fail", "not-evaluated"];
|
|
128
|
+
const reviewBlocked = review.report.checks.some((check) => !run.gate.allowedReviewStatuses.includes(check.status)) ||
|
|
129
|
+
statuses.some((status) => effectiveCounts[status] > 0 &&
|
|
130
|
+
!run.gate.allowedReviewStatuses.includes(status));
|
|
131
|
+
const metricBlocked = rerun.findings.some((finding) => finding.category !== "structural" &&
|
|
132
|
+
!run.gate.allowedMetricFindingSeverities.includes(finding.severity));
|
|
133
|
+
if (reviewBlocked ||
|
|
134
|
+
metricBlocked ||
|
|
135
|
+
run.gate.reviewGate !== "passed" ||
|
|
136
|
+
run.gate.metricGate !== "passed")
|
|
137
|
+
throw new ComplianceError("DIAGNOSTIC_MISMATCH", "Diagnostic execution gates do not recompute as passed", "$.gate");
|
|
138
|
+
}
|
|
139
|
+
function manifestDocument(run, inputArtifacts, preparationArtifacts, preparationLineage, preparationFingerprint, reviewFingerprint) {
|
|
140
|
+
const prepared = run.prepared;
|
|
141
|
+
const expectedCells = createDiagnosticIdentityArray(prepared.expectedCells.length, (index) => {
|
|
142
|
+
const cell = prepared.expectedCells[index];
|
|
143
|
+
return createDiagnosticIdentityObject({
|
|
144
|
+
sourceGroup: createDiagnosticIdentityValue(cell.sourceGroup),
|
|
145
|
+
origin: createDiagnosticIdentityValue(cell.origin),
|
|
146
|
+
valuation: createDiagnosticIdentityValue(cell.valuation),
|
|
147
|
+
source: createDiagnosticIdentityValue(cell.source ?? null),
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
return createDiagnosticIdentityObject({
|
|
151
|
+
definitionIntegrity: createDiagnosticIdentityValue(prepared.definition.definitionIntegrity),
|
|
152
|
+
preparationFingerprint: createDiagnosticIdentityValue(preparationFingerprint),
|
|
153
|
+
runPresetId: createDiagnosticIdentityValue(run.runPresetId),
|
|
154
|
+
datasetArtifactId: createDiagnosticIdentityValue(run.datasetArtifactId),
|
|
155
|
+
inputArtifacts: createDiagnosticIdentityValue(inputArtifacts),
|
|
156
|
+
preparationArtifacts: createDiagnosticIdentityValue(preparationArtifacts),
|
|
157
|
+
preparationLineage: createDiagnosticIdentityValue(preparationLineage),
|
|
158
|
+
inputAudit: createDiagnosticIdentityValue(prepared.inputAudit),
|
|
159
|
+
filter: createDiagnosticIdentityValue(normalizeDiagnosticsFilterIdentity(prepared.filter)),
|
|
160
|
+
groupMap: createDiagnosticIdentityValue(run.groupMap),
|
|
161
|
+
groupDimensions: createDiagnosticIdentityValue(run.groupDimensions),
|
|
162
|
+
completePeriodCutoffs: createDiagnosticIdentityValue(prepared.completePeriodCutoffs),
|
|
163
|
+
expectedCellGridFingerprint: createDiagnosticIdentityValue(prepared.expectedCellsProvided
|
|
164
|
+
? fingerprintDiagnosticIdentity(expectedCells, {
|
|
165
|
+
kind: "diagnostic-expected-cell-grid",
|
|
166
|
+
property: "expectedCells",
|
|
167
|
+
})
|
|
168
|
+
: null),
|
|
169
|
+
executionPolicy: createDiagnosticIdentityObject({
|
|
170
|
+
gate: createDiagnosticIdentityValue(run.gate),
|
|
171
|
+
review: createDiagnosticIdentityObject({
|
|
172
|
+
body: getCompactDiagnosticReviewReceiptIdentityDocument(run.review),
|
|
173
|
+
reportFingerprint: createDiagnosticIdentityValue(reviewFingerprint),
|
|
174
|
+
}),
|
|
175
|
+
}),
|
|
176
|
+
engine: createDiagnosticIdentityValue(Object.freeze({
|
|
177
|
+
packages: Object.freeze({
|
|
178
|
+
core: CORE_PACKAGE_VERSION,
|
|
179
|
+
data: DATA_PACKAGE_VERSION,
|
|
180
|
+
compliance: COMPLIANCE_PACKAGE_VERSION,
|
|
181
|
+
}),
|
|
182
|
+
algorithmVersion: "diagnostics-1",
|
|
183
|
+
})),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Verify an authentic compact completed run and bind completed artifact digests.
|
|
188
|
+
* Synchronous: source bytes were consumed by digestDiagnosticArtifactChunks already.
|
|
189
|
+
* This deliberately replays review/math and compares every identity code unit.
|
|
190
|
+
*/
|
|
191
|
+
export function createCompactDiagnosticRunIdentity(input) {
|
|
192
|
+
const snapshot = record(input, [
|
|
193
|
+
"completedRun",
|
|
194
|
+
"inputArtifacts",
|
|
195
|
+
"preparationArtifacts",
|
|
196
|
+
"preparationLineage",
|
|
197
|
+
], "$");
|
|
198
|
+
const run = snapshot.completedRun;
|
|
199
|
+
try {
|
|
200
|
+
assertCompletedCompactMetricDiagnosticsRun(run);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
bad("completedRun must be an authentic completed compact diagnostic run", "$.completedRun");
|
|
204
|
+
}
|
|
205
|
+
const inputArtifacts = artifacts(snapshot.inputArtifacts, "input", "$.inputArtifacts");
|
|
206
|
+
const preparationArtifacts = artifacts(snapshot.preparationArtifacts, "preparation", "$.preparationArtifacts");
|
|
207
|
+
const preparationLineage = lineage(snapshot.preparationLineage);
|
|
208
|
+
validateArtifactGraph(run, inputArtifacts, preparationArtifacts, preparationLineage);
|
|
209
|
+
rerunAndVerify(run);
|
|
210
|
+
const preparationFingerprint = getCompactPreparedDiagnosticDataFingerprint(run.prepared);
|
|
211
|
+
const reviewFingerprint = getCompactDiagnosticReviewReceiptFingerprint(run.review);
|
|
212
|
+
const manifestIdentityDocument = manifestDocument(run, inputArtifacts, preparationArtifacts, preparationLineage, preparationFingerprint, reviewFingerprint);
|
|
213
|
+
const resultIdentityDocument = getCompactMetricDiagnosticsResultIdentityDocument(run.result);
|
|
214
|
+
const runFingerprint = fingerprintDiagnosticIdentity(manifestIdentityDocument, { kind: "diagnostic-run", property: "manifest" });
|
|
215
|
+
const resultFingerprint = fingerprintDiagnosticIdentity(resultIdentityDocument, { kind: "diagnostic-result", property: "result" });
|
|
216
|
+
const runResultFingerprint = `fnv1a64-jcs-v1:${canonicalFnv1a64({ identityVersion: 1, kind: "diagnostic-run-result", runFingerprint, resultFingerprint })}`;
|
|
217
|
+
const definition = run.prepared.definition;
|
|
218
|
+
const provenance = Object.freeze({
|
|
219
|
+
definition: Object.freeze({
|
|
220
|
+
definition: definition.definition,
|
|
221
|
+
identities: Object.freeze({
|
|
222
|
+
algorithm: "fnv1a64-jcs-v1",
|
|
223
|
+
formulaById: Object.freeze({ ...definition.formulaFingerprints }),
|
|
224
|
+
calculationByInstanceId: Object.freeze({
|
|
225
|
+
...definition.calculationFingerprints,
|
|
226
|
+
}),
|
|
227
|
+
definition: definition.definitionIntegrity,
|
|
228
|
+
}),
|
|
229
|
+
}),
|
|
230
|
+
inputArtifacts,
|
|
231
|
+
preparationArtifacts,
|
|
232
|
+
preparationLineage,
|
|
233
|
+
preparationFingerprint,
|
|
234
|
+
reviewFingerprint,
|
|
235
|
+
manifestIdentityDocument,
|
|
236
|
+
resultIdentityDocument,
|
|
237
|
+
runFingerprint,
|
|
238
|
+
resultFingerprint,
|
|
239
|
+
runResultFingerprint,
|
|
240
|
+
});
|
|
241
|
+
verified.set(provenance, run);
|
|
242
|
+
return provenance;
|
|
243
|
+
}
|
|
244
|
+
export function assertVerifiedCompactDiagnosticRunProvenance(value) {
|
|
245
|
+
if (value === null || typeof value !== "object" || !verified.has(value))
|
|
246
|
+
bad("Value is not authentic verified compact diagnostic provenance", "$");
|
|
247
|
+
}
|
|
248
|
+
/** Internal transport plumbing; deliberately not exported from the package index. */
|
|
249
|
+
export function getCompactDiagnosticRunOwner(provenance) {
|
|
250
|
+
assertVerifiedCompactDiagnosticRunProvenance(provenance);
|
|
251
|
+
return verified.get(provenance);
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=diagnosticCompactRun.js.map
|