refactor: migrate frontend to React + Tailwind, add Docker + tests

Replace the vanilla-TS innerHTML frontend with a type-checked React
component tree (React 19 + Tailwind v4 + Vite).

Frontend:
- 14 components: Header, Stepper, LoginPage, LoginModal, SignPage,
  DropZone, DevicePicker, ProgressCard, SavedAccountsList, TrustModal,
  TwoFactorModal, Button, Field, Chip, Modal
- lib/ extracts: storage (10 localStorage keys preserved), pair-record,
  account-session, log-parser, ids, use-log hook
- flows/ encapsulate async pair/login/sign/install with dependency injection
- Accounts page as main view with Add Account modal
- Fullscreen progress overlay during sign/install
- Account selector + device picker on Sign page
- Security notice in login modal (server trust warning)
- All addLog calls mirrored to console.log for devtools debugging

Build:
- bun run dev: submodule init + install + wasm dist + vite + wrangler
- bun run setup: one-shot project bootstrap
- Docker: multi-stage bun build → nginx on :3000
- build:wasm:dist copies pre-built src→dist (no Rust/Emscripten needed)
- jszip/node-forge/fflate pre-bundled for CJS→ESM conversion

Tests:
- 163 vitest tests (happy-dom): all lib, components, App integration,
  WASM dist artifact checks, libcurl Apple connectivity, anisette init
  error handling

Cleanup:
- Delete yarn.lock (bun.lock canonical), expand .gitignore
- Remove README.zh.md, rewrite README.md + AGENTS.md
- Update libcurl.js submodule to f65d440 (CI build artifacts)
This commit is contained in:
Lakr
2026-04-13 17:02:45 +08:00
parent 3ed8ddc5dc
commit afec333aa0
79 changed files with 6543 additions and 6392 deletions

View File

@@ -0,0 +1,81 @@
/**
* Integration test: verify the patched libcurl.js can load and reach Apple's
* GSA endpoint through the WISP backend.
*
* Requires `wrangler dev --port 8787` running. Skipped automatically if the
* backend is unreachable.
*/
import { describe, expect, it, beforeAll } from 'vitest';
import { access } from 'node:fs/promises';
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = resolve(dirname(fileURLToPath(import.meta.url)), '../../..');
describe('libcurl.js Apple connectivity', () => {
it('binary/libcurl_full.mjs exists in the submodule', async () => {
await expect(access(resolve(root, 'wasm/libcurl-wasm/binary/libcurl_full.mjs'))).resolves.toBeUndefined();
});
it('binary/libcurl.mjs exists in the submodule', async () => {
await expect(access(resolve(root, 'wasm/libcurl-wasm/binary/libcurl.mjs'))).resolves.toBeUndefined();
});
it('binary/libcurl.wasm exists in the submodule', async () => {
await expect(access(resolve(root, 'wasm/libcurl-wasm/binary/libcurl.wasm'))).resolves.toBeUndefined();
});
it('dist/bundled.mjs exists and re-exports from binary', async () => {
const { readFile } = await import('node:fs/promises');
const content = await readFile(resolve(root, 'wasm/libcurl-wasm/dist/bundled.mjs'), 'utf-8');
expect(content).toContain('../binary/libcurl_full.mjs');
});
it('frontend/public/anisette/libcurl_full.mjs matches the submodule binary', async () => {
const { readFile } = await import('node:fs/promises');
const [submodule, publicCopy] = await Promise.all([
readFile(resolve(root, 'wasm/libcurl-wasm/binary/libcurl_full.mjs')),
readFile(resolve(root, 'frontend/public/anisette/libcurl_full.mjs')),
]);
expect(submodule.equals(publicCopy)).toBe(true);
});
describe('WISP backend connectivity (requires wrangler dev)', () => {
let backendAvailable = false;
beforeAll(async () => {
try {
const resp = await fetch('http://localhost:8787/healthz', {
signal: AbortSignal.timeout(2000),
});
backendAvailable = resp.ok;
} catch {
backendAvailable = false;
}
});
it('WISP backend healthcheck returns ok', () => {
if (!backendAvailable) {
console.log(' [skipped] wrangler dev not running on :8787');
return;
}
expect(backendAvailable).toBe(true);
});
it('WISP endpoint accepts WebSocket upgrade', async () => {
if (!backendAvailable) {
console.log(' [skipped] wrangler dev not running on :8787');
return;
}
// Just verify the upgrade endpoint exists — actual WS connection
// requires the libcurl WASM runtime which only works in a browser.
const resp = await fetch('http://localhost:8787/wisp/', {
signal: AbortSignal.timeout(2000),
});
// Without Upgrade header, should get 426
expect(resp.status).toBe(426);
const body = (await resp.json()) as { error?: string };
expect(body.error).toContain('WebSocket upgrade required');
});
});
});