import assert from "node:assert/strict"; import crypto from "node:crypto"; import fs from "node:fs/promises"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { createServerJobOutputReceipt, SERVER_JOB_OUTPUT_LIMITS } from "./server-job-output.mjs"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); const reportPath = path.join(root, "tests/golden/M13-04F/server-job-output-report.json"); const manifestPath = path.join(root, "tests/golden/M13-04F/manifest.json"); const hashFile = async (file) => crypto.createHash("sha256").update(await fs.readFile(file)).digest("hex"); const unixFixturePath = ["/home", "runner", "project", "source.blend"].join("/"); const windowsFixturePath = ["C:", "Users", "runner", "job", "stderr.log"].join("\\"); const fileFixturePath = ["file:", "", "tmp", "internal.log"].join("/"); const receipt = createServerJobOutputReceipt({ stdout: `INFO source=${unixFixturePath} authorization: Bearer abc123 token="top-secret"\n` + "x".repeat(80_000), stderr: `ERROR ${windowsFixturePath} ${fileFixturePath}\n` + "y".repeat(80_000), }); assert.equal(receipt.execution, "DISABLED"); assert.equal(receipt.stdout.truncated, true); assert.equal(receipt.stderr.truncated, true); assert.ok(receipt.totalRedactions >= 5); assert.doesNotMatch(JSON.stringify(receipt), /abc123|top-secret|\/home\/runner|C:\\Users|file:\/\//u); assert.ok(receipt.totalEmittedBytes <= SERVER_JOB_OUTPUT_LIMITS.totalBytes); const report = { schemaVersion: 1, task: "M13-04F", operation: "SERVER_JOB_OUTPUT_REDACTION", limits: SERVER_JOB_OUTPUT_LIMITS, normal: createServerJobOutputReceipt({ stdout: "Blender 5.2 background\n", stderr: "" }), oversized: receipt, negative: { missingOutput: createServerJobOutputReceipt({ stdout: "", stderr: "" }).totalOriginalBytes, invalidBudget: "SERVER_JOB_OUTPUT_INVALID", }, execution: "DISABLED", nextTask: "M13-04G", }; if (process.env.UPDATE_M13_04F_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-04F", parentTask: "M13-04E", nextTask: "M13-04G" }); 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-output-ok stdoutTruncated=1 stderrTruncated=1 redactions=${receipt.totalRedactions} totalBounded=1 execution=DISABLED next=${manifest.nextTask}\n`);