Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 668d1c883edf6c068f187431ce2ad5710833efc0
parent 6124d708628610d8507b5e16ee75384b7a2e87ec
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 18 Nov 2026 12:05:07 -0500

review 1 M1: "Archive this account" from a library makes the channel with sync off -- a never-synced channel with a URL was due at the scheduler's next tick

From a library, with no "fetch": true, the new <handle>-x channel's
priority tier is written `paused` BEFORE the channel is created (and
cleared if the creation fails), so there is no moment at which it exists
and is due. `paused` is the one switch the sync scheduler, Sync all and
the four lanes all ask (isChannelPaused): common/jobs/xLeadSyncOff.test.ts
shows the channel due without it and, with it, not due, not eligible in
the schedule view, and out of every operation. The ops answer carries
syncOff and one sentence (sync off, nothing asked of X, how to turn sync
on and run the first fetch); umtool's page and CLI print that sentence
whole. An X search channel's lead is archived exactly as before:
xLeadArchiveMode pins both.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Acommon/jobs/xLeadSyncOff.test.ts | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/lib/xSearch/leads.ts | 27+++++++++++++++++++++++++++
Meditor/app/api/ops/x-search-lead/route.ts | 22+++++++++++++++++-----
Meditor/app/channels/[slug]/xSearchActions.ts | 34++++++++++++++++++++++++++--------
Meditor/e2e/x-trending.spec.ts | 10+++++++++-
Mscripts/archilyzer-ops.mjs | 9+++++++--
Mumtool/app/api/library/archive/route.ts | 6++++--
Mumtool/components/tools/library/OrganisePanel.tsx | 6+++---
Mumtool/e2e/fixtures/editor-stub-trending.mjs | 13++++++++++++-
Mumtool/e2e/library.spec.ts | 11+++++++----
Mumtool/lib/library/cli.mjs | 12+++++++++---
Mumtool/lib/library/organise.test.mjs | 19+++++++++++++------
Mumtool/lib/library/presses.mjs | 10++++++----
13 files changed, 209 insertions(+), 39 deletions(-)

