/** * The shell's configuration holds what tauri-platforms.md decided (D3–D7, D10, D11). Each of * these is a value that fails silently at runtime, or worse, only after a release: a changed * identifier or origin leaves the player's rose behind in the old app. */ import { existsSync, readFileSync } from 'node:fs'; import { dirname, join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { describe, expect, it } from 'vitest'; import { CSP } from '../../rosea/csp.js'; import { PRODUCT_NAME } from '../../../packages/schema/src/constants.js'; const SRC_TAURI = join(dirname(fileURLToPath(import.meta.url)), '..', 'src-tauri'); /** The parts of a Tauri config these tests read. */ interface TauriConf { productName?: string; identifier?: string; version?: string; build: { frontendDist: string; beforeBuildCommand: string; beforeDevCommand: string; devUrl: string }; app: { windows: Record[]; security: Record }; bundle: { targets?: string[] }; plugins?: unknown; } const json = (name: string): TauriConf => JSON.parse(readFileSync(join(SRC_TAURI, name), 'utf8')) as TauriConf; const conf = json('tauri.conf.json'); const window = conf.app.windows[0] ?? {}; describe('tauri.conf.json', () => { it('names the app with the product name, in the bundle and the window title (D3)', () => { expect(conf.productName).toBe(PRODUCT_NAME); expect(window['title']).toBe(PRODUCT_NAME); }); it('keeps the identifier it was released with: a new one is a different app (D3)', () => { expect(conf.identifier).toBe('cz.mareknovak.domi.rosea'); }); it("reads its version from the game's package.json (D3)", () => { expect(conf.version).toBe('../../rosea/package.json'); const pkg = JSON.parse(readFileSync(resolve(SRC_TAURI, String(conf.version)), 'utf8')) as Record; expect(pkg['name']).toBe('@rosea/app'); expect(pkg['version']).toMatch(/^\d+\.\d+\.\d+$/); }); it("delivers the PWA's content-security policy, the same string (D4)", () => { expect(conf.app.security['csp']).toBe(CSP); }); it("wraps the game's shell build and nothing else (D1, D2)", () => { expect(conf.build.frontendDist).toBe('../../rosea/dist-tauri'); expect(resolve(SRC_TAURI, conf.build.frontendDist)).toBe(resolve(SRC_TAURI, '..', '..', 'rosea', 'dist-tauri')); expect(conf.build.beforeBuildCommand).toBe('pnpm --filter @rosea/app build:shell'); expect(conf.build.beforeDevCommand).toBe('pnpm --filter @rosea/app dev:shell'); }); it('runs its dev server on 127.0.0.1 only (CLAUDE.md §5.7)', () => { expect(new URL(conf.build.devUrl).hostname).toBe('127.0.0.1'); const app = JSON.parse(readFileSync(join(SRC_TAURI, '..', '..', 'rosea', 'package.json'), 'utf8')) as { scripts: Record }; expect(app['scripts']['dev:shell']).toContain('--host 127.0.0.1'); expect(app['scripts']['dev:shell']).toContain('--port 5173'); expect(conf.build.devUrl).toBe('http://127.0.0.1:5173'); }); it('keeps the https origin it was released with: IndexedDB lives per origin (D10)', () => { expect(window['useHttpsScheme']).toBe(true); }); it("switches WebView2's own traffic off (D7)", () => { const args = String(window['additionalBrowserArgs']); for (const flag of [ '--disable-background-networking', '--disable-component-update', '--disable-domain-reliability', '--disable-sync', '--no-pings', '--disable-client-side-phishing-detection', '--dns-prefetch-disable' ]) { expect(args.split(' ')).toContain(flag); } const disabled = /--disable-features=(\S+)/.exec(args)?.[1]?.split(',') ?? []; for (const feature of [ // Tauri's own defaults, which a custom list must repeat. 'msWebOOUI', 'msPdfOOUI', 'msSmartScreenProtection', 'DnsOverHttpsUpgrade', 'msExperimentationAndConfigurationService', 'AutofillServerCommunication', 'OptimizationHints' ]) { expect(disabled).toContain(feature); } }); it('builds only what each system can make (D11)', () => { expect(json('tauri.windows.conf.json').bundle.targets).toEqual(['nsis']); expect(json('tauri.macos.conf.json').bundle.targets).toEqual(['app', 'dmg']); expect(json('tauri.linux.conf.json').bundle.targets).toEqual(['deb', 'appimage']); expect(conf.bundle.targets).toBeUndefined(); }); it('applies the Android privacy patch before the game is built for Android (D6)', () => { const before = json('tauri.android.conf.json').build.beforeBuildCommand; const patch = before.indexOf('pnpm --filter @rosea/tauri android:privacy'); expect(patch).toBe(0); expect(before.indexOf('&& pnpm --filter @rosea/app build:shell')).toBeGreaterThan(patch); }); }); describe('domi-rosea://open, from the installer (fabrica-release.md F5)', () => { const windows = JSON.parse(readFileSync(join(SRC_TAURI, 'tauri.windows.conf.json'), 'utf8')) as { bundle: { windows?: { nsis?: { installerHooks?: string; installMode?: string } } }; }; const hooksPath = windows.bundle.windows?.nsis?.installerHooks ?? ''; const hooks = existsSync(join(SRC_TAURI, hooksPath)) ? readFileSync(join(SRC_TAURI, hooksPath), 'utf8') : ''; /** The NSIS statements of one macro, comments dropped. */ const macro = (name: string): string[] => (new RegExp(`!macro ${name}\\r?\\n([\\s\\S]*?)!macroend`).exec(hooks)?.[1] ?? '') .split(/\r?\n/) .map((l) => l.trim()) .filter((l) => l !== '' && !l.startsWith(';')); it('the Windows installer runs the hooks file, and installs for the current user only', () => { expect(hooksPath).toBe('./windows/hooks.nsh'); expect(hooks).not.toBe(''); const nsis = (conf.bundle as { windows?: { nsis?: { installMode?: string } } }).windows?.nsis; expect(nsis?.installMode).toBe('currentUser'); }); it('registers exactly the domi-rosea scheme under HKCU, opening the installed exe with the address', () => { expect(macro('NSIS_HOOK_POSTINSTALL')).toEqual([ 'WriteRegStr HKCU "Software\\Classes\\domi-rosea" "" "URL:Rosea Domi"', 'WriteRegStr HKCU "Software\\Classes\\domi-rosea" "URL Protocol" ""', `WriteRegStr HKCU "Software\\Classes\\domi-rosea\\DefaultIcon" "" '"$INSTDIR\\\${MAINBINARYNAME}.exe",0'`, `WriteRegStr HKCU "Software\\Classes\\domi-rosea\\shell\\open\\command" "" '"$INSTDIR\\\${MAINBINARYNAME}.exe" "%1"'` ]); }); it('the uninstaller removes that key and nothing else', () => { expect(macro('NSIS_HOOK_POSTUNINSTALL')).toEqual(['DeleteRegKey HKCU "Software\\Classes\\domi-rosea"']); }); it('writes nowhere else: no machine-wide key, no other hook', () => { expect(hooks).not.toMatch(/HKLM|HKCR|HKEY_/); expect([...hooks.matchAll(/!macro (\w+)/g)].map((m) => m[1])).toEqual(['NSIS_HOOK_POSTINSTALL', 'NSIS_HOOK_POSTUNINSTALL']); }); }); describe('the Rust side (D5)', () => { it('depends on tauri alone: no plugin, no SDK', () => { const cargo = readFileSync(join(SRC_TAURI, 'Cargo.toml'), 'utf8'); const deps = /\n\[dependencies\]\n([\s\S]*?)(?:\n\[|$)/.exec(cargo)?.[1] ?? ''; const names = deps .split('\n') .map((l) => /^([A-Za-z0-9_-]+)\s*=/.exec(l)?.[1]) .filter((n): n is string => n !== undefined); expect(names).toEqual(['tauri']); expect(cargo).not.toMatch(/\[target\.[^\]]*dependencies\]/); }); it('grants the page no IPC: there is no capabilities folder', () => { expect(existsSync(join(SRC_TAURI, 'capabilities'))).toBe(false); expect(conf.app.security['capabilities']).toBeUndefined(); }); it('declares no plugin configuration', () => { expect(conf.plugins).toBeUndefined(); }); });