mirror of
https://github.com/morluto/rea
synced 2026-10-28 06:46:47 -04:00
ba3869c597
* refactor(domain): consolidate canonical ordering and digest helpers Single owner for code-point ordering (domain/canonicalOrdering.ts) and canonical JSON digests (domain/comparisonSemantics.ts). Delete all local compareCodePoints/compareText/digestCanonical duplicates and migrate every importer. No re-export shims. * fix(ci): allow slower real browser startup
95 lines
2.9 KiB
TypeScript
95 lines
2.9 KiB
TypeScript
import { canonicalDigest } from "./comparisonSemantics.js";
|
|
import type {
|
|
DimensionName,
|
|
FunctionComparisonResult,
|
|
FunctionDimension,
|
|
} from "./functionComparisonSchemas.js";
|
|
|
|
export interface DimensionResultInput {
|
|
readonly dimension: DimensionName;
|
|
readonly status: "unchanged" | "changed";
|
|
readonly left: unknown;
|
|
readonly right: unknown;
|
|
readonly links: readonly string[];
|
|
readonly providersDiffer: boolean;
|
|
readonly leftCount: number | null;
|
|
readonly rightCount: number | null;
|
|
readonly textDelta: FunctionDimension["text_delta"];
|
|
readonly limitations: readonly string[];
|
|
}
|
|
|
|
export const dimensionResult = (
|
|
input: DimensionResultInput,
|
|
): FunctionDimension => {
|
|
const context = {
|
|
dimension: input.dimension,
|
|
left_digest: digest(input.left),
|
|
right_digest: digest(input.right),
|
|
left_count: input.leftCount,
|
|
right_count: input.rightCount,
|
|
text_delta: input.textDelta,
|
|
evidence_links: [...input.links],
|
|
limitations: [...input.limitations],
|
|
};
|
|
if (input.status === "unchanged")
|
|
return {
|
|
...context,
|
|
status: "unchanged",
|
|
conclusion_kind: "derived_relationship",
|
|
};
|
|
return {
|
|
...context,
|
|
status: "changed",
|
|
conclusion_kind: input.providersDiffer
|
|
? "contradiction"
|
|
: "derived_relationship",
|
|
};
|
|
};
|
|
|
|
export const unresolvedDimension = (input: {
|
|
readonly dimension: DimensionName;
|
|
readonly status: "truncated" | "unknown";
|
|
readonly links: readonly string[];
|
|
readonly leftCount: number | null;
|
|
readonly rightCount: number | null;
|
|
readonly limitations: readonly string[];
|
|
}): FunctionDimension => ({
|
|
dimension: input.dimension,
|
|
status: input.status,
|
|
left_digest: null,
|
|
right_digest: null,
|
|
left_count: input.leftCount,
|
|
right_count: input.rightCount,
|
|
text_delta: null,
|
|
conclusion_kind: "unresolved_branch",
|
|
evidence_links: [...input.links],
|
|
limitations: [...input.limitations],
|
|
});
|
|
|
|
export const overallStatus = (
|
|
dimensions: readonly FunctionDimension[],
|
|
match: FunctionComparisonResult["function_match"]["status"],
|
|
): FunctionComparisonResult["status"] => {
|
|
if (dimensions.some(({ status }) => status === "truncated"))
|
|
return "truncated";
|
|
if (
|
|
match === "ambiguous" ||
|
|
dimensions.some(({ status }) => status === "unknown")
|
|
)
|
|
return "unknown";
|
|
if (match === "mismatched") return "changed";
|
|
return dimensions.some(({ status }) => status === "changed")
|
|
? "changed"
|
|
: "unchanged";
|
|
};
|
|
|
|
export const summarize = (dimensions: readonly FunctionDimension[]) => ({
|
|
unchanged: dimensions.filter(({ status }) => status === "unchanged").length,
|
|
changed: dimensions.filter(({ status }) => status === "changed").length,
|
|
truncated: dimensions.filter(({ status }) => status === "truncated").length,
|
|
unknown: dimensions.filter(({ status }) => status === "unknown").length,
|
|
});
|
|
|
|
const digest = (value: unknown): string =>
|
|
canonicalDigest(value, "Function comparison");
|