feat(desktop): embed BoosAPI Desktop client as a subproject
Vendor the rebranded BoosAPI Desktop client (Tauri + Vue) into metapi as a monorepo subdirectory under desktop/. Source only — node_modules, dist, Cargo target and the upstream .git history are excluded. desktop/ keeps its own independent Cargo workspace (desktop/src-tauri with crates/*); it is not part of the backend boosapi crate, so a `cargo check` at the metapi root still compiles only the backend. Build the desktop app from desktop/src-tauri per desktop/README.md. Note: app icons are still placeholder assets pending the final BoosAPI logo. The updater signing keys live outside the repo and are not included.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { buildKaTeXCDNWorkerSource, createKaTeXWorkerFromCDN } from '../../src/workers/katexCdnWorker'
|
||||
|
||||
describe('katex CDN worker factory', () => {
|
||||
it('builds classic worker source with importScripts', () => {
|
||||
const src = buildKaTeXCDNWorkerSource({
|
||||
katexUrl: 'https://cdn.example.com/katex.min.js',
|
||||
mhchemUrl: 'https://cdn.example.com/mhchem.min.js',
|
||||
mode: 'classic',
|
||||
})
|
||||
expect(src).toContain('importScripts(')
|
||||
expect(src).toContain('katex.min.js')
|
||||
expect(src).toContain('mhchem.min.js')
|
||||
})
|
||||
|
||||
it('builds module worker source with dynamic import(url)', () => {
|
||||
const src = buildKaTeXCDNWorkerSource({
|
||||
katexUrl: 'https://cdn.example.com/katex.mjs',
|
||||
mhchemUrl: 'https://cdn.example.com/mhchem.mjs',
|
||||
mode: 'module',
|
||||
workerOptions: { type: 'module' },
|
||||
})
|
||||
expect(src).toContain('await import(')
|
||||
expect(src).toContain('katex.mjs')
|
||||
expect(src).toContain('mhchem.mjs')
|
||||
})
|
||||
|
||||
it('is SSR-safe and returns null worker when Worker is unavailable', () => {
|
||||
const prev = (globalThis as any).Worker
|
||||
try {
|
||||
;(globalThis as any).Worker = undefined
|
||||
const handle = createKaTeXWorkerFromCDN({
|
||||
katexUrl: 'https://cdn.example.com/katex.min.js',
|
||||
mode: 'classic',
|
||||
})
|
||||
expect(handle.worker).toBeNull()
|
||||
expect(typeof handle.dispose).toBe('function')
|
||||
}
|
||||
finally {
|
||||
;(globalThis as any).Worker = prev
|
||||
}
|
||||
})
|
||||
|
||||
it('creates a Worker instance when Worker exists (stubbed in tests)', () => {
|
||||
const handle = createKaTeXWorkerFromCDN({
|
||||
katexUrl: 'https://cdn.example.com/katex.min.js',
|
||||
mode: 'classic',
|
||||
debug: true,
|
||||
})
|
||||
expect(handle.worker).toBeTruthy()
|
||||
expect(typeof handle.dispose).toBe('function')
|
||||
})
|
||||
|
||||
it('defaults module workerOptions.type to "module"', () => {
|
||||
const prev = (globalThis as any).Worker
|
||||
const calls: any[] = []
|
||||
class CaptureWorker {
|
||||
onmessage: ((event: MessageEvent) => void) | null = null
|
||||
onerror: ((event: ErrorEvent) => void) | null = null
|
||||
constructor(_url: string, opts?: WorkerOptions) {
|
||||
calls.push({ opts })
|
||||
}
|
||||
|
||||
addEventListener() {}
|
||||
removeEventListener() {}
|
||||
postMessage() {}
|
||||
terminate() {}
|
||||
}
|
||||
try {
|
||||
;(globalThis as any).Worker = CaptureWorker as any
|
||||
const handle = createKaTeXWorkerFromCDN({
|
||||
katexUrl: 'https://cdn.example.com/katex.mjs',
|
||||
mode: 'module',
|
||||
})
|
||||
expect(handle.worker).toBeTruthy()
|
||||
expect(calls[0]?.opts?.type).toBe('module')
|
||||
}
|
||||
finally {
|
||||
;(globalThis as any).Worker = prev
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,84 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import {
|
||||
clearKaTeXWorker,
|
||||
renderKaTeXInWorker,
|
||||
setKaTeXWorker,
|
||||
setKaTeXWorkerMaxConcurrency,
|
||||
WORKER_BUSY_CODE,
|
||||
} from '../../src/workers/katexWorkerClient'
|
||||
|
||||
// A minimal controllable fake Worker for tests
|
||||
class FakeWorker {
|
||||
onmessage: ((ev: MessageEvent<any>) => any) | null = null
|
||||
onerror: ((ev: ErrorEvent) => any) | null = null
|
||||
private inbox: Array<{ id: string, content: string, displayMode: boolean }> = []
|
||||
|
||||
postMessage(data: { id: string, content: string, displayMode: boolean }) {
|
||||
// store request, do not auto-resolve
|
||||
this.inbox.push({ id: data.id, content: data.content, displayMode: data.displayMode })
|
||||
}
|
||||
|
||||
// Resolve the oldest pending request
|
||||
resolveNext(htmlFactory?: (content: string) => string) {
|
||||
const msg = this.inbox.shift()
|
||||
if (!msg)
|
||||
return false
|
||||
const html = htmlFactory ? htmlFactory(msg.content) : `<span>${msg.content}</span>`
|
||||
this.onmessage?.({
|
||||
data: { id: msg.id, html, content: msg.content, displayMode: msg.displayMode },
|
||||
} as any)
|
||||
return true
|
||||
}
|
||||
|
||||
// For completeness
|
||||
terminate() {}
|
||||
}
|
||||
|
||||
describe('katexWorkerClient concurrency cap', () => {
|
||||
let worker: FakeWorker
|
||||
|
||||
beforeEach(() => {
|
||||
worker = new FakeWorker()
|
||||
setKaTeXWorker(worker as unknown as Worker)
|
||||
setKaTeXWorkerMaxConcurrency(5)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
clearKaTeXWorker()
|
||||
})
|
||||
|
||||
it('6th concurrent render rejects with WORKER_BUSY; after freeing one, retry succeeds', async () => {
|
||||
const contents = ['a', 'b', 'c', 'd', 'e', 'f']
|
||||
|
||||
// Fire 5 in-flight renders that will remain pending
|
||||
const p1 = renderKaTeXInWorker(contents[0], true, 2000)
|
||||
const p2 = renderKaTeXInWorker(contents[1], true, 2000)
|
||||
const p3 = renderKaTeXInWorker(contents[2], true, 2000)
|
||||
const p4 = renderKaTeXInWorker(contents[3], true, 2000)
|
||||
const p5 = renderKaTeXInWorker(contents[4], true, 2000)
|
||||
|
||||
// 6th should be busy
|
||||
await expect(renderKaTeXInWorker(contents[5], true, 2000)).rejects.toMatchObject({ code: WORKER_BUSY_CODE })
|
||||
|
||||
// Free one slot by resolving one of the pending requests
|
||||
worker.resolveNext()
|
||||
|
||||
// Now retry the 6th; it should be accepted and resolve once we resolveNext again
|
||||
const p6 = renderKaTeXInWorker(contents[5], true, 2000)
|
||||
|
||||
// Resolve remaining in some order
|
||||
worker.resolveNext(c => `<ok>${c}</ok>`) // resolves one of p2..p6
|
||||
worker.resolveNext(c => `<ok>${c}</ok>`)
|
||||
worker.resolveNext(c => `<ok>${c}</ok>`)
|
||||
worker.resolveNext(c => `<ok>${c}</ok>`)
|
||||
worker.resolveNext(c => `<ok>${c}</ok>`)
|
||||
|
||||
const results = await Promise.all([p1, p2, p3, p4, p5, p6].map(p => p.catch(e => e)))
|
||||
|
||||
// Ensure all resolved to HTML strings, not errors
|
||||
for (const r of results) {
|
||||
expect(typeof r).toBe('string')
|
||||
expect(r).toMatch(/<ok>|<span>/)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,78 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { buildMermaidCDNWorkerSource, createMermaidWorkerFromCDN } from '../../src/workers/mermaidCdnWorker'
|
||||
|
||||
describe('mermaid CDN worker factory', () => {
|
||||
it('builds classic worker source with importScripts', () => {
|
||||
const src = buildMermaidCDNWorkerSource({
|
||||
mermaidUrl: 'https://cdn.example.com/mermaid.min.js',
|
||||
mode: 'classic',
|
||||
})
|
||||
expect(src).toContain('importScripts(')
|
||||
expect(src).toContain('mermaid.min.js')
|
||||
})
|
||||
|
||||
it('builds module worker source with dynamic import(url)', () => {
|
||||
const src = buildMermaidCDNWorkerSource({
|
||||
mermaidUrl: 'https://cdn.example.com/mermaid.esm.min.mjs',
|
||||
mode: 'module',
|
||||
workerOptions: { type: 'module' },
|
||||
})
|
||||
expect(src).toContain('await import(')
|
||||
expect(src).toContain('mermaid.esm.min.mjs')
|
||||
})
|
||||
|
||||
it('is SSR-safe and returns null worker when Worker is unavailable', () => {
|
||||
const prev = (globalThis as any).Worker
|
||||
try {
|
||||
;(globalThis as any).Worker = undefined
|
||||
const handle = createMermaidWorkerFromCDN({
|
||||
mermaidUrl: 'https://cdn.example.com/mermaid.esm.min.mjs',
|
||||
mode: 'module',
|
||||
})
|
||||
expect(handle.worker).toBeNull()
|
||||
expect(typeof handle.dispose).toBe('function')
|
||||
}
|
||||
finally {
|
||||
;(globalThis as any).Worker = prev
|
||||
}
|
||||
})
|
||||
|
||||
it('creates a Worker instance when Worker exists (stubbed in tests)', () => {
|
||||
const handle = createMermaidWorkerFromCDN({
|
||||
mermaidUrl: 'https://cdn.example.com/mermaid.esm.min.mjs',
|
||||
mode: 'module',
|
||||
debug: true,
|
||||
})
|
||||
expect(handle.worker).toBeTruthy()
|
||||
expect(typeof handle.dispose).toBe('function')
|
||||
})
|
||||
|
||||
it('defaults module workerOptions.type to "module"', () => {
|
||||
const prev = (globalThis as any).Worker
|
||||
const calls: any[] = []
|
||||
class CaptureWorker {
|
||||
onmessage: ((event: MessageEvent) => void) | null = null
|
||||
onerror: ((event: ErrorEvent) => void) | null = null
|
||||
constructor(_url: string, opts?: WorkerOptions) {
|
||||
calls.push({ opts })
|
||||
}
|
||||
|
||||
addEventListener() {}
|
||||
removeEventListener() {}
|
||||
postMessage() {}
|
||||
terminate() {}
|
||||
}
|
||||
try {
|
||||
;(globalThis as any).Worker = CaptureWorker as any
|
||||
const handle = createMermaidWorkerFromCDN({
|
||||
mermaidUrl: 'https://cdn.example.com/mermaid.esm.min.mjs',
|
||||
mode: 'module',
|
||||
})
|
||||
expect(handle.worker).toBeTruthy()
|
||||
expect(calls[0]?.opts?.type).toBe('module')
|
||||
}
|
||||
finally {
|
||||
;(globalThis as any).Worker = prev
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user