import { test, expect } 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"; // --------------------------------------------------------------------------- // A new article (release 27 S8): its first iteration โ€” a sweep the editor // runs โ€” over the editor stub. The form is Create's "Article from a question" // (/create?make=article, P5; it was /articles/new, which redirects there). // The generation policy moved to /settings/generation: settings.spec.ts. // // WRITES articles/new-e2e/ (through the stub; 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 = "new-e2e"; 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, [urls.newArticleHref(), "/api/articles/policy", "/api/articles/channels"]); }); test.afterAll(() => { rmSync(path.join(FIXTURE, "articles", ARTICLE), { recursive: true, force: true }); }); test("/drafts and /articles/new land on Create's article form, and Work (/articles) links to Create", async ({ page }) => { for (const old of ["/drafts", "/articles/new"]) { await page.goto(old); await expect(page).toHaveURL(/\/create\?make=article$/); await expect(page.getByRole("form", { name: "new article" })).toBeVisible(); } await page.goto("/articles"); await page.locator("[data-work-create]").click(); await expect(page).toHaveURL(/\/create$/); }); test("a new article: question, channels, the local pipeline โ€” its first iteration runs, and the page is its iterations", async ({ page }) => { await page.goto(urls.newArticleHref()); const form = page.getByRole("form", { name: "new article" }); await form.getByRole("textbox", { name: "question" }).fill("What did the channel say about the vote?"); await form.getByRole("textbox", { name: "find a channel" }).fill("site"); await form.getByRole("button", { name: /^Site Channel/ }).click(); await expect(form.locator("[data-picked='sitechan']")).toBeVisible(); // An id that is taken is named before anything is sent. await form.getByRole("textbox", { name: "article id" }).fill("delta"); await expect(form).toContainText("an article by that id exists"); await form.getByRole("textbox", { name: "article id" }).fill(ARTICLE); // The agent's cap is the policy's per-sweep default, editable only down. await form.getByRole("textbox", { name: "cap" }).fill("9"); await form.getByRole("button", { name: "Start" }).click(); await expect(form.getByRole("alert")).toContainText("at most the policy's $5"); // The agent's extractor is the policy's unless this sweep names its own (release 28 F2). await expect(form.getByRole("combobox", { name: "extractor for this sweep" })).toHaveValue("claude-haiku-4-5"); await form.getByRole("combobox", { name: "extractor for this sweep" }).selectOption("claude-haiku-5-5"); // The estimate is said before anything runs (P5): what such runs have spent // (the fixture's ledger: one $0.42 sweep on claude-sonnet-5-5), under the cap. await expect(form.locator("[data-estimate]")).toContainText("1 earlier run on claude-sonnet-5-5: typical $0.42, most $0.42 ยท stops at $9.00 (its cap)"); await form.getByRole("textbox", { name: "cap" }).fill("5"); await expect(form.locator("[data-estimate]")).toContainText("stops at $5.00 (its cap)"); await form.getByRole("radio", { name: /pipeline/ }).check(); await expect(form.getByRole("combobox", { name: "model" })).toHaveValue("qwen3:8b"); await expect(form.locator("[data-estimate]")).toContainText("Runs on the local model: no API spend"); await expect(form.getByRole("combobox", { name: "extractor for this sweep" }), "the pipeline has no extractor").toHaveCount(0); await form.getByRole("button", { name: "Start" }).click(); await expect(page).toHaveURL(new RegExp(`/articles/${ARTICLE}\\?tab=iterations$`)); const asked = stubAsked("report-draft").at(-1)!; expect(asked).toMatchObject({ task: "sweep", article: ARTICLE, question: "What did the channel say about the vote?", channels: ["sitechan"], model: "qwen3:8b" }); expect(asked).not.toHaveProperty("maxUsd"); expect(asked).not.toHaveProperty("extractorModel"); const first = page.locator("[data-iteration='1']"); await expect(first).toHaveAttribute("data-kind", "sweep"); await expect(first).toHaveAttribute("data-status", "done", { timeout: 20_000 }); await page.goto("/articles"); await expect(page.locator(`[data-lit-line][data-piece='a:articles/${ARTICLE}']`)).toHaveAttribute("data-status", "in the making"); });