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.
96 lines
3.8 KiB
JavaScript
96 lines
3.8 KiB
JavaScript
// Browser check of the live client against a stub SSE server.
|
|
// Needs Playwright: set PLAYWRIGHT_DIR to a directory whose node_modules has
|
|
// it. Without it the check prints a skip note and exits 0. Headless only.
|
|
import http from "node:http";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { createRequire } from "node:module";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
const assets = path.resolve(here, "../../crates/flare-ui/assets");
|
|
const dir = process.env.PLAYWRIGHT_DIR;
|
|
if (!dir) {
|
|
console.log("skip: PLAYWRIGHT_DIR not set");
|
|
process.exit(0);
|
|
}
|
|
const { chromium } = createRequire(path.join(dir, "x.js"))("playwright");
|
|
|
|
const PAGE = `<!doctype html><meta charset="utf-8"><title>live</title>
|
|
<div class="bf-kv" data-live data-key="temp"><span class="bf-kv-value">-- C</span></div>
|
|
<figure data-live data-island="chart" data-key="temp"><canvas width="200" height="80"></canvas></figure>
|
|
<script src="/live.js"></script><script src="/chart.js"></script>
|
|
<script>
|
|
var live = new FlareLive.Live("/sse", {staleAfterMs: 600, backoffMinMs: 100, backoffMaxMs: 200});
|
|
FlareLive.bindStaleMarker(live, document);
|
|
FlareChart.bindCharts(live, document);
|
|
live.start();
|
|
window.__live = live;
|
|
</script>`;
|
|
|
|
let mode = "stream"; // stream | silent | refuse
|
|
let opens = 0;
|
|
const server = http.createServer((req, res) => {
|
|
if (req.url === "/") {
|
|
res.setHeader("content-type", "text/html");
|
|
return res.end(PAGE);
|
|
}
|
|
if (req.url === "/live.js" || req.url === "/chart.js") {
|
|
res.setHeader("content-type", "text/javascript");
|
|
return res.end(fs.readFileSync(path.join(assets, "js", req.url.slice(1))));
|
|
}
|
|
if (req.url === "/sse") {
|
|
opens++;
|
|
if (mode === "refuse") { res.statusCode = 503; return res.end(); }
|
|
res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-store" });
|
|
res.write(": open\n\n");
|
|
if (mode === "silent") return;
|
|
let n = 0;
|
|
const iv = setInterval(() => {
|
|
n++;
|
|
res.write(`data: ${JSON.stringify({ k: "temp", v: 20 + n })}\n\n`);
|
|
}, 100);
|
|
req.on("close", () => clearInterval(iv));
|
|
return;
|
|
}
|
|
res.statusCode = 404;
|
|
res.end();
|
|
});
|
|
|
|
function check(cond, msg) {
|
|
if (!cond) throw new Error("FAIL: " + msg);
|
|
console.log("ok: " + msg);
|
|
}
|
|
|
|
await new Promise((r) => server.listen(0, "127.0.0.1", r));
|
|
const base = `http://127.0.0.1:${server.address().port}`;
|
|
const browser = await chromium.launch({ headless: true });
|
|
try {
|
|
const page = await browser.newPage();
|
|
page.on("pageerror", (e) => console.log("pageerror", e.message));
|
|
await page.goto(base + "/");
|
|
await page.waitForFunction(() => window.__live.samples("temp").length >= 3, null, { timeout: 5000 });
|
|
const txt = await page.textContent(".bf-kv-value");
|
|
check(/^\d+ C$/.test(txt.trim()), `reading text updated (${txt.trim()})`);
|
|
check(!(await page.locator(".bf-kv").evaluate((e) => e.classList.contains("bf-stale"))), "fresh stream is not stale");
|
|
const inked = await page.locator("canvas").evaluate((c) => {
|
|
const d = c.getContext("2d").getImageData(0, 0, c.width, c.height).data;
|
|
for (let i = 3; i < d.length; i += 4) if (d[i] !== 0) return true;
|
|
return false;
|
|
});
|
|
check(inked, "chart canvas has drawn pixels");
|
|
|
|
mode = "silent";
|
|
await page.evaluate(() => window.__live.es.close() || window.__live.es.onerror());
|
|
await page.waitForFunction(() => document.querySelector(".bf-kv").classList.contains("bf-stale"), null, { timeout: 5000 });
|
|
check(true, "dropped stream marks readings stale");
|
|
|
|
mode = "stream";
|
|
const before = opens;
|
|
await page.waitForFunction(() => !document.querySelector(".bf-kv").classList.contains("bf-stale"), null, { timeout: 8000 });
|
|
check(opens > before, "client reconnected and cleared the stale marker");
|
|
} finally {
|
|
await browser.close();
|
|
server.close();
|
|
}
|