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

| ID | Task | Branch | Verification | Status |
|---|---|---|---|---|
| _(empty)_ | | | | |
| T3.3 | History | `arch/tts/t3.3` | 93 Vitest (10 new); ESLint; `tsc --noEmit`; Prettier (CRLF); live + mock Vite builds; mock-mode Chromium 15/15 (narrow starts collapsed, summary toggle, empty state, 2 entries with preview/voice/time, restore loads subtitles + audio, delete one keeps the other, delete open entry clears playback, no console errors); 196 pytest; Ruff check/format; strict mypy; `git diff --check` | PR pending review |

## Remaining

Expand All @@ -51,9 +51,7 @@ _All P2 tasks done._

### P3 — UI against contracts

| ID | Task | Files | Deps | Acceptance criteria (summary) |
|---|---|---|---|---|
| T3.3 | History | `frontend/src/` history component | T0.5 | History preview, restore, and individual deletion |
_T3.3 in progress (see Doing)._

### P4 — Integration

Expand Down Expand Up @@ -132,3 +130,8 @@ _All P2 tasks done._
- T3.2 accessibility decision: word spans are mouse-only seek targets; sentence cue `<button>`s, the ±5 s buttons, and the keyboard shortcuts are the keyboard paths, avoiding thousands of tab stops on a 10k-word input. T4.2 owns the a11y pass and should revisit if it wants word-level keyboard seek. `PlaybackPanel` also renders the T3.1 succeeded-without-audio ready state instead of assuming a blob exists.
- T3.2 downstream contract (T3.3): `SubtitleView` and `DownloadBar` are prop-driven; history restore only needs `SELECT_HISTORY_ITEM` with a detail + audio URL, and `PlaybackPanel` picks it up with no further wiring.
- T3.2 shared-file note: `App.tsx` and `styles.css` are not assigned to T3.2 but received additive edits — T3.1's placeholder comment hands playback to T3.2/T3.3, so `App.tsx` now renders `PlaybackPanel` and keeps the history placeholder for T3.3; `styles.css` gained playback/subtitle/download rules. `contracts.ts`, `appContext.tsx`, and `api/*` were untouched (all needed types/actions already existed).
- T3.3 decisions: `HistoryPanel` is a native `<details>` disclosure. §12's "collapsed by default on narrow viewports" is read once at mount from `matchMedia("(max-width: 700px)")`; afterwards the user's toggle wins (resizing does not collapse it). Restore is offered only for `succeeded` rows and loads detail + audio blob via `getGeneration`/`getAudioBlob` then `SELECT_HISTORY_ITEM` — no SSE, per the T3.1/T3.2 contract — and deliberately does not overwrite the input text or voice/rate/volume. The restored object URL is revoked when playback moves to another entry/generation or the panel unmounts. Failed and cancelled rows stay visible and deletable but cannot be restored; delete is disabled for `queued`/`running`/`cancelling` rows because the API answers 409 `GENERATION_BUSY`. There is no delete confirmation dialog (T4.2 can add one).
- T3.3 history refresh: the list loads on mount and once per terminal current generation that is not already listed, so a just-finished generation appears without polling. The mock keeps history in memory only (a reload clears it); live persistence and the 20-entry eviction stay T4.1's scope.
- T3.3 testability: without jsdom, row rules live in exported pure helpers (`canRestore`, `canDelete`, `historyStatusText`, `historyPreview`, `formatHistoryTime`, `historyStartsOpen`) and the presentational `HistoryList` is rendered with `renderToStaticMarkup`. Interactive behavior was verified in mock mode with a temporary headless-Chromium Playwright script (removed after the run, not committed).
- T3.3 shared-file note: `App.tsx` and `styles.css` are not assigned to T3.3 but received additive edits — T3.1/T3.2 left the history placeholder for this task, so `App.tsx` now renders `HistoryPanel`, and `styles.css` gained history/disclosure rules. `contracts.ts`, `appContext.tsx`, `api/*`, and the mock were untouched (all needed actions and methods already existed).
- T3.3 frozen downstream (T5.1 AC13 spec): rows use classes `.history-item`, `.history-preview`, `.history-meta`, `.history-actions`; controls carry `aria-label="Open generation: <preview>"` and `aria-label="Delete generation: <preview>"`; the count line is `N saved generation(s)` and the empty state reads "Nothing here yet. Generate audio and it will appear in this list."
15 changes: 5 additions & 10 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
/**
* Single page layout (ARCHITECTURE.md section 12).
*
* Sections stack in their documented order. The history section stays as a
* placeholder until T3.3 replaces it, so that task can own its component file.
* Sections stack in their documented order: ErrorBanner, InputPanel,
* VoicePanel, GenerateBar, PlaybackPanel, HistoryPanel.
*/

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 { HistoryPanel } from "./components/HistoryPanel";
import { InputPanel } from "./components/InputPanel";
import { PlaybackPanel } from "./components/PlaybackPanel";
import { VoicePanel } from "./components/VoicePanel";
import { clampRate, clampVolume } from "./components/validation";
import { useApp } from "./state/appContext";

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

