Adds packages/window-warmup (@magpie-community/page-window-warmup 0.1.0), by YangHonghang: a page plugin whose host part runs a service on 127.0.0.1:3492 and, on a schedule (after a quota window resets, daily at a set time, or every N hours), sends "hi" with max_tokens 16 through magpie's gateway to a provider/account/model the user picks. The registry entry moves from the author's own npm package magpie-window-warmup to this one. The package README opens with the zh/en warning that sends spend real quota and that some vendors (Claude subscriptions especially) may treat scheduled requests as unusual use. Reviewed at 07a0b217adb2a111f839c984cbc955c5bb45b68d: - Outside packages/window-warmup only README.md and registry.json change; no workflow and no other package. - The service binds 127.0.0.1, checks Host (DNS rebinding) and Origin (null or itself), needs a per-process 32-byte token on /api/*, and serves the index with a nonce CSP. - It reaches only MAGPIE_ADDR (default 127.0.0.1:3425). providers.json is read for sha256 key fingerprints only; no spawn, eval or outside hosts. - A window task sends at most once per resetsAt (or once per hour when idle); daily/every tasks catch up only the latest missed point, once. Run on mote (bun 1.4.2): - HOME=$(mktemp -d) bun test at the repo root: 5142 pass, 15 skip, 0 fail. - scripts/check.mjs ok. - packages/window-warmup bun test: 242 pass (dist.test rebuilds dist byte for byte). - browser.test.ts with Playwright 1.62.0: chromium and webkit pass. Bun ignores NODE_PATH, so it needs node_modules/playwright linked and PLAYWRIGHT_BROWSERS_PATH set under a temp HOME; without them it skips. Not tried: a real send through a live magpie gateway, and tsc --noEmit (no typescript on mote).
104 lines
4.4 KiB
TypeScript
104 lines
4.4 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
||
import { readFileSync, existsSync } from "node:fs";
|
||
import { join } from "node:path";
|
||
|
||
// 收录与可发现性回归。依据(magpie 源码):
|
||
// - 社区插件靠 magpie-community/plugins 的 registry.json 收录,magpie 自己从 npm 取最新版
|
||
// (internal/plugin/market.go),发版无需同步清单;只有名称、图标、简介变化才改这条。
|
||
// - 插件页搜索框把 [名称, 包名, 当前语言 summary, providers, npm 发布者] 拼成一串做小写子串匹配
|
||
// (internal/gui/assets/plugins.js 的 match,不分词):所以 summary 必须带上用户会搜的词。
|
||
// - 带 community: true 的 page 条目才会出现在不搜索时的「Pages」分区。
|
||
|
||
type Pkg = {
|
||
name: string;
|
||
description: string;
|
||
main?: string;
|
||
files: string[];
|
||
keywords: string[];
|
||
author?: string;
|
||
repository: { url: string; directory?: string };
|
||
};
|
||
|
||
type Entry = {
|
||
package: string;
|
||
name: string;
|
||
kind?: string;
|
||
community?: boolean;
|
||
icon?: string;
|
||
summary: Record<string, string>;
|
||
};
|
||
|
||
const pkgDir = join(import.meta.dir, "..");
|
||
const repoRoot = join(pkgDir, "..", "..");
|
||
const pkg: Pkg = JSON.parse(readFileSync(join(pkgDir, "package.json"), "utf8")) as Pkg;
|
||
const registry = JSON.parse(readFileSync(join(repoRoot, "registry.json"), "utf8")) as { plugins: Entry[] };
|
||
const entry = registry.plugins.find((p) => p.package === pkg.name);
|
||
const readme = readFileSync(join(pkgDir, "README.md"), "utf8");
|
||
|
||
// 与 plugins.js 的 match 同一公式:当前语言的搜索串(zh 用户看 summary.zh,其余语言回退 en)
|
||
const searchable = (lang: "zh" | "en"): string =>
|
||
[entry?.name ?? "", pkg.name, entry?.summary?.[lang] ?? entry?.summary?.en ?? ""].join(" ").toLowerCase();
|
||
|
||
// 插件页只匹配「当前语言」的 summary:中文词查 zh,英文词查 en;名称与包名两边都在
|
||
const ZH_WORDS = ["窗口预热", "预热", "窗口", "额度", "配额", "定时", "定时消息", "保活", "重置", "订阅", "每周"];
|
||
const EN_WORDS = [
|
||
"warm up", "keep-alive", "keep alive", "quota", "usage window",
|
||
"rate limit", "scheduled messages", "schedule", "daily", "reset",
|
||
];
|
||
const NAME_WORDS = ["window warmup", "warmup"];
|
||
|
||
describe("registry.json 收录", () => {
|
||
test("这一条存在,字段与包一致", () => {
|
||
expect(entry, `registry.json 里没有 ${pkg.name}`).toBeDefined();
|
||
expect(entry?.kind).toBe("page");
|
||
expect(entry?.community).toBe(true);
|
||
expect(entry?.summary.zh).toBeTruthy();
|
||
expect(entry?.summary.en).toBeTruthy();
|
||
});
|
||
|
||
test("图标指向本仓库包内文件,不用个人仓库的 raw 地址", () => {
|
||
expect(entry?.icon).toBe(
|
||
"https://raw.githubusercontent.com/magpie-community/plugins/main/packages/window-warmup/page/icon.svg",
|
||
);
|
||
expect(existsSync(join(pkgDir, "page", "icon.svg"))).toBe(true);
|
||
});
|
||
|
||
test("每个搜索词按界面语言命中对应搜索串", () => {
|
||
for (const w of NAME_WORDS) {
|
||
expect(searchable("zh"), `「${w}」未命中中文搜索串`).toContain(w);
|
||
expect(searchable("en"), `「${w}」未命中英文搜索串`).toContain(w);
|
||
}
|
||
for (const w of ZH_WORDS) expect(searchable("zh"), `「${w}」未命中中文搜索串`).toContain(w);
|
||
for (const w of EN_WORDS) expect(searchable("en"), `「${w}」未命中英文搜索串`).toContain(w);
|
||
});
|
||
|
||
test("README 提到作者与源码位置", () => {
|
||
expect(readme).toContain("YangHonghang");
|
||
expect(readme).toContain("magpie-community/plugins");
|
||
});
|
||
});
|
||
|
||
describe("包契约(magpie 宿主与社区仓库约定)", () => {
|
||
test("包名、入口、仓库目录", () => {
|
||
expect(pkg.name).toBe("@magpie-community/page-window-warmup");
|
||
expect(pkg.repository.directory).toBe("packages/window-warmup");
|
||
expect(pkg.main === undefined || existsSync(join(pkgDir, pkg.main))).toBe(true);
|
||
});
|
||
|
||
test("files 只列发布必需的文件,且包含 dist 与 page", () => {
|
||
expect(pkg.files).toContain("dist");
|
||
expect(pkg.files).toContain("page");
|
||
for (const f of pkg.files) expect(["dist", "page", "README.md", "LICENSE"]).toContain(f);
|
||
});
|
||
|
||
test("keywords 保留插件发现契约词", () => {
|
||
for (const w of ["magpie", "magpie-page", "magpie-plugin"]) {
|
||
expect(pkg.keywords, `keywords 缺「${w}」`).toContain(w);
|
||
}
|
||
});
|
||
|
||
test("author 是作者本人", () => {
|
||
expect(pkg.author ?? "").toContain("YangHonghang");
|
||
});
|
||
});
|