// SPDX-License-Identifier: GPL-3.0-only // Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) // (V10.8.77, a user: "the sound editor used to show modules, for a few updates now it is a vertical list") editor.html's // knownLayout against the firmware's own counts: P_COUNT, G_COUNT and P_E0 compiled from core.h of each commit named // (default: web/STABLE and web/PREVIEW), each must be a known layout, so the SOUND page shows its modules, not the plain // list. Also: every older layout still known, a firmware with parameters appended at the end still known. // node web/editor_layout_test.mjs [ ...] // Needs git (the commits fetched) and a C compiler. Run by emulator.yml before the site is deployed. import fs from "fs"; import os from "os"; import path from "path"; import { execFileSync } from "child_process"; const HERE = path.dirname(new URL(import.meta.url).pathname); const html = fs.readFileSync(path.join(HERE, "editor.html"), "utf8"); const a = html.indexOf("const EXPECT = "), b = html.indexOf("const P = {", a); const knownLayout = new Function(html.slice(a, b) + "; return knownLayout;")(); let fails = 0; const ok = (c, what) => { console.log(`${what.padEnd(96)} ${c ? "ok" : "FAIL"}`); if (!c) fails++; }; for (const [pcount, gcount, pe0] of [[123, 73, 115], [120, 66, 112], [99, 36, 91], [91, 27, 83], [57, 27, 49]]) ok(knownLayout({ pcount, gcount, pe0 }), `an older layout still known: P_COUNT ${pcount} G_COUNT ${gcount} P_E0 ${pe0}`); ok(knownLayout({ pcount: 125, gcount: 80, pe0: 117 }), "parameters appended at the end (P_COUNT 125, G_COUNT 80): still known"); ok(!knownLayout({ pcount: 123, gcount: 77, pe0: 100 }), "an engine block not last (P_E0 100 of 123): the plain list"); const commits = process.argv.slice(2).length ? process.argv.slice(2) : ["STABLE", "PREVIEW"].map((f) => fs.readFileSync(path.join(HERE, f), "utf8").trim()); const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "edlay-")); fs.writeFileSync(path.join(tmp, "pc.c"), '#include "core.h"\n#include \nint main(void){printf("%d %d %d\\n",(int)P_COUNT,(int)G_COUNT,(int)P_E0);return 0;}\n'); for (const c of [...new Set(commits)]) { const src = path.join(tmp, c); fs.mkdirSync(src); for (const f of execFileSync("git", ["ls-tree", "--name-only", c, "firmware/src/"], { encoding: "utf8" }).split("\n")) if (f.endsWith(".h")) fs.writeFileSync(path.join(src, path.basename(f)), execFileSync("git", ["show", `${c}:${f}`], { maxBuffer: 1 << 26 })); execFileSync("cc", ["-w", "-I" + src, path.join(tmp, "pc.c"), "-o", path.join(src, "pc")]); const [pcount, gcount, pe0] = execFileSync(path.join(src, "pc"), { encoding: "utf8" }).trim().split(" ").map(Number); ok(knownLayout({ pcount, gcount, pe0 }), `firmware ${c.slice(0, 7)} (P_COUNT ${pcount} G_COUNT ${gcount} P_E0 ${pe0}): the modules, not the plain list`); } fs.rmSync(tmp, { recursive: true, force: true }); console.log(fails ? `editor-layout: ${fails} FAILED` : "editor-layout: all ok"); process.exit(fails ? 1 : 0);