Files
lobehub__lobehub/scripts/spaHtmlPaths.test.ts
Innei 1001a58a22 ✨ feat(workbench): React Router framework mode SSR on Cloudflare Workers (#18473)
* ♻️ refactor(spa): extract verify/acceptance into apps/workbench

Move the Workbench SPA into apps/workbench and serve /verify and
/acceptance from that runtime for every web UA. The main SPA no
longer registers those page routes, so they drop out of its bundle.

* 🔧 chore(docker): wire the workbench workspace into image builds

Copy apps/workbench/package.json before pnpm i so Docker can resolve
the extracted SPA. Keep generateSpaTemplates optional for Cloud, and
require the HTML only when WORKBENCH_REQUIRED=1 (build:docker).

* ♻️ refactor(workbench): hard-navigate only from markdown entity links

Keep Link and useWorkspaceAwareNavigate in-router. Markdown verify,
acceptance, and mobile agent-doc links document-navigate. Drop the
__WORKBENCH__ Vite define; Electron still skips hard-nav for portals.

* ♻️ refactor(verify): slot-inject origin conversation and decouple shared components

* 🐛 fix(i18n): make vite glob loaders independent of the vite root

* ✨ feat(workbench): React Router framework mode SSR on Cloudflare Workers

* 🐛 fix(verify): render viewer-timezone timestamps only after hydration

* 💚 ci(workbench): deploy with affected detection and PR build verification

* 📝 docs(skills): micro-app split and gateway routing playbook

* 🐛 fix(workbench): track app/lib swallowed by the root lib/ ignore rules

* ✨ feat(workbench): signed-in acceptance list sidebar on detail pages

* 🐛 fix(workbench): survive shared-origin gateway quirks in client navigation

* 💄 style(workbench): surface error detail on the boundary page

* 💄 style(workbench): adopt the shared ErrorCapture page for the root boundary

* 💄 style(verify): drop the app-home back arrow from the acceptance list panel

* 🔧 chore(workbench): persist only error logs in wrangler observability

* 📝 docs(skills): record Docker vs Cloud hosting for micro apps

OSS Docker still builds and serves the SPA in-image. Cloud Next must
not build, rewrite, or CDN-upload it — gateway routes to the Worker.

* 💄 style(workbench): pin the acceptance logo while the list panel slides

* 🐛 fix(workbench): only show the acceptance sidebar when signed in

* 🐛 fix(verify): drop namespace prefix on bound verify translations
2026-08-19 18:21:00 +08:00

55 lines
2.0 KiB
TypeScript

import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { afterEach, describe, expect, it } from 'vitest';
import { requireWorkbenchHtmlPath, resolveWorkbenchHtmlPath } from './spaHtmlPaths';
const testRoots: string[] = [];
afterEach(() => {
for (const root of testRoots.splice(0)) rmSync(root, { force: true, recursive: true });
});
describe('resolveWorkbenchHtmlPath', () => {
it('prefers dist/workbench/index.workbench.html when both files exist', () => {
const root = mkdtempSync(path.join(tmpdir(), 'spa-html-workbench-'));
testRoots.push(root);
mkdirSync(path.join(root, 'dist/workbench'), { recursive: true });
writeFileSync(path.join(root, 'dist/workbench/index.workbench.html'), 'preferred');
writeFileSync(path.join(root, 'dist/workbench/index.html'), 'fallback');
expect(resolveWorkbenchHtmlPath(root)).toBe(
path.resolve(root, 'dist/workbench/index.workbench.html'),
);
});
it('falls back to dist/workbench/index.html', () => {
const root = mkdtempSync(path.join(tmpdir(), 'spa-html-workbench-fallback-'));
testRoots.push(root);
mkdirSync(path.join(root, 'dist/workbench'), { recursive: true });
writeFileSync(path.join(root, 'dist/workbench/index.html'), 'fallback');
expect(resolveWorkbenchHtmlPath(root)).toBe(path.resolve(root, 'dist/workbench/index.html'));
});
it('returns undefined when the Workbench HTML is missing', () => {
const root = mkdtempSync(path.join(tmpdir(), 'spa-html-workbench-missing-'));
testRoots.push(root);
expect(resolveWorkbenchHtmlPath(root)).toBeUndefined();
});
});
describe('requireWorkbenchHtmlPath', () => {
it('throws when the Workbench HTML is missing', () => {
const root = mkdtempSync(path.join(tmpdir(), 'spa-html-workbench-required-'));
testRoots.push(root);
expect(() => requireWorkbenchHtmlPath(root)).toThrow(/Workbench SPA build is required/);
});
});