Files
workinf_Blender_Wasm/tools/web/generate-wbv2-paint-selection.mjs
mes123456 784193df83
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
Advance deduplicated paint capability coverage
2026-08-28 13:52:16 +08:00

51 lines
10 KiB
JavaScript

import assert from "node:assert/strict";
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import { execFileSync } from "node:child_process";
import { fileURLToPath } from "node:url";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
const write = process.argv.includes("--write");
const absolute = (file) => path.join(root, file);
const read = (file) => fs.readFileSync(absolute(file), "utf8");
const json = (file) => JSON.parse(read(file));
const sha256 = (file) => crypto.createHash("sha256").update(fs.readFileSync(absolute(file))).digest("hex");
const digestText = (value) => crypto.createHash("sha256").update(value).digest("hex");
const outputRoot = "tests/golden/WBV2-P16-001";
const reportPath = `${outputRoot}/paint-selection-report.json`;
const candidatePath = `${outputRoot}/paint-candidate-set.json`;
const statusPath = "docs/status/WBV2-P16-001.md";
const planPath = `${outputRoot}/paint-task-plan.json`;
const manifestPath = `${outputRoot}/manifest.json`;
const parentPath = "tests/golden/WBV2-P16-000/manifest.json";
const inventoryPath = "tests/golden/WBV2-P0-002/parity-map.json";
const sourceReportPath = "tests/golden/WBV2-P4-003/sculpt-report.json";
const sourceRunnerPath = "tools/web/check-paint-roundtrip.mjs";
const sourceApiPath = "blender-5.2.0/source/blender/web_engine/web_engine_api.cpp";
const sourceTestPath = "web/tests/e2e/paint-pbvh-capability.spec.ts";
const colorFixturePath = "tests/files/web/attribute_scene.blend";
const weightFixturePath = "tests/files/web/rigged_shape_scene.blend";
const parent = json(parentPath); const inventory = json(inventoryPath); const sourceReport = json(sourceReportPath);
assert.equal(parent.task, "WBV2-P16-000"); assert.equal(parent.status, "done"); assert.equal(parent.nextTask, "WBV2-P16-001");
for (const artifact of Object.values(parent.artifacts ?? {})) assert.equal(sha256(artifact.path), artifact.sha256, artifact.path);
assert.equal(inventory.summary.inventoryEntries, 6900); assert.equal(inventory.summary.pendingLegacyEntries, 6618); assert.equal(sourceReport.desktop.status, "EXACT"); assert.equal(sourceReport.wasm.status, "EXACT");
const apiSource = read(sourceApiPath); const runnerSource = read(sourceRunnerPath); const testSource = read(sourceTestPath);
assert.match(apiSource, /setVertexColors/); assert.match(apiSource, /setVertexWeights/); assert.match(runnerSource, /setVertexColors/); assert.match(runnerSource, /setVertexWeights/); assert.match(testSource, /queryPaintPBVHCapability/);
const candidates = inventory.entries.filter((entry) => entry.capabilityId === "CAP-SCULPT-PAINT").map((entry) => ({ id: entry.id, kind: entry.kind, family: entry.family, sourceTask: entry.sourceTask, legacyState: entry.legacyState, state: entry.state, targetImplementationClass: entry.targetImplementationClass }));
assert.equal(candidates.length, 117); assert.equal(candidates.filter((entry) => entry.legacyState === "pending").length, 117);
const behavior = { capability: "SCULPT.PAINT_ATTRIBUTES", operations: ["setVertexColors", "setVertexWeights"], fixtures: [colorFixturePath, weightFixturePath], positive: ["uniform-corner-colors", "normalized-weights", "undo", "redo", "save-reopen"], negative: ["invalid-color-index", "unknown-weight-group"], browser: "chromium", engine: "compiled-WASM-WebEngine-Main" };
const behaviorHash = digestText(JSON.stringify(behavior));
const candidate = { schemaVersion: 1, task: "WBV2-P16-001", operation: "PAINT_CAPABILITY_CANDIDATE_SELECTION", status: "READY", source: { inventory: inventoryPath, inventorySha256: sha256(inventoryPath), sourceReport: sourceReportPath, sourceReportSha256: sha256(sourceReportPath), runner: sourceRunnerPath, runnerSha256: sha256(sourceRunnerPath), api: sourceApiPath, apiSha256: sha256(sourceApiPath), chromiumBoundaryTest: sourceTestPath, chromiumBoundaryTestSha256: sha256(sourceTestPath), colorFixture: colorFixturePath, colorFixtureSha256: sha256(colorFixturePath), weightFixture: weightFixturePath, weightFixtureSha256: sha256(weightFixturePath) }, candidate: { capabilityId: "SCULPT.PAINT_ATTRIBUTES", representativeBehavior: behavior, behaviorHash, dedupeKey: `SCULPT.PAINT_ATTRIBUTES|${behaviorHash}|${sha256(sourceApiPath)}|${sha256(colorFixturePath)}|${sha256(weightFixturePath)}`, sourceBacked: true, chromiumProductionReady: true, fullFamilyParity: false }, inventory: { matchedEntries: candidates.length, pending: candidates.length, remainderExplicit: true }, entries: candidates, policy: { sourceHistoryReadOnly: true, representativeSliceOnly: true, noRepeatedExecution: true, duplicateValidationAvoided: true, fullHistoricalReproduction: false } };
const report = { schemaVersion: 1, task: "WBV2-P16-001", operation: "SELECT_PAINT_CAPABILITY_BATCH", status: "PASS", candidate: candidate.candidate, inventory: candidate.inventory, source: candidate.source, matchedEntryDigest: digestText(JSON.stringify(candidates)), efficiency: { oneCapabilityScan: true, existingPaintEvidenceReused: true, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, duplicateValidationAvoided: true }, nextTask: "WBV2-P16-002" };
if (!write) { process.stdout.write(`wbv2-paint-selection-ok task=WBV2-P16-001 matched=117 capability=SCULPT.PAINT_ATTRIBUTES behaviorHash=${behaviorHash} pending=6618 repeatedRuns=0 next=WBV2-P16-002\n`); process.exit(0); }
fs.mkdirSync(absolute(outputRoot), { recursive: true }); fs.writeFileSync(absolute(candidatePath), `${JSON.stringify(candidate, null, 2)}\n`); fs.writeFileSync(absolute(reportPath), `${JSON.stringify(report, null, 2)}\n`);
fs.writeFileSync(absolute(statusPath), `# WBV2-P16-001 status\n\n- task: \`WBV2-P16-001\`; parent: \`WBV2-P16-000\`; status: \`done\`\n- selected capability: \`SCULPT.PAINT_ATTRIBUTES\`; operations: vertex colors and vertex weights\n- matched inventory entries: \`117\`; inventory remains \`6900\` total, \`6618\` pending\n- behavior hash: \`${behaviorHash}\`; dedupe key binds API and fixture hashes\n- existing paint evidence reused: \`true\`; repeated Blender/Chromium runs: \`0\`\n- representative slice: \`true\`; full-family parity: \`false\`\n- nextTask: \`WBV2-P16-002\`\n\nOnly one unique color/weight behavior batch will be executed in Chromium. The 117 matched entries remain pending until their individual behavior evidence exists.\n`);
const previousPlan = json("tests/golden/WBV2-P16-000/paint-task-plan.json"); const nextPlan = structuredClone(previousPlan); nextPlan.parentRecoveryPlan = { path: "tests/golden/WBV2-P16-000/paint-task-plan.json", sha256: sha256("tests/golden/WBV2-P16-000/paint-task-plan.json") }; nextPlan.tasks = nextPlan.tasks.map((task) => task.id === "WBV2-P16-001" ? { ...task, status: "done", ready: false } : task.id === "WBV2-P16-002" ? { ...task, status: "in_progress", ready: true } : { ...task, ready: false }); fs.writeFileSync(absolute(planPath), `${JSON.stringify(nextPlan, null, 2)}\n`);
fs.writeFileSync(absolute("docs/tasks/WBV2-P16-002.md"), read("docs/tasks/WBV2-P16-002.md").replace("- status: planned", "- status: in_progress")); execFileSync(process.execPath, [absolute("tools/web/generate-v2-task-index.mjs"), "--plan-path", absolute(planPath)], { cwd: root, stdio: "inherit" }); execFileSync(process.execPath, [absolute("tools/web/check-task-context.mjs"), "--task", "WBV2-P16-001", "--write"], { cwd: root, stdio: "inherit" });
const artifactPaths = { parentManifest: parentPath, inventory: inventoryPath, sourceReport: sourceReportPath, sourceRunner: sourceRunnerPath, sourceApi: sourceApiPath, sourceTest: sourceTestPath, colorFixture: colorFixturePath, weightFixture: weightFixturePath, candidate: candidatePath, report: reportPath, generator: "tools/web/generate-wbv2-paint-selection.mjs", status: statusPath, parityPlan: planPath, taskContext: `${outputRoot}/task-context.json` }; const artifacts = Object.fromEntries(Object.entries(artifactPaths).map(([name, file]) => [name, { path: file, sha256: sha256(file) }])); const manifest = { schemaVersion: 1, task: "WBV2-P16-001", parentTask: "WBV2-P16-000", operation: "SELECT_PAINT_CAPABILITY_BATCH", status: "done", enablingTask: true, parityStateChange: false, runtime: "READ_ONLY_SOURCE_CANDIDATE_SELECTION", artifacts, assertions: { capability: "SCULPT.PAINT_ATTRIBUTES", matchedInventoryEntries: 117, inventoryTotal: 6900, inventoryPending: 6618, sourceApiBound: true, existingEvidenceReused: true, representativeSliceOnly: true, fullFamilyParity: false, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, duplicateValidationAvoided: true, deterministic: true, historicalReproduction: false }, nextTask: "WBV2-P16-002" }; fs.writeFileSync(absolute(manifestPath), `${JSON.stringify(manifest, null, 2)}\n`);
let queue = read("docs/EXECUTION_QUEUE.md"); queue = queue.replace(/\| 当前任务 \| `[^`]+` \|/u, "| 当前任务 | `WBV2-P16-002` |").replace(/\| parent manifest \| `[^`]+` \|/u, "| parent manifest | `tests/golden/WBV2-P16-001/manifest.json` |").replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u, "| 任务卡 | [`tasks/WBV2-P16-002.md`](tasks/WBV2-P16-002.md) |"); fs.writeFileSync(absolute("docs/EXECUTION_QUEUE.md"), queue);
let nextTask = read("nextTask.md"); nextTask = nextTask.replace(/\| Current task when this file was written \| `[^`]+` \|/u, "| Current task when this file was written | `WBV2-P16-002` |").replace(/\| Current task state \| `[^`]+` \|/u, "| Current task state | `in_progress` |").replace(/\| Parent manifest \| `[^`]+` \|/u, "| Parent manifest | `tests/golden/WBV2-P16-001/manifest.json` |").replace(/\| Current task card \| `[^`]+` \|/u, "| Current task card | `docs/tasks/WBV2-P16-002.md` |").replace(/\| Current task-context nextTask \| `[^`]+` \|/u, "| Current task-context nextTask | `WBV2-P16-003` |").replace(/\| Focused command \| `[^`]+` \|/u, "| Focused command | `npm --prefix web run test:e2e -- --workers=1 tests/e2e/wbv2-paint-attributes-production.spec.ts` |"); fs.writeFileSync(absolute("nextTask.md"), nextTask);
process.stdout.write(`wbv2-paint-selection-written task=WBV2-P16-001 matched=117 capability=SCULPT.PAINT_ATTRIBUTES behaviorHash=${behaviorHash} pending=6618 next=WBV2-P16-002 artifacts=${Object.keys(artifacts).length}\n`);