import assert from "node:assert/strict"; import crypto from "node:crypto"; import fs from "node:fs/promises"; import path from "node:path"; import { execFile } from "node:child_process"; import { promisify } from "node:util"; import { fileURLToPath } from "node:url"; const exec = promisify(execFile); const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); const blender = process.env.BLENDER_BIN ?? path.join(root, "build_blender_5.2.0/bin/blender"); const startup = path.join(root, "tools/web/server-job-startup.py"); const reportPath = path.join(root, "tests/golden/M13-04E/server-job-startup-report.json"); const manifestPath = path.join(root, "tests/golden/M13-04E/manifest.json"); const hashFile = async (file) => crypto.createHash("sha256").update(await fs.readFile(file)).digest("hex"); const args = ["--background", "--factory-startup", "--python", startup, "--", "SERVER_JOB_STARTUP_V1"]; const result = await exec(blender, args, { cwd: root, maxBuffer: 2 * 1024 * 1024 }); const lines = result.stdout.trim().split(/\r?\n/).map((line) => line.trim()).filter((line) => line.startsWith("{")); assert.equal(lines.length, 1, result.stdout); const receipt = JSON.parse(lines[0]); assert.equal(receipt.schemaVersion, 1); assert.equal(receipt.runtime, "BLENDER_BACKGROUND_FACTORY_STARTUP"); assert.equal(receipt.background, true); assert.match(receipt.version, /^5\.2\./); assert.deepEqual(receipt.argv, ["SERVER_JOB_STARTUP_V1"]); const report = { schemaVersion: 1, task: "M13-04E", operation: "SERVER_JOB_BLENDER_STARTUP", blender, argv: args, receipt, factoryStartup: true, background: true, userPrefsDisabled: true, fixedStartupScript: true, execution: "DISABLED", nextTask: "M13-04F" }; if (process.env.UPDATE_M13_04E_REPORT === "1") { await fs.mkdir(path.dirname(reportPath), { recursive: true }); await fs.writeFile(reportPath, `${JSON.stringify(report, null, 2)}\n`); } assert.deepEqual(JSON.parse(await fs.readFile(reportPath, "utf8")), report); const manifest = JSON.parse(await fs.readFile(manifestPath, "utf8")); assert.deepEqual({ schemaVersion: manifest.schemaVersion, task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask }, { schemaVersion: 1, task: "M13-04E", parentTask: "M13-04D", nextTask: "M13-04F" }); for (const artifact of Object.values(manifest.artifacts)) assert.equal(await hashFile(path.join(root, artifact.path)), artifact.sha256, `artifact hash mismatch ${artifact.path}`); process.stdout.write(`server-job-startup-ok blender=5.2 background=1 factory=1 userPrefs=0 fixedScript=1 execution=DISABLED next=${manifest.nextTask}\n`);