Files
alkane-os/third-party/flare-ui/dash-editor/tools/make-vectors.mjs
T
x ad31cfbafa Vendor flare-ui v0.2.9 and prove the schema-driven UI in an image
Spike, not the final UI: it answers whether flare-ui can drive Alkane OS's
on-box pages, and what it costs.

What works:

- schema/alkane-bb.json authors the sidebar as data (3 sections, 14 tabs);
- src/bin/ui-spike.rs renders it through flare_ui::nav + flare_ui::shell, so
  the unified sidebar, ordering and surface filtering come from the schema
  rather than from hand-written HTML;
- the render uses the shared bf- design tokens, the same ones the rest of the
  suite uses.

Size, measured rather than assumed (armv7, release, stripped):

  ui-baseline   323 KiB   (maud + serde_json, no flare-ui)
  ui-spike      771 KiB   (flare-ui + wschema + sha2)
  marginal      448 KiB

Vendoring: third-party/flare-ui is the full v0.2.9 tree pinned in
flare-ui/flare-ui.lock (a partial archive does not compile, since the crate
include_str!s assets from dash-editor/). vendor/ is re-generated as a cargo
directory source with the new registry dependencies (maud, sha2, typenum,
digest, generic-array, block-buffer, crypto-common, cfg-if, etc.) so the build
still works offline. third-party/README.md records how to re-pin.
2026-11-04 14:06:25 -06:00

99 lines
5.3 KiB
JavaScript

// Regenerates vectors/ and vectors/cases.json. The cases are written out here
// once, so a reader of this file sees every rule beside the input that tests it.
//
// node tools/make-vectors.mjs
import fs from "node:fs";
import path from "node:path";
import { checksum } from "./wdash.mjs";
const out = path.join(import.meta.dirname, "..", "vectors");
const AT = "2026-10-02T14:05:09Z";
const header = (document, extra = {}) => ({
wdash: 1, name: "Compressor station", author: "operator", exported_at: AT,
checksum: checksum(document), document, ...extra,
});
const basic = {
version: 3,
blocks: [
{ id: "head", title: "Station", body: { kind: "heading", value: { literal: "Compressor station" }, level: 2 } },
{ id: "top", title: "Readings", body: { kind: "group", flow: "row", children: [
{ id: "cpu", title: "CPU", width: 6, body: { kind: "metric", value: { source: "warden.metrics.cpu_pct" }, unit: "%" } },
{ id: "relay", title: "Relay 1", width: 6, body: { kind: "status", value: { source: "warden.relays.r1" }, unit: "" } },
] } },
{ id: "tank", title: "Tank", body: { kind: "gauge", value: { source: "telemetry.rs485.level" }, unit: "%", min: 0, max: 100,
thresholds: { caution: 20, critical: 10, rising: false } } },
{ id: "note", title: "Note", body: { kind: "text", value: { literal: "Check the pump" } } },
],
};
// RFC 8785 is where implementations drift, so this one is written as text:
// the spellings below are what a hand-edited file holds, and each one has a
// canonical form a careless serializer gets wrong.
const numbersText = `{"version": 3, "blocks": [
{"id": "range", "title": "Range", "body": {"kind": "gauge", "value": {"source": "warden.metrics.cpu_pct"},
"unit": "C", "min": -40.50, "max": 1000.0}},
{"id": "later", "title": "Later", "body": {"kind": "future_dial",
"zeta": 1e21, "alpha": 0.0000001, "beta": -0.0, "big": 12345678901234567890,
"small": -1.5e-9, "third": 0.3333333333333333, "huge": 100000000000000000000000,
"\\u00e9t\\u00e9": "Caf\\u00e9 \\u2603", "\\uffff": 1, "\\ud83d\\ude00": "\\ud83d\\ude00",
"z": "tab\\tquote\\"slash/", "Z": [1.5, 2e-7, true, null]}}
]}`;
const numbers = JSON.parse(numbersText);
const files = {};
const cases = [];
function add(file, body, flare, warden, layer, reason) {
files[file] = typeof body === "string" ? body : JSON.stringify(body, null, 2) + "\n";
const c = { file, layer, flare, warden };
if (reason) c.reason = reason;
cases.push(c);
}
add("basic.wdash", header(basic), "ok", "ok", "document");
// The numbers file keeps its hand spelling, so the checksum is over the parsed
// document while the bytes on disk are not canonical. That is the point.
add("numbers.wdash", `{"wdash": 1, "name": "Numbers", "author": "", "exported_at": "${AT}",
"checksum": "${checksum(numbers)}",
"document": ${numbersText}}
`, "ok", "ok", "document");
add("unknown-kind.wdash", header({ version: 3, blocks: [
{ id: "flow", title: "Flow", body: { kind: "sankey", links: [{ from: "a", to: "b" }] } }] }), "ok", "ok", "document");
add("bad-checksum.wdash", header(basic, { checksum: "sha256:" + "0".repeat(64) }), "refuse", "refuse", "header", "checksum");
add("unknown-header-field.wdash", header(basic, { signature: "none" }), "refuse", "refuse", "header", "signature");
{
const missing = header(basic); delete missing.author;
add("missing-field.wdash", missing, "refuse", "refuse", "header", "author");
}
add("newer-format.wdash", header(basic, { wdash: 2, signature: "later" }), "refuse", "refuse", "version", "newer");
add("bad-stamp.wdash", header(basic, { exported_at: "2026-10-02 14:05" }), "refuse", "refuse", "header", "exported_at");
add("control-name.wdash", header(basic, { name: "Two\nlines" }), "refuse", "refuse", "header", "name");
{
const doc = { version: 3, blocks: [{ id: "a", title: "A", colour: "red", body: { kind: "text", value: { literal: "x" } } }] };
add("unknown-frame-field.wdash", header(doc), "refuse", "refuse", "document", "colour");
}
{
const doc = { version: 3, blocks: [{ id: "a", title: "A", body: { kind: "metric", value: { source: "warden.net.hosts_online" }, unit: "", threshold: 5 } }] };
add("unknown-attribute.wdash", header(doc), "refuse", "refuse", "document", "threshold");
}
{
const doc = { version: 3, blocks: [], theme: "dark" };
add("unknown-document-field.wdash", header(doc), "refuse", "refuse", "document", "theme");
}
{
const doc = { version: 3, blocks: [{ id: "a", title: "A", body: { kind: "text", value: { literal: "x", source: "warden.net.hosts_online" } } }] };
add("two-values.wdash", header(doc), "refuse", "refuse", "document", "value");
}
{
const doc = { version: 2, blocks: [{ id: "a", title: "A", x: 0, y: 0, width: 6, height: 1,
body: { kind: "metric", value: { source: "warden.metrics.cpu_pct" }, unit: "%" } }] };
add("document-v2.wdash", header(doc), "ok", "refuse", "document", "version 2");
}
add("document-v9.wdash", header({ version: 9, blocks: [] }), "refuse", "refuse", "document", "version 9");
fs.mkdirSync(out, { recursive: true });
for (const name of fs.readdirSync(out)) fs.rmSync(path.join(out, name));
for (const [name, body] of Object.entries(files)) fs.writeFileSync(path.join(out, name), body);
fs.writeFileSync(path.join(out, "cases.json"), JSON.stringify({ cases }, null, 2) + "\n");
console.log(`${cases.length} cases written to ${out}`);