commit 9f831d0a31c78b4b3af9c22df5e8cb06909cfa64
parent ea059c80d8ad8a9cb0062f6e3d731e9b66c06c94
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 18 Nov 2026 11:02:25 -0500
e2e: x-trending slice 4 -- the editor's spec organises, publishes and breaks out an account over ops; umtool's library spec does the same from the page
editor/e2e/x-trending.spec.ts, a third test: rename; move into a new
topic; a merge refused for an agent and while a read is queued or running,
then done; a publish in two steps (an agent's refused, a stale confirm
refused) into a channel whose config is four plain keys, whose shot is a
copy with its own inode and whose files carry nothing of the library; the
published channel refused by name on fetch-posts, capture-posts, the
availability check, an X run and Configure, with no job made; a
re-publish that adds one post and reports one no longer kept; the
accounts, and an account archived on no site with no job started.
umtool/e2e/library.spec.ts, four tests over the stub editor (which learns
organise-trending, publish-trending, accounts and the lead archive):
rename, move, and a merge behind its confirm with umtool's Mark seen state
following; publish with the slug changed before the first publish, a
re-publish, and the panel at 360 px; the Accounts panel and Archive this
account, which sends no "fetch"; and the three new press routes refused to
anything but the page and stamped the operator's. The slice-3 line that
no button says "publish" now says there is exactly one, the topic's.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
3 files changed, 564 insertions(+), 13 deletions(-)
diff --git a/editor/e2e/x-trending.spec.ts b/editor/e2e/x-trending.spec.ts
@@ -350,3 +350,165 @@ test("an X trending library: judgements, a watch tick, media kept once, gone fro
expect(purged.posts.find((p) => p.id === NEW)?.capture).toBeUndefined();
expect(purged.posts.find((p) => p.id === B)).toMatchObject({ judgement: { state: "drop", by: "operator" } });
});
+
+// SLICE 4 (lane x-trending-publish): the library's topics organised, a topic
+// PUBLISHED into an ordinary channel on no site, and an account broken out.
+// Over ops (umtool's Posts library page is the operator's form of the same
+// actions: umtool/e2e/library.spec.ts). X is never contacted: the one read is
+// the fake browser's, the capture is planted, and archiving an account from a
+// library starts no fetch.
+test("an X trending library: rename, move, merge; a topic published into an ordinary channel that names nothing of the library; an account archived with nothing asked of X", async ({ page, request }) => {
+ test.setTimeout(240_000);
+ await seed();
+ const post = async (action: string, data: Record<string, unknown>) => {
+ const res = await request.post(`${baseUrl}/api/ops/${action}`, { headers: AUTH, data });
+ return { status: res.status(), json: (await res.json()) as Record<string, any> };
+ };
+ const get = async (query: string) => (await (await request.get(`${baseUrl}/api/ops/trending?${query}`, { headers: AUTH })).json()) as Record<string, any>;
+ const A = "1900000000000001001";
+ const B = "1900000000000001002";
+ const D = "1900000000000001004";
+
+ const made = await post("create-channel", { slug: SLUG, fields: { name: "Trending", handling: "transcribe", platform: "x-trending" } });
+ expect(made.status, JSON.stringify(made.json)).toBe(200);
+ expect((await post("read-x-trending", { slug: SLUG, url: FIXTURE_TREND_URL, topic: "Kettle Festival" })).status).toBe(200);
+ await expect.poll(archiveLines, { timeout: 60_000 }).toBe(4);
+ // (The read's job has ended before anything below asks whether one is in flight.)
+ await expect.poll(async () => ((await (await request.get(`${baseUrl}/api/ops/jobs?active=1&slug=${SLUG}`, { headers: AUTH })).json()) as { jobs?: unknown[] }).jobs?.length ?? 0, { timeout: 60_000 }).toBe(0);
+
+ // RENAME (an agent may): the name changes, the id stays.
+ const renamed = await post("organise-trending", { slug: SLUG, op: "rename", topic: "kettle-festival", title: "Kettles 2026" });
+ expect(renamed.json).toMatchObject({ ok: true, topic: "kettle-festival", title: "Kettles 2026", was: "Kettle Festival", changed: true });
+ expect((await get(`slug=${SLUG}`)).topics.map((t: any) => [t.id, t.title])).toEqual([["kettle-festival", "Kettles 2026"]]);
+
+ // MOVE a post into a new topic, then try to merge it back.
+ const moved = await post("organise-trending", { slug: SLUG, op: "move", to: "Spoons", ids: [B], create: true });
+ expect(moved.json).toMatchObject({ ok: true, to: { id: "spoons", title: "Spoons", created: true }, moved: [B], skipped: [] });
+ expect((await get(`slug=${SLUG}&topic=spoons`)).total).toBe(1);
+ // A merge is the operator's: an agent's is refused, and nothing changes.
+ const agentMerge = await post("organise-trending", { slug: SLUG, op: "merge", into: "kettle-festival", from: ["spoons"] });
+ expect(agentMerge.status).toBe(400);
+ expect(String(agentMerge.json.error)).toContain("Merging topics is the operator's press");
+ // …and it waits for a read: one is started (the same page, read again), and the merge is refused while it is queued or running.
+ expect((await post("read-x-trending", { slug: SLUG, url: FIXTURE_TREND_URL })).status).toBe(200);
+ const waiting = await post("organise-trending", { slug: SLUG, op: "merge", into: "kettle-festival", from: ["spoons"], by: "operator" });
+ expect(waiting.status).toBe(400);
+ expect(String(waiting.json.error)).toContain("A read of this library is queued or running: merge its topics once it has finished");
+ expect((await get(`slug=${SLUG}`)).topics).toHaveLength(2);
+ let merged: Record<string, any> = {};
+ await expect
+ .poll(
+ async () => {
+ merged = (await post("organise-trending", { slug: SLUG, op: "merge", into: "kettle-festival", from: ["spoons"], by: "operator" })).json;
+ return merged.ok === true;
+ },
+ { timeout: 90_000 },
+ )
+ .toBe(true);
+ expect(merged).toMatchObject({ into: { id: "kettle-festival", title: "Kettles 2026" }, merged: [{ id: "spoons", title: "Spoons", posts: 1, pages: 0 }], posts: 1 });
+ expect(String(merged.sentence)).toContain("This cannot be undone.");
+ const one = await get(`slug=${SLUG}&topic=spoons`);
+ expect(one.topics.map((t: any) => [t.id, t.posts, t.aliases])).toEqual([["kettle-festival", 4, ["spoons"]]]);
+ expect(one.total).toBe(4);
+
+ // KEEP: the operator keeps A (its capture planted, as a capture job leaves one), an agent keeps D.
+ expect((await post("judge-trending", { slug: SLUG, by: "operator", archive: false, set: [{ id: A, state: "keep", note: "a private note" }] })).json).toMatchObject({ kept: [A] });
+ expect((await post("judge-trending", { slug: SLUG, archive: false, set: [{ id: D, state: "keep" }] })).json).toMatchObject({ kept: [D] });
+ const libCapture = t(`channels/${SLUG}/trending/posts-media/${A}`);
+ await mkdir(libCapture, { recursive: true });
+ await writeFile(`${libCapture}/shot.png`, "FIXTURE SHOT BYTES");
+ await writeFile(
+ `${libCapture}/capture.json`,
+ JSON.stringify({ version: 1, id: A, url: `https://x.com/i/status/${A}`, capturedAt: "2026-11-18T10:00:00.000Z", state: "captured", shot: { name: "shot.png", bytes: 18, sha256: "0".repeat(64) }, mediaState: "skipped", mediaOwed: "kept", media: [] }),
+ );
+
+ // PUBLISH, step one: what would be written. Nothing is.
+ const dry = await post("publish-trending", { slug: SLUG, topic: "kettle-festival", dryRun: true });
+ expect(dry.status, JSON.stringify(dry.json)).toBe(200);
+ expect(dry.json).toMatchObject({ dryRun: true, channel: "kettles-2026", creates: true, kept: 1, posts: 1, ids: [A], already: 0, files: 1, bytes: 18, textOnly: [], noLongerKept: [] });
+ expect(String(dry.json.sentence)).toContain('would make the channel "kettles-2026", on no site, writing 1 post and 1 file (18 B)');
+ expect(await pathExists(rel("channels/kettles-2026"))).toBe(false);
+ // An agent may not publish; a confirm that is not this dry run's is refused.
+ const agent = await post("publish-trending", { slug: SLUG, topic: "kettle-festival", confirm: dry.json.confirm });
+ expect(agent.status).toBe(400);
+ expect(String(agent.json.error)).toContain("Publishing a topic is the operator's press");
+ expect(String((await post("publish-trending", { slug: SLUG, topic: "kettle-festival", confirm: "0".repeat(24), by: "operator" })).json.error)).toContain("has changed since it was counted");
+ expect(await pathExists(rel("channels/kettles-2026"))).toBe(false);
+
+ // Step two, the operator's: an ordinary channel, on no site.
+ const done = await post("publish-trending", { slug: SLUG, topic: "kettle-festival", confirm: dry.json.confirm, by: "operator" });
+ expect(done.status, JSON.stringify(done.json)).toBe(200);
+ expect(done.json).toMatchObject({ dryRun: false, channel: "kettles-2026", creates: true, posts: 1, files: 1 });
+ expect(await readJson<Config & { name?: string }>(rel("channels/kettles-2026/config.json"))).toEqual({ name: "Kettles 2026", handling: "transcribe", sourceKind: "social", platform: "twitter" });
+ const lines = (await readFile(t("channels/kettles-2026/posts/2026-11.jsonl"), "utf8").catch(async () => {
+ const dir = t("channels/kettles-2026/posts");
+ return readFile(`${dir}/${(await readdir(dir))[0]}`, "utf8");
+ })).trim().split("\n").map((l) => JSON.parse(l) as { id: string; slug: string; channelSlug: string; author: string });
+ expect(lines.map((p) => [p.id, p.slug, p.channelSlug, p.author])).toEqual([[A, `kettles-2026/${A}`, "kettles-2026", "teapot_news"]]);
+ // The shot is a COPY: its own inode, one name.
+ const copy = await stat(t(`channels/kettles-2026/posts-media/${A}/shot.png`));
+ expect(await readFile(t(`channels/kettles-2026/posts-media/${A}/shot.png`), "utf8")).toBe("FIXTURE SHOT BYTES");
+ expect(copy.ino).not.toBe((await stat(`${libCapture}/shot.png`)).ino);
+ expect(copy.nlink).toBe(1);
+ // NOTHING OF THE LIBRARY in the channel: not its slug, a judgement, the note, a read, what was owed.
+ const walk = async (dir: string): Promise<string[]> => (await Promise.all((await readdir(dir, { withFileTypes: true })).map((e) => (e.isDirectory() ? walk(`${dir}/${e.name}`) : [`${dir}/${e.name}`])))).flat();
+ for (const file of await walk(t("channels/kettles-2026"))) {
+ const text = await readFile(file, "utf8");
+ for (const word of [`${SLUG}/`, `"${SLUG}"`, "xTrending", "a private note", "judg", "operator", "agent", "mediaOwed", "tr-01", "gone"]) {
+ expect(text.includes(word), `${file} carries ${word}`).toBe(false);
+ }
+ }
+ // On no site; the agent's keep and the undecided posts stayed in the library.
+ expect(JSON.stringify(await readJson<Record<string, unknown>>(rel("sites/demo-site/site.json")))).not.toContain("kettles-2026");
+ expect((await readJson<{ topics: Record<string, { slug: string; posts: Record<string, string> }> }>(rel(`channels/${SLUG}/trending/published.json`))).topics["kettle-festival"]).toMatchObject({ slug: "kettles-2026" });
+
+ // THE PUBLISHED CHANNEL MAKES NO REQUEST: a direct ask is refused with one sentence, and no job is made.
+ const SAYS = "kettles-2026 holds posts published from a private library: it has no account to fetch from";
+ for (const [action, data] of [
+ ["fetch-posts", { slug: "kettles-2026" }],
+ ["capture-posts", { slug: "kettles-2026", ids: [A] }],
+ ["check-post-availability", { slug: "kettles-2026" }],
+ ["x-run", { channels: ["kettles-2026"] }],
+ ["channel-config", { slug: "kettles-2026", patch: { name: "Renamed by hand" } }],
+ ] as const) {
+ const refused = await post(action, data);
+ expect(refused.status, `${action}: ${JSON.stringify(refused.json)}`).toBeGreaterThanOrEqual(400);
+ expect(String(refused.json.error), action).toContain(SAYS);
+ }
+ expect((((await (await request.get(`${baseUrl}/api/ops/jobs?slug=kettles-2026`, { headers: AUTH })).json()) as { jobs?: unknown[] }).jobs ?? []).length).toBe(0);
+ // It is a channel like any other on the editor's pages.
+ await page.goto("/channels/kettles-2026");
+ await expect(page.locator("body")).toContainText("Kettles 2026");
+
+ // RE-PUBLISH adds and removes nothing: A is dropped, B is kept.
+ await post("judge-trending", { slug: SLUG, by: "operator", archive: false, set: [{ id: A, state: "drop" }, { id: B, state: "keep" }] });
+ const again = await post("publish-trending", { slug: SLUG, topic: "spoons", dryRun: true });
+ expect(again.json).toMatchObject({ channel: "kettles-2026", creates: false, kept: 1, posts: 1, ids: [B], already: 0, files: 0, textOnly: [B], noLongerKept: [A] });
+ const second = await post("publish-trending", { slug: SLUG, topic: "kettle-festival", confirm: again.json.confirm, by: "operator" });
+ expect(second.status, JSON.stringify(second.json)).toBe(200);
+ expect(String(second.json.sentence)).toContain("1 post published before is no longer kept: it stays in the channel (a publish removes nothing).");
+ expect((await readFile(t("channels/kettles-2026/posts-archive"), "utf8")).split("\n").filter(Boolean).sort()).toEqual([`twitter ${A}`, `twitter ${B}`]);
+ expect(await pathExists(rel(`channels/kettles-2026/posts-media/${A}/shot.png`))).toBe(true);
+ // A channel of the slug that this publish did not make is never appended to.
+ const taken = await post("publish-trending", { slug: SLUG, topic: "kettle-festival", dryRun: true, channel: "elsewhere" });
+ expect(String(taken.json.error)).toContain('published into the channel "kettles-2026": a topic has one channel');
+
+ // THE ACCOUNTS, and one broken out: <handle>-x on no site, and X is asked nothing.
+ const accounts = await get(`slug=${SLUG}&accounts=1`);
+ expect(accounts.accounts.map((a: any) => a.handle).sort()).toEqual(expect.arrayContaining(["saucer_fan", "spout_clips", "teapot_news"]));
+ expect(accounts.accounts.find((a: any) => a.handle === "saucer_fan")).toMatchObject({ posts: 1, kept: 1, keptByOperator: 1, topics: ["kettle-festival"] });
+ const plan = await post("x-search-lead", { slug: SLUG, handle: "saucer_fan", action: "archive", dryRun: true });
+ expect(plan.json).toMatchObject({ ok: true, dryRun: true, slug: "saucer_fan-x" });
+ expect(await pathExists(rel("channels/saucer_fan-x"))).toBe(false);
+ const archived = await post("x-search-lead", { slug: SLUG, handle: "saucer_fan", action: "archive" });
+ expect(archived.status, JSON.stringify(archived.json)).toBe(200);
+ expect(archived.json).toMatchObject({ ok: true, slug: "saucer_fan-x", jobIds: [] });
+ const account = await readJson<Config>(rel("channels/saucer_fan-x/config.json"));
+ expect(account).toMatchObject({ platform: "twitter", sourceKind: "social", url: "https://x.com/saucer_fan", socialHandle: "saucer_fan" });
+ expect(JSON.stringify(account)).not.toContain(SLUG);
+ expect((((await (await request.get(`${baseUrl}/api/ops/jobs?slug=saucer_fan-x`, { headers: AUTH })).json()) as { jobs?: unknown[] }).jobs ?? []).length).toBe(0);
+ expect(JSON.stringify(await readJson<Record<string, unknown>>(rel("sites/demo-site/site.json")))).not.toContain("saucer_fan-x");
+ expect((await get(`slug=${SLUG}&accounts=1`)).accounts.find((a: any) => a.handle === "saucer_fan").archivedAs).toEqual(["saucer_fan-x"]);
+ const twice = await post("x-search-lead", { slug: SLUG, handle: "saucer_fan", action: "archive" });
+ expect(String(twice.json.error)).toContain("@saucer_fan is already archived: saucer_fan-x.");
+});
diff --git a/umtool/e2e/fixtures/editor-stub-trending.mjs b/umtool/e2e/fixtures/editor-stub-trending.mjs
@@ -1,28 +1,31 @@
// The editor's X trending library, stubbed for umtool's Posts library page
// (library.spec.ts; lane posts-library): GET /api/ops/trending with the judge
-// view's asks, and the three presses — judge-trending, watch-trending,
-// purge-trending — over an invented library held in memory
+// view's asks, and the presses — judge-trending, watch-trending,
+// purge-trending, and (lane x-trending-publish) organise-trending,
+// publish-trending and x-search-lead's archive — over an invented library held in memory
// (library-fixture.mjs libraryState). Every press is RECORDED with the `by`
// it carried, which is the part no page shows.
//
// POST /__stub/trending {reset?: true, mode?: "ok" | "unreachable" | "none"}
// "unreachable": every trending route drops the connection (the editor is down);
// "none": the editor holds no library
-// GET /__stub/trending -> { mode, requests, reads, judgements, captured, watches }
+// GET /__stub/trending -> { mode, requests, reads, judgements, captured, watches, topics, published, archived }
// `reads`: how many times the listing was asked (GET /api/ops/trending) since the reset
//
// Nothing here asks X, or any host, anything.
import { createHash } from "node:crypto";
import { libraryState } from "./library-fixture.mjs";
-let state = libraryState();
+const fresh = () => ({ ...libraryState(), published: {}, archived: {} });
+let state = fresh();
let mode = "ok";
let requests = [];
let reads = 0;
let jobs = 0;
const NOW = "2026-11-18T09:00:00.000Z";
-const ROUTES = ["/api/ops/trending", "/api/ops/judge-trending", "/api/ops/watch-trending", "/api/ops/purge-trending"];
+// Lane x-trending-publish: organise-trending, publish-trending and the lead action's archive.
+const ROUTES = ["/api/ops/trending", "/api/ops/judge-trending", "/api/ops/watch-trending", "/api/ops/purge-trending", "/api/ops/organise-trending", "/api/ops/publish-trending", "/api/ops/x-search-lead"];
const effective = (p) => {
const own = state.judgements.posts[p.id];
@@ -81,7 +84,7 @@ function row(p, detail) {
}
function listing(sp) {
- const topic = sp.get("topic");
+ const topic = topicOf(sp.get("topic"))?.id ?? sp.get("topic");
const detail = sp.get("detail") === "1";
const words = (sp.get("q") ?? "").toLowerCase().split(/\s+/).filter(Boolean);
const author = sp.get("author")?.replace(/^@/, "").toLowerCase() ?? null;
@@ -114,7 +117,8 @@ function listing(sp) {
if (p.gone) counts.gone++;
}
const fresh = seen ? mine.filter((p) => !seen[t.id] || p.firstSeenAt > seen[t.id]).length : null;
- return { id: t.id, title: t.title, posts: mine.length, ...(t.watch ? { watch: { ...t.watch, sentence: watchSentence(t.watch) } } : {}), ...(detail ? { counts } : {}), ...(fresh !== null ? { fresh } : {}), sources: [] };
+ const pub = detail ? state.published?.[t.id] : undefined;
+ return { id: t.id, title: t.title, posts: mine.length, ...(t.aliases?.length ? { aliases: t.aliases } : {}), ...(pub ? { published: { channel: pub.channel, firstAt: NOW, lastAt: NOW, posts: pub.posts.length } } : {}), ...(t.watch ? { watch: { ...t.watch, sentence: watchSentence(t.watch) } } : {}), ...(detail ? { counts } : {}), ...(fresh !== null ? { fresh } : {}), sources: [] };
}),
posts: sp.get("ids") === "1" ? [] : rows.slice(offset, offset + limit).map((p) => row(p, detail)),
total: rows.length,
@@ -124,6 +128,147 @@ function listing(sp) {
};
}
+// ── lane x-trending-publish ────────────────────────────────────────────────
+
+/** A topic by its id, the id of one merged into it, or its name. */
+function topicOf(name) {
+ if (!name) return undefined;
+ return state.topics.find((t) => t.id === name) ?? state.topics.find((t) => t.aliases?.includes(name)) ?? state.topics.find((t) => t.title.toLowerCase() === String(name).toLowerCase());
+}
+const slugOf = (title) => title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
+const live = (w) => !!w && w.on && !w.ended;
+const none = (name) => ({ ok: false, error: `This library has no topic "${name}" (its topics: ${state.topics.map((t) => t.id).join(", ")}).` });
+
+// The editor's rules (common/lib/xTrending/organise.ts): a rename keeps the id; a move changes a post's topic;
+// a merge is the operator's, keeps the merged ids as aliases and ONE watch (the target's when it is live).
+function organise(body) {
+ if (body.by !== "agent" && body.by !== "operator") return { ok: false, error: `"by" is "agent" or "operator"` };
+ if (body.op === "rename") {
+ const topic = topicOf(body.topic);
+ if (!topic) return none(body.topic);
+ const other = state.topics.find((t) => t !== topic && (t.id === body.title || t.title.toLowerCase() === String(body.title).toLowerCase()));
+ if (other) return { ok: false, error: `Topic "${other.title}" (${other.id}) already answers to "${body.title}": a topic's name is its own. Merge the two, or choose another name.` };
+ const was = topic.title;
+ topic.title = String(body.title).trim();
+ return { ok: true, slug: state.slug, op: "rename", topic: topic.id, title: topic.title, was, changed: was !== topic.title, sentence: `Topic "${was}" is now "${topic.title}". Its id stays ${topic.id}: its watch, its posts and their judgements are untouched.` };
+ }
+ if (body.op === "move") {
+ let to = topicOf(body.to);
+ let created = false;
+ if (!to) {
+ if (!body.create) return { ok: false, error: `${none(body.to).error} To move posts into a new topic, say "create": true.` };
+ to = { id: slugOf(body.to), title: body.to };
+ state.topics.push(to);
+ created = true;
+ }
+ const wanted = body.thread ? state.posts.filter((p) => p.thread === body.thread).map((p) => p.id) : body.ids ?? [];
+ const moved = [];
+ const skipped = [];
+ for (const pid of wanted) {
+ const p = state.posts.find((x) => x.id === pid);
+ if (!p) skipped.push({ id: pid, reason: "not in this library" });
+ else if (p.topic === to.id) skipped.push({ id: pid, reason: `already in "${to.title}"` });
+ else {
+ p.topic = to.id;
+ moved.push(pid);
+ }
+ }
+ return { ok: true, slug: state.slug, op: "move", to: { id: to.id, title: to.title, created }, moved, skipped, sentence: `${moved.length} post${moved.length === 1 ? "" : "s"} moved to "${to.title}".${skipped.length ? ` ${skipped.length} post${skipped.length === 1 ? "" : "s"} skipped: ${skipped[0].reason}.` : ""}${moved.length ? " Their judgements and captures are untouched." : ""}` };
+ }
+ if (body.op === "merge") {
+ if (body.by !== "operator") return { ok: false, error: "Merging topics is the operator's press: it cannot be undone (there is no unmerge)." };
+ const into = topicOf(body.into);
+ if (!into) return none(body.into);
+ const from = [];
+ for (const name of body.from ?? []) {
+ const t = topicOf(name);
+ if (!t) return none(name);
+ if (t === into) return { ok: false, error: `"${name}" is the topic that stays ("${into.title}"): a topic is not merged into itself.` };
+ from.push(t);
+ }
+ const merged = from.map((t) => ({ id: t.id, title: t.title, posts: state.posts.filter((p) => p.topic === t.id).length, pages: 1 }));
+ let watchSentence = "";
+ const dropped = [];
+ for (const t of from) {
+ for (const p of state.posts) if (p.topic === t.id) p.topic = into.id;
+ if (live(t.watch)) {
+ if (live(into.watch)) dropped.push(t.title);
+ else {
+ into.watch = t.watch;
+ watchSentence = ` The watch of "${t.title}" is now the watch of "${into.title}".`;
+ }
+ }
+ into.aliases = [...(into.aliases ?? []), t.id, ...(t.aliases ?? [])];
+ state.topics.splice(state.topics.indexOf(t), 1);
+ }
+ if (dropped.length) watchSentence = ` The watch of "${into.title}" stands with its own terms. The watch of ${dropped.map((d) => `"${d}"`).join(", ")} is gone: one topic has one watch.`;
+ const posts = merged.reduce((n, m) => n + m.posts, 0);
+ return { ok: true, slug: state.slug, op: "merge", into: { id: into.id, title: into.title }, merged, posts, pages: 1 + merged.length, watch: { dropped }, sentence: `${merged.map((m) => `"${m.title}"`).join(", ")} ${merged.length === 1 ? "is" : "are"} now part of "${into.title}": ${posts} post${posts === 1 ? "" : "s"} moved. The judgements are untouched. This cannot be undone.${watchSentence}` };
+ }
+ return { ok: false, error: `"op" is "rename", "move" or "merge"` };
+}
+
+// The editor's rule (common/controller/publishXTrending.ts): the posts KEPT BY THE OPERATOR, in two steps held
+// by a digest; the slug fixed at the first publish; a re-publish adds and removes nothing.
+function publish(body) {
+ const topic = topicOf(body.topic);
+ if (!topic) return { ok: false, error: `${state.slug} has no topic "${body.topic}"` };
+ const record = state.published[topic.id];
+ if (record && body.channel !== undefined && body.channel !== record.channel) return { ok: false, error: `"${topic.title}" is published into the channel "${record.channel}": a topic has one channel, fixed at its first publish.` };
+ const channel = record?.channel ?? body.channel ?? slugOf(topic.title);
+ const kept = state.posts.filter((p) => p.topic === topic.id && effective(p)?.state === "keep" && effective(p).by === "operator");
+ if (kept.length === 0) return { ok: false, error: `The operator has kept no post in "${topic.title}": there is nothing to publish. (An agent's keep is a suggestion and is not published.)` };
+ const have = new Set(record?.posts ?? []);
+ const fresh = kept.filter((p) => !have.has(p.id));
+ const files = fresh.reduce((n, p) => n + (state.captured.includes(p.id) ? 1 + (captureFiles(p)?.media.length ?? 0) : 0), 0);
+ const textOnly = kept.filter((p) => !state.captured.includes(p.id)).map((p) => p.id);
+ const noLongerKept = [...have].filter((pid) => !kept.some((p) => p.id === pid));
+ const confirm = createHash("sha256").update(JSON.stringify([state.slug, topic.id, channel, fresh.map((p) => p.id).sort()])).digest("hex").slice(0, 24);
+ const answer = { ok: true, slug: state.slug, library: state.slug, topic: { id: topic.id, title: topic.title }, channel, creates: !record, kept: kept.length, posts: fresh.length, ids: fresh.map((p) => p.id), already: kept.length - fresh.length, files, bytes: files * 68, textOnly, noLongerKept, confirm };
+ const n = (k, what) => `${k} ${what}${k === 1 ? "" : "s"}`;
+ const say = (would) =>
+ fresh.length === 0 && record
+ ? `Nothing to add: the channel "${channel}" already holds the ${n(kept.length, "post")} the operator kept in "${topic.title}".`
+ : `Publishing "${topic.title}" ${record ? (would ? "would add to" : "added to") : would ? "would make" : "made"} the channel "${channel}"${record ? "" : ", on no site,"} ${would ? "writing" : "and wrote"} ${n(fresh.length, "post")} and ${n(files, "file")} (${files * 68} B); ${answer.already} of the ${n(kept.length, "kept post")} ${answer.already === 1 ? "is" : "are"} there already.${noLongerKept.length ? ` ${n(noLongerKept.length, "post")} published before ${noLongerKept.length === 1 ? "is" : "are"} no longer kept: ${noLongerKept.length === 1 ? "it stays" : "they stay"} in the channel (a publish removes nothing).` : ""}`;
+ if (body.dryRun === true) return { ...answer, dryRun: true, sentence: say(true) };
+ if (body.by !== "operator") return { ok: false, error: "Publishing a topic is the operator's press: an agent may ask for the dry run" };
+ if (body.confirm !== confirm) return { ok: false, error: "What would be published has changed since it was counted (a post kept or dropped, a capture finished, a post moved): nothing was written. Ask for the dry run again." };
+ state.published[topic.id] = { channel, posts: [...have, ...fresh.map((p) => p.id)] };
+ return { ...answer, dryRun: false, sentence: say(false) };
+}
+
+function accounts(sp) {
+ const topic = topicOf(sp.get("topic"))?.id ?? null;
+ const rows = new Map();
+ for (const p of state.posts) {
+ if (topic && p.topic !== topic) continue;
+ const row = rows.get(p.author) ?? { handle: p.author, key: p.author.toLowerCase(), name: p.authorName, posts: 0, kept: 0, keptByOperator: 0, topics: [], last: p.createdAt };
+ row.posts++;
+ const j = effective(p);
+ if (j?.state === "keep") {
+ row.kept++;
+ if (j.by === "operator") row.keptByOperator++;
+ }
+ if (!row.topics.includes(p.topic)) row.topics.push(p.topic);
+ if (state.archived[p.author]) row.archivedAs = [state.archived[p.author]];
+ rows.set(p.author, row);
+ }
+ const all = [...rows.values()].sort((a, b) => b.posts - a.posts || (a.key < b.key ? -1 : 1));
+ return { ok: true, slug: state.slug, accounts: all, total: all.length, posts: all.reduce((n, a) => n + a.posts, 0), more: 0 };
+}
+
+// The lead action's archive, for an account of the library: <handle>-x, and NO fetch unless asked.
+function lead(body) {
+ if (body.action !== "archive") return { ok: false, error: `${state.slug} is not an X search channel (its config has no xSearch query).` };
+ const handle = String(body.handle ?? "").replace(/^@/, "");
+ if (!state.posts.some((p) => p.author.toLowerCase() === handle.toLowerCase())) return { ok: false, error: `${state.slug} holds no post by @${handle}: "Archive this account" is for an account in the library.` };
+ if (state.archived[handle]) return { ok: false, error: `@${handle} is already archived: ${state.archived[handle]}.` };
+ const slug = `${handle.toLowerCase()}-x`;
+ if (body.dryRun === true) return { ok: true, dryRun: true, slug, fields: { url: `https://x.com/${handle}` } };
+ state.archived[handle] = slug;
+ return { ok: true, slug, jobIds: body.fetch === true ? [`stub-fetch-${++jobs}`] : [] };
+}
+
function judge(body) {
const before = new Map(state.posts.map((p) => [p.id, effective(p)?.state]));
const written = [];
@@ -188,12 +333,17 @@ export function trendingControl(req, res, url, { json, readBody }) {
if (url.pathname !== "/__stub/trending") return false;
if (req.method === "GET") {
req.resume();
- json(res, 200, { mode, requests, reads, judgements: state.judgements, captured: state.captured, watches: Object.fromEntries(state.topics.map((t) => [t.id, t.watch ?? null])) });
+ json(res, 200, {
+ mode, requests, reads, judgements: state.judgements, captured: state.captured, watches: Object.fromEntries(state.topics.map((t) => [t.id, t.watch ?? null])),
+ topics: state.topics.map((t) => ({ id: t.id, title: t.title, aliases: t.aliases ?? [], posts: state.posts.filter((p) => p.topic === t.id).map((p) => p.id) })),
+ published: state.published,
+ archived: state.archived,
+ });
return true;
}
readBody(req, (body) => {
if (body?.reset === true) {
- state = libraryState();
+ state = fresh();
requests = [];
reads = 0;
jobs = 0;
@@ -227,8 +377,12 @@ export function trendingRoute(req, res, url, { json, readBody, authorization })
json(res, 404, { ok: false, error: `No such channel: ${url.searchParams.get("slug")}` });
return true;
}
+ if (url.searchParams.get("accounts") === "1") {
+ json(res, 200, accounts(url.searchParams));
+ return true;
+ }
const topic = url.searchParams.get("topic");
- if (topic && !state.topics.some((t) => t.id === topic)) {
+ if (topic && !state.topics.some((t) => t.id === topic || t.aliases?.includes(topic))) {
json(res, 400, { ok: false, error: `${state.slug} has no topic "${topic}" (its topics: ${state.topics.map((t) => t.id).join(", ")})` });
return true;
}
@@ -240,7 +394,13 @@ export function trendingRoute(req, res, url, { json, readBody, authorization })
const action = url.pathname.slice("/api/ops/".length);
requests.push({ action, body, authorization });
if (!body || body.slug !== state.slug) return json(res, 400, { ok: false, error: `${body?.slug} is not an X trending library` });
- const answer = action === "judge-trending" ? judge(body) : action === "watch-trending" ? watch(body) : purge(body);
+ const answer =
+ action === "judge-trending" ? judge(body)
+ : action === "watch-trending" ? watch(body)
+ : action === "organise-trending" ? organise(body)
+ : action === "publish-trending" ? publish(body)
+ : action === "x-search-lead" ? lead(body)
+ : purge(body);
json(res, answer.ok ? 200 : 400, answer);
});
return true;
diff --git a/umtool/e2e/library.spec.ts b/umtool/e2e/library.spec.ts
@@ -108,8 +108,10 @@ test("found from Tools; topics on the left with their counts and what each watch
await expect(page.locator(`[data-library-panel="${KETTLES}"]`)).toContainText("6 posts · 4 unjudged · 0 kept · 1 dropped · 1 later");
// It fits a desk without scrolling sideways.
expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth + 1)).toBe(true);
- // Nothing here offers a post to a project, a report or a site.
- await expect(page.locator("[data-posts-library]").getByRole("button", { name: /add to|publish|cut|project|report/i })).toHaveCount(0);
+ // Nothing here offers a post to a project, a report or a site. THE ONE WAY OUT (lane x-trending-publish) is the
+ // topic's own Publish, the operator's, into a channel on no site: one button, and it names no site.
+ await expect(page.locator("[data-posts-library]").getByRole("button", { name: /add to|cut|project|report|site/i })).toHaveCount(0);
+ await expect(page.locator("[data-posts-library]").getByRole("button", { name: /publish/i })).toHaveText(["Publish kept posts…"]);
await expect(page.locator("[data-posts-library]").getByRole("link", { name: /add to|publish/i })).toHaveCount(0);
});
@@ -608,6 +610,233 @@ test("on a phone (360 px): nothing pushes the page sideways, the topics fold, an
await page.screenshot({ path: test.info().outputPath("library-360.png"), fullPage: true });
});
+// ── lane x-trending-publish: organise, publish, the accounts ───────────────
+
+type Slice4 = StubState & { topics: { id: string; title: string; aliases: string[]; posts: string[] }[]; published: Record<string, { channel: string; posts: string[] }>; archived: Record<string, string> };
+const stub4 = async (request: APIRequestContext): Promise<Slice4> => (await request.get(`${STUB}/__stub/trending`)).json();
+
+test("organise: rename a topic, move the selection to another, merge behind a confirm that says it cannot be undone and which watch stands", async ({ page, request }) => {
+ await open(page, { topic: KETTLES });
+ const organise = page.locator(`[data-library-organise="${KETTLES}"]`);
+
+ // RENAME: the id stays (the address does not change), the rail says the new name.
+ await expect(organise.locator("[data-library-rename]")).toBeDisabled();
+ await organise.locator("[data-library-rename-input]").fill("Kettle festival 2026");
+ await organise.locator("[data-library-rename]").click();
+ await expect(status(page)).toHaveText('Topic "Kettle festival" is now "Kettle festival 2026". Its id stays kettle-festival: its watch, its posts and their judgements are untouched.');
+ expect((await last(request)).action).toBe("organise-trending");
+ expect((await last(request)).body).toEqual({ slug: LIB, op: "rename", topic: KETTLES, title: "Kettle festival 2026", by: "operator" });
+ await expect(rail(page).locator(`[data-library-topic="${KETTLES}"]`)).toContainText("Kettle festival 2026");
+ await idle(page);
+
+ // MOVE: what a press would judge (here the selection) goes to the topic chosen.
+ await expect(page.locator("[data-library-move]")).toBeDisabled();
+ await page.getByLabel("Select the post by @kettle_fan").check();
+ await page.locator("[data-library-move-to]").selectOption(CUPS);
+ await page.locator("[data-library-move]").click();
+ await expect(status(page)).toHaveText('1 post moved to "Cup shortage". Their judgements and captures are untouched.');
+ expect((await last(request)).body).toEqual({ slug: LIB, op: "move", to: CUPS, ids: [P.fresh], by: "operator" });
+ await expect(post(page, P.fresh)).toHaveCount(0);
+ expect((await stub4(request)).topics.find((t) => t.id === CUPS)!.posts).toContain(P.fresh);
+ await idle(page);
+
+ // Mark seen first: umtool's own mark must follow the merge.
+ await page.locator("[data-library-seen]").click();
+ await expect(status(page)).toContainText("marked seen");
+ await idle(page);
+ expect(Object.keys(JSON.parse(readFileSync(SEEN, "utf8")).libraries[LIB].topics)).toEqual([KETTLES]);
+
+ // MERGE: asked twice. The first press writes nothing and says what is true of it.
+ await expect(organise.locator("[data-library-merge]")).toBeDisabled();
+ await organise.locator("[data-library-merge-into]").selectOption(CUPS);
+ await organise.locator("[data-library-merge]").click();
+ const plan = page.locator("[data-library-merge-plan]");
+ await expect(plan.locator("[data-library-merge-sentence]")).toContainText("Merge “Kettle festival 2026” into “Cup shortage”?");
+ await expect(plan.locator("[data-library-merge-sentence]")).toContainText("This cannot be undone: there is no unmerge.");
+ await expect(plan.locator("[data-library-merge-sentence]")).toContainText("Both are watched: the watch of “Cup shortage” stands with its own terms, and this topic's watch is gone.");
+ expect((await stub4(request)).requests.filter((r) => r.body.op === "merge")).toHaveLength(0);
+ await plan.locator("[data-library-merge-no]").click();
+ await expect(plan).toHaveCount(0);
+ expect((await stub4(request)).topics.map((t) => t.id)).toContain(KETTLES);
+
+ await organise.locator("[data-library-merge]").click();
+ await plan.locator("[data-library-merge-yes]").click();
+ await expect(status(page)).toContainText('"Kettle festival 2026" is now part of "Cup shortage"');
+ await expect(status(page)).toContainText("This cannot be undone.");
+ await expect(status(page)).toContainText('The watch of "Cup shortage" stands with its own terms.');
+ const merge = (await stub4(request)).requests.filter((r) => r.body.op === "merge");
+ expect(merge.map((r) => r.body)).toEqual([{ slug: LIB, op: "merge", into: CUPS, from: [KETTLES], by: "operator" }]);
+ // The page is on the topic that stays, which now holds the merged posts.
+ await expect(page).toHaveURL(new RegExp(`topic=${CUPS}`));
+ await expect(page.locator(`[data-library-panel="${CUPS}"]`)).toBeVisible();
+ await expect(post(page, P.opening)).toBeVisible();
+ await expect(rail(page).locator(`[data-library-topic="${KETTLES}"]`)).toHaveCount(0);
+ const after = await stub4(request);
+ expect(after.topics.find((t) => t.id === CUPS)!.aliases).toEqual([KETTLES]);
+ // umtool's mark followed: the topic that stays was never marked, so it stays unmarked and the merged one's mark is gone.
+ expect(JSON.parse(readFileSync(SEEN, "utf8")).libraries[LIB].topics).toEqual({});
+});
+
+test("publish: the first press says exactly what would be written and writes nothing; the slug can be changed before a first publish; publishing again adds and removes nothing", async ({ page, request }) => {
+ // No post kept by the operator: nothing to publish (an agent's judgement is not one).
+ await open(page, { topic: CUPS });
+ await expect(page.locator("[data-library-publish]")).toBeDisabled();
+ await expect(page.locator("[data-library-published]")).toHaveText("Not published.");
+
+ await open(page, { topic: KETTLES });
+ await post(page, P.opening).locator('[data-library-press="keep"]').click();
+ await expect(post(page, P.opening)).toHaveAttribute("data-library-judgement", "keep");
+ await idle(page);
+ await page.locator("[data-library-publish]").click();
+ const plan = page.locator("[data-library-publish-plan]");
+ await expect(plan.locator("[data-library-publish-sentence]")).toHaveText('Publishing "Kettle festival" would make the channel "kettle-festival", on no site, writing 1 post and 3 files (204 B); 0 of the 1 kept post are there already.');
+ await expect(plan.locator("[data-library-publish-numbers]")).toHaveText("channel kettle-festival (new, on no site) · 1 post to add · 3 files · 204 B · 0 there already");
+ let r = await last(request);
+ expect(r.action).toBe("publish-trending");
+ expect(r.body).toEqual({ slug: LIB, topic: KETTLES, dryRun: true, by: "operator" });
+ expect((await stub4(request)).published).toEqual({});
+ await idle(page);
+
+ // The slug, changed before the first publish: counted again under it, and the publish waits for that.
+ await plan.locator("[data-library-publish-channel]").fill("Kettles-2026");
+ await expect(plan.locator("[data-library-publish-yes]")).toBeDisabled();
+ await plan.locator("[data-library-publish-recount]").click();
+ await expect(plan.locator("[data-library-publish-numbers]")).toContainText("channel Kettles-2026 (new, on no site)");
+ expect((await last(request)).body).toEqual({ slug: LIB, topic: KETTLES, channel: "Kettles-2026", dryRun: true, by: "operator" });
+ await idle(page);
+ await expect(plan.locator("[data-library-publish-yes]")).toHaveText("Publish 1 post into “Kettles-2026”");
+ await plan.locator("[data-library-publish-yes]").click();
+ await expect(status(page)).toContainText('Publishing "Kettle festival" made the channel "Kettles-2026", on no site, and wrote 1 post and 3 files');
+ r = await last(request);
+ expect(r.body.by).toBe("operator");
+ expect(r.body.channel).toBe("Kettles-2026");
+ expect(r.body.confirm).toMatch(/^[0-9a-f]{24}$/);
+ expect(r.body.dryRun).toBeUndefined();
+ expect((await stub4(request)).published).toEqual({ [KETTLES]: { channel: "Kettles-2026", posts: [P.opening] } });
+ await expect(page.locator("[data-library-published]")).toHaveAttribute("data-library-published", "Kettles-2026");
+ await expect(page.locator("[data-library-published]")).toContainText("Published into the channel “Kettles-2026”: 1 post, last");
+ await idle(page);
+
+ // AGAIN: the opening post is dropped, the reply kept. One is added; the dropped one is reported and stays.
+ await post(page, P.opening).locator('[data-library-press="drop"]').click();
+ await expect(post(page, P.opening)).toHaveAttribute("data-library-judgement", "drop");
+ await idle(page);
+ await post(page, P.reply).locator('[data-library-press="keep"]').click();
+ await expect(post(page, P.reply)).toHaveAttribute("data-library-judgement", "keep");
+ await idle(page);
+ await page.locator("[data-library-publish]").click();
+ await expect(plan.locator("[data-library-publish-numbers]")).toHaveText("channel Kettles-2026 · 1 post to add · 1 file · 68 B · 0 there already · 1 no longer kept, left");
+ await expect(plan.locator("[data-library-publish-sentence]")).toContainText("1 post published before is no longer kept: it stays in the channel (a publish removes nothing).");
+ // The slug is fixed now: no field for it.
+ await expect(plan.locator("[data-library-publish-channel]")).toHaveCount(0);
+ await idle(page);
+ await plan.locator("[data-library-publish-yes]").click();
+ await expect(status(page)).toContainText('added to the channel "Kettles-2026"');
+ expect((await last(request)).body.channel).toBeUndefined();
+ expect((await stub4(request)).published[KETTLES].posts).toEqual([P.opening, P.reply]);
+ await idle(page);
+
+ // On a phone the panel and an open plan fit.
+ await page.setViewportSize({ width: 360, height: 740 });
+ await page.locator("[data-library-publish]").click();
+ await expect(plan.locator("[data-library-publish-sentence]")).toContainText("Nothing to add");
+ await expect(plan.locator("[data-library-publish-yes]")).toHaveCount(0);
+ for (const sel of ["[data-library-organise]", "[data-library-publish-plan]", "[data-library-move-control]"]) {
+ const box = (await page.locator(sel).first().boundingBox())!;
+ expect(box.x, sel).toBeGreaterThanOrEqual(-1);
+ expect(box.x + box.width, sel).toBeLessThanOrEqual(361);
+ }
+ expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth + 1)).toBe(true);
+ await plan.locator("[data-library-publish-no]").click();
+});
+
+test("the accounts: who wrote the posts; Archive this account makes <handle>-x and asks X nothing", async ({ page, request }) => {
+ await open(page);
+ const accounts = page.locator("[data-library-accounts]");
+ await expect(accounts).toHaveAttribute("data-library-accounts", "closed");
+ await accounts.locator("summary").click();
+ await expect(accounts.locator("[data-library-accounts-count]")).toContainText("accounts. Archiving one makes its own X channel, on no site, and asks X nothing: its first fetch is a separate press in the editor.");
+ const row = accounts.locator('[data-library-account="saucer_fan"]');
+ await expect(row).toContainText("@saucer_fan");
+ await expect(row).toContainText("1 post · 0 kept · Kettle festival");
+ await expect(accounts.locator('[data-library-account="teapot_news"]')).toContainText("2 posts");
+
+ // Asked twice; the first press asks the editor nothing.
+ await row.locator("[data-library-archive]").click();
+ await expect(row.locator("[data-library-archive-plan]")).toContainText("Makes the channel “saucer_fan-x”, on no site. Nothing is asked of X.");
+ expect((await stub4(request)).requests.filter((r) => r.action === "x-search-lead")).toHaveLength(0);
+ await row.locator("[data-library-archive-no]").click();
+ await row.locator("[data-library-archive]").click();
+ await row.locator("[data-library-archive-yes]").click();
+ await expect(status(page)).toHaveText('Made the channel "saucer_fan-x" for @saucer_fan, on no site. Nothing was asked of X: its first fetch is a separate press in the editor (or `pnpm ops fetch-posts`).');
+ // The lead action, "archive", and NO fetch.
+ const r = await last(request);
+ expect(r.action).toBe("x-search-lead");
+ expect(r.body).toEqual({ slug: LIB, handle: "saucer_fan", action: "archive", name: "Saucer Fan" });
+ expect((await stub4(request)).archived).toEqual({ saucer_fan: "saucer_fan-x" });
+ await expect(row.locator("[data-library-account-archived]")).toHaveText("archived as saucer_fan-x");
+ await expect(row.locator("[data-library-archive]")).toHaveCount(0);
+
+ // Of one topic.
+ await open(page, { topic: CUPS });
+ await page.locator("[data-library-accounts] summary").click();
+ await expect(page.locator("[data-library-account]")).toHaveCount(1);
+ await expect(page.locator('[data-library-account="cup_other"]')).toContainText("2 posts · 0 kept");
+});
+
+test("the organise, publish and archive routes take a press from umtool's own page only, and stamp it the operator's", async ({ request, baseURL }) => {
+ const page = asPage(baseURL);
+ const bodies: Record<string, Record<string, unknown>> = {
+ organise: { lib: LIB, op: "rename", topic: "lids", title: "Lids and tops", by: "agent" },
+ publish: { lib: LIB, topic: KETTLES, dryRun: true, by: "agent" },
+ archive: { lib: LIB, handle: "lid_watch", dryRun: true, fetch: true },
+ };
+ // A request no browser sent — curl, a script, an agent, with a bearer or with nothing — is refused before its body is read.
+ const before = (await stub(request)).requests.length;
+ for (const [route, data] of Object.entries(bodies)) {
+ for (const headers of [{}, { authorization: "Bearer umtool-e2e-token" }, { ...page, authorization: "Bearer umtool-e2e-token" }, { origin: "https://example.org", "sec-fetch-site": "cross-site" }] as Record<string, string>[]) {
+ const res = await request.post(`/api/library/${route}`, { headers, data });
+ expect(res.status(), `${route} ${JSON.stringify(headers)}`).toBe(403);
+ if (!headers.origin || headers.authorization) expect((await res.json()).error).toContain("`organise-trending` / `publish-trending` or `umtool library`");
+ }
+ }
+ for (const data of [{ lib: LIB, op: "merge", into: KETTLES, from: [CUPS] }, { lib: LIB, topic: KETTLES, confirm: "FAKE-TEST-VALUE01234567" }]) {
+ expect((await request.post(`/api/library/${"op" in data ? "organise" : "publish"}`, { data })).status()).toBe(403);
+ }
+ expect((await stub(request)).requests.length).toBe(before);
+
+ // The page's own press, whatever its body says about who.
+ expect((await request.post("/api/library/organise", { headers: page, data: bodies.organise })).status()).toBe(200);
+ expect((await last(request)).body).toEqual({ slug: LIB, op: "rename", topic: "lids", title: "Lids and tops", by: "operator" });
+ // No post kept by the operator: the editor's refusal, in its words.
+ const none = await request.post("/api/library/publish", { headers: page, data: bodies.publish });
+ expect(none.status()).toBe(400);
+ expect((await none.json()).error).toContain('The operator has kept no post in "Kettle festival"');
+ expect((await last(request)).body).toEqual({ slug: LIB, topic: KETTLES, dryRun: true, by: "operator" });
+ // A publish with no dry run's confirm asks the editor nothing.
+ const asked = (await stub(request)).requests.length;
+ const noConfirm = await request.post("/api/library/publish", { headers: page, data: { lib: LIB, topic: KETTLES } });
+ expect(noConfirm.status()).toBe(400);
+ expect((await noConfirm.json()).error).toContain('carries the "confirm" its dry run answered');
+ expect((await stub(request)).requests.length).toBe(asked);
+ // Archive never sends "fetch", even when the body asks for it.
+ const dry = await request.post("/api/library/archive", { headers: page, data: bodies.archive });
+ expect(dry.status()).toBe(200);
+ expect((await last(request)).body).toEqual({ slug: LIB, handle: "lid_watch", action: "archive", dryRun: true });
+ expect((await dry.json()).sentence).toBe('Would make the channel "lid_watch-x" for @lid_watch, on no site. Nothing is asked of X: its first fetch is a separate press in the editor.');
+ // An agent's merge cannot come through the page's route dressed as the operator's without a browser; from the page it is the operator's.
+ expect((await request.post("/api/library/organise", { headers: page, data: { lib: LIB, op: "merge", into: KETTLES, from: ["lids"], by: "agent" } })).status()).toBe(200);
+ expect((await last(request)).body).toEqual({ slug: LIB, op: "merge", into: KETTLES, from: ["lids"], by: "operator" });
+
+ // The accounts read: umtool's own pages only, never cached.
+ const read = await request.get(`/api/library/accounts?lib=${LIB}`);
+ expect(read.status()).toBe(200);
+ expect(read.headers()["cache-control"]).toBe("private, no-store");
+ expect((await read.json()).accounts.map((a: { handle: string }) => a.handle)).toContain("teapot_news");
+ expect((await request.get(`/api/library/accounts?lib=${LIB}`, { headers: { "sec-fetch-site": "cross-site" } })).status()).toBe(403);
+ expect((await request.get("/api/library/accounts?lib=../x")).status()).toBe(400);
+});
+
test("with the editor down, or holding no library, the page says so in a sentence", async ({ page, request }) => {
await reset(request, "unreachable");
await page.goto(lib());