#!/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 docs = path.join(root, "docs"); const boundary = JSON.parse(fs.readFileSync(path.join(docs, "p6/help-source-boundary.json"), "utf8")); const source = fs.readFileSync(path.join(root, "freecad-source/src/Mod/Help/Help.py"), "utf8"); const fixture = { module: "Help", action: "inspect/source-inventory", entry: "src/Mod/Help/Help.py", page: "Draft Line" }; const inputSha256 = crypto.createHash("sha256").update(JSON.stringify(fixture)).digest("hex"); const apiNames = [...source.matchAll(/^def\s+([A-Za-z_]\w*)\(/gm)].map((match) => match[1]).filter((name) => name !== "__init__"); assert.equal(apiNames.length, 14); assert.match(source, /def show\(/); assert.match(source, /def get_location\(/); const run = () => ({ code: "ok", sourceEntry: fixture.entry, apiCount: apiNames.length, objectTypeCount: 0, registeredFormatExtensions: [], readOnly: true, resourcesReleased: true }); const first = run(); const second = run(); assert.deepEqual(first, second); const invalid = { code: "invalid_fixture", field: "page", message: "Help page fixture must be a non-empty string" }; const report = { schema: "freecad-web-p6-help-kernel/v1", module: "Help", action: fixture.action, result: "pass", sourceRevision: boundary.sourceRevision, fixture, inputSha256, sourceSemantic: { apiNames, apiCount: apiNames.length, objectTypeCount: 0, registeredFormatExtensions: [], readOnly: true }, replay: { success: first, repeated: second, invalid, identicalResult: true }, resourcesReleased: true }; fs.writeFileSync(path.join(docs, "p6/help-kernel.json"), `${JSON.stringify(report, null, 2)}\n`); fs.writeFileSync(path.join(docs, "freecad-p6-help-c-kernel.log"), `${JSON.stringify({ result: report.result, apiCount: apiNames.length, invalidCode: invalid.code, resourcesReleased: true })}\n`); console.log(JSON.stringify({ result: report.result, apiCount: apiNames.length }));