2 lines
7.4 KiB
JavaScript
2 lines
7.4 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=f=>path.join(root,f);const read=f=>fs.readFileSync(abs(f),"utf8");const json=f=>JSON.parse(read(f));const sha=f=>crypto.createHash("sha256").update(fs.readFileSync(abs(f))).digest("hex");const out="tests/golden/WBV2-P18-002",parentPath="tests/golden/WBV2-P18-001/manifest.json",selectionPath="tests/golden/WBV2-P18-001/object-create-selection-report.json",productionPath=`${out}/object-create-production.json`,secondPath=`${out}/object-create-production.second.json`,reportPath=`${out}/object-create-receipt-report.json`,planPath=`${out}/create-task-plan.json`,manifestPath=`${out}/manifest.json`,statusPath="docs/status/WBV2-P18-002.md",apiPath="blender-5.2.0/source/blender/web_engine/web_engine_api.cpp",testPath="web/tests/e2e/wbv2-object-create-production.spec.ts",fixturePath="tests/files/web/basic_scene.blend";const parent=json(parentPath),selection=json(selectionPath),production=json(productionPath),second=json(secondPath);assert.equal(parent.status,"done");assert.equal(parent.nextTask,"WBV2-P18-002");for(const a of Object.values(parent.artifacts??{}))assert.equal(sha(a.path),a.sha256,a.path);assert.equal(selection.status,"PASS");assert.equal(selection.candidate.legacyId,"operator:object.add");assert.deepEqual(production,second);assert.equal(production.browser,"chromium");assert.equal(production.fixtureSha256,sha(fixturePath));assert.equal(production.afterCount,production.beforeCount+1);assert.equal(production.createRevision,2);assert.equal(production.undoRevision,3);assert.equal(production.redoRevision,4);assert.notEqual(production.malformed.code,"NO_ERROR");assert.equal(production.malformedRevisionPreserved,true);assert.equal(production.reopenedCount,production.afterCount);assert.equal(production.reopenedRevision,1);const receipt={schemaVersion:1,task:"WBV2-P18-002",operation:"OBJECT_CREATE_ENGINE_RECEIPT",status:"PASS",browser:"chromium",queueMutation:false,source:{manifest:parentPath,manifestSha256:sha(parentPath),selection:selectionPath,selectionSha256:sha(selectionPath),api:apiPath,apiSha256:sha(apiPath),test:testPath,testSha256:sha(testPath),fixture:fixturePath,fixtureSha256:sha(fixturePath)},production:{report:productionPath,reportSha256:sha(productionPath),secondReport:secondPath,secondReportSha256:sha(secondPath),deterministic:true,beforeCount:production.beforeCount,afterCount:production.afterCount,createdNode:production.createdNode,revisions:[production.baseRevision,production.createRevision,production.undoRevision,production.redoRevision],malformed:production.malformed,malformedRevisionPreserved:production.malformedRevisionPreserved,reopenedCount:production.reopenedCount,reopenedRevision:production.reopenedRevision,saveReopen:"EXACT"},inventoryBindings:[{id:"operator:object.add",evidence:"createPrimitive(CUBE)",exact:true,reason:"bounded protocol command creates and persists a primitive object"}],assertions:{distinctObjectCreated:true,undoRedoSequential:true,malformedRejected:true,mainUnchangedOnMalformed:true,saveReopenExact:true,deterministic:true,inventoryBindingsExact:true,representativeSliceOnly:true,fullFamilyParity:false,historicalReproduction:false},nextTask:"WBV2-P18-003"};if(!process.argv.includes("--write")){console.log("wbv2-create-receipt-ok task=WBV2-P18-002 binding=operator:object.add revisions=SEQUENTIAL malformed=REJECTED saveReopen=EXACT deterministic=true next=WBV2-P18-003");process.exit(0)}fs.mkdirSync(abs(out),{recursive:true});fs.writeFileSync(abs(reportPath),`${JSON.stringify(receipt,null,2)}\n`);fs.writeFileSync(abs(statusPath),`# WBV2-P18-002 status\n\n- task: \`WBV2-P18-002\`; parent: \`WBV2-P18-001\`; status: \`done\`\n- exact inventory binding: \`operator:object.add\` via \`createPrimitive(CUBE)\`\n- objects: \`${production.beforeCount} -> ${production.afterCount}\`; revisions: \`1 -> 4\` sequential\n- malformed primitive rejected; save/reopen: \`EXACT\`; deterministic second run: \`true\`\n- effective pending before overlay: \`6615\`; representative slice: \`true\`\n- nextTask: \`WBV2-P18-003\`\n`);const previous=json("tests/golden/WBV2-P18-001/create-task-plan.json"),next=structuredClone(previous);next.parentRecoveryPlan={path:"tests/golden/WBV2-P18-001/create-task-plan.json",sha256:sha("tests/golden/WBV2-P18-001/create-task-plan.json")};next.tasks=next.tasks.map(t=>t.id==="WBV2-P18-002"?{...t,status:"done",ready:false}:t.id==="WBV2-P18-003"?{...t,status:"in_progress",ready:true}:{...t,ready:false});fs.writeFileSync(abs(planPath),`${JSON.stringify(next,null,2)}\n`);fs.writeFileSync(abs("docs/tasks/WBV2-P18-003.md"),read("docs/tasks/WBV2-P18-003.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-P18-002","--write"],{cwd:root,stdio:"inherit"});const paths={parentManifest:parentPath,selection:selectionPath,api:apiPath,test:testPath,fixture:fixturePath,production:productionPath,secondProduction:secondPath,report:reportPath,generator:"tools/web/generate-wbv2-create-receipt.mjs",status:statusPath,parityPlan:planPath,taskContext:`${out}/task-context.json`};const artifacts=Object.fromEntries(Object.entries(paths).map(([n,f])=>[n,{path:f,sha256:sha(f)}]));fs.writeFileSync(abs(manifestPath),`${JSON.stringify({schemaVersion:1,task:"WBV2-P18-002",parentTask:"WBV2-P18-001",operation:"OBJECT_CREATE_ENGINE_RECEIPT",status:"done",enablingTask:false,parityStateChange:true,runtime:"PLAYWRIGHT_CHROMIUM_WEBENGINE_WASM",artifacts,assertions:{exactInventoryBindings:1,boundInventoryIds:["operator:object.add"],distinctObjectCreated:true,undoRedoSequential:true,malformedRejected:true,saveReopen:"EXACT",deterministic:true,representativeSliceOnly:true,fullFamilyParity:false,inventoryTotal:6900,baseInventoryPending:6618,effectivePending:6615,historicalReproduction:false},nextTask:"WBV2-P18-003"},null,2)}\n`);let q=read("docs/EXECUTION_QUEUE.md");q=q.replace(/\| 当前任务 \| `[^`]+` \|/u,"| 当前任务 | `WBV2-P18-003` |").replace(/\| parent manifest \| `[^`]+` \|/u,"| parent manifest | `tests/golden/WBV2-P18-002/manifest.json` |").replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u,"| 任务卡 | [`tasks/WBV2-P18-003.md`](tasks/WBV2-P18-003.md) |");fs.writeFileSync(abs("docs/EXECUTION_QUEUE.md"),q);let n=read("nextTask.md");n=n.replace(/\| Current task when this file was written \| `[^`]+` \|/u,"| Current task when this file was written | `WBV2-P18-003` |").replace(/\| Current task state \| `[^`]+` \|/u,"| Current task state | `in_progress` |").replace(/\| Parent manifest \| `[^`]+` \|/u,"| Parent manifest | `tests/golden/WBV2-P18-002/manifest.json` |").replace(/\| Current task card \| `[^`]+` \|/u,"| Current task card | `docs/tasks/WBV2-P18-003.md` |").replace(/\| Current task-context nextTask \| `[^`]+` \|/u,"| Current task-context nextTask | `NONE` |").replace(/\| Focused command \| `[^`]+` \|/u,"| Focused command | `node tools/web/generate-wbv2-create-gate.mjs --write` |");fs.writeFileSync(abs("nextTask.md"),n);console.log("wbv2-create-receipt-written task=WBV2-P18-002 binding=operator:object.add revisions=SEQUENTIAL malformed=REJECTED saveReopen=EXACT deterministic=true next=WBV2-P18-003");
|