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
12 changes: 7 additions & 5 deletions docs/TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Statuses: done (PR merged) · doing (branch open, pending review) · remaining

| ID | Task | Branch | Verification | Status |
|---|---|---|---|---|
| _(empty)_ | | | | |
| T3.1 | App shell + input + voice + generate | `arch/tts/t3.1` | 51 Vitest (17 new); ESLint; `tsc --noEmit`; Prettier (CRLF); live + mock Vite builds; mock-mode Chromium check (AC3/AC4/AC6, upload, preview playback, generate→succeeded, cancel); 196 pytest; Ruff check/format; strict mypy; `git diff --check` | Awaiting PR review |

## Remaining

Expand All @@ -45,15 +45,12 @@ _All P1 tasks done._

### P2 — HTTP surface

| ID | Task | Files | Deps | Acceptance criteria (summary) |
|---|---|---|---|---|
| T2.1 | Uploads + voices routes | `src/tts/api/routes/uploads.py`, `voices.py` | T0.3, T1.1 | Upload validation, preview WAV, no-voice response |
_All P2 tasks done._

### P3 — UI against contracts

| ID | Task | Files | Deps | Acceptance criteria (summary) |
|---|---|---|---|---|
| T3.1 | App shell + input + voice + generate | `frontend/src/App.tsx`, components, state wiring | T0.5 | Input/upload, validation, settings ranges, voice preview, no-voice guidance |
| T3.2 | Playback + downloads | `frontend/src/` playback components and hook | T0.5 | Highlight/seek/reset behavior and correctly named downloads |
| T3.3 | History | `frontend/src/` history component | T0.5 | History preview, restore, and individual deletion |

Expand Down Expand Up @@ -124,3 +121,8 @@ _All P1 tasks done._
- T2.2 SSE: sends `RETRY_LINE` once, then `subscriber.events()` frames until the terminal event; `Cache-Control: no-cache` and `X-Accel-Buffering: no` mitigate R6. No explicit unsubscribe on client disconnect — the manager closes the subscriber queue at the terminal event, so no stream registration leaks. Unknown ids (malformed or well-formed) are 404 before the stream opens.
- T2.2 test layout: `tests/unit/test_api_generations_routes.py` and `tests/integration/test_api_generations_flow.py` (unique basenames; see the T1.2 note). Unit tests use a fake job manager with a real DAL so no engine is imported; the integration test runs a real generation against `en_US-lessac-medium` and verifies SSE replay, detail, WAV, SRT/VTT, and delete.
- T2.3 scope resolution: expanded §14.2 to include app lifespan/service wiring, CLI serving and voice installation, and persisted default-voice responses in health and voice-list routes; the tracker note had assigned startup wiring to T2.3 while the original owned-file list omitted it. `jobs.manager.bootstrap` already existed from T1.6 and is reused. Unit tests disable automatic bootstrap except for the explicit offline-startup case. On this Windows checkout, `npm run format:check` assumes LF while tracked frontend files are checked out as CRLF (`core.autocrlf=true`); `npm run format:check -- --end-of-line crlf` passes without changing files.
- T3.1 decisions: `App.tsx` bootstraps `listVoices` + `getSettings` on mount and applies the persisted default voice, rate, and volume through the existing §12 actions (no new reducer actions; `appContext.tsx` untouched). Local pre-flight validation lives in the new T3.1-owned `components/validation.ts`: empty/whitespace → `EMPTY_INPUT` without a request, >50,000 chars → `INPUT_TOO_LONG`, no selected voice → `NO_VOICES_INSTALLED`. `MAX_INPUT_CHARS` mirrors §11's default because §9 does not expose the server's configured limit; the server remains authoritative. Sliders clamp into §9.2 ranges (`clampRate`, `clampVolume`) and show numeric values.
- T3.1 settings persistence: §12 assigns `putSettings` on blur to `VoicePanel`, so T3.1 implements it and loads persisted settings on mount; §14.2's T4.1 wording "settings persistence" is reduced to live-mode verification. Live persistence is unverified here because the mock API resets on reload.
- T3.1 downstream contract (T3.2): `GenerateBar` owns the only SSE subscription and sets `current.audioUrl` after fetching the detail + audio blob. If the blob fetch fails after a `succeeded` event (or the detail fetch fails), the current entry is unlocked with `audioUrl`/`detail` absent and an error banner is shown, so `PlaybackPanel` must render a ready-state message instead of assuming audio exists. T3.3's history restore should load detail + audio via `SELECT_HISTORY_ITEM` without opening a stream.
- T3.1 testing: no jsdom/Testing Library was added (§5 lists vitest only). 17 new Vitest tests cover validation/clamping and static markup (no-voice explanation, control ranges, section order); AC3, AC4, AC6, text upload, preview playback, generate→succeeded, and cancel were verified in mock mode with a temporary headless-Chromium Playwright script (removed after the run, not committed).
- T3.1 shared-file note: `styles.css` (created by T0.5, not assigned to a later task) received additive form/progress styles; `components/validation.ts` is a new T3.1-owned helper module not listed in §6's frontend tree. The P2 "remaining" table was already marked done in an uncommitted edit at task start; it was kept because it matches T2.3's merged state.
12 changes: 11 additions & 1 deletion frontend/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function renderApp(): string {
);
}

