import { test } from "node:test"; import assert from "node:assert/strict"; import { connectWith, fakeEditor, isError, textOf } from "./editorOps.testkit"; // ─── x_search_leads (release 38 lane S), through tools/call ─── // // One GET on the fake editor (/api/ops/channel/?leads=1); what is pinned // is the request sent and the words the agent reads. const EDITOR = "http://editor.test"; test("x_search_leads: the leads read through the editor, ranked as it answers them", async () => { const { deps, sent } = fakeEditor(() => ({ status: 200, body: { ok: true, slug: "zephyr-search", leads: { query: "zephyr", search: "zephyr · since 2025-01-01", walk: "searched 2025-01-01 – 2026-10-21", posts: 4, authors: 3, more: 1, hidden: [{ handle: "spam_bot", count: 9 }], leads: [ { handle: "alice", name: "Alice", count: 2, reposts: 1, first: "2025-02-01T00:00:00.000Z", last: "2025-03-01T00:00:00.000Z", sample: { url: "https://x.com/alice/status/1", text: "the zephyr archive", createdAt: "2025-03-01T00:00:00.000Z" }, }, { handle: "bob", count: 1, reposts: 0, first: "2025-04-01T00:00:00.000Z", last: "2025-04-01T00:00:00.000Z", sample: { url: "https://x.com/bob/status/2", text: "zephyr", createdAt: "2025-04-01T00:00:00.000Z" }, archivedAs: ["bob-x"], }, ], }, }, }), { ARCHILYZER_EDITOR_URL: EDITOR, WORKER_TOKEN: "t" }); const client = await connectWith(deps); const res = await client.callTool({ name: "x_search_leads", arguments: { channel: "zephyr-search", limit: 2 } }); const url = new URL(sent[0].url); assert.equal(url.pathname, "/api/ops/channel/zephyr-search"); assert.equal(url.searchParams.get("leads"), "1"); assert.equal(url.searchParams.get("limit"), "2"); const t = textOf(res); assert.match(t, /^X search zephyr-search: zephyr · since 2025-01-01/); assert.match(t, /4 matching posts from 3 accounts/); assert.match(t, /1\. @alice \(Alice\) — 2 matches \(1 reposts\), 2025-02-01 – 2025-03-01/); assert.match(t, /2\. @bob — 1 match, 2025-04-01 – 2025-04-01 · archived as bob-x/); assert.match(t, /… 1 more accounts/); assert.match(t, /Never archive \(hidden\): @spam_bot/); }); test("x_search_leads: refusals — no channel, a bad limit, the editor's own sentence", async () => { const { deps } = fakeEditor(() => ({ status: 400, body: { ok: false, error: "demo is not an X search channel (its config has no xSearch query)." } }), { ARCHILYZER_EDITOR_URL: EDITOR, WORKER_TOKEN: "t", }); const client = await connectWith(deps); const none = await client.callTool({ name: "x_search_leads", arguments: { channel: "" } }); assert.ok(isError(none)); assert.match(textOf(none), /channel is required/); const bad = await client.callTool({ name: "x_search_leads", arguments: { channel: "demo", limit: 0 } }); assert.match(textOf(bad), /limit is a whole number, 1–500/); const refused = await client.callTool({ name: "x_search_leads", arguments: { channel: "demo" } }); assert.ok(isError(refused)); assert.match(textOf(refused), /the editor refused \(HTTP 400\): demo is not an X search channel/); });