Archilyzer · Source

archilyzer

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

commit d295e00732e916a210378ccacf65cac16908ecd0
parent 712c8a87bcb691b5242651506ce8d355770a7c26
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 18 Nov 2026 01:50:45 -0500

settings: the form is not sent autoQueue; the two session sections stream in

The form was handed the whole settings object. The four lanes' policy
trees (autoQueue) are most of settings.json on a large corpus (110 KB of
120 KB here), are read by nothing in the form, and were serialised into
the document twice. The form is sent the settings without them.

A save cannot lose them: the action builds its patch from the submitted
fields alone and saveSettings merges it over the stored file. Pinned by
a test through the real action (saveSettingsAction.test.ts).

The X session and archive.today sections each read a session's state
off the disk; they stream in behind the form instead of holding it.

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

Diffstat:
Meditor/app/settings/components/SettingsForm.tsx | 4+++-
Meditor/app/settings/page.tsx | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
Aeditor/app/settings/saveSettingsAction.test.ts | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 171 insertions(+), 17 deletions(-)

diff --git a/editor/app/settings/components/SettingsForm.tsx b/editor/app/settings/components/SettingsForm.tsx @@ -39,7 +39,9 @@ import { } from "../../components/SocialLinksField"; type Props = { - initial: SiteSettings; + // The settings WITHOUT `autoQueue` (the lanes' policy trees): this form + // reads none of it, and the page does not send it (settings/page.tsx). + initial: Omit<SiteSettings, "autoQueue">; }; export function SettingsForm({ initial }: Props) { diff --git a/editor/app/settings/page.tsx b/editor/app/settings/page.tsx @@ -1,4 +1,5 @@ import type { Metadata } from "next"; +import { Suspense } from "react"; import Link from "next/link"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { displayPath } from "yt-dlp-transcript-common/lib/privacy/privacy-server"; @@ -8,6 +9,8 @@ import { resolveXCookieSourceFor } from "yt-dlp-transcript-common/social/xBrowse import { xCookieSourceView } from "yt-dlp-transcript-common/social/xCookieSource"; import { xPostsVisibility } from "yt-dlp-transcript-common/lib/postsVisibility"; import { SettingsForm } from "./components/SettingsForm"; +import { SkeletonPanel, StreamFilled } from "../components/StreamSkeleton"; +import { e2eStreamDelay } from "../lib/streamDelay"; import { xSourceForDisplay } from "../lib/xSourceDisplay"; import { XSessionSection } from "./components/XSessionSection"; import { xMaxCookieAgeMinutes } from "yt-dlp-transcript-common/social/xCookieSource"; @@ -37,14 +40,15 @@ export default async function SettingsPage() { ["galleryDlBin", paths.galleryDlBin], ]; - // The X session broker's current state and the X login source in use (see - // xSessionActions.ts). The source is resolved here, not read: with no stored - // choice it depends on cookiesFromBrowser and the profile. - const xSession = await readXSessionStatus(paths); - // Drawn by the client: its spec and label through settings.privacy. - const xSource = xSourceForDisplay( - xCookieSourceView(await resolveXCookieSourceFor(paths, settings)), - ); + // THE FORM GETS WHAT IT EDITS, NOT THE WHOLE FILE. `autoQueue` — the four + // lanes' policy trees, most of settings.json on a large corpus — is edited + // on the operation pages and /channels and read by nothing in this form, and + // it was serialised into the document twice (the HTML and the component + // payload). Leaving it out cannot lose it: the save builds its patch from + // the submitted fields alone and merges it over the stored file + // (settings/actions.ts; pinned in saveSettingsAction.test.ts). + const { autoQueue: _autoQueue, ...formSettings } = settings; + void _autoQueue; return ( <div className="flex flex-col gap-8"> @@ -96,21 +100,25 @@ export default async function SettingsPage() { , beside the workers it describes. </p> </div> - <SettingsForm initial={settings} /> + <SettingsForm initial={formSettings} /> </section> + {/* THE TWO SESSION SECTIONS STREAM. Each reads a session's state off + the disk (X's profile and cookie source; archive.today's), and the + form above must not wait for either. */} <section className="flex flex-col gap-3 border-t border-border pt-6"> - <XSessionSection - initial={xSession} - initialSource={xSource} - initialVisibility={xPostsVisibility(settings)} - initialMaxCookieAge={xMaxCookieAgeMinutes(settings.social.x)} - /> + <Suspense fallback={<SkeletonPanel name="settings-x" height={X_SECTION_PX} />}> + <XSection /> + </Suspense> </section> {/* Release 37 lane F: archive.today's host, pace and session. */} <section className="flex flex-col gap-3 border-t border-border pt-6"> - <ArchiveSourcesSection initial={settings.archives} session={await readArchiveSessionStatus(paths)} /> + <Suspense + fallback={<SkeletonPanel name="settings-archives" height={ARCHIVE_SECTION_PX} />} + > + <ArchivesSection /> + </Suspense> </section> <section className="flex flex-col gap-3 border-t border-border pt-6"> @@ -146,3 +154,42 @@ export default async function SettingsPage() { </div> ); } + +// The skeletons' heights in px: each section as it stands with no session +// connected (e2e/streaming.spec.ts holds them to the boxes that replace them). +const X_SECTION_PX = 507; +const ARCHIVE_SECTION_PX = 198; + +async function XSection() { + await e2eStreamDelay(); + const paths = getPaths(); + const settings = getSettings(); + // The X session broker's current state and the X login source in use (see + // xSessionActions.ts). The source is resolved here, not read: with no stored + // choice it depends on cookiesFromBrowser and the profile. + const xSession = await readXSessionStatus(paths); + // Drawn by the client: its spec and label through settings.privacy. + const xSource = xSourceForDisplay( + xCookieSourceView(await resolveXCookieSourceFor(paths, settings)), + ); + return ( + <StreamFilled name="settings-x" className="flex flex-col gap-3"> + <XSessionSection + initial={xSession} + initialSource={xSource} + initialVisibility={xPostsVisibility(settings)} + initialMaxCookieAge={xMaxCookieAgeMinutes(settings.social.x)} + /> + </StreamFilled> + ); +} + +async function ArchivesSection() { + await e2eStreamDelay(); + const session = await readArchiveSessionStatus(getPaths()); + return ( + <StreamFilled name="settings-archives" className="flex flex-col gap-3"> + <ArchiveSourcesSection initial={getSettings().archives} session={session} /> + </StreamFilled> + ); +} diff --git a/editor/app/settings/saveSettingsAction.test.ts b/editor/app/settings/saveSettingsAction.test.ts @@ -0,0 +1,105 @@ +import { mkdtempSync, readFileSync } from "node:fs"; +import { rm } from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; +import { test, after } from "node:test"; +import assert from "node:assert/strict"; + +// Run with: pnpm -C editor exec tsx --test "app/**/*.test.ts" +// +// THE SETTINGS FORM IS NOT SENT `autoQueue` (settings/page.tsx): the four +// lanes' policy trees are most of settings.json on a large corpus, the form +// reads none of them, and they were serialised into /settings twice. That is +// only safe while a save from the form cannot write settings back without +// them — which holds because the action builds its patch from the SUBMITTED +// FIELDS alone and saveSettings merges it over the stored file. This pins it: +// a save through the real action, from a form that never saw `autoQueue`, +// leaves every lane's tree, and every other block the form does not edit, +// exactly as stored. +// +// SETTINGS SEAM as in saveSettings.test.ts: getPaths() memoizes, so +// SETTINGS_FILE is set before the module under test is imported. + +const ROOT = mkdtempSync(path.join(os.tmpdir(), "save-settings-action-")); +process.env.TRANSCRIPTS_DIR = ROOT; +process.env.SETTINGS_FILE = path.join(ROOT, "settings.json"); + +const { saveSettingsAction } = await import("./actions"); +const { defaultSiteSettings, getSettings, writeSettings } = await import( + "yt-dlp-transcript-common/lib/settings" +); + +after(() => rm(ROOT, { recursive: true, force: true })); + +// What the form posts: its own fields, and nothing of any other block. +function formOf(over: Record<string, string> = {}): FormData { + const s = getSettings(); + const fields: Record<string, string> = { + adminTitle: s.adminTitle, + homepageUrl: s.homepageUrl ?? "", + maxTranscriptPageBytes: String(s.maxTranscriptPageBytes), + sleepBetweenDownloadsSeconds: String(s.sleepBetweenDownloadsSeconds), + autoRefreshIntervalSeconds: String(s.autoRefreshIntervalSeconds), + minFreeDiskGB: String(s.minFreeDiskGB), + resumeMarginGB: String(s.resumeMarginGB), + pacingJitterPercent: String(Math.round(s.pacing.jitter * 100)), + downloadFormat: s.downloadFormat, + sourceVideoQuality: s.sourceVideoQuality, + reportDebouncePreset: s.reportDebouncePreset, + archiveStorageBucket: "", + archiveStoragePublicBaseUrl: "", + maxParallelBuilds: String(s.buildPipeline.maxParallelBuilds), + dockerImage: s.buildPipeline.dockerImage, + dockerfile: s.buildPipeline.dockerfile, + socialLinksJson: "[]", + ...over, + }; + const form = new FormData(); + for (const [k, v] of Object.entries(fields)) form.set(k, v); + return form; +} + +test("a save from the settings form keeps autoQueue, which the form is never sent", async () => { + // A stored file whose lanes are NOT the defaults: a held lane, a changed + // order, and a policy tree with a channel in it. + const stored = defaultSiteSettings(); + const lanes = Object.keys(stored.autoQueue) as Array<keyof typeof stored.autoQueue>; + assert.ok(lanes.length >= 4, "the four lanes"); + for (const lane of lanes) { + const l = stored.autoQueue[lane] as unknown as Record<string, unknown>; + l.held = true; + l.enabled = true; + } + stored.channelPriority.channels = { "some-channel": { tier: "low" } }; + stored.workers = []; + await writeSettings(stored); + const before = getSettings(); + assert.equal((before.autoQueue[lanes[0]] as unknown as { held: boolean }).held, true); + + // No field of the form names autoQueue: it has nothing to post it with. + const form = formOf({ adminTitle: "Renamed by the form" }); + assert.deepEqual( + [...form.keys()].filter((k) => /autoQueue|channelPriority|workers/i.test(k)), + [], + ); + + const result = await saveSettingsAction(undefined, form); + assert.deepEqual(result, { ok: true }); + + const after_ = getSettings(); + assert.equal(after_.adminTitle, "Renamed by the form"); + assert.deepEqual(after_.autoQueue, before.autoQueue); + assert.deepEqual(after_.channelPriority, before.channelPriority); + assert.deepEqual(after_.workers, before.workers); + // And on disk, not only through the reader's defaults. + const raw = JSON.parse(readFileSync(process.env.SETTINGS_FILE!, "utf8")); + assert.deepEqual(raw.autoQueue, JSON.parse(JSON.stringify(before.autoQueue))); +}); + +test("a refused save writes nothing", async () => { + const before = readFileSync(process.env.SETTINGS_FILE!, "utf8"); + const result = await saveSettingsAction(undefined, formOf({ adminTitle: "" })); + assert.equal(result.ok, false); + assert.equal(readFileSync(process.env.SETTINGS_FILE!, "utf8"), before); +}); +