diff --git a/common/jobs/xLeadSyncOff.test.ts b/common/jobs/xLeadSyncOff.test.ts @@ -0,0 +1,69 @@ +// "ARCHIVE THIS ACCOUNT" FROM A LIBRARY ASKS X NOTHING, NOW OR LATER (lane +// x-trending-publish, review 1 M1). The channel it makes has a URL and has +// never synced: the most overdue channel the scheduler knows. So it is made +// with its priority tier `paused`, and this pins that every automatic door +// honours that one switch: the sync scheduler (selectDueChannels and the +// schedule view), Sync all's skip, and the four lanes. And that an X SEARCH +// channel's lead is archived exactly as before. +// +// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test jobs/xLeadSyncOff.test.ts + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import type { ChannelConfig } from "../lib/channelConfig"; +import { channelsForOperation, isChannelPaused, PRIORITY_OPERATIONS, sanitizeChannelPriority } from "../lib/channelPriority"; +import { defaultSyncScheduler } from "../lib/settings"; +import { xLeadArchiveMode, xLeadChannelFields, xLeadChannelSlug, xLeadSyncOffSentence } from "../lib/xSearch/leads"; +import { buildScheduleView, selectDueChannels } from "./syncScheduler"; +import { emptySchedulerState } from "./syncSchedulerState"; + +const NOW = Date.parse("2026-11-18T12:00:00.000Z"); +const scheduler = { ...defaultSyncScheduler(), enabled: true, defaultIntervalMinutes: 60, quietHoursStart: null, quietHoursEnd: null }; + +// The channel as "Archive this account" makes it: the lead's own fields, never synced. +const slug = xLeadChannelSlug("saucer_fan"); +const fields = xLeadChannelFields({ handle: "saucer_fan" }); +const config = { handling: "transcribe", name: fields.name, url: fields.url, platform: "twitter", sourceKind: "social", postFetcher: fields.postFetcher, socialHandle: fields.socialHandle } as ChannelConfig; +const channels = [{ slug, config }]; +const due = (priority: ReturnType<typeof sanitizeChannelPriority>) => + selectDueChannels({ channels, scheduler, state: emptySchedulerState(), activeSlugs: new Set<string>(), now: NOW, priority }).due; + +test("the mode: from a library nothing is fetched and sync is off unless fetch is asked; from a search channel nothing changed", () => { + assert.deepEqual(xLeadArchiveMode({ library: true }), { fetchNow: false, syncOff: true }); + assert.deepEqual(xLeadArchiveMode({ library: true, fetch: false }), { fetchNow: false, syncOff: true }); + assert.deepEqual(xLeadArchiveMode({ library: true, fetch: true }), { fetchNow: true, syncOff: false }); + // AN X SEARCH CHANNEL'S LEAD, AS IT ALWAYS WAS: the first fetch starts unless `fetch: false`; sync is never touched. + assert.deepEqual(xLeadArchiveMode({ library: false }), { fetchNow: true, syncOff: false }); + assert.deepEqual(xLeadArchiveMode({ library: false, fetch: true }), { fetchNow: true, syncOff: false }); + assert.deepEqual(xLeadArchiveMode({ library: false, fetch: false }), { fetchNow: false, syncOff: false }); +}); + +test("WITHOUT the switch the new channel is fetched at the scheduler's next tick: a never-synced channel with a URL is due at once", () => { + assert.deepEqual(due(sanitizeChannelPriority({ channels: {} })), [slug]); +}); + +test("with its tier paused it is not due, not eligible, skipped by Sync all's question, and in no lane", () => { + const priority = sanitizeChannelPriority({ channels: { [slug]: { tier: "paused" } } }); + // The sync scheduler. + assert.deepEqual(due(priority), []); + const view = buildScheduleView({ channels, scheduler, state: emptySchedulerState(), now: NOW, priority }); + assert.equal(view[0].autoSyncEligible, false); + // Sync all asks exactly this (editor channels/actions.ts syncAllChannelsAction: "paused for sync"). + assert.equal(isChannelPaused(priority, slug, "sync"), true); + // The four lanes, and sync: every operation there is. + for (const op of PRIORITY_OPERATIONS) { + assert.equal(isChannelPaused(priority, slug, op), true, op); + assert.deepEqual(channelsForOperation(priority, [slug], op), [], op); + } + // Turned on again (tier normal): due, as any channel. + assert.deepEqual(due(sanitizeChannelPriority({ channels: { [slug]: { tier: "normal" } } })), [slug]); +}); + +test("the sentence says the three things: sync off, nothing asked of X, and how to turn sync on and run the first fetch", () => { + assert.equal( + xLeadSyncOffSentence("saucer_fan-x", "@saucer_fan"), + `Made the channel "saucer_fan-x" for @saucer_fan, on no site, with sync off (its priority is paused): nothing was asked of X, and nothing will be until you say so. ` + + `To turn sync on, set its priority to normal on /channels (pnpm ops channel-priority --json '{"slugs":["saucer_fan-x"],"tier":"normal"}'). ` + + `Its first fetch is Fetch posts on its page (pnpm ops fetch-posts --json '{"slug":"saucer_fan-x"}').`, + ); +}); diff --git a/common/lib/xSearch/leads.ts b/common/lib/xSearch/leads.ts @@ -151,3 +151,30 @@ export function xLeadChannelFields(lead: { handle: string; name?: string }): Rec socialHandle: handle, }; } + +// WHAT "ARCHIVE THIS ACCOUNT" DOES BESIDE MAKING THE CHANNEL, by where the +// lead came from (lane x-trending-publish, review 1 M1). +// +// From an X SEARCH channel's leads, as always: the first fetch starts unless +// `fetch: false`, and the channel syncs like any other. +// +// From an X TRENDING LIBRARY's accounts: NOTHING IS ASKED OF X unless `fetch: +// true`. Not starting the first fetch is not enough: a channel with a URL +// that has never synced is the most overdue one the scheduler knows, and the +// next tick would fetch it. So the channel is made with SYNC OFF: its +// priority tier `paused` (lib/channelPriority.ts), the one switch the sync +// scheduler, Sync all and the four lanes all ask (`isChannelPaused`). +export function xLeadArchiveMode(o: { library: boolean; fetch?: boolean }): { fetchNow: boolean; syncOff: boolean } { + if (o.library) return o.fetch === true ? { fetchNow: true, syncOff: false } : { fetchNow: false, syncOff: true }; + return { fetchNow: o.fetch !== false, syncOff: false }; +} + +// What is said of a channel made with sync off: the page, the ops answer and +// the CLI print this, whole. +export function xLeadSyncOffSentence(slug: string, handle: string): string { + return ( + `Made the channel "${slug}" for @${handle.replace(/^@/, "")}, on no site, with sync off (its priority is paused): nothing was asked of X, and nothing will be until you say so. ` + + `To turn sync on, set its priority to normal on /channels (pnpm ops channel-priority --json '{"slugs":["${slug}"],"tier":"normal"}'). ` + + `Its first fetch is Fetch posts on its page (pnpm ops fetch-posts --json '{"slug":"${slug}"}').` + ); +} diff --git a/editor/app/api/ops/x-search-lead/route.ts b/editor/app/api/ops/x-search-lead/route.ts @@ -23,10 +23,16 @@ export const dynamic = "force-dynamic"; // AN X TRENDING LIBRARY'S ACCOUNTS ARE LEADS TOO (lane x-trending-publish): // with `slug` a library, "archive" makes `<handle>-x` for an account that // wrote a post the library holds — on no site, naming nothing of the library -// — and ASKS X NOTHING: there the first fetch is not started unless `fetch: -// true` (it is a separate press, `pnpm ops fetch-posts`). "never" and -// "restore" are a search channel's only. Read the accounts with -// `get trending <slug> --accounts`. +// — and ASKS X NOTHING, now or later: no first fetch is started, and the +// channel is made with SYNC OFF (its priority tier `paused`, which the sync +// scheduler, Sync all and the lanes all honour; a never-synced channel with a +// URL would otherwise be fetched at the scheduler's next tick). The answer +// then carries `syncOff: true` and `sentence`, which says how to turn sync on +// (`pnpm ops channel-priority`, tier "normal") and run the first fetch +// (`pnpm ops fetch-posts`). `fetch: true` asks for the ordinary behaviour +// instead: the first fetch started, sync on. "never" and "restore" are a +// search channel's only. Read the accounts with `get trending <slug> +// --accounts`. export async function POST(request: Request) { return ops(request, ["slug", "handle", "action", "name", "fetch", "dryRun"], async (body) => { const slug = reqSlug(body, "slug"); @@ -42,7 +48,13 @@ export async function POST(request: Request) { if (!res.ok) return opsFail(res.error); if (res.dryRun) return NextResponse.json({ ok: true, dryRun: true, slug: res.slug, fields: res.fields }); const jobIds = res.jobIds ?? []; - return NextResponse.json({ ok: true, slug: res.slug, jobIds, ...(jobIds.length === 1 ? { jobId: jobIds[0] } : {}) }); + return NextResponse.json({ + ok: true, + slug: res.slug, + jobIds, + ...(jobIds.length === 1 ? { jobId: jobIds[0] } : {}), + ...(res.syncOff ? { syncOff: true, sentence: res.sentence } : {}), + }); } if (body.dryRun !== undefined || body.name !== undefined || body.fetch !== undefined) { return opsFail(`"dryRun", "name" and "fetch" apply only to action "archive"`); diff --git a/editor/app/channels/[slug]/xSearchActions.ts b/editor/app/channels/[slug]/xSearchActions.ts @@ -18,10 +18,11 @@ import { import { isXTrendingLibrary } from "yt-dlp-transcript-common/lib/xTrending/library-server"; import { safeRevalidate } from "../../lib/safeRevalidate"; import { applyChannelFormPatch } from "../components/channelConfigToForm"; -import { createChannelFromForm } from "../actions"; +import { applyChannelPriorityPresetAction, createChannelFromForm, setChannelTierAction } from "../actions"; +import { xLeadArchiveMode, xLeadSyncOffSentence } from "yt-dlp-transcript-common/lib/xSearch/leads"; export type XLeadActionResult = - | { ok: true; slug?: string; jobIds?: string[]; exclude?: string[]; changed?: boolean; dryRun?: boolean; fields?: Record<string, string> } + | { ok: true; slug?: string; jobIds?: string[]; exclude?: string[]; changed?: boolean; dryRun?: boolean; fields?: Record<string, string>; syncOff?: boolean; sentence?: string } | { ok: false; error: string }; export async function readXSearchLeadsAction( @@ -46,15 +47,32 @@ export async function archiveXSearchLeadAction( applyChannelFormPatch(fd, plan.fields); fd.set("slug", plan.slug); // From an X TRENDING LIBRARY's accounts (lane x-trending-publish) the press - // makes the channel and asks X nothing: the first fetch is its own press - // (`fetch: true` asks for it here). From a search channel's leads it starts, - // as it always did, unless `fetch: false`. + // makes the channel and asks X nothing, now or at the scheduler's next tick: + // the channel is made with SYNC OFF (lib/xSearch/leads.ts xLeadArchiveMode + // says why). The tier is written BEFORE the channel is, so there is no + // moment at which the new channel exists and is due. From a search + // channel's leads nothing changes: the first fetch starts unless `fetch: + // false`, and no priority is written. const library = await isXTrendingLibrary(getPaths().channelsDir, slug); - if (opts.fetch ?? !library) fd.set("fetchPostsNow", "on"); + const mode = xLeadArchiveMode({ library, ...(opts.fetch !== undefined ? { fetch: opts.fetch } : {}) }); + if (mode.fetchNow) fd.set("fetchPostsNow", "on"); + if (mode.syncOff) { + const paused = await setChannelTierAction([plan.slug], "paused"); + if (paused?.error) return { ok: false, error: `The channel was not made: its sync could not be switched off first (${paused.error}).` }; + } const created = await createChannelFromForm(fd); - if (!created.ok) return { ok: false, error: created.error }; + if (!created.ok) { + // No channel: no entry for it either. + if (mode.syncOff) await applyChannelPriorityPresetAction([plan.slug], "clear"); + return { ok: false, error: created.error }; + } safeRevalidate([`/channels/${slug}`, `/channels/${created.slug}`, "/channels"]); - return { ok: true, slug: created.slug, jobIds: created.jobIds }; + return { + ok: true, + slug: created.slug, + jobIds: created.jobIds, + ...(mode.syncOff ? { syncOff: true, sentence: xLeadSyncOffSentence(created.slug, handle) } : {}), + }; } // Never archive (hidden: true) and its undo (hidden: false). diff --git a/editor/e2e/x-trending.spec.ts b/editor/e2e/x-trending.spec.ts @@ -502,7 +502,15 @@ test("an X trending library: rename, move, merge; a topic published into an ordi 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: [] }); + expect(archived.json).toMatchObject({ ok: true, slug: "saucer_fan-x", jobIds: [], syncOff: true }); + // M1: MADE WITH SYNC OFF. A never-synced channel with a URL is the most overdue one the scheduler knows, so + // without this its next tick would fetch it. The sentence says so and how to turn it on. + expect(String(archived.json.sentence)).toBe( + `Made the channel "saucer_fan-x" for @saucer_fan, on no site, with sync off (its priority is paused): nothing was asked of X, and nothing will be until you say so. To turn sync on, set its priority to normal on /channels (pnpm ops channel-priority --json '{"slugs":["saucer_fan-x"],"tier":"normal"}'). Its first fetch is Fetch posts on its page (pnpm ops fetch-posts --json '{"slug":"saucer_fan-x"}').`, + ); + const settings = await readJson<{ channelPriority?: { channels?: Record<string, { tier?: string }> } }>(testPaths().settingsFile); + expect(settings.channelPriority?.channels?.["saucer_fan-x"]).toMatchObject({ tier: "paused" }); + // (That a paused tier keeps it out of the scheduler, Sync all and the lanes: common/jobs/xLeadSyncOff.test.ts.) 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); diff --git a/scripts/archilyzer-ops.mjs b/scripts/archilyzer-ops.mjs @@ -1837,8 +1837,13 @@ export function usage() { " An X TRENDING LIBRARY's accounts (get trending <slug> --accounts) are", " leads too: with \"slug\" a library, \"archive\" creates <handle>-x for an", " account that wrote a post the library holds, on no site, naming nothing", - " of the library, and ASKS X NOTHING: there the first fetch is not started", - " unless \"fetch\": true (it is its own step: fetch-posts). \"never\" and", + " of the library, and ASKS X NOTHING, now or later: no first fetch is", + " started and the channel is made with SYNC OFF (its priority tier", + " paused, which the scheduler, Sync all and the lanes honour) ->", + " {slug, jobIds: [], syncOff: true, sentence}. The sentence says how to", + " turn sync on (channel-priority, tier normal) and run the first fetch", + " (fetch-posts). \"fetch\": true asks for the ordinary behaviour instead", + " (the first fetch started, sync on). \"never\" and", " \"restore\" are a search channel's only.", "", 'rename-channel moves a channel to a new slug, as Danger → Rename does:', diff --git a/umtool/app/api/library/archive/route.ts b/umtool/app/api/library/archive/route.ts @@ -9,8 +9,10 @@ export const dynamic = "force-dynamic"; // the editor's `x-search-lead`, action "archive", for an account that wrote a // post the library holds — `<handle>-x`, an X channel on NO site that names // nothing of the library. The page's press only (lib/library/route.ts). IT -// ASKS X NOTHING: this route never sends "fetch"; the new channel's first -// fetch is a separate press in the editor. +// ASKS X NOTHING, now or later: this route never sends "fetch", and the editor +// makes the channel with SYNC OFF (a never-synced channel with a URL would +// otherwise be fetched at the scheduler's next tick). The answer's sentence is +// the editor's: it says how to turn sync on and run the first fetch. export async function POST(request: Request) { return press(request, (body) => archivePress(ask, body)); } diff --git a/umtool/components/tools/library/OrganisePanel.tsx b/umtool/components/tools/library/OrganisePanel.tsx @@ -17,7 +17,7 @@ import type { LibraryTopic } from "@/lib/library/load"; // publish the posts the operator KEPT, into an ordinary channel on no // site: the first press says exactly what would be written // accounts who wrote the library's posts; "Archive this account" makes -// <handle>-x on no site and asks X nothing +// <handle>-x on no site, with sync off, and asks X nothing type Run = (what: () => Promise<string | void>) => Promise<void>; @@ -277,7 +277,7 @@ export function AccountsPanel({ lib, topic, topics, off, run }: { lib: string; t <> <p className="m-0 mt-2 text-[12px] text-muted" data-library-accounts-count={state.total}> {state.total} account{state.total === 1 ? "" : "s"} - {state.more ? `, the first ${state.accounts.length} shown` : ""}. Archiving one makes its own X channel, on no site, and asks X nothing: its first fetch is a separate press in the editor. + {state.more ? `, the first ${state.accounts.length} shown` : ""}. Archiving one makes its own X channel, on no site, with sync off: nothing is asked of X until you turn its sync on or fetch it in the editor. </p> <ul className="m-0 mt-2 list-none space-y-1.5 p-0"> {state.accounts.map((a) => { @@ -297,7 +297,7 @@ export function AccountsPanel({ lib, topic, topics, off, run }: { lib: string; t </span> ) : asking === a.handle ? ( <span role="alertdialog" aria-label="Archive this account" className="inline-flex flex-wrap items-center gap-1.5" data-library-archive-plan={a.handle}> - Makes the channel “{a.handle.toLowerCase()}-x”, on no site. Nothing is asked of X. + Makes the channel “{a.handle.toLowerCase()}-x”, on no site, with sync off. Nothing is asked of X. <Button size="sm" variant="go" diff --git a/umtool/e2e/fixtures/editor-stub-trending.mjs b/umtool/e2e/fixtures/editor-stub-trending.mjs @@ -266,7 +266,18 @@ function lead(body) { 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}`] : [] }; + if (body.fetch === true) return { ok: true, slug, jobIds: [`stub-fetch-${++jobs}`] }; + // The editor's sentence (common/lib/xSearch/leads.ts xLeadSyncOffSentence). + return { + ok: true, + slug, + jobIds: [], + syncOff: true, + sentence: + `Made the channel "${slug}" for @${handle}, on no site, with sync off (its priority is paused): nothing was asked of X, and nothing will be until you say so. ` + + `To turn sync on, set its priority to normal on /channels (pnpm ops channel-priority --json '{"slugs":["${slug}"],"tier":"normal"}'). ` + + `Its first fetch is Fetch posts on its page (pnpm ops fetch-posts --json '{"slug":"${slug}"}').`, + }; } function judge(body) { diff --git a/umtool/e2e/library.spec.ts b/umtool/e2e/library.spec.ts @@ -755,7 +755,7 @@ test("the accounts: who wrote the posts; Archive this account makes <handle>-x a 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."); + await expect(accounts.locator("[data-library-accounts-count]")).toContainText("accounts. Archiving one makes its own X channel, on no site, with sync off: nothing is asked of X until you turn its sync on or fetch it 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"); @@ -763,12 +763,15 @@ test("the accounts: who wrote the posts; Archive this account makes <handle>-x a // 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."); + await expect(row.locator("[data-library-archive-plan]")).toContainText("Makes the channel “saucer_fan-x”, on no site, with sync off. 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 editor's sentence, whole: sync off, nothing asked of X, how to turn sync on and run the first fetch. + await expect(status(page)).toHaveText( + `Made the channel "saucer_fan-x" for @saucer_fan, on no site, with sync off (its priority is paused): nothing was asked of X, and nothing will be until you say so. To turn sync on, set its priority to normal on /channels (pnpm ops channel-priority --json '{"slugs":["saucer_fan-x"],"tier":"normal"}'). Its first fetch is Fetch posts on its page (pnpm ops fetch-posts --json '{"slug":"saucer_fan-x"}').`, + ); // The lead action, "archive", and NO fetch. const r = await last(request); expect(r.action).toBe("x-search-lead"); @@ -823,7 +826,7 @@ test("the organise, publish and archive routes take a press from umtool's own pa 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.'); + expect((await dry.json()).sentence).toBe('Would make the channel "lid_watch-x" for @lid_watch, on no site, with sync off. Nothing is asked of X.'); // 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" }); diff --git a/umtool/lib/library/cli.mjs b/umtool/lib/library/cli.mjs @@ -42,7 +42,7 @@ export const LIBRARY_USAGE = [ " the operator's kept posts into a channel on no site", "umtool library accounts <lib> [--topic T] [--limit N] [--json] the library's accounts: posts, kept, topics", "umtool library archive <lib> <handle> [--name NAME] [--dry-run] [--fetch]", - " <handle>-x on no site; asks X nothing unless --fetch", + " <handle>-x on no site, with sync off; asks X nothing unless --fetch", ].join("\n"); class Refusal extends Error {} @@ -283,8 +283,14 @@ export async function libraryCommand(args, deps = {}) { const handle = words[2]; if (!handle) throw new Refusal("archive: umtool library archive <lib> <handle>"); const done = await archiveAccount(ask, { slug: lib, handle: handle.replace(/^@/, ""), ...(flags["--name"] ? { name: flags["--name"] } : {}), ...(flags["--dry-run"] ? { dryRun: true } : {}), ...(flags["--fetch"] ? { fetch: true } : {}) }); - const asked = flags["--fetch"] && !flags["--dry-run"] ? `Its first fetch was started${done.jobIds?.length ? ` (${done.jobIds.join(", ")})` : ""}.` : "Nothing was asked of X: its first fetch is a separate step (pnpm ops fetch-posts)."; - say(done, `${flags["--dry-run"] ? "Would make" : "Made"} the channel "${done.slug}" for @${handle.replace(/^@/, "")}, on no site. ${flags["--dry-run"] ? "A dry run creates nothing." : asked}`); + const h = handle.replace(/^@/, ""); + const text = flags["--dry-run"] + ? `Would make the channel "${done.slug}" for @${h}, on no site${flags["--fetch"] ? ", and start its first fetch" : ", with sync off. Nothing is asked of X"}. A dry run creates nothing.` + : flags["--fetch"] + ? `Made the channel "${done.slug}" for @${h}, on no site. Its first fetch was started${done.jobIds?.length ? ` (${done.jobIds.join(", ")})` : ""}.` + : // The editor's own sentence: sync off, nothing asked of X, how to turn sync on and run the first fetch. + String(done.sentence ?? `Made the channel "${done.slug}" for @${h}, on no site.`); + say(done, text); return 0; } throw new Refusal(`library: unknown verb "${sub}"\n${LIBRARY_USAGE}`); diff --git a/umtool/lib/library/organise.test.mjs b/umtool/lib/library/organise.test.mjs @@ -15,6 +15,7 @@ import { archivePress, organisePress, PressError, publishPress } from "./presses import { markSeen, mergeSeen, seenFile, seenOf } from "./seen.mjs"; const CONFIRM = "FAKE-TEST-VALUE01234567"; +const SYNC_OFF = (slug, handle) => `Made the channel "${slug}" for @${handle}, on no site, with sync off (its priority is paused): nothing was asked of X, and nothing will be until you say so. To turn sync on, set its priority to normal on /channels. Its first fetch is Fetch posts on its page.`; function editor({ refuse } = {}) { const asked = []; @@ -32,7 +33,11 @@ function editor({ refuse } = {}) { ? { ok: true, dryRun: true, channel: b.channel ?? "kettles", creates: true, posts: 2, files: 3, bytes: 204, confirm: CONFIRM, sentence: 'Publishing "Kettles" would make the channel "kettles", on no site.' } : { ok: true, dryRun: false, channel: "kettles", creates: true, posts: 2, files: 3, bytes: 204, confirm: CONFIRM, sentence: 'Publishing "Kettles" made the channel "kettles", on no site.' }; } - if (route === "/api/ops/x-search-lead") return b.dryRun ? { ok: true, dryRun: true, slug: `${b.handle}-x`, fields: {} } : { ok: true, slug: `${b.handle}-x`, jobIds: b.fetch ? ["job-1"] : [] }; + if (route === "/api/ops/x-search-lead") { + if (b.dryRun) return { ok: true, dryRun: true, slug: `${b.handle}-x`, fields: {} }; + // From a library with no "fetch": sync off, and the editor's own sentence. + return b.fetch ? { ok: true, slug: `${b.handle}-x`, jobIds: ["job-1"] } : { ok: true, slug: `${b.handle}-x`, jobIds: [], syncOff: true, sentence: SYNC_OFF(`${b.handle}-x`, b.handle) }; + } if (route.startsWith("/api/ops/trending?")) { return { ok: true, accounts: [{ handle: "teapot_news", posts: 3, kept: 2, keptByOperator: 1, topics: ["kettles", "cups"], archivedAs: ["teapot_news-x"] }, { handle: "saucer_fan", posts: 1, kept: 0, keptByOperator: 0, topics: ["cups"] }], total: 2, posts: 4, more: 0 }; } @@ -133,9 +138,11 @@ test("the publish press: two steps, the operator's; a confirm that is not a dry test("Archive this account from the page: the lead action, and never a fetch", async () => { const e = editor(); const dry = await archivePress(e.ask, { lib: "lib", handle: "@saucer_fan", name: "Saucer Fan", dryRun: true, fetch: true }); - assert.match(dry.sentence, /^Would make the channel "saucer_fan-x" for @saucer_fan, on no site\. Nothing is asked of X/); + assert.equal(dry.sentence, 'Would make the channel "saucer_fan-x" for @saucer_fan, on no site, with sync off. Nothing is asked of X.'); const done = await archivePress(e.ask, { lib: "lib", handle: "saucer_fan", fetch: true }); - assert.match(done.sentence, /^Made the channel "saucer_fan-x" for @saucer_fan, on no site\. Nothing was asked of X/); + // The editor's sentence, whole: sync off, nothing asked of X, how to turn sync on and run the first fetch. + assert.equal(done.sentence, SYNC_OFF("saucer_fan-x", "saucer_fan")); + assert.equal(done.syncOff, true); assert.deepEqual(e.posts().map((p) => p.body), [ { slug: "lib", handle: "saucer_fan", action: "archive", name: "Saucer Fan", dryRun: true }, { slug: "lib", handle: "saucer_fan", action: "archive" }, @@ -208,11 +215,11 @@ test("umtool library accounts and archive: the accounts by posts; archive asks X assert.equal(e.asked[0].route, "/api/ops/trending?slug=lib&accounts=1&topic=cups&limit=20"); assert.equal(view.lines[0], "2 accounts over 4 posts\n@teapot_news 3 posts · 2 kept · topics: kettles, cups · archived as teapot_news-x\n@saucer_fan 1 post · 0 kept · topics: cups"); const dry = await cli(["archive", "lib", "@saucer_fan", "--dry-run"], e, root); - assert.match(dry.lines[0], /^Would make the channel "saucer_fan-x" for @saucer_fan, on no site\. A dry run creates nothing\.$/); + assert.equal(dry.lines[0], 'Would make the channel "saucer_fan-x" for @saucer_fan, on no site, with sync off. Nothing is asked of X. A dry run creates nothing.'); const made = await cli(["archive", "lib", "saucer_fan", "--name", "Saucer Fan"], e, root); - assert.match(made.lines[0], /^Made the channel "saucer_fan-x" for @saucer_fan, on no site\. Nothing was asked of X/); + assert.equal(made.lines[0], SYNC_OFF("saucer_fan-x", "saucer_fan")); const fetched = await cli(["archive", "lib", "saucer_fan", "--fetch"], e, root); - assert.match(fetched.lines[0], /Its first fetch was started \(job-1\)\.$/); + assert.equal(fetched.lines[0], 'Made the channel "saucer_fan-x" for @saucer_fan, on no site. Its first fetch was started (job-1).'); assert.deepEqual(e.posts().map((p) => p.body), [ { slug: "lib", handle: "saucer_fan", action: "archive", dryRun: true }, { slug: "lib", handle: "saucer_fan", action: "archive", name: "Saucer Fan" }, diff --git a/umtool/lib/library/presses.mjs b/umtool/lib/library/presses.mjs @@ -234,8 +234,8 @@ export async function publishPress(ask, body) { /** * POST /api/library/archive: { lib, handle, name?, dryRun? } — "Archive this account": the editor's - * x-search-lead (action "archive") for an account of the library. It makes `<handle>-x` on NO site and ASKS X - * NOTHING: this route never sends "fetch" (the first fetch is the editor's own press). Answers + * x-search-lead (action "archive") for an account of the library. It makes `<handle>-x` on NO site, WITH SYNC OFF, + * and ASKS X NOTHING, now or at the scheduler's next tick: this route never sends "fetch". Answers * { ok, slug, jobIds?, dryRun?, fields?, sentence }. */ export async function archivePress(ask, body) { @@ -246,9 +246,11 @@ export async function archivePress(ask, body) { const out = await archiveAccount(ask, { slug: lib, handle, ...(body.name ? { name: body.name } : {}), ...(body.dryRun === true ? { dryRun: true } : {}) }); return { ...out, + // The made channel's sentence is the EDITOR's (sync off, nothing asked of X, how to turn sync on and run the + // first fetch): nothing is added to it here. sentence: body.dryRun === true - ? `Would make the channel "${out.slug}" for @${handle}, on no site. Nothing is asked of X: its first fetch is a separate press in the editor.` - : `Made the channel "${out.slug}" for @${handle}, on no site. Nothing was asked of X: its first fetch is a separate press in the editor (or \`pnpm ops fetch-posts\`).`, + ? `Would make the channel "${out.slug}" for @${handle}, on no site, with sync off. Nothing is asked of X.` + : String(out.sentence ?? `Made the channel "${out.slug}" for @${handle}, on no site.`), }; }