import { test, expect } from "@playwright/test"; import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { portFor } from "yt-dlp-transcript-common/lib/ports.mjs"; import { WARM_TIMEOUT, warm } from "./warm"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // A PUBLIC ARCHIVE IS A FIRST-CLASS SOURCE (demo epic D1), umtool's half: the // Source chip's "Connect an archive…" (Read it → Connect, through the editor's // `archives` action — the stub's, which writes the fixture's settings) and // "Article from a question"'s Source field, which lists the archive's own // channels. The archive is the editor stub's /archive-stub (the synthetic // draft corpus, served as a published site serves it); nothing leaves // loopback. The engine — the sweep over it, the remote-only channel, the // links — is the editor suite's remote-archive.spec.ts. // // WRITES the fixture's settings.json remoteArchives (removed after) // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const STUB = `http://127.0.0.1:${portFor("EDITOR_STUB_PORT")}`; const ORIGIN = `${STUB}/archive-stub`; const HANDLE = `remote:${ORIGIN}`; test.beforeAll(async ({ playwright }) => { test.setTimeout(WARM_TIMEOUT); await warm(playwright, ["/research", urls.newArticleHref(), "/api/articles/sources"]); }); test.afterAll(async () => { await fetch(`${STUB}/api/ops/archives`, { method: "POST", headers: { authorization: "Bearer umtool-e2e-token", "content-type": "application/json" }, body: JSON.stringify({ remove: ORIGIN }), }).catch(() => {}); }); test("the Source chip connects an archive by its address: read it, connect, and the scope is that archive's", async ({ page }) => { await page.goto("/research"); const source = page.getByRole("combobox", { name: "Source" }); await expect(source.locator("option", { hasText: "Connect an archive…" })).toHaveCount(1); await source.selectOption({ label: "Connect an archive…" }); const form = page.getByRole("form", { name: "connect an archive" }); await form.getByRole("textbox", { name: "archive origin" }).fill(`${ORIGIN}/`); await form.getByRole("button", { name: "Read it" }).click(); const probe = form.locator(`[data-archive-probe="${ORIGIN}"]`); await expect(probe).toContainText("Stubalyzer"); await expect(probe).toContainText("2 channels"); await expect(probe).toContainText("Synth Kitchen"); // Read, not saved. expect(JSON.parse(readFileSync(path.join(FIXTURE, "settings.json"), "utf8")).remoteArchives ?? []).toEqual([]); await form.getByRole("button", { name: "Connect" }).click(); await expect(form).toHaveCount(0); await expect(source).toHaveValue(HANDLE); await expect(source.locator("option:checked")).toContainText("Stubalyzer · connected"); // The scope is the archive's: its two channels. await expect(page.locator("[data-scope]")).toContainText("All 2 channels"); const saved = JSON.parse(readFileSync(path.join(FIXTURE, "settings.json"), "utf8")).remoteArchives; expect(saved).toEqual([expect.objectContaining({ id: "stubalyzer", origin: ORIGIN, title: "Stubalyzer" })]); }); test("Article from a question offers the connected archive as its source, and lists that archive's channels", async ({ page }) => { await page.goto(urls.newArticleHref()); const form = page.getByRole("form", { name: "new article" }); const source = form.getByRole("combobox", { name: "source" }); await expect(source.locator(`option[value="${HANDLE}"]`)).toHaveCount(1); // The fixture's editor holds channels of its own: the local corpus stays the default. await expect(source).toHaveValue(""); await source.selectOption(HANDLE); await form.getByRole("textbox", { name: "find a channel" }).fill("synth"); await expect(form.getByRole("button", { name: /^Synth Kitchen/ })).toBeVisible(); await expect(form.getByRole("button", { name: /^Synth Other Kitchen/ })).toBeVisible(); await form.getByRole("button", { name: /^Synth Kitchen/ }).click(); await expect(form.locator("[data-picked='synth-kitchen']")).toBeVisible(); });