33 lines
2.8 KiB
JavaScript
33 lines
2.8 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import crypto from "node:crypto";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { spawnSync } from "node:child_process";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
const fixtureRoot = path.join(root, "tests/files/web/m12_ply_negative_v1");
|
|
const reportPath = path.join(root, "tests/golden/M12-07I/negative-report.json");
|
|
const manifestPath = path.join(root, "tests/golden/M12-07I/manifest.json");
|
|
const generator = path.join(root, "tools/web/generate-ply-negative-fixtures.mjs");
|
|
const sha256 = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex");
|
|
const readJson = (file) => JSON.parse(fs.readFileSync(file, "utf8"));
|
|
const manifest = readJson(manifestPath);
|
|
const report = readJson(reportPath);
|
|
assert.deepEqual({ schemaVersion: manifest.schemaVersion, task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask }, { schemaVersion: 1, task: "M12-07I", parentTask: "M12-07H", nextTask: "M12-07J" });
|
|
assert.deepEqual({ schemaVersion: report.schemaVersion, task: report.task, operation: report.operation, nextTask: report.nextTask }, { schemaVersion: 1, task: "M12-07I", operation: "PLY_NEGATIVE_FORMAT_LIST_COUNT", nextTask: "M12-07J" });
|
|
assert.deepEqual(report.cases.map((item) => item.expectedCode), ["PLY_FORMAT_UNSUPPORTED", "PLY_DATA_TRUNCATED", "PLY_IMPORT_BUDGET_EXCEEDED: vertex"]);
|
|
for (const file of report.files) assert.equal(sha256(fs.readFileSync(path.join(fixtureRoot, file.name))), file.sha256, `hash mismatch ${file.name}`);
|
|
for (const artifact of Object.values(manifest.artifacts)) assert.equal(sha256(fs.readFileSync(path.join(root, artifact.path))), artifact.sha256, `artifact hash mismatch ${artifact.path}`);
|
|
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "m12-07i-ply-"));
|
|
try {
|
|
const output = path.join(temporary, "negative-report.json");
|
|
const result = spawnSync(process.execPath, [generator], { cwd: root, env: { ...process.env, M12_PLY_NEGATIVE_OUTPUT: temporary, M12_PLY_NEGATIVE_REPORT: output }, encoding: "utf8" });
|
|
assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);
|
|
assert.deepEqual(readJson(output), report, "PLY negative report is not deterministic");
|
|
for (const file of report.files) assert.deepEqual(fs.readFileSync(path.join(temporary, file.name)), fs.readFileSync(path.join(fixtureRoot, file.name)), `${file.name} bytes are not deterministic`);
|
|
}
|
|
finally { fs.rmSync(temporary, { recursive: true, force: true }); }
|
|
process.stdout.write(`ply-negative-fixtures-ok cases=${report.cases.length} bigEndian=PLY_FORMAT_UNSUPPORTED malformed=PLY_DATA_TRUNCATED oversized=PLY_IMPORT_BUDGET_EXCEEDED deterministic=true next=${report.nextTask}\n`);
|