54 lines
10 KiB
JavaScript
54 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-P15-001";
|
|
const reportPath = `${outputRoot}/lighting-selection-report.json`;
|
|
const candidatePath = `${outputRoot}/lighting-candidate-set.json`;
|
|
const statusPath = "docs/status/WBV2-P15-001.md";
|
|
const planPath = `${outputRoot}/lights-task-plan.json`;
|
|
const manifestPath = `${outputRoot}/manifest.json`;
|
|
const parentPath = "tests/golden/WBV2-P15-000/manifest.json";
|
|
const inventoryPath = "tests/golden/WBV2-P0-002/parity-map.json";
|
|
const sourceApiPath = "blender-5.2.0/source/blender/web_engine/web_engine_api.cpp";
|
|
const sourceTestPath = "web/tests/e2e/lighting-field-roundtrip.spec.ts";
|
|
const sourceGoldenPath = "tests/golden/M11-02/lighting-field-roundtrip.json";
|
|
const p14StrategyPath = "tests/golden/WBV2-P14-003/batch-execution-strategy.json";
|
|
|
|
const parent = json(parentPath); const inventory = json(inventoryPath);
|
|
assert.equal(parent.task, "WBV2-P15-000"); assert.equal(parent.status, "done"); assert.equal(parent.nextTask, "WBV2-P15-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);
|
|
const apiSource = read(sourceApiPath); const testSource = read(sourceTestPath); const golden = json(sourceGoldenPath); const strategy = json(p14StrategyPath);
|
|
assert.match(apiSource, /setCameraProperties/); assert.match(apiSource, /setLightProperties/); assert.match(apiSource, /setWorldProperties/);
|
|
assert.match(testSource, /setCameraProperties/); assert.match(testSource, /setLightProperties/); assert.match(testSource, /setWorldProperties/);
|
|
assert.equal(strategy.policy.browser, "chromium"); assert.equal(strategy.policy.fanoutOnlyOnUniqueBehavior, true); assert.equal(strategy.policy.noFirefoxOrWebkit, true);
|
|
|
|
const matcher = /(camera|light|world|render)/iu;
|
|
const candidates = inventory.entries.filter((entry) => matcher.test(`${entry.id} ${entry.family} ${entry.ownerFamily} ${entry.sourceTask}`)).map((entry) => ({ id: entry.id, kind: entry.kind, capabilityId: entry.capabilityId, family: entry.family, ownerFamily: entry.ownerFamily, sourceTask: entry.sourceTask, legacyState: entry.legacyState, state: entry.state, targetImplementationClass: entry.targetImplementationClass }));
|
|
assert(candidates.length > 0);
|
|
const counts = candidates.reduce((acc, entry) => { acc[entry.legacyState] = (acc[entry.legacyState] ?? 0) + 1; return acc; }, {});
|
|
const behavior = { capability: "RENDER.LIGHTING_FIELDS", operations: ["setCameraProperties", "setLightProperties", "setWorldProperties"], positive: ["field-edit", "undo", "redo", "save-reopen"], negative: ["invalid-camera-range", "missing-data-id"], browser: "chromium", engine: "compiled-WASM-WebEngine-Main", sourceGolden: golden.fixture ?? "M11-02/lighting-field-roundtrip.json" };
|
|
const behaviorHash = digestText(JSON.stringify(behavior));
|
|
const candidate = { schemaVersion: 1, task: "WBV2-P15-001", operation: "LIGHTING_CAPABILITY_CANDIDATE_SELECTION", status: "READY", source: { inventory: inventoryPath, inventorySha256: sha256(inventoryPath), api: sourceApiPath, apiSha256: sha256(sourceApiPath), test: sourceTestPath, testSha256: sha256(sourceTestPath), golden: sourceGoldenPath, goldenSha256: sha256(sourceGoldenPath), strategy: p14StrategyPath, strategySha256: sha256(p14StrategyPath) }, candidate: { capabilityId: "RENDER.LIGHTING_FIELDS", representativeBehavior: behavior, behaviorHash, dedupeKey: `RENDER.LIGHTING_FIELDS|${behaviorHash}|${sha256(sourceApiPath)}|${sha256(sourceTestPath)}`, sourceBacked: true, chromiumProductionReady: true, fullFamilyParity: false }, inventory: { matchedEntries: candidates.length, counts, total: inventory.summary.inventoryEntries, pending: inventory.summary.pendingLegacyEntries, remainderExplicit: true }, entries: candidates, policy: { sourceHistoryReadOnly: true, representativeSliceOnly: true, noRepeatedExecution: true, duplicateValidationAvoided: true, fullHistoricalReproduction: false } };
|
|
const report = { schemaVersion: 1, task: "WBV2-P15-001", operation: "SELECT_LIGHTING_CAPABILITY_BATCH", status: "PASS", candidate: candidate.candidate, inventory: candidate.inventory, source: candidate.source, matchedEntryDigest: digestText(JSON.stringify(candidates)), efficiency: { oneSourceScan: true, existingStrategyReused: true, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, duplicateValidationAvoided: true }, nextTask: "WBV2-P15-002" };
|
|
if (!write) { process.stdout.write(`wbv2-lighting-selection-ok task=WBV2-P15-001 matched=${candidates.length} capability=RENDER.LIGHTING_FIELDS behaviorHash=${behaviorHash} pending=6618 repeatedRuns=0 next=WBV2-P15-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-P15-001 status\n\n- task: \`WBV2-P15-001\`; parent: \`WBV2-P15-000\`; status: \`done\`\n- selected capability: \`RENDER.LIGHTING_FIELDS\`; operations: Camera, Light, World fields\n- matched inventory entries: \`${candidates.length}\`; inventory remains \`6900\` total, \`6618\` pending\n- behavior hash: \`${behaviorHash}\`\n- dedupe key binds source API/test hashes; repeated Blender/Chromium runs: \`0\`\n- representative slice: \`true\`; full-family parity: \`false\`\n- nextTask: \`WBV2-P15-002\`\n\nThe candidate is selected from the existing parity map and source/test implementations. Only one unique Camera/Light/World behavior batch will be executed; matching inventory entries remain coverage references, not completion claims.\n`);
|
|
const previousPlan = json("tests/golden/WBV2-P15-000/lights-task-plan.json"); const nextPlan = structuredClone(previousPlan); nextPlan.parentRecoveryPlan = { path: "tests/golden/WBV2-P15-000/lights-task-plan.json", sha256: sha256("tests/golden/WBV2-P15-000/lights-task-plan.json") }; nextPlan.tasks = nextPlan.tasks.map((task) => task.id === "WBV2-P15-001" ? { ...task, status: "done", ready: false } : task.id === "WBV2-P15-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-P15-002.md"), read("docs/tasks/WBV2-P15-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-P15-001", "--write"], { cwd: root, stdio: "inherit" });
|
|
const artifactPaths = { parentManifest: parentPath, inventory: inventoryPath, strategy: p14StrategyPath, sourceApi: sourceApiPath, sourceTest: sourceTestPath, sourceGolden: sourceGoldenPath, candidate: candidatePath, report: reportPath, generator: "tools/web/generate-wbv2-lighting-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-P15-001", parentTask: "WBV2-P15-000", operation: "SELECT_LIGHTING_CAPABILITY_BATCH", status: "done", enablingTask: true, parityStateChange: false, runtime: "READ_ONLY_SOURCE_CANDIDATE_SELECTION", artifacts, assertions: { capability: "RENDER.LIGHTING_FIELDS", matchedInventoryEntries: candidates.length, inventoryTotal: 6900, inventoryPending: 6618, sourceApiBound: true, chromiumTestBound: true, representativeSliceOnly: true, fullFamilyParity: false, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, duplicateValidationAvoided: true, deterministic: true, historicalReproduction: false }, nextTask: "WBV2-P15-002" }; fs.writeFileSync(absolute(manifestPath), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
let queue = read("docs/EXECUTION_QUEUE.md"); queue = queue.replace(/\| 当前任务 \| `[^`]+` \|/u, "| 当前任务 | `WBV2-P15-002` |").replace(/\| parent manifest \| `[^`]+` \|/u, "| parent manifest | `tests/golden/WBV2-P15-001/manifest.json` |").replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u, "| 任务卡 | [`tasks/WBV2-P15-002.md`](tasks/WBV2-P15-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-P15-002` |").replace(/\| Current task state \| `[^`]+` \|/u, "| Current task state | `in_progress` |").replace(/\| Parent manifest \| `[^`]+` \|/u, "| Parent manifest | `tests/golden/WBV2-P15-001/manifest.json` |").replace(/\| Current task card \| `[^`]+` \|/u, "| Current task card | `docs/tasks/WBV2-P15-002.md` |").replace(/\| Current task-context nextTask \| `[^`]+` \|/u, "| Current task-context nextTask | `WBV2-P15-003` |").replace(/\| Focused command \| `[^`]+` \|/u, "| Focused command | `npm --prefix web run test:e2e -- --workers=1 tests/e2e/wbv2-lighting-fields-production.spec.ts` |"); fs.writeFileSync(absolute("nextTask.md"), nextTask);
|
|
process.stdout.write(`wbv2-lighting-selection-written task=WBV2-P15-001 matched=${candidates.length} capability=RENDER.LIGHTING_FIELDS behaviorHash=${behaviorHash} pending=6618 next=WBV2-P15-002 artifacts=${Object.keys(artifacts).length}\n`);
|