Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docs/TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Statuses: done (PR merged) · doing (branch open, pending review) · remaining

| ID | Task | Branch | Verification | Status |
|---|---|---|---|---|
| _(empty)_ | | | | |
| T5.1 | E2E suite | `arch/tts/t5.1` | 15/15 Playwright specs (AC1–AC15) against the real `en_US-lessac-medium`, run three times including once from empty data dirs; `tsc -p tests/e2e --noEmit`; 201 pytest unit + 16 integration; 111 Vitest; Ruff; mypy; ESLint; frontend `tsc`; Prettier; PR CI pending | Pending review |

## Remaining

Expand Down Expand Up @@ -65,7 +65,6 @@ _All P4 tasks done._

| ID | Task | Files | Deps | Acceptance criteria (summary) |
|---|---|---|---|---|
| T5.1 | E2E suite | `tests/e2e/` | T4.1 | All 15 acceptance criteria tested or recorded as manual checks |
| T5.2 | Docs | `README.md`, `docs/USER_GUIDE.md`, `docs/KNOWN_LIMITATIONS.md`, `docs/PRD.md` | T5.1 | Fresh-machine workflow completes using README alone |
| T5.3 | Measurement | `tests/measure.py`, `docs/MEASUREMENTS.md` | T4.1 | Performance and timing measurements with hardware note |

