import { CorrectiveCommandRegistry } from "./corrective-command-registry"; import { CaseSurface, SurfaceReceipt } from "./corrective-case-runner"; export const ATOMIC_CORRECTIVE_FAMILIES = [ "CORE_DNA_RNA", "CORE_MESH", "CORE_OBJECT", "CORE_SCENE_GRAPH", "MATERIAL_RENDER", "MEDIA_IO", "MESH_EDITING", "MODIFIER_SYSTEM", "NODES_GRAPH", "OBJECT_OPERATIONS", "OTHER_OPERATOR", "RIG_ANIMATION", "SCULPT_PAINT", "SIMULATION", "UI_EDITOR", ] as const; export const CORRECTIVE_FAMILIES = [...ATOMIC_CORRECTIVE_FAMILIES, "ASSET_CATALOG", "MODIFIER", "MESH"] as const; export type CorrectiveFamily = typeof CORRECTIVE_FAMILIES[number]; export interface CorrectiveFamilyCase { id: string; family: CorrectiveFamily; registry: CorrectiveCommandRegistry; surface: CaseSurface; command: unknown; mainRevision: number; } export interface CorrectiveFamilyResult extends CorrectiveFamilyCase { receipt: SurfaceReceipt; } const CASE_ID = /^[A-Za-z][A-Za-z0-9._:-]{0,127}$/u; export async function runCorrectiveFamilyCases(cases: readonly CorrectiveFamilyCase[]): Promise { const ids = new Set(); for (const testCase of cases) { if (!testCase || !CASE_ID.test(testCase.id) || ids.has(testCase.id)) throw new Error(`family case id is invalid or duplicated: ${testCase?.id ?? "unknown"}`); ids.add(testCase.id); if (!CORRECTIVE_FAMILIES.includes(testCase.family)) throw new Error(`unsupported corrective family: ${testCase.family}`); if (!(testCase.registry instanceof CorrectiveCommandRegistry)) throw new Error(`family case registry is invalid: ${testCase.id}`); if (!Number.isSafeInteger(testCase.mainRevision) || testCase.mainRevision < 0) throw new Error(`family case revision is invalid: ${testCase.id}`); } return Promise.all(cases.map(async (testCase) => ({ ...testCase, receipt: await testCase.registry.dispatch(testCase.surface, { command: testCase.command, mainRevision: testCase.mainRevision }) }))); } export function summarizeCorrectiveFamilyResults(results: readonly CorrectiveFamilyResult[]): Partial> { const summary: Partial> = {}; for (const result of results) { const bucket = (summary[result.family] ??= { total: 0, finished: 0, unchanged: 0 }); bucket.total += 1; if (result.receipt.result.status === "FINISHED") bucket.finished += 1; if (result.receipt.result.mainMutation === "UNCHANGED") bucket.unchanged += 1; } return summary; }