const assert = require("node:assert/strict"); const fs = require("node:fs"); const path = require("node:path"); const root = path.join(__dirname, ".."); const read = relative => fs.readFileSync(path.join(root, relative), "utf8"); const settings = read("src/admin/web/settings.js"); const certificateApi = read("src/admin/web/certificate-api.js"); const core = read("src/admin/web/app/core.js"); const cache = read("src/admin/web/cache-panel.js"); const transform = read("src/admin/web/transform-panel.js"); const traffic = read("src/admin/web/traffic-panel.js"); const openapi = JSON.parse(read("src/admin/openapi.json")); assert.match(settings, /authenticated && name === "certificate-api"[^\n]+rustProxyCertificateApi\?\.load/); assert.match(settings, /authenticated && active === "certificate-api"[^\n]+rustProxyCertificateApi\?\.load/); assert.ok(!/renderCertificateApi\(\);\s*loadCertificateApi\(\);\s*\}\)\(\);\s*$/.test(certificateApi), "Certificate API must not fetch credentials when its module is initialized"); assert.match(core, /async function refresh\(force = false, includeLogs = false\)/); assert.match(core, /if \(includeLogs\) tasks\.push\(rustProxyRefresh\.manual\("logs-fallback"\)\)/); assert.match(core, /refresh\(true, true\)\.catch/); for (const [name, source, endpoint] of [ ["cache", cache, "/api/cache"], ["transform", transform, "/api/transform"], ["traffic", traffic, "/api/traffic"], ]) { assert.ok(/view=live/.test(source) || /set\(\"view\", \"live\"\)/.test(source), `${name} panel must use the lightweight polling view`); assert.match(source, /data\.revision !== staticRevision/, `${name} panel must invalidate static data on config revision changes`); assert.match(source, /reset\(\)[\s\S]{0,220}staticData = null[\s\S]{0,120}staticRevision = null/, `${name} panel reset must discard static cached API data`); const operation = openapi.paths[endpoint].get; const view = (operation.parameters || []).find(parameter => parameter.name === "view"); assert.deepEqual(view?.schema?.enum, ["live"], `${endpoint} must document view=live`); } assert.equal(openapi.info.version, "0.36.0"); console.log("Panel refresh/API contract checks: OK");