A page that shows how many tokens each model has left across your accounts. It is estimated from magpie's quota windows (/v1/magpie/quotas) and past usage rounds: the median tokens per percent over the rounds that can be used, or one round, or "sparse". The report carries no prose. The page words everything in English or Chinese. The service binds only to loopback, checks the Host, refuses a foreign Origin, wants a per-run key for Origin null, serves index.html to navigations only, and writes nothing under HOME. page-model-quota 0.1.0.
Run at the reviewed head dd8d44164d505088efeb07d80784128134aad213, on the Windows box (mote's sshd was refusing connections):
- node --test test/*.test.mjs: 14 pass. bun test: 14 pass. bun scripts/check.mjs: exit 0. It merges cleanly with main 86d3febf.
- Broken by hand: taking the space out of " (from past rounds)" again turns i18n.test red (13 of 14).
At a5d9a8c5, on mote and in WSL (from the review): the Host, Origin, key and navigate-only checks each went red when broken. Wrong Hosts got 403, Origin null without a key got 401, traversal got 404, and a restart rotated the key. The page rendered in Chromium and WebKit at 1200px and 420px, with no Chinese in English. Since then, only the English note's space, an unused usableRounds, the English gateway error and template-literal coverage in the i18n test have changed.
Not tried: in a real magpie window with real quota windows.
46 lines
2.0 KiB
JavaScript
46 lines
2.0 KiB
JavaScript
import test from "node:test";
|
||
import assert from "node:assert/strict";
|
||
import { readFileSync } from "node:fs";
|
||
import { join } from "node:path";
|
||
|
||
const dir = join(import.meta.dirname, "..");
|
||
const read = (file) => readFileSync(join(dir, file), "utf8");
|
||
|
||
// 报表里只放语言无关的值,词由页面按语言给出。中文出现在报表里,
|
||
// 英文页面就会显示中文。
|
||
test("the report carries no prose for the page to print", () => {
|
||
const source = read("lib/report.mjs");
|
||
const code = source
|
||
.split("\n")
|
||
.filter((line) => !/^\s*(\/\/|\*)/.test(line))
|
||
.join("\n");
|
||
// 双引号字符串和模板字符串都要查:任何一种带上中文,英文页面就会显示中文。
|
||
const literals = [
|
||
...[...code.matchAll(/"([^"\\\n]*[\u4e00-\u9fff][^"\\\n]*)"/g)].map((m) => m[1]),
|
||
...[...code.matchAll(/`([^`\\\n]*[\u4e00-\u9fff][^`\\\n]*)`/g)].map((m) => m[1]),
|
||
];
|
||
// 只有识别窗口名字用的正则里允许中文,字符串字面量一个都不该有。
|
||
assert.deepEqual(literals, []);
|
||
});
|
||
|
||
test("an unassigned model and an account with no user have no words in them", () => {
|
||
const source = read("lib/report.mjs");
|
||
assert.match(source, /addModel\(models, "", tokens, poolKey, ""\)/);
|
||
assert.doesNotMatch(source, /未分模型/);
|
||
assert.doesNotMatch(source, /无账号/);
|
||
assert.match(source, /group\.user \? `\$\{group\.provider\}\/\$\{group\.user\}·\$\{p\.label\}` : `\$\{group\.provider\}·\$\{p\.label\}`/);
|
||
});
|
||
|
||
test("the low-confidence word brings its own brackets", () => {
|
||
const app = read("ui/app.js");
|
||
assert.match(app, /historical: " \(from past rounds\)"/);
|
||
assert.match(app, /historical: "(按历史轮次估)"/);
|
||
assert.match(app, /fmtTokens\(pool\.tokens\) \+ t\.historical/);
|
||
assert.doesNotMatch(app, /"(" \+ t\.historical/);
|
||
});
|
||
|
||
test("the page declares its own language", () => {
|
||
const app = read("ui/app.js");
|
||
assert.match(app, /document\.documentElement\.lang = lang === "zh" \? "zh-CN" : "en"/);
|
||
});
|