/** * The `domi-app.toml` Rosea ships for Atrium Domi (atrium-adoption.md; Atrium docs/APP_CONTRACT.md v0). Rosea ships * a file Atrium accepts, ships it next to the `.exe` with the icon it names, and keeps her name, version and * identity in the places they already live. The hostile fixtures prove that the check refuses what Atrium refuses, * and refuses it for Atrium's reason. */ import { readdirSync, readFileSync } from 'node:fs'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { describe, expect, it } from 'vitest'; import { PRODUCT_NAME } from '../../../packages/schema/src/constants.js'; import { ATRIUM, MANIFEST, domiApp, gameVersion, toToml } from '../scripts/domi-app.js'; import { checkManifest } from './domi-app-rules.js'; const HERE = dirname(fileURLToPath(import.meta.url)); const SRC_TAURI = join(HERE, '..', 'src-tauri'); const FIXTURES = join(HERE, 'fixtures', 'domi-app'); const shipped = toToml(domiApp(gameVersion())); const bytes = (s: string): Uint8Array => new TextEncoder().encode(s); describe('domi-app.toml', () => { it('is accepted by the rules of APP_CONTRACT ยง2', () => { expect(checkManifest(bytes(shipped))).toBeNull(); }); it("names her as the product does, at the game's version, with her Aula id", () => { const m = domiApp(gameVersion()); expect(m.name).toBe(PRODUCT_NAME); expect(m.version).toBe(JSON.parse(readFileSync(join(HERE, '..', '..', 'rosea', 'package.json'), 'utf8')).version); expect(m.id).toBe('rosea'); expect(shipped).toContain(`name = "${PRODUCT_NAME}"`); }); it('is not hostable until her own window and origin are kept (R1), and asks for nothing', () => { const m = domiApp('0.1.0'); expect(m.hostable).toBe(false); expect(shipped).not.toContain('ui_bundle'); expect(shipped).not.toContain('capabilities'); }); it('is shipped next to the .exe on Windows only, with the icon it names', () => { const win = JSON.parse(readFileSync(join(SRC_TAURI, 'tauri.windows.conf.json'), 'utf8')) as { bundle: { resources: Record }; }; expect(win.bundle.resources).toEqual({ [MANIFEST]: 'domi-app.toml', [ATRIUM.icon.from]: ATRIUM.icon.file }); expect(domiApp('0.1.0').icon).toBe(ATRIUM.icon.file); // The shared config would put it into the Android and macOS packages too. const shared = JSON.parse(readFileSync(join(SRC_TAURI, 'tauri.conf.json'), 'utf8')) as { bundle: Record }; expect(shared.bundle['resources']).toBeUndefined(); }); it('is made before every desktop build and never committed', () => { const pkg = JSON.parse(readFileSync(join(HERE, '..', 'package.json'), 'utf8')) as { scripts: Record }; expect(pkg.scripts['build:desktop']).toMatch(/tsx scripts\/domi-app\.ts && tauri build( |$)/); expect(pkg.scripts['dev']).toContain('tsx scripts/domi-app.ts'); const ignore = readFileSync(join(HERE, '..', '..', '..', '.gitignore'), 'utf8'); expect(ignore).toContain('apps/rosea-tauri/src-tauri/atrium/'); }); it('escapes a quote or a backslash, so no value can add a key', () => { const hostile = toToml({ ...domiApp('0.1.0'), label: 'Rose"\nfree = false\n#\\' }); expect(checkManifest(bytes(hostile))).toEqual({ field: 'label', reason: 'control_char' }); expect(hostile.split('\n').filter((l) => l.startsWith('free'))).toEqual(['free = true']); }); }); describe('a hostile domi-app.toml is refused, with the reason Atrium Domi logs', () => { const files = readdirSync(FIXTURES).filter((f) => f.endsWith('.toml')); it('has one fixture for each rule it claims', () => { expect(files.length).toBeGreaterThanOrEqual(27); }); for (const file of files) { const [field, reason] = file.replace(/(-\d+)?\.toml$/, '').split('.') as [string, string]; it(`${file}: ${field === 'file' ? '' : `${field} `}${reason}`, () => { const refusal = checkManifest(new Uint8Array(readFileSync(join(FIXTURES, file)))); expect(refusal).toEqual({ field: field === 'file' ? null : field, reason }); }); } });