useEffect(() => {
let cancelled = false;
Expand Down Expand Up @@ -75,13 +76,7 @@ export function App() {

<PlaybackPanel />

<section className="section" aria-labelledby="history-heading">
<h2 id="history-heading">History</h2>
<p className="hint">Recent generations can be restored or deleted.</p>
<p className="stat">
{state.history.total} saved generation{state.history.total === 1 ? "" : "s"}
</p>
</section>
<HistoryPanel />

<footer className="app-footer">
<p>Everything runs on this machine; nothing is uploaded.</p>
Expand Down
163 changes: 163 additions & 0 deletions frontend/src/components/HistoryPanel.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import { AppProvider } from "../state/appContext";
import type { GenerationSummary } from "../types/contracts";
import {
canDelete,
canRestore,
formatHistoryTime,
historyPreview,
historyStartsOpen,
historyStatusText,
HistoryList,
HistoryPanel,
} from "./HistoryPanel";

const SUCCEEDED: GenerationSummary = {
generationId: "6f0c8e2a-0000-4000-8000-000000000001",
status: "succeeded",
createdAt: "2026-11-17T14:25:30Z",
sourceType: "text",
inputPreview: "Hello world.",
inputFilename: null,
voiceId: "en_US-lessac-medium",
voiceName: "en_US-lessac-medium",
rate: 1,
volume: 1,
durationSeconds: 1.2,
error: null,
};

const FAILED: GenerationSummary = {
...SUCCEEDED,
generationId: "6f0c8e2a-0000-4000-8000-000000000002",
status: "failed",
durationSeconds: null,
error: { code: "ENGINE_ERROR", message: "The speech engine produced no audio for this text." },
};

const RUNNING: GenerationSummary = {
...SUCCEEDED,
generationId: "6f0c8e2a-0000-4000-8000-000000000003",
status: "running",
durationSeconds: null,
};

const FILE_SOURCE: GenerationSummary = {
...SUCCEEDED,
generationId: "6f0c8e2a-0000-4000-8000-000000000004",
sourceType: "file",
inputPreview: " ",
inputFilename: "notes.txt",
};

function renderList(items: GenerationSummary[], total = items.length): string {
return renderToStaticMarkup(
<HistoryList
items={items}
total={total}
busy={null}
onRestore={() => undefined}
onDelete={() => undefined}
/>,
);
}

describe("history row rules", () => {
it("restores only finished generations", () => {
expect(canRestore(SUCCEEDED)).toBe(true);
expect(canRestore(FAILED)).toBe(false);
expect(canRestore(RUNNING)).toBe(false);
expect(canRestore({ ...SUCCEEDED, status: "cancelled" })).toBe(false);
});

it("deletes only terminal generations", () => {
expect(canDelete(SUCCEEDED)).toBe(true);
expect(canDelete(FAILED)).toBe(true);
expect(canDelete({ ...SUCCEEDED, status: "cancelled" })).toBe(true);
for (const status of ["queued", "running", "cancelling"] as const) {
expect(canDelete({ ...SUCCEEDED, status })).toBe(false);
}
});

it("describes every status, including the failure reason", () => {
expect(historyStatusText(SUCCEEDED)).toBe("Ready · 1 s");
expect(historyStatusText({ ...SUCCEEDED, durationSeconds: null })).toBe("Ready");
expect(historyStatusText(FAILED)).toContain("produced no audio");
expect(historyStatusText({ ...FAILED, error: null })).toBe("Failed");
expect(historyStatusText({ ...SUCCEEDED, status: "cancelled" })).toBe("Cancelled");
expect(historyStatusText(RUNNING)).toBe("Generating…");
expect(historyStatusText({ ...SUCCEEDED, status: "queued" })).toBe("Queued");
expect(historyStatusText({ ...SUCCEEDED, status: "cancelling" })).toBe("Cancelling…");
});

it("falls back to the file name when the preview is blank", () => {
expect(historyPreview(SUCCEEDED)).toBe("Hello world.");
expect(historyPreview(FILE_SOURCE)).toBe("notes.txt");
expect(historyPreview({ ...SUCCEEDED, inputPreview: " " })).toBe("(no preview)");
});

it("opens on wide viewports and starts collapsed when narrow", () => {
expect(historyStartsOpen(false)).toBe(true);
expect(historyStartsOpen(true)).toBe(false);
});

it("formats valid timestamps locally and keeps malformed ones verbatim", () => {
const expected = new Date(SUCCEEDED.createdAt).toLocaleString(undefined, {
dateStyle: "medium",
timeStyle: "short",
});
expect(formatHistoryTime(SUCCEEDED.createdAt)).toBe(expected);
expect(formatHistoryTime("not-a-date")).toBe("not-a-date");
});
});

describe("HistoryList", () => {
it("explains the empty state and counts entries", () => {
const empty = renderList([]);
expect(empty).toContain("0 saved generations");
expect(empty).toContain("Generate audio and it will appear in this list.");
expect(renderList([SUCCEEDED])).toContain("1 saved generation");
});

it("renders preview, voice, time, and status for each entry", () => {
const html = renderList([SUCCEEDED, FAILED]);
expect(html).toContain("Hello world.");
expect(html).toContain("en_US-lessac-medium");
expect(html).toContain("<time");
expect(html).toContain("Ready · 1 s");
expect(html).toContain("Failed: The speech engine produced no audio");
expect(html.match(/<li/g)).toHaveLength(2);
});

it("enables Open only for finished rows and Delete only for terminal ones", () => {
const html = renderList([SUCCEEDED, { ...RUNNING, inputPreview: "Still generating." }]);
expect(html).toMatch(
/<button[^>]*aria-label="Open generation: Hello world\."[^>]*>Open<\/button>/,
);
expect(html).not.toMatch(/<button[^>]*disabled[^>]*aria-label="Open generation: Hello world\./);
expect(html).toMatch(
/<button[^>]*disabled[^>]*aria-label="Open generation: Still generating\.[^>]*>Open<\/button>/,
);
expect(html).toMatch(
/<button[^>]*aria-label="Delete generation: Hello world\.[^>]*>Delete<\/button>/,
);
expect(html).toMatch(
/<button[^>]*disabled[^>]*aria-label="Delete generation: Still generating\.[^>]*>Delete<\/button>/,
);
});
});

describe("HistoryPanel", () => {
it("renders an open disclosure with the empty list", () => {
const html = renderToStaticMarkup(
<AppProvider>
<HistoryPanel />
</AppProvider>,
);
expect(html).toContain("<details");
expect(html).toMatch(/<details[^>]*open/);
expect(html).toContain('id="history-heading"');
expect(html).toContain("0 saved generations");
});
});
Loading