// The teaser video (media/teaser): the scan text it shows is the real `storebound scan` output of the teaser fixtures, // every cut sits on the beat grid, every caption is short and stays readable, every scene holds long enough. import { beforeAll, describe, expect, test } from 'bun:test'; import { join } from 'node:path'; const ROOT = join(import.meta.dir, '..'); const CLI = join(ROOT, 'cli', 'index.ts'); const FX = join(import.meta.dir, 'fixtures', 'scan'); interface Scene { id: string; from: number; to: number; start: number; end: number; in: string | null } interface Finding { sev: string; guideline: string; title: string; where: string; fix: string; skill: string } interface Teaser { BEAT: number; DURATION: number; SCENES: Scene[]; CAPTIONS: { id: string; lines: string[] }[]; captionTimes(): { id: string; words: string; count: number; at: number; from: number; to: number; hold: number }[]; SCAN_HEAD: { text: string }[]; SDKS: { name: string; what: string; dep: string; where: string }[]; RISKS_LINE: string; FINDINGS: Finding[]; RESCAN_LINE: string; RESCAN_NONE: string; DECL_LINES: { what: string; value: string; where: string }[]; DECL_ASK: string; CMD: string; } const path: string = join(ROOT, 'media/teaser/script.js'); const T = (await import(path)) as Teaser; const scanText = (dir: string, demo: boolean): string => { const env = { ...process.env, NO_COLOR: '1', REVIEW_DEMO_USER: demo ? 'demo@example.com' : '', REVIEW_DEMO_PASSWORD: demo ? 'example' : '' }; const r = Bun.spawnSync(['bun', CLI, 'scan', '--dir', join(FX, dir)], { env, stdout: 'pipe', stderr: 'pipe' }); // exit code 1 when blockers are found (the fixture before the fixes), 0 after expect(r.exitCode).toBe(demo ? 0 : 1); return r.stdout.toString() + r.stderr.toString(); }; let before = '', after = ''; beforeAll(() => { before = scanText('teaser', false); after = scanText('teaser-fixed', true); }); describe('teaser: the scan text is real', () => { test('command, header, SDKs and the risks line come from `storebound scan` of tests/fixtures/scan/teaser', () => { expect(T.CMD).toBe('storebound scan'); for (const l of T.SCAN_HEAD) expect(before).toContain(l.text); for (const s of T.SDKS) expect(before).toMatch(new RegExp(`${s.name}\\s+${s.what.replace(/[()]/g, '\\$&')} · ${s.dep} \\(${s.where}\\)`)); expect(before).toContain(T.RISKS_LINE); }); test('the five findings: severity, guideline, title, file:line, a verbatim piece of the fix, the skill', () => { expect(T.FINDINGS).toHaveLength(5); const blocks = before.split(/\n\s+\d\. /).slice(1); T.FINDINGS.forEach((f, i) => { const b = blocks[i]!; expect(b.startsWith(`${f.sev.padEnd(7)} ${f.guideline} · App Store · ${f.title}`)).toBe(true); expect(b).toContain(`at ${f.where}`); expect(b).toContain(`skill: ${f.skill}`); expect(b.match(/fix: (.*)/)![1]).toContain(f.fix); }); }); test('declarations proposal lines', () => { for (const d of T.DECL_LINES) expect(before).toContain(`detected ${d.what}: ${d.value}`); for (const d of T.DECL_LINES) expect(before).toContain(`(${d.where})`); expect(before).toContain(T.DECL_ASK); }); test('the re-scan after the fixes (tests/fixtures/scan/teaser-fixed, demo account in the environment) is clean', () => { expect(after).toContain(T.RESCAN_LINE); expect(after).toContain(T.RESCAN_NONE); }); }); describe('teaser: timing', () => { const near = (x: number): boolean => Math.abs(x / T.BEAT - Math.round(x / T.BEAT)) < 1e-9; test('scenes are contiguous, cover the video and cut on the beat', () => { expect(T.SCENES[0]!.start).toBe(0); for (let i = 1; i < T.SCENES.length; i++) expect(T.SCENES[i]!.start).toBe(T.SCENES[i - 1]!.end); expect(T.SCENES.at(-1)!.end).toBeCloseTo(T.DURATION, 9); for (const s of T.SCENES) expect(near(s.start), s.id).toBe(true); expect(T.DURATION).toBeGreaterThan(29); expect(T.DURATION).toBeLessThan(35); }); test('every scene holds at least 2.5 s', () => { for (const s of T.SCENES) expect(s.end - s.start, s.id).toBeGreaterThanOrEqual(2.5); }); test('captions: at most 7 words, fully on screen for at least 1.2 s, never overlapping', () => { const c = T.captionTimes(); expect(c).toHaveLength(T.CAPTIONS.length); for (const x of c) { expect(x.count, x.words).toBeLessThanOrEqual(7); expect(x.hold, x.words).toBeGreaterThanOrEqual(1.2); } for (let i = 1; i < c.length; i++) expect(c[i]!.at).toBeGreaterThanOrEqual(c[i - 1]!.to); }); });