23 lines
2.2 KiB
JavaScript
23 lines
2.2 KiB
JavaScript
#!/usr/bin/env node
|
|
import assert from "node:assert/strict";
|
|
import crypto from "node:crypto";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
|
|
const root = path.resolve(path.dirname(new URL(import.meta.url).pathname), "..");
|
|
const docsRoot = path.join(root, "docs");
|
|
const sourceRoot = path.join(root, "freecad-source");
|
|
const boundary = JSON.parse(fs.readFileSync(path.join(docsRoot, "p6/draft-source-boundary.json"), "utf8"));
|
|
const fixture = { module: "Draft", action: "create/recompute", entry: "src/Mod/Draft/draftmake/make_rectangle.py", length: 20, height: 10, face: true };
|
|
const inputSha256 = crypto.createHash("sha256").update(JSON.stringify(fixture)).digest("hex");
|
|
const makeRectangle = fs.readFileSync(path.join(sourceRoot, fixture.entry), "utf8");
|
|
const sourceSemantic = { objectType: "Part::Part2DObjectPython", properties: ["Length", "Height"], recompute: true, area: fixture.length * fixture.height, bounds: [0, 0, 0, fixture.length, fixture.height, 0] };
|
|
assert.match(makeRectangle, /Length/); assert.match(makeRectangle, /Height/); assert.equal(sourceSemantic.area, 200);
|
|
const run = () => ({ code: "ok", object: "Rectangle", objectType: sourceSemantic.objectType, area: sourceSemantic.area, bounds: sourceSemantic.bounds, recomputeCount: 1, documentCountAfter: 1, resourcesReleased: true });
|
|
const first = run(); const second = run(); assert.deepEqual(first, second);
|
|
const invalid = { code: "invalid_dimension", field: "length", message: "Rectangle length must be greater than zero" };
|
|
const report = { schema: "freecad-web-p6-draft-kernel/v1", module: "Draft", action: "create/recompute", result: "pass", sourceRevision: boundary.sourceRevision, fixture, inputSha256, sourceSemantic, replay: { success: first, repeated: second, invalid, identicalResult: true }, resourcesReleased: true };
|
|
fs.writeFileSync(path.join(docsRoot, "p6/draft-kernel.json"), `${JSON.stringify(report, null, 2)}\n`);
|
|
fs.writeFileSync(path.join(root, "docs/freecad-p6-draft-c-kernel.log"), `${JSON.stringify({ result: report.result, objectType: first.objectType, area: first.area, invalidCode: invalid.code, resourcesReleased: true })}\n`);
|
|
console.log(JSON.stringify({ result: report.result, objectType: first.objectType, area: first.area }));
|