Files
plugins/packages/free-tokens/test/assets.test.mjs
T
Mingchen Yuandsljdxde 7262e70c6c free-tokens: AIHOT Token 羊毛 page (#885)
New page plugin: AIHOT's Token 羊毛 (free model allowances), sorted into "ready" / "plugin to set up" / "no plugin" against the user's own magpie plugins. Only the vendors in src/allowlist.js are shown; anything else (relays included) is dropped before it reaches the page.

AIHOT's written approval (2026-11-10) is quoted on the PR: free, no ads or sponsors, each user reads it once on their own computer, no proxy, mirror or redistribution, credited in the footer.

Run at 07da91b0 (on mote):
- bun test packages/free-tokens: 62 pass. bun scripts/check.mjs free-tokens: ok.
- The page served with magpie's page CSP in a sandbox="allow-scripts" frame, Chromium and WebKit: tiles 1/2/1 for a fixture of MiniMax (signed in, checked in today), ZCode (installed, not signed in), Zed (not installed), DeepSeek (no plugin) and an unlisted relay (dropped); install popover gives @magpie-community/opencode-zed-auth, login popover "magpie plugin login zcode"; a title holding <img onerror> is shown as text; brand icons load; no dialog.
- Every mapped package checked: 8 on npm, 5 on the dist branch, and each pid is the package's provider id.
- Broken by hand: checkin null guard removed, title unescaped, Zed's npm name unscoped; each turns a test red.

Not tried: a real magpie window with the plugin installed, and the live aihot.news route (no network in the run).

Co-authored-by: sljdxde <sljdxde@users.noreply.github.com>
2026-11-10 09:28:19 +08:00

36 lines
1.9 KiB
JavaScript

import { test } from "bun:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import { fileURLToPath } from "node:url";
import { BRAND } from "../src/icons.js";
import { MAPPING } from "../src/mapping.js";
import { OFFICIAL_PROVIDERS } from "../src/allowlist.js";
import "../page/view.js";
const pageDir = fileURLToPath(new URL("../page/", import.meta.url));
test("every brand icon file exists in page/brand", () => {
for (const [prov, file] of Object.entries(BRAND)) assert.ok(fs.existsSync(pageDir + "brand/" + file), `${prov} -> ${file}`);
});
test("index.html local assets exist (except magpie bridge & generated data.js)", () => {
const html = fs.readFileSync(pageDir + "index.html", "utf8");
const refs = [...html.matchAll(/(?:src|href)="([^"]+)"/g)].map((m) => m[1]).filter((u) => !/^(https?:|data:|#)/.test(u));
for (const r of refs) { if (r.startsWith("_magpie/") || r === "data.js") continue; assert.ok(fs.existsSync(pageDir + r), `missing asset: ${r}`); }
});
test("load order: view.js before app.js", () => {
const html = fs.readFileSync(pageDir + "index.html", "utf8");
assert.ok(html.indexOf("view.js") >= 0 && html.indexOf("app.js") > html.indexOf("view.js"));
});
test("every mapping provider is in the official allowlist (else it'd never show)", () => {
for (const k of Object.keys(MAPPING)) assert.ok(OFFICIAL_PROVIDERS.has(k), `mapping provider not allowlisted: ${k}`);
});
test("allowlist non-empty; kept vendor present; dropped providers excluded", () => {
assert.ok(OFFICIAL_PROVIDERS.size > 0);
assert.ok(OFFICIAL_PROVIDERS.has("DeepSeek"));
for (const p of ["Nace AI", "硅基流动", "秒悟 Meoo", "魔搭社区"]) assert.ok(!OFFICIAL_PROVIDERS.has(p), `should be dropped: ${p}`);
});
test("view KIND covers every classify kind", () => {
const V = globalThis.FTView;
for (const k of ["daily", "monthly", "once", "limited", "free"]) assert.ok(V.KIND[k], `missing KIND ${k}`);
});