mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 22:11:12 +00:00
refactor(reconstruction): share claim summary counting (#16465)
This commit is contained in:
1 parent
32d77cad74
commit
4a140519f9
2 files changed
+35
-37
No files matched your search
@@ -41,11 +41,11 @@ import {
|
||||
import type { ProcessObservationSource } from "./process/processObservation.js";
|
||||
import { digestCanonicalValue } from "./canonicalDigest.js";
|
||||
import {
|
||||
countReconstructionClaimKinds,
|
||||
reconstructionClaimResultSchema,
|
||||
reconstructionClaimSelector,
|
||||
reconstructionSpecificationSchema,
|
||||
reconstructionVerificationResultSchema,
|
||||
summarizeReconstructionClaims,
|
||||
type ReconstructionClaim as Claim,
|
||||
type ReconstructionClaimResult as ClaimResult,
|
||||
type ReconstructionObservedStatus as ObservedStatus,
|
||||
@@ -147,14 +147,14 @@ export const verifyReconstruction = (
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.claim_id, right.claim_id),
|
||||
);
|
||||
const failed = count(results, "fail");
|
||||
const unresolved = count(results, "unknown");
|
||||
const summary = summarizeReconstructionClaims(results);
|
||||
const probes = reconstructionProbes(results, heads);
|
||||
const evidenceLinks = uniqueSorted(
|
||||
results.flatMap(({ evidence_links: links }) => links),
|
||||
);
|
||||
const output = {
|
||||
status: failed > 0 ? "fail" : unresolved > 0 ? "unknown" : "pass",
|
||||
status:
|
||||
summary.failed > 0 ? "fail" : summary.unknown > 0 ? "unknown" : "pass",
|
||||
specification_sha256: digestCanonicalValue(
|
||||
{
|
||||
...specification,
|
||||
@@ -164,13 +164,7 @@ export const verifyReconstruction = (
|
||||
},
|
||||
"Reconstruction specification",
|
||||
),
|
||||
summary: {
|
||||
total: results.length,
|
||||
passed: count(results, "pass"),
|
||||
failed,
|
||||
unknown: unresolved,
|
||||
...countReconstructionClaimKinds(results),
|
||||
},
|
||||
summary,
|
||||
claims: {
|
||||
items: results,
|
||||
},
|
||||
@@ -817,10 +811,6 @@ const classify = (
|
||||
return "pass";
|
||||
};
|
||||
|
||||
const count = (
|
||||
items: readonly ClaimResult[],
|
||||
status: ClaimResult["status"],
|
||||
): number => items.filter((item) => item.status === status).length;
|
||||
const sameSet = (left: readonly string[], right: readonly string[]): boolean =>
|
||||
uniqueSorted(left).length === uniqueSorted(right).length &&
|
||||
uniqueSorted(left).every((id, index) => id === uniqueSorted(right)[index]);
|
||||
@@ -127,16 +127,28 @@ export const reconstructionClaimResultSchema = z.object({
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
|
||||
export const countReconstructionClaimKinds = (
|
||||
claims: readonly Pick<ReconstructionClaimResult, "kind">[],
|
||||
) => ({
|
||||
behavioral: claims.filter(({ kind }) => kind === "behavioral").length,
|
||||
structural: claims.filter(
|
||||
({ kind }) =>
|
||||
kind === "structural-function" || kind === "structural-artifact",
|
||||
).length,
|
||||
visual: claims.filter(({ kind }) => kind === "visual").length,
|
||||
});
|
||||
export const summarizeReconstructionClaims = (
|
||||
claims: readonly Pick<ReconstructionClaimResult, "kind" | "status">[],
|
||||
) => {
|
||||
const summary = {
|
||||
total: claims.length,
|
||||
passed: 0,
|
||||
failed: 0,
|
||||
unknown: 0,
|
||||
behavioral: 0,
|
||||
structural: 0,
|
||||
visual: 0,
|
||||
};
|
||||
for (const { kind, status } of claims) {
|
||||
if (status === "pass") summary.passed++;
|
||||
else if (status === "fail") summary.failed++;
|
||||
else summary.unknown++;
|
||||
if (kind === "behavioral") summary.behavioral++;
|
||||
else if (kind === "visual") summary.visual++;
|
||||
else summary.structural++;
|
||||
}
|
||||
return summary;
|
||||
};
|
||||
|
||||
/** Evidence-cited result over every declared claim. */
|
||||
export const reconstructionVerificationResultSchema = z
|
||||
@@ -168,25 +180,21 @@ export const reconstructionVerificationResultSchema = z
|
||||
})
|
||||
.superRefine((result, context) => {
|
||||
const { summary } = result;
|
||||
const claims = result.claims.items;
|
||||
const kinds = countReconstructionClaimKinds(claims);
|
||||
const observed = summarizeReconstructionClaims(result.claims.items);
|
||||
const expectedStatus =
|
||||
summary.failed > 0 ? "fail" : summary.unknown > 0 ? "unknown" : "pass";
|
||||
const issues = [
|
||||
[
|
||||
summary.passed !==
|
||||
claims.filter(({ status }) => status === "pass").length ||
|
||||
summary.failed !==
|
||||
claims.filter(({ status }) => status === "fail").length ||
|
||||
summary.unknown !==
|
||||
claims.filter(({ status }) => status === "unknown").length,
|
||||
summary.passed !== observed.passed ||
|
||||
summary.failed !== observed.failed ||
|
||||
summary.unknown !== observed.unknown,
|
||||
"Claim status counts must summarize retained claims",
|
||||
["summary"],
|
||||
],
|
||||
[
|
||||
summary.behavioral !== kinds.behavioral ||
|
||||
summary.structural !== kinds.structural ||
|
||||
summary.visual !== kinds.visual,
|
||||
summary.behavioral !== observed.behavioral ||
|
||||
summary.structural !== observed.structural ||
|
||||
summary.visual !== observed.visual,
|
||||
"Claim kind counts must summarize retained claims",
|
||||
["summary"],
|
||||
],
|
||||
@@ -202,7 +210,7 @@ export const reconstructionVerificationResultSchema = z
|
||||
["summary", "total"],
|
||||
],
|
||||
[
|
||||
result.claims.items.length !== summary.total,
|
||||
observed.total !== summary.total,
|
||||
"Retained claims must equal the summary total",
|
||||
["claims", "items"],
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user