Adds the Fingerprint page plugin (packages/fingerprint): it checks whether a model behind the local magpie gateway answers like the model it claims to be.
Reviewed at 531ca11f4 (KaranocaVe). Run at that head merged with main 848497c, through mote-run on the Mac mini with Bun 1.4.2:
- bun run rebuild from the committed bun.lock (frozen, --ignore-scripts): typecheck, 30/30 tests, build; diff -r against the committed dist/ is empty.
- HOME=$(mktemp -d) bun test: 3838 pass, 0 fail. bun scripts/check.mjs: exit 0.
- Offline preload refusing every non-loopback fetch/socket: 30/30, nothing refused.
- Broken by hand, each red: ensureDetector() in bootstrap, dropping ttl: Infinity, validating the job after the download.
Maintainer decision: the reference data comes from two third-party hosts (lm.ikale.io, cdn.jsdmirror.com), only on an explicit Download or a valid job, and both are named on the page, in registry.json and the READMEs. It is data used locally to rank candidates and is sent nowhere; the @latest fallback has no pinned hash, so a bad snapshot would rank wrongly, which the page states.
Not on npm yet (E404): magpie installs it from the dist branch until an owner publishes the first version.
70 lines
2.5 KiB
TypeScript
70 lines
2.5 KiB
TypeScript
import { expect, test } from 'bun:test';
|
|
import { readFile } from 'node:fs/promises';
|
|
import { runInNewContext } from 'node:vm';
|
|
|
|
const source = await readFile(new URL('../page/boot.js', import.meta.url), 'utf8');
|
|
async function boot(lang?: string, remote = false, port = 3488) {
|
|
const elements = {
|
|
status: { textContent: 'Connecting to Fingerprint…' },
|
|
title: { textContent: 'Fingerprint' },
|
|
};
|
|
const document = {
|
|
title: 'Fingerprint',
|
|
documentElement: { lang: 'en' },
|
|
getElementById: (id: keyof typeof elements) => elements[id],
|
|
};
|
|
let destination: URL | undefined;
|
|
const service = remote ? '' : 'http://127.0.0.1:3488/';
|
|
await runInNewContext(source, {
|
|
URL,
|
|
document,
|
|
window: {
|
|
magpie: {
|
|
ready: Promise.resolve({ dark: true, ...(lang ? { lang } : {}) }),
|
|
service,
|
|
context: { provider: { id: 'vendor' } },
|
|
options: { get: async () => ({ port }) },
|
|
onAction() {},
|
|
onTheme() {},
|
|
},
|
|
},
|
|
location: {
|
|
hostname: remote ? 'magpie.example' : '127.0.0.1',
|
|
href: 'http://127.0.0.1/boot/index.html',
|
|
replace: (url: string) => {
|
|
destination = new URL(url);
|
|
},
|
|
},
|
|
});
|
|
return { document, elements, destination };
|
|
}
|
|
|
|
test('boot defaults to English and follows host languages before navigation', async () => {
|
|
for (const [lang, htmlLang, status] of [
|
|
[undefined, 'en', 'Connecting'],
|
|
['fr', 'en', 'Connecting'],
|
|
['zh-CN', 'zh-Hans', '正在连接'],
|
|
['zh-TW', 'zh-Hant', '正在連線'],
|
|
['zh-Hant-HK', 'zh-Hant', '正在連線'],
|
|
['zh_HK', 'zh-Hant', '正在連線'],
|
|
['ja', 'ja', '接続中'],
|
|
['de-DE', 'de', 'Verbindung'],
|
|
]) {
|
|
const result = await boot(lang);
|
|
expect(result.document.documentElement.lang).toBe(htmlLang!);
|
|
expect(result.elements.status.textContent).toContain(status!);
|
|
expect(result.destination?.searchParams.get('provider')).toBe('vendor');
|
|
expect(result.destination?.searchParams.get('uiOrigin')).toBe('http://127.0.0.1:3488');
|
|
expect(result.destination?.searchParams.get('lang')).toBe(lang || null);
|
|
}
|
|
});
|
|
|
|
test('boot localizes remote-service guidance and invalid-port errors', async () => {
|
|
const remote = await boot('zh-TW', true);
|
|
expect(remote.destination).toBeUndefined();
|
|
expect(remote.elements.status.textContent).toContain('遠端外掛');
|
|
const invalid = await boot('de', false, -1);
|
|
expect(invalid.destination).toBeUndefined();
|
|
expect(invalid.elements.status.textContent).toContain('Ungültiger Port');
|
|
});
|