Archilyzer · Source

archilyzer

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

commit 0cd0e3fa249950c9b6222d3c339d2040cb752e8e
parent 24b70f3818de7cade05dffb9affa0df9f25bf23d
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 17 Nov 2026 21:10:07 -0500

x-trending review 1 (SHOULD 2): the marker cannot be switched off

The marker alone decides (previous commit). The channel form forces a library's kind
to "social" and refuses any other by name; a Configure save or channel-config patch
that changes a library's platform, kind or URL, or removes the marker, is refused
before anything is written, with the library's own sentence (asked of the platform
choice before the parse, and of the parsed config after it). Create with platform
"x-trending" and sourceKind "video" is refused.

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

Diffstat:
Meditor/app/api/ops/read-x-trending/route.test.ts | 22+++++++++++++++++++++-
Meditor/app/channels/actions.ts | 32++++++++++++++++++++------------
Meditor/app/channels/components/parseChannelForm.ts | 8+++++++-
3 files changed, 48 insertions(+), 14 deletions(-)

diff --git a/editor/app/api/ops/read-x-trending/route.test.ts b/editor/app/api/ops/read-x-trending/route.test.ts @@ -1,6 +1,6 @@ import test from "node:test"; import assert from "node:assert/strict"; -import { access, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; +import { access, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; @@ -174,6 +174,26 @@ test("create-channel refuses a library on a site and a library with a URL; nothi assert.equal(await exists(path.join(ROOT, "channels", "made-trending")), false); }); +test("the marker cannot be switched off: no create or patch changes a library's kind, platform or URL", async () => { + const fields = { name: "Video trending", handling: "transcribe", platform: "x-trending" }; + const video = await call(create, { fields: { ...fields, sourceKind: "video" } }); + assert.equal(video.status, 400); + assert.match(String(video.json.error), /An X trending library is a posts channel: its kind cannot be "video"/); + assert.equal(await exists(path.join(ROOT, "channels", "video-trending")), false); + const before = await readFile(path.join(lib, "config.json"), "utf8"); + for (const [patch, sentence] of [ + [{ sourceKind: "video" }, /its kind cannot be "video"/], + [{ url: "https://x.com/example" }, /An X trending library has no URL/], + [{ platform: "youtube" }, /is an X trending library and stays one/], + [{ platform: "", url: "https://www.youtube.com/@example/videos", sourceKind: "video" }, /is an X trending library and stays one/], + ] as const) { + const r = await call(configure, { slug: "trending", patch }); + assert.equal(r.status, 400, JSON.stringify(patch)); + assert.match(String(r.json.error), sentence, JSON.stringify(patch)); + } + assert.equal(await readFile(path.join(lib, "config.json"), "utf8"), before, "the config is untouched"); +}); + test("Configure cannot turn a library into an ordinary channel, an account into a library, or put a library on a site", async () => { const unmade = await call(configure, { slug: "trending", patch: { platform: "twitter", socialHandle: "example" } }); assert.equal(unmade.status, 400); diff --git a/editor/app/channels/actions.ts b/editor/app/channels/actions.ts @@ -379,24 +379,32 @@ export async function updateChannelAction( const paths = getPaths(); const existing = await readChannelConfig(paths, slug); if (!existing) return { error: `Channel "${slug}" not found`, values }; + // A library is made one when it is created and stays one (lane x-trending). + // Asked of the platform choice before the parse, so the refusal is this + // sentence and not whatever the other platform's fields would complain of. + const libraryProblem = (becomes: boolean) => + Boolean(existing.xTrending) === becomes + ? null + : existing.xTrending + ? `${slug} is an X trending library and stays one: its platform cannot be changed. Delete the channel to be rid of it.` + : `${slug} is not an X trending library, and Configure cannot make it one: create a new channel with platform "X trending library".`; + const asked = libraryProblem(String(formData.get("platform") ?? "") === "x-trending"); + if (asked) return { error: asked, values }; let parsed; try { parsed = parseChannelForm(formData, { stored: existing }); } catch (e) { return { error: (e as Error).message, values }; } - // A library is made one when it is created and stays one (lane x-trending): - // a Configure save that would turn a private library into an ordinary - // channel (which a site may hold), or an account's channel into a library, - // is refused before anything is written. - if (Boolean(existing.xTrending) !== Boolean(parsed.config.xTrending)) { - return { - error: existing.xTrending - ? `${slug} is an X trending library and stays one: its platform cannot be changed. Delete the channel to be rid of it.` - : `${slug} is not an X trending library, and Configure cannot make it one: create a new channel with platform "X trending library".`, - values, - }; - } + // And of the parsed config: whatever the fields said, the marker neither + // appears nor disappears, and a library stays a posts channel on X, no URL. + const parsedProblem = + libraryProblem(Boolean(parsed.config.xTrending)) ?? + (parsed.config.xTrending && + (parsed.config.platform !== "twitter" || parsed.config.sourceKind !== "social" || parsed.config.url) + ? libraryProblem(false) + : null); + if (parsedProblem) return { error: parsedProblem, values }; // A stored value today's checks refuse, saved unchanged: the save stands. // The form has no place for a warning, so the server log says it. for (const w of parsed.warnings) console.warn(`Channel ${slug} saved with a warning: ${w}`); diff --git a/editor/app/channels/components/parseChannelForm.ts b/editor/app/channels/components/parseChannelForm.ts @@ -170,8 +170,10 @@ export function parseChannelForm( // explicit "social" wins, otherwise infer from the platform so a social URL // pasted into the form does the right thing without a hidden field. const sourceKindRaw = String(formData.get("sourceKind") ?? "").trim(); + // A library is a posts channel whatever the request says of its kind (and + // parseXTrendingFields refused any other kind by name). const sourceKind: ChannelConfig["sourceKind"] | undefined = - sourceKindRaw === "social" || (!sourceKindRaw && isSocialPlatform(platform)) + xTrending || sourceKindRaw === "social" || (!sourceKindRaw && isSocialPlatform(platform)) ? "social" : sourceKindRaw === "video" ? "video" @@ -558,6 +560,10 @@ export const X_TRENDING_PLATFORM_CHOICE = "x-trending"; // none — and a cap out of range is refused, never clamped. function parseXTrendingFields(formData: FormData, url: string | undefined): XTrendingConfig { if (url) throw new Error(X_TRENDING_HAS_NO_URL); + const kind = stringOrUndef(formData, "sourceKind"); + if (kind !== undefined && kind !== "social") { + throw new Error(`An X trending library is a posts channel: its kind cannot be "${kind}".`); + } const cap = (key: string, max: number, what: string): number | undefined => { const raw = stringOrUndef(formData, key); if (raw === undefined) return undefined;