Expand Down Expand Up @@ -151,3 +150,9 @@ _All P4 tasks done._
- T4.3 decision (closes T1.6's `TTS_FAULT` note): `TTS_FAULT` is now read only by `config.py`, which adds a `fault` field to `Settings` (`none` by default, `engine` the test fault), normalizes case/whitespace, falls back to `none` with a warning on an unknown value, and logs "Fault injection enabled: engine" when armed. `jobs/manager.py` compares `self._settings.fault` and no longer touches `os.environ`, so §7.1 is true again; §7.1's field list was updated in this PR (§14.4). Dependent tests switched from env mutation to fault-enabled fixtures: `tests/unit/test_jobs_manager.py` gained a `fault_harness` fixture (built by the shared `_build_harness` helper) and `tests/integration/test_jobs_pipeline.py` gained a `fault_environment` fixture (built by `_build_environment(tmp_path, fault=...)`).
- T4.3 logging: the two failure branches call the new `_log_preview(text)` helper (`text[:LOG_PREVIEW_CHARS]`, 80 chars) so the input preview can never exceed §11's limit; the existing WARNING line still carries the §9.1 code and the failure reason, and the exception keeps the traceback at ERROR. No production behavior other than `TTS_FAULT`'s source changed — the §11 log lines (start/success/failure/cancel, degraded timings, eviction, offline first run) already existed.
- T4.3 enforcement test: new `tests/unit/test_observability.py` (unique basename, per the T1.2 note) proves a failed generation logs `ENGINE_ERROR` + the reason + the 80-char preview, and uses `difflib.SequenceMatcher` to assert the longest common run between the >80-char input and all captured log text is ≤ 80 characters (the marker after char 80 never appears, no timing JSON is logged). It also pins `Settings.load()` fault parsing (default/override/unknown) and proves a manager built with `fault="none"` succeeds even when `TTS_FAULT=engine` is set in the environment.
- T5.1 decisions: the suite is serial (`workers: 1`, `fullyParallel: false`, `retries: 0`, 180 s per test) because synthesis is single-worker and AC13 describes one shared library. Two real `tts` servers back the run: the main one on 8321 (CI starts it; locally Playwright starts it, or reuses a healthy one) using `.venv/e2e-data` locally and `$RUNNER_TEMP/tts-data` in CI, plus a `TTS_FAULT=engine` server on 8322 with its own data dir for AC11 (faults are read once at startup, so AC11 cannot share the main process). Both start offline: `scripts/ensure-data.mjs` copies `voices/` from `.venv/tts-data/voices` (local) or the main data dir (CI's restored cache) before `tts` runs, so neither server downloads a voice.
- T5.1 wiring: `@playwright/test` resolves through `tests/e2e/tsconfig.json`'s `paths` to `frontend/node_modules/@playwright/test` (no root `package.json` and no `@types/node` was added); `support/node-shims.d.ts` declares the few Node builtins the support layer uses. `PYTHON` in `support/env.ts` prefers `TTS_E2E_PYTHON`, then the repo `.venv`, then `python`/`python3` (CI has no repo virtualenv). Playwright failure artifacts go to the ignored `.venv/e2e-artifacts`. `npx tsc -p tests/e2e --noEmit` is clean.
- T5.1 AC7 tolerance: `WORD_START_TOLERANCE_MS = 100` in `support/env.ts` is assumption A-3's target for word-start accuracy, measured by seeking in the UI and comparing `audio.currentTime`; T5.3 owns the final listening measurement and the constant follows its result. The spec also checks timing structure, monotonicity, bounds within the file, and that the last word does not extend past the audio. That last check is one-sided: Piper pads the final sentence with up to ~0.5 s of silence, so the last word may end before the file does.
- T5.1 results: 15/15 specs pass against the real `en_US-lessac-medium`, three consecutive runs (one from empty data dirs to prove voice seeding) at ~24 s each. AC11 runs on the fault server and proves the failed row has no `.wav`/`.part` while the main server's history total and a prior ready entry stay intact and restorable; AC12 cancels a 5,000-char slow-rate job and proves no partial file, no audio, no downloads; AC9/AC10 parse the downloaded WAV/SRT/VTT bytes (not API bodies) and cross-check download names, RIFF sizes, and cue timing; AC15 drives the whole flow with Tab/Enter/Space only.
- T5.1 browser finding (recorded, no production change): a native `<audio controls>` element absorbs several Tab presses inside its own shadow controls, and when a generation finishes the Generate button is replaced, so focus returns to the document and forward Tab skips ahead to the sentence cues. Keyboard users can still play from the main landmark with the documented Space shortcut; AC15 reaches that landmark through the skip link. This is existing UI behavior outside T5.1's owned files, noted for T5.2.
- T5.1 verification: 15/15 Playwright specs (three runs, one from empty data dirs); `npx tsc -p tests/e2e --noEmit`; 201 pytest unit; 16 integration (`TTS_DATA_DIR=.venv/tts-data`, `--basetemp .venv/ptmp-t51-int`); 111 Vitest; Ruff check/format; strict mypy; ESLint; frontend `tsc --noEmit`; Prettier (CRLF); `git diff --check`. PR CI must confirm the two-server topology on Linux.
1 change: 1 addition & 0 deletions tests/e2e/fixtures/texts/one-char.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
1 change: 1 addition & 0 deletions tests/e2e/fixtures/texts/sample-200.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This text was uploaded as plain text, and it proves the upload path reaches the same input box. The content stays editable, so it can be corrected before it is spoken, exactly like typed input. Uploading alone never starts a generation.
1 change: 1 addition & 0 deletions tests/e2e/fixtures/texts/sample-5000.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation. The quick brown fox jumps over the lazy dog while the acceptance suite waits for a chance to cancel this deliberately long generation.
3 changes: 3 additions & 0 deletions tests/e2e/fixtures/unsupported.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Notes

This Markdown file is deliberately not a plain-text upload. The app should reject it and name the accepted type.
98 changes: 98 additions & 0 deletions tests/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Playwright configuration for the acceptance suite (ARCHITECTURE.md section
* 14.2 T5.1, section 15).
*
* Two `tts` servers back the run:
*
* - the main server on `TTS_E2E_PORT` (8321), which CI starts itself before
* Playwright and which this config starts locally when it is absent;
* - a fault-armed server on `TTS_E2E_FAULT_PORT` (8322) with `TTS_FAULT=engine`
* for AC11. Fault injection is a `Settings` value read at startup, so one
* long-running process cannot switch modes.
*
* The suite is serial: synthesis is single-worker by design and the history
* assertions describe a shared library.
*/

import path from "node:path";
import { defineConfig, devices } from "@playwright/test";
import {
FAULT_DATA_DIR,
FAULT_PORT,
FAULT_URL,
MAIN_DATA_DIR,
MAIN_PORT,
MAIN_URL,
PYTHON,
REPO_ROOT,
VOICE_SOURCE,
} from "./support/env";

const SEED_SCRIPT = path.join(__dirname, "scripts", "ensure-data.mjs");

/** Seed the data dir, then run `tts` from the repository root. */
function serverCommand(): string {
return `"${process.execPath}" "${SEED_SCRIPT}" && "${PYTHON}" -m tts`;
}

const commonEnv = {
...process.env,
TTS_HOST: "127.0.0.1",
};

export default defineConfig({
testDir: "./specs",
// Failure artifacts (traces, screenshots) go to the repository's ignored
// scratch directory instead of the frontend working directory.
outputDir: path.join(REPO_ROOT, ".venv", "e2e-artifacts"),
fullyParallel: false,
workers: 1,
retries: 0,
forbidOnly: process.env["CI"] !== undefined,
timeout: 180_000,
expect: { timeout: 15_000 },
reporter:
process.env["CI"] !== undefined ? [["list"], ["github"]] : [["list"]],
use: {
baseURL: MAIN_URL,
acceptDownloads: true,
trace: "retain-on-failure",
screenshot: "only-on-failure",
video: "off",
launchOptions: { args: ["--autoplay-policy=no-user-gesture-required"] },
},
webServer: [
{
command: serverCommand(),
url: `${MAIN_URL}/api/health`,
cwd: REPO_ROOT,
// CI starts this server itself; locally Playwright starts it on demand.
reuseExistingServer: true,
timeout: 180_000,
env: {
...commonEnv,
TTS_DATA_DIR: MAIN_DATA_DIR,
TTS_PORT: MAIN_PORT,
TTS_E2E_SEED_DIR: MAIN_DATA_DIR,
TTS_E2E_SEED_SOURCE: VOICE_SOURCE,
},
},
{
command: serverCommand(),
url: `${FAULT_URL}/api/health`,
cwd: REPO_ROOT,
// A stale server may be unarmed or hold stale history, so never reuse one.
reuseExistingServer: false,
timeout: 180_000,
env: {
...commonEnv,
TTS_DATA_DIR: FAULT_DATA_DIR,
TTS_PORT: FAULT_PORT,
TTS_FAULT: "engine",
TTS_E2E_SEED_DIR: FAULT_DATA_DIR,
TTS_E2E_SEED_SOURCE: VOICE_SOURCE,
},
},
],
projects: [{ name: "chromium", use: { ...devices["Desktop Chrome"] } }],
});
51 changes: 51 additions & 0 deletions tests/e2e/scripts/ensure-data.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Seeds an E2E data directory with the Piper voice before `tts` starts.
*
* Both E2E servers need `voices/` in their data directory: the main one so the
* UI lists a voice without a first-run download, the fault-armed one (AC11) so
* it can render its first sentence and then trip the injected fault. Copying
* the developer's cached voice keeps the suite offline and fast.
*
* Inputs (set by playwright.config.ts):
* TTS_E2E_SEED_DIR - data directory to seed
* TTS_E2E_SEED_SOURCE - existing voices directory to copy from
*
* Exits 0 when the directory already holds a voice, when a copy succeeded, or
* when no source exists (the server then bootstraps the default voice).
*/

import { cpSync, existsSync, mkdirSync, readdirSync } from "node:fs";
import path from "node:path";

const target = process.env["TTS_E2E_SEED_DIR"];
const source = process.env["TTS_E2E_SEED_SOURCE"];

if (!target) {
console.error("ensure-data: TTS_E2E_SEED_DIR is required");
process.exit(1);
}

const voices = path.join(target, "voices");
const hasVoice = () =>
existsSync(voices) &&
readdirSync(voices).some((name) => name.endsWith(".onnx"));

if (hasVoice()) {
process.exit(0);
}

mkdirSync(voices, { recursive: true });

if (
source &&
existsSync(source) &&
readdirSync(source).some((name) => name.endsWith(".onnx"))
) {
cpSync(source, voices, { recursive: true });
console.log(`ensure-data: copied voices into ${voices}`);
process.exit(0);
}

console.log(
`ensure-data: no voice source at ${source ?? "(unset)"}; the server will bootstrap one.`,
);
56 changes: 56 additions & 0 deletions tests/e2e/specs/ac01-offline-generation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* AC1 (PRD section 8): pasted multi-paragraph text generates playable audio
* with no outbound network request.
*
* CI cannot physically disconnect the machine, so "offline" is proven the way
* ARCHITECTURE.md section 15 prescribes: every request is intercepted, and any
* non-local one is aborted and recorded. AC14 repeats the guard across the full
* export workflow; this spec covers generation and playback.
*/

import { expect, test } from "@playwright/test";
import { getGeneration } from "../support/api";
import { uniqueText } from "../support/run";
import {
audioState,
generateInUi,
installLocalOnlyNetwork,
openApp,
resourceOrigins,
} from "../support/ui";

test("AC1: generation and playback make no outbound request", async ({
page,
request,
}) => {
const network = await installLocalOnlyNetwork(page);
await openApp(page);

const text = uniqueText(
"Hello world. This is the offline acceptance check.\n\nParagraph breaks are preserved.",
);
const generationId = await generateInUi(page, text);

const before = await audioState(page);
expect(before).not.toBeNull();
expect(before?.duration ?? 0).toBeGreaterThan(0.5);

await page.getByRole("button", { name: "Play audio" }).click();
await expect
.poll(async () => (await audioState(page))?.currentTime ?? 0, {
timeout: 30_000,
})
.toBeGreaterThan(0.2);
await page.getByRole("button", { name: "Pause audio" }).click();

const detail = await getGeneration(request, generationId);
expect(detail.status).toBe("succeeded");
expect(detail.durationSeconds ?? 0).toBeGreaterThan(0.5);
expect(detail.wordTimings?.length ?? 0).toBeGreaterThan(0);

expect(network.external).toEqual([]);
const origins = await resourceOrigins(page);
expect(
origins.filter((origin) => !origin.startsWith("http://127.0.0.1")),
).toEqual([]);
});
46 changes: 46 additions & 0 deletions tests/e2e/specs/ac02-file-upload.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* AC2 (PRD section 8): an uploaded plain-text file fills the input view, stays
* editable, and generates audio like typed input. Uploading on its own never
* starts a generation (ARCHITECTURE.md section 9.2).
*/

import { expect, test } from "@playwright/test";
import { fixturePath } from "../support/fixtures";
import {
startGeneration,
openApp,
READY_STATUS,
waitForStatus,
} from "../support/ui";

test("AC2: an uploaded plain-text file behaves like typed input", async ({
page,
}) => {
await openApp(page);

await page
.locator("#input-file")
.setInputFiles(fixturePath("texts", "sample-200.txt"));

const input = page.locator("#input-text");
await expect(page.getByText("loaded from sample-200.txt")).toBeVisible();
await expect(input).toHaveValue(
/proves the upload path reaches the same input box/,
);
await expect(page.locator("#input-count")).toContainText("characters");

// Editable: append a sentence by keyboard before generating.
await input.press("End");
await page.keyboard.type(" Edited by hand.");
await expect(input).toHaveValue(/Edited by hand\.$/);

// The generation is the explicit second step, not part of the upload.
await expect(page.locator("audio[aria-label='Generated audio']")).toHaveCount(
0,
);
await startGeneration(page);
await waitForStatus(page, READY_STATUS);
await expect(
page.locator("audio[aria-label='Generated audio']"),
).toBeVisible();
});
Loading
Loading