describe("App placeholder", () => {
describe("App shell", () => {
it("renders the section stack in the documented order", () => {
const html = renderApp();
const headings = [
Expand All @@ -26,6 +26,16 @@ describe("App placeholder", () => {
expect([...positions].sort((a, b) => a - b)).toEqual(positions);
});

it("renders the input, voice, and generate controls", () => {
const html = renderApp();
expect(html).toContain('id="input-text"');
expect(html).toContain('accept=".txt,text/plain"');
expect(html).toContain('id="voice-select"');
expect(html).toContain('id="rate-slider"');
expect(html).toContain('id="volume-slider"');
expect(html).toMatch(/<button[^>]*disabled[^>]*>Generate audio<\/button>/);
});

it("shows the no-voice state and empty history", () => {
const html = renderApp();
expect(html).toContain("No voices installed");
Expand Down
106 changes: 58 additions & 48 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,64 @@
/**
* Placeholder shell for the single page (ARCHITECTURE.md section 12).
* Single page layout (ARCHITECTURE.md section 12).
*
* Sections are laid out in their final order so the component tasks (T3.1–T3.3)
* can replace each one without moving the page furniture.
* Sections stack in their documented order. The playback and history sections
* stay as placeholders until T3.2/T3.3 replace them, so each task can own its
* own component file.
*/

import { apiMode } from "./api";
import { useEffect } from "react";
import { api, apiMode } from "./api";
import { toApiError } from "./api/client";
import { ErrorBanner } from "./components/ErrorBanner";
import { GenerateBar } from "./components/GenerateBar";
import { InputPanel } from "./components/InputPanel";
import { VoicePanel } from "./components/VoicePanel";
import { clampRate, clampVolume } from "./components/validation";
import { useApp } from "./state/appContext";

export function App() {
const { state } = useApp();
const selectedVoice = state.voices.find((voice) => voice.id === state.selectedVoiceId);
const { state, dispatch } = useApp();

useEffect(() => {
let cancelled = false;

async function bootstrap(): Promise<void> {
try {
const list = await api.listVoices();
if (cancelled) {
return;
}
dispatch({ type: "VOICES_LOADED", voices: list.items });
if (list.items.some((voice) => voice.id === list.defaultVoiceId)) {
dispatch({ type: "SET_VOICE", voiceId: list.defaultVoiceId });
}

const settings = await api.getSettings();
if (cancelled) {
return;
}
dispatch({ type: "SET_RATE", rate: clampRate(settings.rate) });
dispatch({ type: "SET_VOLUME", volume: clampVolume(settings.volume) });
if (list.items.some((voice) => voice.id === settings.defaultVoiceId)) {
dispatch({ type: "SET_VOICE", voiceId: settings.defaultVoiceId });
}
} catch (error) {
if (cancelled) {
return;
}
const failure = toApiError(error);
dispatch({
type: "SET_ERROR",
error: { code: failure.code, message: failure.message, details: failure.details },
});
}
}

void bootstrap();
return () => {
cancelled = true;
};
}, [dispatch]);

return (
<div className="app">
Expand All @@ -20,48 +68,10 @@ export function App() {
{apiMode === "mock" ? <p className="badge">Mock mode: sample data</p> : null}
</header>

{state.error !== null && (
<section className="section banner" role="alert" aria-labelledby="error-heading">
<h2 id="error-heading">Something went wrong</h2>
<p>{state.error.message}</p>
</section>
)}

<section className="section" aria-labelledby="input-heading">
<h2 id="input-heading">Text</h2>
<p className="hint">Paste text or upload a .txt file for review.</p>
<p className="stat">
{state.inputText.length.toLocaleString()} characters
{state.sourceFilename === null ? "" : ` · ${state.sourceFilename}`}
</p>
</section>

<section className="section" aria-labelledby="voice-heading">
<h2 id="voice-heading">Voice and settings</h2>
<p className="hint">Choose an installed voice, preview it, and set rate and volume.</p>
<p className="stat">
{state.voices.length === 0
? "No voices installed"
: `${state.voices.length} voice${state.voices.length === 1 ? "" : "s"} · ${
selectedVoice?.name ?? "none selected"
}`}
</p>
<p className="stat">
Rate {state.rate.toFixed(1)}× · Volume {Math.round(state.volume * 100)}%
</p>
</section>

<section className="section" aria-labelledby="generate-heading">
<h2 id="generate-heading">Generate</h2>
<p className="hint">Start, watch progress, and cancel a generation.</p>
<p className="stat">
{state.current === null
? "Nothing generated yet"
: `${state.current.status} · sentence ${state.current.sentenceIndex} of ${
state.current.sentenceCount
}`}
</p>
</section>
<ErrorBanner />
<InputPanel />
<VoicePanel />
<GenerateBar />

<section className="section" aria-labelledby="playback-heading">
<h2 id="playback-heading">Playback and subtitles</h2>
Expand Down
32 changes: 32 additions & 0 deletions frontend/src/components/ErrorBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Single error surface for the whole page (ARCHITECTURE.md section 16: every
* frontend error goes through here with its message and corrective action).
*/

import { useApp } from "../state/appContext";

export function ErrorBanner() {
const { state, dispatch } = useApp();

if (state.error === null) {
return null;
}

return (
<section className="section banner" role="alert" aria-labelledby="error-heading">
<div className="banner-heading">
<h2 id="error-heading">Something went wrong</h2>
<button
type="button"
className="secondary"
onClick={() => {
dispatch({ type: "CLEAR_ERROR" });
}}
>
Dismiss
</button>
</div>
<p>{state.error.message}</p>
</section>
);
}
28 changes: 28 additions & 0 deletions frontend/src/components/GenerateBar.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import { AppProvider } from "../state/appContext";
import { GenerateBar } from "./GenerateBar";

function renderBar(): string {
return renderToStaticMarkup(
<AppProvider>
<GenerateBar />
</AppProvider>,
);
}

describe("GenerateBar", () => {
it("disables generation with an install explanation when there are no voices", () => {
const html = renderBar();
expect(html).toMatch(/<button[^>]*disabled[^>]*>Generate audio<\/button>/);
expect(html).toContain("No voices installed, so generation is disabled.");
expect(html).toContain("tts add-voice");
expect(html).not.toContain("Cancel generation");
});

it("starts from the empty state without a progress bar", () => {
const html = renderBar();
expect(html).toContain("Nothing generated yet");
expect(html).not.toContain("<progress");
});
});
Loading