Files
workinf_Blender_Wasm/tools/web/generate-wbv2-delete-selection.mjs
mes123456 3ab47ae2e9
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 object deletion coverage
2026-08-28 16:59:15 +08:00

61 lines
7.8 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 abs = (file) => path.join(root, file);
const read = (file) => fs.readFileSync(abs(file), "utf8");
const json = (file) => JSON.parse(read(file));
const sha = (file) => crypto.createHash("sha256").update(fs.readFileSync(abs(file))).digest("hex");
const digest = (value) => crypto.createHash("sha256").update(value).digest("hex");
const out = "tests/golden/WBV2-P22-001";
const parentPath = "tests/golden/WBV2-P22-000/manifest.json";
const inventoryPath = "tests/golden/WBV2-P0-002/parity-map.json";
const apiPath = "blender-5.2.0/source/blender/web_engine/web_engine_api.cpp";
const protocolPath = "web/protocol/web-engine.ts";
const planPath = `${out}/delete-task-plan.json`;
const reportPath = `${out}/object-delete-selection-report.json`;
const candidatePath = `${out}/object-delete-candidate-set.json`;
const manifestPath = `${out}/manifest.json`;
const statusPath = "docs/status/WBV2-P22-001.md";
const parent = json(parentPath);
const inventory = json(inventoryPath);
assert.equal(parent.status, "done");
assert.equal(parent.nextTask, "WBV2-P22-001");
for (const artifact of Object.values(parent.artifacts ?? {})) assert.equal(sha(artifact.path), artifact.sha256, artifact.path);
assert.equal(inventory.summary.inventoryEntries, 6900);
assert.equal(inventory.summary.pendingLegacyEntries, 6618);
assert.match(read(apiPath), /deleteObject/);
assert.match(read(protocolPath), /deleteObject/);
const target = inventory.entries.find((entry) => entry.id === "operator:object.delete");
assert.ok(target);
assert.equal(target.legacyState, "pending");
const behavior = { capability: "OBJECT_OPERATIONS.DELETE", operation: "deleteObject", positive: ["object-delete", "undo", "redo", "save-reopen"], negative: ["missing-id", "linked-object"], browser: "chromium", engine: "compiled-WASM-WebEngine-Main" };
const behaviorHash = digest(JSON.stringify(behavior));
const candidate = { schemaVersion: 1, task: "WBV2-P22-001", operation: "OBJECT_DELETE_CANDIDATE_SELECTION", status: "READY", source: { inventory: inventoryPath, inventorySha256: sha(inventoryPath), api: apiPath, apiSha256: sha(apiPath), protocol: protocolPath, protocolSha256: sha(protocolPath) }, candidate: { capabilityId: "OBJECT_OPERATIONS.DELETE", legacyId: target.id, legacyTask: target.evidence.legacyTask, behavior, behaviorHash, dedupeKey: `OBJECT_OPERATIONS.DELETE|${behaviorHash}|${sha(apiPath)}|${sha(protocolPath)}`, sourceBacked: true, chromiumProductionReady: true, fullFamilyParity: false }, inventory: { matchedEntries: 1, pending: 1, total: 6900, basePending: 6618, effectivePending: 6611, remainderExplicit: true }, entries: [{ id: target.id, sourceTask: target.sourceTask, legacyState: target.legacyState, targetImplementationClass: target.targetImplementationClass }], policy: { sourceHistoryReadOnly: true, representativeSliceOnly: true, noRepeatedExecution: true, duplicateValidationAvoided: true, fullHistoricalReproduction: false } };
const report = { schemaVersion: 1, task: "WBV2-P22-001", operation: "SELECT_OBJECT_DELETE_BATCH", status: "PASS", candidate: candidate.candidate, inventory: candidate.inventory, source: candidate.source, matchedEntryDigest: digest(target.id), efficiency: { oneEntryScan: true, existingEvidenceReused: true, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, duplicateValidationAvoided: true }, nextTask: "WBV2-P22-002" };
if (!process.argv.includes("--write")) { console.log(`wbv2-delete-selection-ok task=WBV2-P22-001 legacyId=${target.id} behaviorHash=${behaviorHash} pending=6611 repeatedRuns=0 next=WBV2-P22-002`); process.exit(0); }
fs.mkdirSync(abs(out), { recursive: true });
fs.writeFileSync(abs(candidatePath), `${JSON.stringify(candidate, null, 2)}\n`);
fs.writeFileSync(abs(reportPath), `${JSON.stringify(report, null, 2)}\n`);
fs.writeFileSync(abs(statusPath), `# WBV2-P22-001 status\n\n- task: \`WBV2-P22-001\`; parent: \`WBV2-P22-000\`; status: \`done\`\n- selected behavior: \`deleteObject\`; exact candidate: \`operator:object.delete\`\n- base inventory: \`6900\` total, \`6618\` pending; effective carried overlay: \`6611\` pending\n- behavior hash: \`${behaviorHash}\`; duplicate validation: \`forbidden\`\n- nextTask: \`WBV2-P22-002\`\n`);
const previousPlan = json("tests/golden/WBV2-P22-000/delete-task-plan.json");
const nextPlan = structuredClone(previousPlan);
nextPlan.parentRecoveryPlan = { path: "tests/golden/WBV2-P22-000/delete-task-plan.json", sha256: sha("tests/golden/WBV2-P22-000/delete-task-plan.json") };
nextPlan.tasks = nextPlan.tasks.map((task) => task.id === "WBV2-P22-001" ? { ...task, status: "done", ready: false } : task.id === "WBV2-P22-002" ? { ...task, status: "in_progress", ready: true } : { ...task, ready: false });
fs.writeFileSync(abs(planPath), `${JSON.stringify(nextPlan, null, 2)}\n`);
fs.writeFileSync(abs("docs/tasks/WBV2-P22-002.md"), read("docs/tasks/WBV2-P22-002.md").replace("- status: planned", "- status: in_progress"));
execFileSync(process.execPath, [abs("tools/web/generate-v2-task-index.mjs"), "--plan-path", abs(planPath)], { cwd: root, stdio: "inherit" });
execFileSync(process.execPath, [abs("tools/web/check-task-context.mjs"), "--task", "WBV2-P22-001", "--write"], { cwd: root, stdio: "inherit" });
const artifactPaths = { parentManifest: parentPath, inventory: inventoryPath, api: apiPath, protocol: protocolPath, candidate: candidatePath, report: reportPath, generator: "tools/web/generate-wbv2-delete-selection.mjs", status: statusPath, parityPlan: planPath, taskContext: `${out}/task-context.json` };
const artifacts = Object.fromEntries(Object.entries(artifactPaths).map(([name, file]) => [name, { path: file, sha256: sha(file) }]));
fs.writeFileSync(abs(manifestPath), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P22-001", parentTask: "WBV2-P22-000", operation: "SELECT_OBJECT_DELETE_BATCH", status: "done", enablingTask: true, parityStateChange: false, runtime: "READ_ONLY_SOURCE_CANDIDATE_SELECTION", artifacts, assertions: { legacyId: target.id, inventoryTotal: 6900, basePending: 6618, effectivePending: 6611, sourceApiBound: true, representativeSliceOnly: true, fullFamilyParity: false, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, duplicateValidationAvoided: true, deterministic: true, historicalReproduction: false }, nextTask: "WBV2-P22-002" }, null, 2)}\n`);
let queue = read("docs/EXECUTION_QUEUE.md"); queue = queue.replace(/\| 当前任务 \| `[^`]+` \|/u, "| 当前任务 | `WBV2-P22-002` |").replace(/\| parent manifest \| `[^`]+` \|/u, "| parent manifest | `tests/golden/WBV2-P22-001/manifest.json` |").replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u, "| 任务卡 | [`tasks/WBV2-P22-002.md`](tasks/WBV2-P22-002.md) |"); fs.writeFileSync(abs("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-P22-002` |").replace(/\| Current task state \| `[^`]+` \|/u, "| Current task state | `in_progress` |").replace(/\| Parent manifest \| `[^`]+` \|/u, "| Parent manifest | `tests/golden/WBV2-P22-001/manifest.json` |").replace(/\| Current task card \| `[^`]+` \|/u, "| Current task card | `docs/tasks/WBV2-P22-002.md` |").replace(/\| Current task-context nextTask \| `[^`]+` \|/u, "| Current task-context nextTask | `WBV2-P22-003` |").replace(/\| Focused command \| `[^`]+` \|/u, "| Focused command | `npm --prefix web run test:e2e -- --workers=1 tests/e2e/wbv2-object-delete-production.spec.ts` |"); fs.writeFileSync(abs("nextTask.md"), nextTask);
console.log(`wbv2-delete-selection-written task=WBV2-P22-001 legacyId=${target.id} behaviorHash=${behaviorHash} next=WBV2-P22-002 artifacts=${Object.keys(artifacts).length}`);