commit 8365e46b3a1fd25ab4281be4f28f7b84a67131f4
parent a06f5a4163d1877f892781e4903f0b85ebe4fe7b
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 11 Nov 2026 08:20:17 -0500
e2e: a public archive as a first-class source, against a stub archive -- connect, sweep, project, windows, links (demo epic D1 item 7)
editor/e2e/remote-archive.spec.ts: a fresh editor with NO channels and a stub
archive (the synthetic draft corpus served over loopback HTTP, an older
corpus.json with no per-channel platform, so the record fallback names it):
connect it on /sites (Read it, Connect); a question swept over it on the
local model (the fake ollama, the recorded pipeline run) -- the iteration
records its source, every link in sweep.md is on the stub's origin; umtool's
chain steps as its job runs them (current, windows, manifest) -- the cited
channel registered remote-only (config only, no url, platform from the
record), every cited window on disk (the fake yt-dlp), the project's QR
origin the stub; the channel list's "remote only"; a link opened on the stub
lands at its second.
umtool/e2e/remote-archive.spec.ts: the Source chip's "Connect an archive…"
(Read it shows the archive's title, channels and videos and writes nothing;
Connect saves it and the scope becomes the archive's two channels) and
Article from a question's Source field listing the archive's own channels.
The editor stub serves the archive under /archive-stub and answers the
`archives` action into the fixture's settings, which the app now reads
(SETTINGS_FILE: make-fixture copies the checkout's settings.json, so every
other spec reads what it read before); TRANSCRIPT_SITE_URL cleared and the
archive cache the fixture's own.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat:
6 files changed, 420 insertions(+), 0 deletions(-)
diff --git a/editor/e2e/remote-archive.spec.ts b/editor/e2e/remote-archive.spec.ts
@@ -0,0 +1,206 @@
+import { test, expect, type APIRequestContext } from "@playwright/test";
+import { spawnSync } from "node:child_process";
+import { createServer, type Server } from "node:http";
+import { mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promises";
+import os from "node:os";
+import { dirname, extname, join, normalize, resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+import { startFakeOllama, type FakeOllama } from "../../common/testing/llm/fakeOllama.mjs";
+import { writeDraftCorpus } from "../../common/testing/draft/corpus.mjs";
+import { baseUrl } from "./baseUrl";
+import { resetData, testPaths } from "./helpers";
+
+// A PUBLIC ARCHIVE IS A FIRST-CLASS SOURCE (demo epic D1, item 7): a fresh
+// editor with NO channels of its own, a STUB ARCHIVE (the synthetic draft
+// corpus served over loopback HTTP as a published site serves it — an older
+// corpus.json, no per-channel platform, so the resolver's record fallback is
+// what names the platform), and nothing fetched from the network:
+//
+// connect /sites → Connected archives: Read it (the probe), Connect
+// sweep a question over the archive on the local model (the fake ollama,
+// the recorded pipeline run): its links on the STUB's origin
+// project umtool's chain, step by step as its job runs them (current,
+// windows, manifest): the editor registers the cited channel
+// REMOTE-ONLY and fetches its windows (the fake yt-dlp); the
+// project's QR origin is the stub
+// link a citation's link opens on the stub at its second
+//
+// The stub's own page at `/` says which moment it was asked for.
+
+const AUTH = { authorization: "Bearer test-worker-token" };
+const REPO = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..");
+const RUNS = join(REPO, "common", "testing", "draft", "runs");
+const CHAIN_RUN = join(REPO, "umtool", "lib", "report", "chain-run.mjs");
+
+const TYPES: Record<string, string> = { ".json": "application/json", ".html": "text/html" };
+
+async function startStubArchive(dir: string): Promise<{ url: string; asked: string[]; close: () => Promise<void> }> {
+ const asked: string[] = [];
+ const server: Server = createServer(async (req, res) => {
+ const u = new URL(req.url ?? "/", "http://stub");
+ asked.push(u.pathname);
+ if (u.pathname === "/" || u.pathname === "/index.html") {
+ // The archive's viewer, as far as a link needs it: which moment.
+ const v = u.searchParams.get("v") ?? "";
+ const t = u.searchParams.get("t") ?? "";
+ res.writeHead(200, { "content-type": "text/html" });
+ res.end(`<!doctype html><title>stub archive</title><p id="moment" data-v="${v.replace(/"/g, "")}" data-t="${t.replace(/"/g, "")}">v=${v} t=${t}</p>`);
+ return;
+ }
+ const file = normalize(join(dir, decodeURIComponent(u.pathname)));
+ if (!file.startsWith(dir)) {
+ res.writeHead(403).end();
+ return;
+ }
+ try {
+ const body = await readFile(file);
+ res.writeHead(200, { "content-type": TYPES[extname(file)] ?? "application/octet-stream", "access-control-allow-origin": "*" });
+ res.end(body);
+ } catch {
+ res.writeHead(404).end("not found");
+ }
+ });
+ await new Promise<void>((r) => server.listen(0, "127.0.0.1", () => r()));
+ const port = (server.address() as { port: number }).port;
+ return { url: `http://127.0.0.1:${port}`, asked, close: () => new Promise((r) => server.close(() => r())) };
+}
+
+async function jobUntil(request: APIRequestContext, id: string, ms = 120_000) {
+ const t0 = Date.now();
+ let last = "";
+ while (Date.now() - t0 < ms) {
+ const res = await request.get(`${baseUrl}/api/ops/job/${id}?tail=60`, { headers: AUTH });
+ const body = (await res.json()) as { job?: { status?: string }; status?: string; tail?: string[] };
+ last = body.job?.status ?? body.status ?? "";
+ if (["done", "failed", "cancelled"].includes(last)) return body;
+ await new Promise((r) => setTimeout(r, 400));
+ }
+ throw new Error(`job ${id} is still ${last}`);
+}
+
+test.describe.configure({ mode: "serial" });
+
+let stub: Awaited<ReturnType<typeof startStubArchive>>;
+let ol: FakeOllama;
+let scratch: string;
+
+test.beforeAll(async () => {
+ scratch = await mkdtemp(join(os.tmpdir(), "e2e-remote-archive-"));
+ const dir = join(scratch, "archive");
+ await writeDraftCorpus(dir);
+ // A build of its own, so no other run's cached copy answers for it.
+ const corpus = JSON.parse(await readFile(join(dir, "corpus.json"), "utf8"));
+ await writeFile(join(dir, "corpus.json"), JSON.stringify({ ...corpus, spec: 5, generatedAt: new Date().toISOString() }));
+ stub = await startStubArchive(dir);
+ ol = await startFakeOllama();
+});
+
+test.afterAll(async () => {
+ await stub?.close();
+ await ol?.close();
+ await rm(scratch, { recursive: true, force: true });
+});
+
+test("a fresh editor with no channels: connect the stub archive, sweep it on the local model, fetch the cut's windows as a remote-only channel, open a link at its second", async ({ page, request }) => {
+ test.setTimeout(300_000);
+ await resetData(null);
+ const paths = testPaths();
+ expect(await readdir(join(paths.transcriptsDir, "channels"))).toEqual([]);
+ const settings = JSON.parse(await readFile(paths.settingsFile, "utf8"));
+ const projects = join(scratch, "projects");
+ await writeFile(paths.settingsFile, JSON.stringify({ ...settings, minFreeDiskGB: 0, generation: { ...(settings.generation ?? {}), ollamaUrl: ol.url, projectsRoot: projects } }, null, 2));
+ await fetch(`${baseUrl}/api/test/invalidate-cache`).catch(() => {});
+
+ // ─── connect, in the UI ───
+ await page.goto(`${baseUrl}/sites`);
+ const panel = page.locator("[data-connected-archives]");
+ await expect(panel.getByText("No archive connected.")).toBeVisible();
+ await panel.getByLabel("archive origin").fill(`${stub.url}/`);
+ await panel.getByRole("button", { name: "Read it" }).click();
+ const probe = panel.locator(`[data-archive-probe="${stub.url}"]`);
+ await expect(probe).toContainText("Synth Kitchen");
+ await expect(probe).toContainText(/2 channels · \d+ videos/);
+ await panel.getByRole("button", { name: "Connect" }).click();
+ await expect(panel.getByRole("list", { name: "connected archives" }).locator("li")).toHaveCount(1);
+ const listed = await (await request.get(`${baseUrl}/api/ops/archives`, { headers: AUTH })).json();
+ expect(listed.archives).toEqual([expect.objectContaining({ origin: stub.url })]);
+
+ // ─── a question, swept over the archive on the local model ───
+ const run = JSON.parse(await readFile(join(RUNS, "sweep-pipeline.json"), "utf8"));
+ for (const turn of run.turns) ol.push(turn);
+ const draft = await request.post(`${baseUrl}/api/ops/report-draft`, {
+ headers: AUTH,
+ data: { task: "sweep", article: "remote-e2e", model: run.model, question: run.question, channels: run.channels, source: `remote:${stub.url}` },
+ });
+ const started = (await draft.json()) as { ok?: boolean; error?: string; jobId?: string };
+ expect(draft.status(), started.error).toBe(200);
+ const job = await jobUntil(request, started.jobId!);
+ expect(job.job?.status ?? job.status, (job.tail ?? []).join("\n")).toBe("done");
+ const itDir = join(paths.transcriptsDir, "reports", "remote-e2e", "iterations", "1");
+ const iteration = JSON.parse(await readFile(join(itDir, "iteration.json"), "utf8"));
+ expect(iteration.scope.source).toBe(`remote:${stub.url}`);
+ const report = JSON.parse(await readFile(join(itDir, "report.json"), "utf8"));
+ const cited = Object.values(report.citations as Record<string, { kind: string; channel: string; id: string; start: number }>).filter((c) => c.kind === "video");
+ expect(cited.length).toBeGreaterThan(0);
+ const sweep = await readFile(join(itDir, "sweep.md"), "utf8");
+ const links = [...sweep.matchAll(/\((https?:\/\/[^)\s]+\?v=[^)\s]+)\)/g)].map((m) => m[1]);
+ expect(links.length).toBeGreaterThan(0);
+ for (const l of links) expect(l.startsWith(`${stub.url}/?v=`), l).toBe(true);
+ // Nothing was asked of the editor's own corpus (it has none), and the stub was read.
+ expect(stub.asked).toContain("/corpus.json");
+ expect(stub.asked.some((p) => p.startsWith("/transcripts/synth-kitchen/"))).toBe(true);
+
+ // ─── the project: the chain's steps as its job runs them ───
+ const env: Record<string, string> = {
+ ...(process.env as Record<string, string>),
+ TRANSCRIPTS_DIR: paths.transcriptsDir,
+ SETTINGS_FILE: paths.settingsFile,
+ EXPORT_PUBLIC_DIR: join(scratch, "public"),
+ EXPORT_INDEX_DIR: join(scratch, ".export-index"),
+ EXPORT_BUILDS_DIR: join(scratch, ".export-builds"),
+ ARCHIVE_CACHE_DIR: join(scratch, ".archive-cache"),
+ ARCHILYZER_EDITOR_URL: baseUrl,
+ WORKER_TOKEN: "test-worker-token",
+ };
+ delete env.ARTICLES_DIR;
+ const step = (name: string) => {
+ const r = spawnSync(process.execPath, ["--import", "tsx", CHAIN_RUN, "step", "remote-e2e", "1", name, "--projects-root", projects], {
+ cwd: REPO,
+ env: env as NodeJS.ProcessEnv,
+ encoding: "utf8",
+ timeout: 180_000,
+ });
+ return { code: r.status, out: `${r.stdout}\n${r.stderr}` };
+ };
+ for (const name of ["current", "windows", "manifest"]) {
+ const r = step(name);
+ expect(r.code, `${name}: ${r.out}`).toBe(0);
+ }
+ // The cited channel is registered REMOTE-ONLY: config only, its platform from the archive's record.
+ const config = JSON.parse(await readFile(join(paths.transcriptsDir, "channels", "synth-kitchen", "config.json"), "utf8"));
+ expect(config).toMatchObject({ remoteOnly: true, remoteArchive: stub.url, platform: "youtube", downloadMode: "manual" });
+ expect(config.url).toBeUndefined();
+ // Every cited window is on disk under it.
+ for (const c of cited) {
+ const clips = await readdir(join(paths.transcriptsDir, "channels", c.channel, "data", c.id, "clips")).catch(() => [] as string[]);
+ expect(clips.filter((f) => f.endsWith(".mp4")).length, `${c.channel}/${c.id}`).toBeGreaterThan(0);
+ }
+ const manifest = JSON.parse(await readFile(join(projects, "remote-e2e", "i1", "video.manifest.json"), "utf8"));
+ expect(manifest.provenance.siteOrigin).toBe(stub.url);
+
+ // The channel list says what it is.
+ await page.goto(`${baseUrl}/channels`);
+ await expect(page.getByRole("note", { name: "remote-only channel synth-kitchen" })).toBeVisible();
+
+ // ─── a citation's link opens on the stub at its second ───
+ const link = links[0];
+ const at = new URL(link);
+ const t = at.searchParams.get("t");
+ expect(t, link).not.toBeNull();
+ const [channel, id] = (at.searchParams.get("v") ?? "").split("/");
+ // The second is the cited moment's: a citation of that recording starts there.
+ expect(cited.some((c) => c.channel === channel && c.id === id && Math.floor(c.start) === Number(t)), `${link} against ${JSON.stringify(cited)}`).toBe(true);
+ await page.goto(link);
+ await expect(page.locator("#moment")).toHaveAttribute("data-t", t!);
+ await expect(page.locator("#moment")).toHaveAttribute("data-v", `${channel}/${id}`);
+});
diff --git a/umtool/e2e/fixtures/editor-stub-archives.mjs b/umtool/e2e/fixtures/editor-stub-archives.mjs
@@ -0,0 +1,109 @@
+// demo epic D1: a published archive served by the stub editor's own port,
+// under /archive-stub (the synthetic draft corpus — common/testing/draft — as
+// a site serves it), and the editor's `archives` action (POST
+// /api/ops/archives): `connect` reads the origin's corpus.json and, unless
+// `dryRun`, writes settings.remoteArchives into SETTINGS_FILE (the fixture's
+// copy, which umtool's source picker reads); `remove` drops one. Nothing
+// leaves loopback.
+
+import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
+import path from "node:path";
+import { writeDraftCorpus } from "yt-dlp-transcript-common/testing/draft/corpus.mjs";
+
+export const ARCHIVE_PREFIX = "/archive-stub";
+
+/** Write the stub archive's files under `dir` (once, at the stub's start). */
+export async function prepareArchiveStub(dir) {
+ mkdirSync(dir, { recursive: true });
+ await writeDraftCorpus(dir);
+ const corpus = JSON.parse(readFileSync(path.join(dir, "corpus.json"), "utf8"));
+ writeFileSync(
+ path.join(dir, "corpus.json"),
+ JSON.stringify({ ...corpus, spec: 6, generatedAt: new Date().toISOString(), site: { id: "stubalyzer", title: "Stubalyzer" } }),
+ );
+}
+
+/**
+ * GET /archive-stub/<file>: the archive's static files, written on the first
+ * ask (make-fixture.mjs empties the fixture root while the stub starts, so
+ * nothing is written before a spec asks). True when answered.
+ */
+export function archiveStubRoute(req, res, url, { dir }) {
+ if (req.method !== "GET" || !url.pathname.startsWith(`${ARCHIVE_PREFIX}/`)) return false;
+ const rel = decodeURIComponent(url.pathname.slice(ARCHIVE_PREFIX.length));
+ const file = path.normalize(path.join(dir, rel));
+ if (!file.startsWith(dir)) {
+ res.writeHead(403).end();
+ return true;
+ }
+ const ready = existsSync(path.join(dir, "corpus.json")) ? Promise.resolve() : prepareArchiveStub(dir);
+ ready.then(
+ () => {
+ try {
+ const body = readFileSync(file);
+ res.writeHead(200, { "content-type": "application/json" });
+ res.end(body);
+ } catch {
+ res.writeHead(404).end("not found");
+ }
+ },
+ (e) => res.writeHead(500).end(String(e?.message ?? e)),
+ );
+ return true;
+}
+
+const settingsOf = (file) => {
+ try {
+ return JSON.parse(readFileSync(file, "utf8"));
+ } catch {
+ return {};
+ }
+};
+
+/** POST /api/ops/archives. True when answered. */
+export function archivesRoute(req, res, url, { json, readBody, settingsFile }) {
+ if (url.pathname !== "/api/ops/archives") return false;
+ if (req.method === "GET") {
+ json(res, 200, { ok: true, archives: settingsOf(settingsFile).remoteArchives ?? [] });
+ return true;
+ }
+ if (req.method !== "POST") return false;
+ readBody(req, async (body) => {
+ const settings = settingsOf(settingsFile);
+ const list = Array.isArray(settings.remoteArchives) ? settings.remoteArchives : [];
+ if (typeof body?.remove === "string") {
+ const next = list.filter((a) => a.id !== body.remove && a.origin !== body.remove);
+ writeFileSync(settingsFile, JSON.stringify({ ...settings, remoteArchives: next }, null, 2));
+ return json(res, 200, { ok: true, removed: list.find((a) => !next.includes(a)) ?? null });
+ }
+ const origin = String(body?.connect ?? "").trim().replace(/\/+$/, "");
+ if (!/^https?:\/\//.test(origin)) return json(res, 400, { ok: false, error: `"${origin}" is not an archive's address` });
+ let corpus;
+ try {
+ const r = await fetch(`${origin}/corpus.json`);
+ if (!r.ok) return json(res, 502, { ok: false, error: `${origin}/corpus.json answered HTTP ${r.status}` });
+ corpus = await r.json();
+ } catch (e) {
+ return json(res, 502, { ok: false, error: `${origin}/corpus.json did not answer: ${e.message}` });
+ }
+ const channels = (corpus.channels ?? []).map((c) => ({ slug: c.slug, name: c.name ?? c.slug, videoCount: c.videoCount ?? null }));
+ const probe = {
+ origin,
+ siteId: corpus.site?.id ?? null,
+ title: corpus.site?.title ?? origin,
+ description: "",
+ spec: corpus.spec ?? null,
+ generatedAt: corpus.generatedAt ?? null,
+ totals: { channels: channels.length, videos: channels.reduce((n, c) => n + (c.videoCount ?? 0), 0) },
+ channels,
+ };
+ const have = list.find((a) => a.origin === origin);
+ const archive = have ?? { id: probe.siteId ?? "archive", origin, title: probe.title, addedAt: new Date().toISOString() };
+ if (!have && body?.dryRun !== true) {
+ mkdirSync(path.dirname(settingsFile), { recursive: true });
+ writeFileSync(settingsFile, JSON.stringify({ ...settings, remoteArchives: [...list, archive] }, null, 2));
+ }
+ return json(res, 200, { ok: true, probe, archive, already: have ? true : body?.dryRun === true ? null : false });
+ });
+ return true;
+}
diff --git a/umtool/e2e/fixtures/editor-stub.mjs b/umtool/e2e/fixtures/editor-stub.mjs
@@ -27,6 +27,7 @@ import { fileURLToPath } from "node:url";
import { fetchWindowsRoute } from "./editor-stub-fetch-windows.mjs";
import { importPageRoute } from "./editor-stub-import-page.mjs";
import { caseStagesRoute } from "./editor-stub-case-stages.mjs";
+import { archiveStubRoute, archivesRoute } from "./editor-stub-archives.mjs";
import { readReactions } from "yt-dlp-transcript-common/lib/clips/reactions.mjs";
import { readSuggestions, suggestionsDocOf, writeSuggestions } from "yt-dlp-transcript-common/lib/clips/suggest.mjs";
import { checkAssistOps } from "yt-dlp-transcript-common/lib/report/videoAssistOps.mjs";
@@ -36,6 +37,11 @@ import { checkGroupProposals, cutSections, groupProposalsDocOf, writeGroupPropos
const PORT = portFor("EDITOR_STUB_PORT");
const CHANNELS = process.env.CHANNELS_DIR ?? "";
const TOKEN = process.env.WORKER_TOKEN ?? "";
+// demo epic D1: the published archive this stub serves (/archive-stub) and the
+// settings file its `archives` action writes — the fixture's, which umtool's
+// source picker reads (playwright.config.ts SETTINGS_FILE).
+const ARCHIVE_STUB_DIR = path.join(path.dirname(CHANNELS || process.cwd()), "archive-stub");
+const SETTINGS = process.env.SETTINGS_FILE ?? path.join(path.dirname(CHANNELS || process.cwd()), "settings.json");
// Where the spec reads what was asked for.
const LOG = process.env.E2E_EDITOR_STUB_LOG ?? path.join(process.cwd(), "editor-stub.requests.json");
@@ -1223,6 +1229,8 @@ const server = http.createServer((req, res) => {
const url = new URL(req.url ?? "/", `http://127.0.0.1:${PORT}`);
if (url.pathname === "/health") return json(res, 200, { ok: true });
+ // A published archive's files (demo epic D1): public, like a site's.
+ if (archiveStubRoute(req, res, url, { dir: ARCHIVE_STUB_DIR })) return;
// A job's log is ungated on the editor (GET /api/jobs/<id>/log).
if (url.pathname.startsWith("/api/jobs/") && fetchWindowsRoute(req, res, url, fwCtx)) return;
@@ -1265,6 +1273,8 @@ const server = http.createServer((req, res) => {
// Release 37 S4: Import this capture (editor-stub-import-page.mjs).
if (importPageRoute(req, res, url, { channels: CHANNELS, json, readBody, push: (r) => (requests.push(r), record()) })) return;
if ((url.pathname === "/api/ops/fetch-windows" || url.pathname.startsWith("/api/ops/job/")) && fetchWindowsRoute(req, res, url, fwCtx)) return;
+ // demo epic D1: Connect an archive (the Source chip).
+ if (archivesRoute(req, res, url, { json, readBody, settingsFile: SETTINGS })) return;
if (url.pathname.startsWith("/api/ops/") && generationRoute(req, res, url, auth) !== null) return;
// THE OPS DOOR, stubbed alongside the media one.
diff --git a/umtool/e2e/fixtures/make-fixture.mjs b/umtool/e2e/fixtures/make-fixture.mjs
@@ -21,6 +21,7 @@ import {
import { spawnSync } from "node:child_process";
import { createHash } from "node:crypto";
import path from "node:path";
+import { fileURLToPath } from "node:url";
import { SONG_DATA } from "../../song/paths.mjs";
import { songCapabilities } from "./song-capabilities.mjs";
import { makeSitesFixture } from "./sites-fixture.mjs";
@@ -2608,6 +2609,14 @@ makeDeleteFixture({ dest, articles: ARTICLES, reports });
// R1: Research's local corpus (research-public/, TRANSCRIPT_LOCAL_DIR) and the
// held channels its inventory reads on disk.
const { pub: RESEARCH_PUBLIC } = makeResearchFixture({ dest, channels: CHANNELS });
+// demo epic D1: the settings file the app and the editor stub read
+// (playwright.config.ts SETTINGS_FILE) -- a copy of the checkout's, so every
+// spec reads what it read before, and Connect an archive (remote-archive.spec)
+// writes the fixture's, never the checkout's. A clone with none: {}.
+{
+ const checkout = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "settings.json");
+ writeFileSync(path.join(dest, "settings.json"), existsSync(checkout) ? readFileSync(checkout, "utf8") : "{}\n");
+}
// Two channel context notes to review (digest-context.spec.ts), on channels already made above.
makeDigestContextFixture({ dest, channels: CHANNELS });
// R2: a research board with a drifted quote and an `en`-track one (REPORTS_ROOT is dest).
diff --git a/umtool/e2e/remote-archive.spec.ts b/umtool/e2e/remote-archive.spec.ts
@@ -0,0 +1,79 @@
+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();
+});
diff --git a/umtool/playwright.config.ts b/umtool/playwright.config.ts
@@ -164,6 +164,8 @@ export default defineConfig({
// article store, and a video revision's project under gen-projects.
ARTICLES_DIR: `${FIXTURE}/articles`,
E2E_GEN_PROJECTS: `${FIXTURE}/gen-projects`,
+ // demo epic D1: the archives action writes the fixture's settings.
+ SETTINGS_FILE: `${FIXTURE}/settings.json`,
},
},
{
@@ -192,6 +194,11 @@ export default defineConfig({
// Research's local corpus (R1): the fixture's composed public dir, read as
// the MCP's --local reads one -- never the checkout's export/public.
`TRANSCRIPT_LOCAL_DIR=${FIXTURE}/research-public TRANSCRIPT_HUB_URL= ` +
+ // The settings the app reads (demo epic D1): the fixture's copy of the
+ // checkout's (make-fixture.mjs), so Connect an archive writes there; no
+ // archive from the shell's TRANSCRIPT_SITE_URL; the archive cache the
+ // fixture's own (common/lib/archiveCache-server.ts).
+ `SETTINGS_FILE=${FIXTURE}/settings.json TRANSCRIPT_SITE_URL= ARCHIVE_CACHE_DIR=${FIXTURE}/archive-cache ` +
// The generation usage ledger (release 27): the fixture's, never the
// checkout's .generation/usage.jsonl.
`GENERATION_USAGE_FILE=${FIXTURE}/generation-usage.jsonl ` +