forge
Explore
Log in

Don't you dare go Hollow

🐛 label podcast job stages instead of raw keys

Browse files at this commit

e0d51114ea293b9917749b12cd955d6e853931ebAhmet Kaan GümüşParent: 45f3d41
  • fix
    • 🐛 label podcast job stages instead of raw keys
Show full message
fix: 🐛 label podcast job stages instead of raw keys

- the stage trail mapped queued/script/tts/mux/done and the service's
  other stage tuples (ocr, plan, kaynak, metin, ingest, scriptler,
  quiz, ses) through the exam/module label pattern
- an unknown stage still shows the raw key; failed and cancelled stay
  job states, already labeled, not stages
src/components/notes/podcast-panel.test.tsxmodified+2 -1
@@ -49,7 +49,8 @@ describe("PodcastPanel", () => {
4949 expect(podcastApi.postPodcastJob).toHaveBeenCalledWith({ source_id: "note-7", format: "tek_ogretici" });
5050 });
5151 expect(sessionStorage.getItem("hezarfen.podcast.note-7")).toBe("j1");
52- expect(screen.getByText("Waiting in queue")).toBeTruthy();
52+ expect(screen.getAllByText("Waiting in queue")).toHaveLength(2);
53+ expect(screen.queryByText("queued")).toBeNull();
5354 });
5455
5556 it("points the audio element at the job's audio door, not the artifact path", async () => {
src/components/notes/podcast-panel.tsxmodified+1 -2
@@ -233,8 +233,7 @@ export function PodcastPanel(props: { noteId: string; active?: boolean; noteTitl
233233 </Show>
234234 </span>
235235 </div>
236- {/* The stage names itself in the service's own vocabulary and is not
237- an enumerated set, so the values are shown as they came. */}
236+ {/* Known stage keys are labeled; a stage newer than the map shows as sent. */}
238237 <Show when={stages().length > 0}>
239238 <PodcastStageTrail entries={stages()} live={working()} label={t("podcast.stageLabel")} />
240239 </Show>
src/components/notes/podcast-stage-trail.test.tsxmodified+27 -20
@@ -1,37 +1,48 @@
11 import { cleanup, render, screen } from "@solidjs/testing-library";
2-import { afterEach, describe, expect, it, vi } from "vitest";
2+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
33 import { PodcastStageTrail } from "@/components/notes/podcast-stage-trail";
4+import { PreferencesProvider } from "@/stores/preferences-context";
45
56 const T = Date.UTC(2026, 0, 2, 10, 0, 0);
67
8+function trail(props: { entries: { stage: string; at: number }[]; live: boolean }) {
9+ return (
10+ <PreferencesProvider>
11+ <PodcastStageTrail entries={props.entries} live={props.live} label="Aşamalar" />
12+ </PreferencesProvider>
13+ );
14+}
15+
716 describe("PodcastStageTrail", () => {
17+ beforeEach(() => {
18+ localStorage.setItem("hezarfen.locale", "en");
19+ });
20+
821 afterEach(() => {
922 cleanup();
23+ localStorage.removeItem("hezarfen.locale");
1024 vi.useRealTimers();
1125 vi.restoreAllMocks();
1226 });
1327
1428 it("times each stage by the one that replaced it", () => {
15- render(() => (
16- <PodcastStageTrail
17- entries={[
29+ render(() =>
30+ trail({
31+ entries: [
1832 { stage: "queued", at: T },
1933 { stage: "synthesizing", at: T + 12_000 },
20- ]}
21- live={false}
22- label="Aşamalar"
23- />
24- ));
34+ ],
35+ live: false,
36+ }),
37+ );
2538
26- expect(screen.getByText("queued")).toBeTruthy();
39+ expect(screen.getByText("Waiting in queue")).toBeTruthy();
2740 expect(screen.getByText("synthesizing")).toBeTruthy();
2841 expect(screen.getByText("00:12")).toBeTruthy();
2942 });
3043
3144 it("leaves the last stage of a settled job without a span to guess at", () => {
32- render(() => (
33- <PodcastStageTrail entries={[{ stage: "queued", at: T }]} live={false} label="Aşamalar" />
34- ));
45+ render(() => trail({ entries: [{ stage: "queued", at: T }], live: false }));
3546
3647 expect(screen.getByText("—")).toBeTruthy();
3748 });
@@ -40,17 +51,13 @@ describe("PodcastStageTrail", () => {
4051 vi.useFakeTimers();
4152 vi.setSystemTime(T + 7_000);
4253
43- render(() => (
44- <PodcastStageTrail entries={[{ stage: "queued", at: T }]} live label="Aşamalar" />
45- ));
54+ render(() => trail({ entries: [{ stage: "queued", at: T }], live: true }));
4655
4756 expect(screen.getByText("00:07")).toBeTruthy();
4857 });
4958
50- it("shows the service's own stage names verbatim", () => {
51- render(() => (
52- <PodcastStageTrail entries={[{ stage: "some_unknown_stage", at: T }]} live label="Aşamalar" />
53- ));
59+ it("shows an unknown stage as the service sent it", () => {
60+ render(() => trail({ entries: [{ stage: "some_unknown_stage", at: T }], live: true }));
5461
5562 expect(screen.getByText("some_unknown_stage")).toBeTruthy();
5663 });
src/components/notes/podcast-stage-trail.tsxmodified+4 -1
@@ -1,6 +1,8 @@
11 import { For, createSignal, onCleanup } from "solid-js";
22 import { cn } from "@/lib/cn";
33 import { formatDurationClock } from "@/lib/format";
4+import { podcastStageLabel } from "@/lib/podcast-stage-labels";
5+import { useT } from "@/stores/preferences-context";
46
57 export type PodcastStageEntry = {
68 /** The service's own stage name, stored as it came. */
@@ -21,6 +23,7 @@ const TICK_MS = 1_000;
2123 * inventing the steps before that would be making up a history we never saw.
2224 */
2325 export function PodcastStageTrail(props: { entries: PodcastStageEntry[]; live: boolean; label: string }) {
26+ const t = useT();
2427 const [now, setNow] = createSignal(Date.now());
2528 const timer = window.setInterval(() => setNow(Date.now()), TICK_MS);
2629 onCleanup(() => window.clearInterval(timer));
@@ -51,7 +54,7 @@ export function PodcastStageTrail(props: { entries: PodcastStageEntry[]; live: b
5154 )}
5255 />
5356 <span class={cn("min-w-0 flex-1 truncate", running() ? "font-medium text-foreground" : "text-muted-foreground")}>
54- {entry.stage}
57+ {podcastStageLabel(entry.stage, t)}
5558 </span>
5659 <span class="shrink-0 tabular-nums text-muted-foreground">
5760 {spanOf(index()) == null ? "—" : formatDurationClock(spanOf(index())!)}
src/i18n/locales/en.tsmodified+13 -0
@@ -1043,6 +1043,19 @@ export const en: Dict = {
10431043 "podcast.noNotesHint": "Add a note to one of your courses before creating audio.",
10441044 "podcast.format": "Narration style",
10451045 "podcast.stageLabel": "Stages",
1046+ "podcast.stage.queued": "Waiting in queue",
1047+ "podcast.stage.ocr": "Reading the document",
1048+ "podcast.stage.plan": "Planning the episode",
1049+ "podcast.stage.kaynak": "Reading the source",
1050+ "podcast.stage.metin": "Extracting the text",
1051+ "podcast.stage.ingest": "Taking in the source",
1052+ "podcast.stage.script": "Writing the script",
1053+ "podcast.stage.scriptler": "Writing the script",
1054+ "podcast.stage.quiz": "Adding questions",
1055+ "podcast.stage.tts": "Narrating",
1056+ "podcast.stage.ses": "Narrating",
1057+ "podcast.stage.mux": "Mixing",
1058+ "podcast.stage.done": "Ready",
10461059 "podcast.etaHint": "Estimated time: about {secs}s",
10471060 "podcast.format.duz_okuma": "Straight reading",
10481061 "podcast.format.tek_ogretici": "Single instructor",
src/i18n/locales/tr.tsmodified+13 -0
@@ -1039,6 +1039,19 @@ export const tr: Dict = {
10391039 "podcast.noNotesHint": "Ses oluşturmadan önce derslerinizden birine not ekleyin.",
10401040 "podcast.format": "Anlatım biçimi",
10411041 "podcast.stageLabel": "Aşamalar",
1042+ "podcast.stage.queued": "Sırada bekliyor",
1043+ "podcast.stage.ocr": "Belge okunuyor",
1044+ "podcast.stage.plan": "Bölüm planlanıyor",
1045+ "podcast.stage.kaynak": "Kaynak okunuyor",
1046+ "podcast.stage.metin": "Metin çıkarılıyor",
1047+ "podcast.stage.ingest": "Kaynak alınıyor",
1048+ "podcast.stage.script": "Metin yazılıyor",
1049+ "podcast.stage.scriptler": "Metin yazılıyor",
1050+ "podcast.stage.quiz": "Sorular ekleniyor",
1051+ "podcast.stage.tts": "Seslendiriliyor",
1052+ "podcast.stage.ses": "Seslendiriliyor",
1053+ "podcast.stage.mux": "Birleştiriliyor",
1054+ "podcast.stage.done": "Hazır",
10421055 "podcast.etaHint": "Tahmini süre: yaklaşık {secs} sn",
10431056 "podcast.format.duz_okuma": "Düz okuma",
10441057 "podcast.format.tek_ogretici": "Tek öğretici",
src/i18n/messages.tsmodified+13 -0
@@ -1030,6 +1030,19 @@ export type MessageKey =
10301030 | "podcast.noNotesHint"
10311031 | "podcast.format"
10321032 | "podcast.stageLabel"
1033+ | "podcast.stage.queued"
1034+ | "podcast.stage.ocr"
1035+ | "podcast.stage.plan"
1036+ | "podcast.stage.kaynak"
1037+ | "podcast.stage.metin"
1038+ | "podcast.stage.ingest"
1039+ | "podcast.stage.script"
1040+ | "podcast.stage.scriptler"
1041+ | "podcast.stage.quiz"
1042+ | "podcast.stage.tts"
1043+ | "podcast.stage.ses"
1044+ | "podcast.stage.mux"
1045+ | "podcast.stage.done"
10331046 | "podcast.etaHint"
10341047 | "podcast.format.duz_okuma"
10351048 | "podcast.format.tek_ogretici"
src/lib/podcast-stage-labels.test.tsadded+24 -0
@@ -0,0 +1,24 @@
1+import { expect, test } from "vitest";
2+import { en } from "@/i18n/locales/en";
3+import { tr } from "@/i18n/locales/tr";
4+import type { MessageKey } from "@/i18n/messages";
5+import { PODCAST_STAGE_KEYS, podcastStageLabel } from "./podcast-stage-labels";
6+
7+const locales = { en, tr } as const;
8+
9+test("every known stage has a non-empty label in both locales", () => {
10+ for (const stage of Object.keys(PODCAST_STAGE_KEYS)) {
11+ for (const [name, dict] of Object.entries(locales)) {
12+ const label = podcastStageLabel(stage, (key) => dict[key]);
13+ expect(label, `${name}:${stage}`).not.toBe("");
14+ expect(label, `${name}:${stage}`).not.toBe(stage);
15+ }
16+ }
17+});
18+
19+test("an unknown stage falls back to the raw key", () => {
20+ const t = (key: MessageKey) => key;
21+ expect(podcastStageLabel("synthesizing", t)).toBe("synthesizing");
22+ expect(podcastStageLabel("toString", t)).toBe("toString");
23+ expect(podcastStageLabel("", t)).toBe("");
24+});
src/lib/podcast-stage-labels.tsadded+36 -0
@@ -0,0 +1,36 @@
1+import type { MessageKey } from "@/i18n/messages";
2+
3+type Translate = (key: MessageKey, params?: Record<string, string>) => string;
4+
5+/**
6+ * Pipeline stage keys the job trail can show.
7+ *
8+ * The backend forwards `stage` as a free string (`PodcastJobStatus.stage`).
9+ * The frontend records `queued` itself before the first poll; the service
10+ * then reports one of its mode tuples and `done` when the job finishes:
11+ * simulate `ocr → plan → script → tts → mux`, API `kaynak → metin → script →
12+ * tts → mux`, local `ingest → scriptler → quiz → ses`. `failed` / `cancelled`
13+ * are job states, not stages — a cancel clears the stage, a failure keeps
14+ * the last one.
15+ */
16+export const PODCAST_STAGE_KEYS = {
17+ queued: "podcast.stage.queued",
18+ ocr: "podcast.stage.ocr",
19+ plan: "podcast.stage.plan",
20+ kaynak: "podcast.stage.kaynak",
21+ metin: "podcast.stage.metin",
22+ ingest: "podcast.stage.ingest",
23+ script: "podcast.stage.script",
24+ scriptler: "podcast.stage.scriptler",
25+ quiz: "podcast.stage.quiz",
26+ tts: "podcast.stage.tts",
27+ ses: "podcast.stage.ses",
28+ mux: "podcast.stage.mux",
29+ done: "podcast.stage.done",
30+} as const satisfies Record<string, MessageKey>;
31+
32+/** Display label for a podcast stage key; an unknown key shows as sent. */
33+export function podcastStageLabel(stage: string, t: Translate): string {
34+ if (!Object.hasOwn(PODCAST_STAGE_KEYS, stage)) return stage;
35+ return t(PODCAST_STAGE_KEYS[stage as keyof typeof PODCAST_STAGE_KEYS]);
36+}