Files
workinf_Blender_Wasm/web/protocol/corrective-family-runner.ts
mes123456 c2c65d3a09
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
Rebuild local Blender WASM environment and recovery evidence
2026-08-27 20:22:15 +08:00

48 lines
2.5 KiB
TypeScript

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<CorrectiveFamilyResult[]> {
const ids = new Set<string>();
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<Record<CorrectiveFamily, { total: number; finished: number; unchanged: number }>> {
const summary: Partial<Record<CorrectiveFamily, { total: number; finished: number; unchanged: number }>> = {};
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;
}