New page plugin @magpie-community/page-usage-tree 0.1.0 by CHENZUDE: magpie's usage as a provider -> account -> model tree, served by a small server that reads the gateway's /v1/magpie/usage and /usage/requests.
The last round (f9e0907) gives the model row's calls cell the calls-cell class, so CALLS values sit under their right-aligned header, adds a test for it, and comments why the server's retry budget is 16 x 100ms.
What was run at f9e09079 (mote, macOS, sandbox HOME):
- In the package: node --test 50 pass; bun test 47 tests, 0 fail.
- f9e09079 merged onto main 8765cf8f: bun scripts/check.mjs ok; whole-repo bun test 6149 pass, 20 skip, 0 fail.
- Playwright against a fake gateway: CALLS header and value right edges 616/616 (1280px), 423/423 (900), 341/341 (760, 621) in Chromium and WebKit. Chromium 1280-620px, WebKit 900/760, both engines at 420px in en and zh: no clipped cell, no sideways scroll, no <select>, no page errors.
- Broken by hand: the old `model.errors ? "bad" : ""` puts values at 544 and 273 and turns "model calls sit under the right-aligned calls header" red (27 pass, 1 fail).
Not tried: a real magpie with real accounts, the desktop app, Windows and Linux.
30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { aggregateGatewayUsage } from "../lib/usage.mjs";
|
|
import { startServer } from "../lib/server.mjs";
|
|
|
|
// A fresh install has no usage yet. The gateway answers with zero calls and
|
|
// no accounts, and the page must show an empty tree with a note, not a 500.
|
|
test("a fresh install has an empty tree, not an error", async (t) => {
|
|
const empty = aggregateGatewayUsage({ calls: 0, accounts: [] }, {}, { period: "7d" });
|
|
|
|
assert.deepEqual(empty.providers, []);
|
|
assert.deepEqual(empty.accounts, []);
|
|
assert.equal(empty.summary.calls, 0);
|
|
assert.equal(empty.summary.accounts, 0);
|
|
assert.ok(empty.warnings.some((item) => item.code === "no-usage"));
|
|
|
|
const info = await startServer({
|
|
port: 0,
|
|
load: async () => empty,
|
|
});
|
|
t.after(() => info.close());
|
|
const res = await fetch(`http://127.0.0.1:${info.port}/api/tree?period=7d`, {
|
|
headers: { "x-usage-tree-token": info.token },
|
|
});
|
|
assert.equal(res.status, 200);
|
|
const body = await res.json();
|
|
assert.deepEqual(body.accounts, []);
|
|
assert.ok(body.warnings.some((item) => item.code === "no-usage"));
|
|
});
|