Reorganize Blender Web execution around capabilities
This commit is contained in:
45
web/protocol/corrective-family-runner.ts
Normal file
45
web/protocol/corrective-family-runner.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { CorrectiveCommandRegistry } from "./corrective-command-registry";
|
||||
import { CaseSurface, SurfaceReceipt } from "./corrective-case-runner";
|
||||
|
||||
export type CorrectiveFamily = "ASSET_CATALOG" | "MODIFIER" | "MESH";
|
||||
|
||||
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 (!["ASSET_CATALOG", "MODIFIER", "MESH"].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[]): Record<CorrectiveFamily, { total: number; finished: number; unchanged: number }> {
|
||||
const summary: Record<CorrectiveFamily, { total: number; finished: number; unchanged: number }> = {
|
||||
ASSET_CATALOG: { total: 0, finished: 0, unchanged: 0 },
|
||||
MODIFIER: { total: 0, finished: 0, unchanged: 0 },
|
||||
MESH: { total: 0, finished: 0, unchanged: 0 },
|
||||
};
|
||||
for (const result of results) {
|
||||
const bucket = summary[result.family]; bucket.total += 1;
|
||||
if (result.receipt.result.status === "FINISHED") bucket.finished += 1;
|
||||
if (result.receipt.result.mainMutation === "UNCHANGED") bucket.unchanged += 1;
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
Reference in New Issue
Block a user