import { writeFile } from "node:fs/promises"; import { test, expect } from "@playwright/test"; import { readJson, resetData, resolvePath, generateReport } from "./helpers"; import { baseUrl } from "./baseUrl"; import type { ChannelConfig } from "yt-dlp-transcript-common/lib/channelConfig"; // The dedicated /cleanup page aggregates each channel's reclaimable audio (from // the snapshot's cleanupBytes) into a headline total, and a per-channel toggle // flips ChannelConfig.excludeFromCleanup to hold a channel's bytes out of that // total without disabling its sweeps. See editor/app/cleanup/*. const SLUG = "test-transcribe"; const CONFIG_REL = `test-transcripts/channels/${SLUG}/config.json`; function dataRel(videoId: string, file: string): string { return `test-transcripts/channels/${SLUG}/data/${videoId}/${file}`; } async function seedTranscript(videoId: string): Promise { await writeFile( resolvePath(dataRel(videoId, "transcript.json")), '{"transcription":[]}\n', ); } test("cleanup page totals reclaimable audio and the per-channel toggle excludes it", async ({ page, }) => { await resetData("one-transcribe-channel-with-audio"); await seedTranscript("vidA"); await seedTranscript("vidB"); await fetch(`${baseUrl}/api/test/invalidate-cache`).catch(() => {}); // Visiting the channel page regenerates the snapshot (with cleanupBytes). await generateReport(page, SLUG); await page.goto(`/channels/${SLUG}`); // The cleanup page hero counts the included channel. await page.goto("/cleanup"); await expect(page.getByText("Reclaimable across 1 channel")).toBeVisible(); const toggle = page.getByRole("button", { name: `toggle cleanup-total inclusion for ${SLUG}`, }); await expect(toggle).toHaveText(/Counted/); await expect(toggle).toHaveAttribute("aria-pressed", "true"); // Excluding the channel writes the flag and drops it from the total. await toggle.click(); await expect( page.getByRole("button", { name: `toggle cleanup-total inclusion for ${SLUG}`, }), ).toHaveText(/Excluded/); await expect( page.getByLabel(`${SLUG} excluded from total`), ).toBeVisible(); { const cfg = await readJson(CONFIG_REL); expect(cfg.excludeFromCleanup).toBe(true); } await page.reload(); await expect(page.getByText("Reclaimable across 0 channels")).toBeVisible(); // Re-including restores it. await page .getByRole("button", { name: `toggle cleanup-total inclusion for ${SLUG}`, }) .click(); await expect( page.getByRole("button", { name: `toggle cleanup-total inclusion for ${SLUG}`, }), ).toHaveText(/Counted/); { const cfg = await readJson(CONFIG_REL); expect(cfg.excludeFromCleanup).toBeUndefined(); } await page.reload(); await expect(page.getByText("Reclaimable across 1 channel")).toBeVisible(); });