Files
SubMiner/e2e/harness/fixtures.ts
sudacode 78eca52b7e test: add headless end-to-end harness (#286)
* test: add headless end-to-end harness and CI job

Boot the built app against a real mpv, a synthetic clip, a fixture Yomitan
dictionary, and a fake AnkiConnect inside a private Xvfb display, then assert
on the overlay DOM and the AnkiConnect requests. Adds the test:e2e lane, an
e2e session CLI for exploratory checks, and a three-platform CI job.

* ci: set e2e temp dir from a step

* test: make e2e session startup robust on slow machines

Bun caps node:test hooks at 5s, so boot the session inside the first test.
Keep pausing until the app's resume retries stop, read cue tokens in one
round trip, and resolve Electron through its package entry so CI downloads
the binary.

* test: harden e2e harness for CI runners

Fail fast when mpv cannot be spawned, read every Yomitan popup frame instead
of trusting target order, and put the chocolatey mpv directory on PATH.

* test: add e2e failure diagnostics and mark Windows job experimental

Report what the overlay showed when a cue never renders, dispose the session
when the overlay cannot be opened, skip popup frames that vanish mid-poll,
and turn off AniSkip lookups in the harness config.

* test: read the lookup popup entry from textContent

* test: capture renderer console and main-side subtitle state in e2e failures

* test: expose the Electron main-process inspector to the e2e harness

Adds session.mainProcess() and 'e2e eval main', and reports main's window
list alongside the overlay state when a cue never renders.

* test: tap subtitle sends and receipts in e2e failure diagnostics

* test: probe alternate main-to-renderer paths in e2e failure diagnostics

* test: select the visible overlay layer, not the primed modal window

Windows and macOS pre-create a hidden modal window that loads the same
renderer document, and the harness could attach to it instead of the
visible overlay. Drops the delivery taps that found this.

* ci: run the Windows e2e job as a normal matrix entry

* test: address review on e2e harness

Slice the app log at a byte offset before decoding, create the session state
file owner-only since it carries the inspector URL, and keep the cue failure
when inspector diagnostics are unavailable.

* test: create the e2e session state file exclusively
2026-10-05 22:00:58 -07:00

93 lines
2.8 KiB
TypeScript

import { execFile } from 'node:child_process';
import fs from 'node:fs';
import { promisify } from 'node:util';
import { writeStoredZipAsync } from '../../src/shared/stored-zip';
const execFileAsync = promisify(execFile);
export const FIXTURE_DICTIONARY_TITLE = 'SubMiner E2E Fixture';
export const FIXTURE_CLIP_SECONDS = 15;
/** Cues of the synthetic clip. Seek to `at` to land inside a cue. */
export const FIXTURE_CUES = [
{ start: 1, end: 4, at: 2, text: '今日はいい天気ですね。' },
{ start: 5, end: 8, at: 6, text: '猫が好きです。' },
{ start: 9, end: 12, at: 10, text: '明日は学校に行きます。' },
] as const;
// [term, reading, part of speech, gloss] for every content word in FIXTURE_CUES.
const FIXTURE_TERMS = [
['今日', 'きょう', 'n', 'today'],
['いい', 'いい', 'adj-i', 'good'],
['天気', 'てんき', 'n', 'weather'],
['猫', 'ねこ', 'n', 'cat'],
['好き', 'すき', 'adj-na', 'liked'],
['明日', 'あした', 'n', 'tomorrow'],
['学校', 'がっこう', 'n', 'school'],
['行く', 'いく', 'v5', 'to go'],
] as const;
function srtTimestamp(seconds: number): string {
return `00:00:${String(seconds).padStart(2, '0')},000`;
}
export function writeFixtureSubtitles(outputPath: string): void {
const blocks = FIXTURE_CUES.map(
(cue, index) =>
`${index + 1}\n${srtTimestamp(cue.start)} --> ${srtTimestamp(cue.end)}\n${cue.text}\n`,
);
fs.writeFileSync(outputPath, blocks.join('\n'), 'utf8');
}
/** Renders a deterministic test-pattern clip with a sine tone, so no real media is needed. */
export async function generateFixtureClip(outputPath: string): Promise<void> {
await execFileAsync('ffmpeg', [
'-nostdin',
'-v',
'error',
'-y',
'-f',
'lavfi',
'-i',
`testsrc2=size=640x360:rate=24:duration=${FIXTURE_CLIP_SECONDS}`,
'-f',
'lavfi',
'-i',
`sine=frequency=440:duration=${FIXTURE_CLIP_SECONDS}`,
'-c:v',
'libx264',
'-preset',
'ultrafast',
'-pix_fmt',
'yuv420p',
'-c:a',
'aac',
outputPath,
]);
}
/** Writes a minimal Yomitan term dictionary so the tokenizer has real entries to match. */
export async function buildFixtureDictionary(outputPath: string): Promise<void> {
const index = {
title: FIXTURE_DICTIONARY_TITLE,
revision: '1',
format: 3,
author: 'SubMiner',
description: 'Synthetic dictionary for the e2e harness.',
};
const termBank = FIXTURE_TERMS.map(([term, reading, partOfSpeech, gloss], sequence) => [
term,
reading,
'',
partOfSpeech,
0,
[gloss],
sequence + 1,
'',
]);
await writeStoredZipAsync(outputPath, [
{ name: 'index.json', data: Buffer.from(JSON.stringify(index), 'utf8') },
{ name: 'term_bank_1.json', data: Buffer.from(JSON.stringify(termBank), 'utf8') },
]);
}