/** * The browser runtime is described in two languages: an Ansible role * installs it, and TypeScript reads it back. Nothing in either language * can see the other, so these are the assertions that keep them agreeing. * * Both facts here have already drifted in other pairs of files in this * repo; neither drift is visible in a diff. */ import { describe, expect, test } from 'bun:test'; import { readFileSync } from 'node:fs'; import { join } from 'node:path'; import { BROWSER_DESCRIPTOR_PATH, BROWSER_EXECUTABLE_PATH, BROWSER_ROOT, } from '@celilo/capabilities'; const MODULE_ROOT = join(import.meta.dir, '../../../../modules/celilo-mgmt'); function read(relativePath: string): string { return readFileSync(join(MODULE_ROOT, relativePath), 'utf-8'); } describe('celilo-mgmt browser provisioning', () => { test('the playbook stamps the module version the manifest declares', () => { // The descriptor records which celilo-mgmt wrote it. No template prefix // exposes a module's own version ($self: resolves module CONFIG), so // the playbook carries a literal — and this is what stops it rotting. const manifestVersion = read('manifest.yml').match(/^version:\s*(\S+)$/m)?.[1]; const playbookVersion = read('ansible/playbook.yml.tpl').match( /celilo_mgmt_version:\s*"([^"]+)"/, )?.[1]; expect(manifestVersion).toBeTruthy(); expect(playbookVersion).toBe(manifestVersion as string); }); test('the role installs into the tree the resolver reads', () => { const debian = read('ansible/roles/celilo-mgmt/tasks/debian.yml'); expect(BROWSER_EXECUTABLE_PATH).toBe(`${BROWSER_ROOT}/current/chrome`); expect(debian).toContain(`PLAYWRIGHT_BROWSERS_PATH: ${BROWSER_ROOT}`); expect(debian).toContain(`dest: ${BROWSER_EXECUTABLE_PATH}`); expect(debian).toContain(`dest: ${BROWSER_DESCRIPTOR_PATH}`); }); test('the install is gated, so a default host downloads nothing', () => { const debian = read('ansible/roles/celilo-mgmt/tasks/debian.yml'); const manifest = read('manifest.yml'); expect(debian).toContain('when: celilo_install_browser | bool'); // The gate is worthless if the flag defaults on: the e2e topology has // no real internet, and the browser comes from an external CDN. expect(manifest).toMatch(/name: install_browser[\s\S]*?default: false/); }); test('the role provisions the headless shell, not full Chromium', () => { // Reversed after measuring celilo-mgr: both builds there are headless // shells and chromium.launch() has been driving one in production all // along. Provisioning the full browser would change what works. const debian = read('ansible/roles/celilo-mgmt/tasks/debian.yml'); expect(debian).toContain('install chromium-headless-shell'); expect(debian).toContain("'flavor': 'headless-shell'"); }); });