import { test, expect, type Page } from "@playwright/test"; import { readFileSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { WARM_TIMEOUT, warm } from "./warm"; import * as urls from "./urls"; import { runHref } from "../lib/research/runs-hrefs"; // --------------------------------------------------------------------------- // An article's Iterations tab (release 27 S8), over the editor stub: its // report-draft "runs" an iteration by writing it into the fixture's article // store (running after 1 s, done after 3 s), never an LLM. // // zeta an article in the making with four iterations (the fixture): // read, and narrated (a step on i1) // iter-e2e made here through the stub, then used, revised, copied, // cancelled and taken into the video chain; removed after // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const STUB_LOG = path.join(FIXTURE, "editor-stub.requests.json"); const ARTICLE = "iter-e2e"; const ZETA = { site: "articles", id: "zeta" }; const stubAsked = (route: string) => (JSON.parse(readFileSync(STUB_LOG, "utf8")) as { route?: string; [k: string]: unknown }[]).filter((r) => r.route === route); test.beforeAll(async ({ playwright }) => { test.setTimeout(WARM_TIMEOUT); await warm(playwright, ["/work?kind=article", urls.articleHref(ZETA), urls.articleHref(ZETA, { tab: "iterations" }), "/api/articles/iterations?article=zeta", "/api/articles/policy"]); }); test.afterAll(() => rmSync(path.join(FIXTURE, "articles", ARTICLE), { recursive: true, force: true })); const card = (page: Page, n: number) => page.locator(`[data-iteration='${n}']`); test("an article in the making: listed as such on Work, opened as its piece, its iterations a tab", async ({ page }) => { // /articles is Work's articles since P3. zeta is in the making, and its // iterations already made a video: at Video, by the one stage rule (P4a-2). await page.goto("/articles"); const row = page.locator("[data-lit-line][data-piece='a:articles/zeta']"); await expect(row).toHaveAttribute("data-status", "in the making"); await expect(row).toHaveAttribute("data-stage", "video"); await row.getByRole("link", { name: "zeta" }).click(); // The article piece (P4a-2) opens on its Overview, the iterations summarised there. await expect(page).toHaveURL(new RegExp(`${urls.articleHref(ZETA)}$`)); await expect(page.locator("[data-article-meta] [data-status]")).toHaveAttribute("data-status", "pending"); // In the making is a state, not a judgement: the neutral state tag, never a verdict colour (P6). await expect(page.locator("[data-article-meta] [data-status]")).toHaveClass(/border-dashed/); await expect(page.locator("[data-article-meta] [data-status]")).not.toHaveClass(/doubt/); await expect(page.locator("[data-piece-iterations='4']")).toBeVisible(); await page.getByTestId("piece-tab-iterations").click(); await expect(page).toHaveURL(new RegExp(`${urls.articleHref(ZETA, { tab: "iterations" }).replace("?", "\\?")}$`)); await expect(page.getByTestId("piece-tab-iterations")).toHaveAttribute("aria-current", "page"); const list = page.getByRole("region", { name: "iterations", exact: true }); await expect(list).toHaveAttribute("data-iterations", "4"); // Newest first. await expect(page.locator("[data-iteration]").first()).toHaveAttribute("data-iteration", "4"); await expect(card(page, 1).locator("[data-usage-model='claude-sonnet-5-5']")).toContainText("$0.42"); await expect(card(page, 2).locator("[data-ops-applied]")).toHaveAttribute("data-ops-applied", "2"); await expect(card(page, 2).locator("[data-checks-failed]")).toHaveAttribute("data-checks-failed", "1"); await expect(card(page, 3)).toContainText("of i1"); await expect(card(page, 4)).toHaveAttribute("data-status", "failed"); await expect(card(page, 4).locator("[data-copy-of]")).toHaveAttribute("data-copy-of", "1"); await expect(card(page, 4)).toContainText("the model stopped at its cap"); // A sweep's row links its run page (R3), the row's quiet secondary action; a revision has none. await expect(card(page, 1).locator("[data-run-link]")).toHaveAttribute("href", runHref("zeta", 1)); await expect(card(page, 4).locator("[data-run-link]")).toHaveAttribute("href", runHref("zeta", 4)); await expect(card(page, 2).locator("[data-run-link]")).toHaveCount(0); await expect(card(page, 3).locator("[data-run-link]")).toHaveCount(0); // Today's spend, from the fixture's usage ledger, against the daily cap. await expect(list.locator("[data-today-usd]")).toHaveAttribute("data-today-usd", "0.42"); await expect(list.locator("[data-today-usd]")).toContainText("of $20.00"); }); test("narrate an iteration's cut on a model: a step, its job followed to done", async ({ page }) => { // The Iterations tab links a cut's media drafts (P4b); narration is drafted // on the Media tab, its job followed on the ONE JobProgress. await page.goto(urls.articleHref(ZETA, { tab: "iterations" })); const one = card(page, 1); await expect(one.locator("[data-media-link]")).toHaveAttribute("href", urls.projectHref("gen-projects/zeta/i1", { tab: "media" })); await one.locator("[data-media-link]").click(); await expect(page).toHaveURL(new RegExp(`${urls.articleHref(ZETA, { tab: "media", project: "gen-projects/zeta/i1" }).replace(/[?]/g, "\\?")}$`)); const narrate = page.locator("[data-media-section='narrate'] [data-draft-task='narrate']"); await narrate.getByRole("combobox", { name: "model for narration" }).selectOption("claude-sonnet-5-5"); await narrate.getByRole("button", { name: "Draft narration" }).click(); await expect(narrate).toHaveAttribute("data-draft-job", "done", { timeout: 20_000 }); const asked = stubAsked("report-draft").at(-1)!; expect(asked).toMatchObject({ task: "narrate", article: "zeta", iteration: 1, model: "claude-sonnet-5-5", authorization: "Bearer umtool-e2e-token" }); await page.goto(urls.articleHref(ZETA, { tab: "iterations" })); await expect(one.locator("[data-step='narrate']")).toHaveAttribute("data-step-status", "done", { timeout: 20_000 }); }); test("use, revise, copy with model, cancel: each through the editor, the list following its jobs", async ({ page, request }) => { test.setTimeout(120_000); const made = await request.post("/api/articles/generate", { data: { task: "sweep", article: ARTICLE, question: "What was said about the vote?", channels: ["sitechan"], model: "qwen3:8b" }, }); expect(made.status()).toBe(200); expect(await made.json()).toMatchObject({ ok: true, iteration: 1 }); await page.goto(urls.articleHref({ site: "articles", id: ARTICLE }, { tab: "iterations" })); await expect(card(page, 1)).toHaveAttribute("data-status", "done", { timeout: 20_000 }); // USE THIS ITERATION: the registry writes the article's report.json. An // outline (P6): the tab's filled action is the Next card's, not a card's. await expect(card(page, 1).getByRole("button", { name: "Use this iteration" })).not.toHaveClass(/signal/); await card(page, 1).getByRole("button", { name: "Use this iteration" }).click(); await expect(page.getByRole("status").filter({ hasText: "the article is i1" })).toBeVisible(); await expect(card(page, 1).locator("[data-current='article']")).toBeVisible(); const report = JSON.parse(readFileSync(path.join(FIXTURE, "articles", ARTICLE, "report.json"), "utf8")); expect(report.title).toBe("Sweep: What was said about the vote?"); // A NEW ITERATION of the report, on the local model, from feedback. await card(page, 1).getByRole("button", { name: "New iteration" }).click(); const form = page.getByRole("form", { name: "new iteration from i1" }); await form.getByRole("combobox", { name: "model for the new iteration from i1" }).selectOption("qwen3:8b"); await form.getByRole("textbox", { name: "feedback" }).fill("Say when she said it."); await form.getByRole("button", { name: "Start iteration" }).click(); await expect(card(page, 2)).toBeVisible(); await expect(page.getByRole("log", { name: "i2 progress" })).toContainText("report-draft revise-report", { timeout: 10_000 }); await expect(card(page, 2)).toHaveAttribute("data-status", "done", { timeout: 20_000 }); await expect(card(page, 2).locator("[data-ops-refused]")).toHaveAttribute("data-ops-refused", "1"); expect(stubAsked("report-draft").at(-1)).toMatchObject({ task: "revise-report", article: ARTICLE, iteration: 1, feedback: "Say when she said it.", model: "qwen3:8b" }); // COPY WITH MODEL: the same base and feedback on another model. await card(page, 2).getByRole("combobox", { name: "copy i2 on model" }).selectOption("claude-sonnet-5-5"); await card(page, 2).getByRole("button", { name: "Copy with model" }).click(); await expect(card(page, 3).locator("[data-copy-of]")).toHaveAttribute("data-copy-of", "2"); await expect(card(page, 3)).toHaveAttribute("data-status", "done", { timeout: 20_000 }); await expect(card(page, 3).locator("[data-usage-model='claude-sonnet-5-5']")).toContainText("$0.37"); expect(stubAsked("report-draft").at(-1)).toMatchObject({ task: "revise-report", copyOf: 2, model: "claude-sonnet-5-5" }); // CANCEL a running one (the stub keeps "slow" running until cancelled). await card(page, 1).getByRole("button", { name: "New iteration" }).click(); await form.getByRole("textbox", { name: "feedback" }).fill("Go slow on this one."); await form.getByRole("button", { name: "Start iteration" }).click(); await expect(card(page, 4)).toHaveAttribute("data-status", "running", { timeout: 10_000 }); await card(page, 4).getByRole("button", { name: "Cancel i4" }).click(); await expect(card(page, 4)).toHaveAttribute("data-status", "cancelled", { timeout: 10_000 }); expect(stubAsked("job").at(-1)).toMatchObject({ verb: "cancel", ids: [expect.stringMatching(/^stub-draft-/)] }); // The editor's refusal is shown in its words. await card(page, 1).getByRole("button", { name: "New iteration" }).click(); await form.getByRole("textbox", { name: "feedback" }).fill("refuse"); await form.getByRole("button", { name: "Start iteration" }).click(); await expect(page.getByRole("region", { name: "iterations", exact: true }).getByRole("alert")).toContainText("the stub refuses this feedback"); }); test("make the video: the chain's steps, run as a umtool job, resumable where it stopped", async ({ page }) => { test.setTimeout(150_000); await page.goto(urls.articleHref({ site: "articles", id: ARTICLE }, { tab: "iterations" })); await card(page, 1).getByRole("button", { name: "Make the video" }).click(); const chain = page.getByRole("region", { name: "i1 video chain" }); await expect(chain.locator("[data-chain-step]")).toHaveCount(10); await chain.getByRole("button", { name: "Run the chain" }).click(); // `current` runs (the article is i1 already); `windows` asks the editor for // the cited windows, which the stub does not serve — so the chain stops // there, recorded, and a start resumes at it. await expect(chain.locator("[data-chain-step='current']")).toHaveAttribute("data-step-status", "done", { timeout: 120_000 }); await expect(chain.locator("[data-chain-step='windows']")).toHaveAttribute("data-step-status", "failed", { timeout: 60_000 }); await expect(chain.locator("[data-chain-job]")).toHaveAttribute("data-chain-job", "failed"); await expect(chain.getByRole("combobox", { name: "i1 chain from step" })).toContainText("resume (windows)"); });