// AN X SEARCH CHANNEL end to end (release 38 lane S): a search URL pasted into // the New channel form makes one (its dates lifted into the form, the Sites // section replaced by "never on a site"); its first fetch walks the search // through the fake gallery-dl's search mode, which answers posts by several // accounts; the channel page's Leads ranks them, Never archive hides one and // Restore brings it back, and Archive this account creates `-x` on no // site and fetches it. // // X is NEVER contacted: e2e/fixtures/bin/fake-gallery-dl.mjs answers every // read. The login the search needs is a cookies-from-browser spec the fake // ignores. import { test, expect } from "@playwright/test"; import { readFile } from "node:fs/promises"; import { generateReport, pathExists, readJson, resetData, resolvePath, testPaths, writeSettings, writeSite } from "./helpers"; type Config = { platform?: string; sourceKind?: string; postFetcher?: string; socialHandle?: string; url?: string; xSearch?: { query: string; since?: string; until?: string; exclude?: string[] }; }; const SEARCH_URL = "https://x.com/search?q=zephyr%20since%3A2026-04-01%20until%3A2026-07-01&src=typed_query"; const archiveLines = async (slug: string): Promise => { const file = `${testPaths().transcriptsDir}/channels/${slug}/posts-archive`; return (await pathExists(file)) ? (await readFile(resolvePath(file), "utf8")).split("\n").filter(Boolean).length : 0; }; test("an X search channel: the form, the walk, the leads, Never archive and Archive this account", async ({ page }) => { await resetData("empty"); await writeSettings({ cookiesFromBrowser: "firefox" }); await writeSite("demo-site", { siteTitle: "Demo" }); await generateReport(page, "new"); await page.goto("/channels/new"); await page.locator('input[name="url"]').fill(SEARCH_URL); await expect(page.locator('select[name="platform"]')).toHaveValue("x-search"); await expect(page.getByLabel("x search query")).toHaveValue("zephyr"); await expect(page.getByLabel("x search since")).toHaveValue("2026-04-01"); await expect(page.getByLabel("x search until")).toHaveValue("2026-07-01"); await expect(page.locator("[data-x-search-no-site]")).toBeVisible(); await expect(page.locator('input[name="socialHandle"]')).toHaveCount(0); await expect(page.locator('select[name="audioFormat"]')).toHaveCount(0); await page.locator('input[name="name"]').fill("Zephyr search"); await page.locator('input[name="slug"]').fill("zephyr-search"); // "Fetch posts now" is on by default: the create starts the first walk. await page.getByRole("button", { name: /create|add channel|save/i }).first().click(); const configPath = `${testPaths().transcriptsDir}/channels/zephyr-search/config.json`; await expect .poll(async () => ((await pathExists(configPath)) ? await readJson(configPath) : null), { timeout: 15_000 }) .toMatchObject({ platform: "twitter", sourceKind: "social", postFetcher: "x-gallery-dl", url: "https://x.com/search?q=zephyr&f=live", xSearch: { query: "zephyr", since: "2026-04-01", until: "2026-07-01" }, }); expect((await readJson(configPath)).socialHandle).toBeUndefined(); // Four matching posts by three accounts. await expect.poll(() => archiveLines("zephyr-search"), { timeout: 30_000 }).toBe(4); const site = await readJson<{ channels: { slug: string }[] }>(`${testPaths().transcriptsDir}/sites/demo-site/site.json`); expect(site.channels).toEqual([]); await generateReport(page, "zephyr-search"); await page.goto("/channels/zephyr-search"); await expect(page.getByLabel("x search query")).toHaveText("zephyr"); await expect(page.getByRole("button", { name: "fetch older posts" })).toHaveCount(0); const leads = page.locator("[data-x-search-leads]"); await expect(leads.getByLabel("leads summary")).toHaveText(/3 accounts across 4 matching posts/); // Most matches first, then the most recent. await expect(leads.locator("tr[data-x-lead]")).toHaveCount(3); const rows = leads.locator("tr[data-x-lead]"); await expect(rows.nth(0)).toHaveAttribute("data-x-lead", "leadone"); await expect(rows.nth(1)).toHaveAttribute("data-x-lead", "leadtwo"); await expect(rows.nth(2)).toHaveAttribute("data-x-lead", "leadthree"); await expect(leads.getByLabel("matches for leadone")).toHaveText("2"); // Never archive: hidden here, kept in the channel's xSearch.exclude. await leads.getByRole("button", { name: "never archive leadthree", exact: true }).click(); await expect(leads.locator('tr[data-x-lead="leadthree"]')).toHaveCount(0); await expect(leads.locator("[data-x-search-hidden] summary")).toHaveText("Never archive (1)"); expect((await readJson(configPath)).xSearch?.exclude).toEqual(["leadthree"]); await leads.locator("[data-x-search-hidden] summary").click(); await leads.getByRole("button", { name: "restore leadthree" }).click(); await expect(leads.locator('tr[data-x-lead="leadthree"]')).toHaveCount(1); await expect.poll(async () => (await readJson(configPath)).xSearch?.exclude).toBeUndefined(); // Archive this account: leadone-x, an X channel on no site, its first fetch started. await leads.getByRole("button", { name: "archive leadone", exact: true }).click(); await expect(leads.getByRole("status")).toHaveText(/Created leadone-x on no site/); const leadConfig = `${testPaths().transcriptsDir}/channels/leadone-x/config.json`; await expect .poll(async () => ((await pathExists(leadConfig)) ? await readJson(leadConfig) : null), { timeout: 15_000 }) .toMatchObject({ platform: "twitter", sourceKind: "social", socialHandle: "leadone", url: "https://x.com/leadone" }); await expect.poll(() => archiveLines("leadone-x"), { timeout: 30_000 }).toBe(3); const after = await readJson<{ channels: { slug: string }[] }>(`${testPaths().transcriptsDir}/sites/demo-site/site.json`); expect(after.channels).toEqual([]); // The lead now names the channel that archives it. await page.reload(); await expect(page.locator('tr[data-x-lead="leadone"]')).toContainText("Archived as leadone-x"); await expect(page.getByRole("button", { name: "archive leadone", exact: true })).toHaveCount(0); });