Archilyzer · Source

archilyzer

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

commit a3bdce4d7974f9b209345271da7164956cf6563a
parent e20af68f80aeed0f405ec0b233cad552a4ba6010
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 13 Oct 2026 23:33:00 -0400

editor: a site's Delete shows its plan first, then Confirm; force behind its own confirmation (r28 M9)

Danger → Delete on /sites goes through H5's plan-first delete
(publish/siteDelete.ts, as pnpm ops delete-site): the plan — the paths
removed (sites/<id>/, its publish state and bundle, compose's staging),
their size and files, what is kept, what refuses — then Confirm. A plan
refused only for what force answers (a deploy target, a deploy on record,
reports of its own) offers Delete with force behind an I-understand box;
any other refusal offers nothing. e2e: site-delete.spec.ts; sites-crud's
delete follows the plan.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Meditor/app/sites/actions.ts | 41++++++++++++++++++++++++++++++++++++++---
Meditor/app/sites/components/SiteListActions.tsx | 133++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
Aeditor/e2e/site-delete.spec.ts | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Meditor/e2e/sites-crud.spec.ts | 5+++--
4 files changed, 219 insertions(+), 23 deletions(-)

diff --git a/editor/app/sites/actions.ts b/editor/app/sites/actions.ts @@ -13,7 +13,6 @@ import { import { getSite, writeSite, - deleteSite, isValidSiteId, reservedSiteIdProblem, parseRelatedSites, @@ -30,6 +29,13 @@ import { resolveDefaultGroupId, } from "yt-dlp-transcript-common/lib/channelGroups"; import { migrateToSites } from "yt-dlp-transcript-common/controller/migrateToSites"; +import { + SiteDeleteRefusedError, + deleteSiteByPlan, + planSiteDelete, + siteDeleteBlocked, + type SiteDeletePlan, +} from "yt-dlp-transcript-common/publish/siteDelete"; import { socialLinksForSave } from "yt-dlp-transcript-common/lib/socialLinks"; import { formValues, type FormState, type FormValues } from "../lib/formState"; import { reportSiteKeysFromForm } from "./lib/reportSiteKeys"; @@ -316,12 +322,41 @@ export async function saveSiteAction( export type DeleteResult = { ok: true } | { ok: false; error: string }; +export type SiteDeletePlanResult = { ok: true; plan: SiteDeletePlan } | { ok: false; error: string }; + +// Danger → Delete is plan-first (release 28 M9, through H5's +// publish/siteDelete.ts, as `pnpm ops delete-site`): the plan — what is +// removed (sites/<id>/, its publish state and bundle, compose's staging), what +// is kept, what refuses — then the delete. Read only. +export async function planSiteDeleteAction(siteId: string): Promise<SiteDeletePlanResult> { + try { + return { ok: true, plan: await planSiteDelete(siteId, getPaths()) }; + } catch (err) { + return { ok: false, error: err instanceof Error ? err.message : String(err) }; + } +} + +// The delete, its plan made again under the locks. `force` answers the +// forceable refusals only (a deploy target, a deploy on record, reports of its +// own); no site, a site dir that is a link and a publish stage running refuse +// whatever. export async function deleteSiteAction( siteId: string, -): Promise<DeleteResult> { + opts: { force?: boolean } = {}, +): Promise<DeleteResult & { plan?: SiteDeletePlan }> { + const force = opts.force === true; try { - await deleteSite(siteId, getPaths()); + const plan = await planSiteDelete(siteId, getPaths()); + if (siteDeleteBlocked(plan, force)) { + const why = plan.refusals.filter((r) => !force || !r.forceable).map((r) => r.reason); + return { ok: false, error: `refused: ${why.join("; ")}`, plan }; + } + const r = await deleteSiteByPlan(siteId, getPaths(), { force }); + if (r.failed.length) { + return { ok: false, error: `not everything was removed: ${r.failed.map((f) => `${f.path} (${f.error})`).join("; ")}`, plan: r.plan }; + } } catch (err) { + if (err instanceof SiteDeleteRefusedError) return { ok: false, error: err.message, plan: err.plan }; return { ok: false, error: err instanceof Error ? err.message : String(err) }; } // No revalidatePath: the button refreshes the page itself (release 24 H5, diff --git a/editor/app/sites/components/SiteListActions.tsx b/editor/app/sites/components/SiteListActions.tsx @@ -2,32 +2,129 @@ import { useState, useTransition } from "react"; import { useRouter } from "next/navigation"; -import { deleteSiteAction, migrateToSitesAction } from "../actions"; +import { deleteSiteAction, migrateToSitesAction, planSiteDeleteAction } from "../actions"; +import type { SiteDeletePlan } from "yt-dlp-transcript-common/publish/siteDelete"; // Both actions save without revalidating and refresh the page here (release 24 // H5, lib/formState.ts seedAfterSave says why). + +const size = (n: number) => + n < 1024 ? `${n} B` : n < 1024 ** 2 ? `${(n / 1024).toFixed(1)} KiB` : n < 1024 ** 3 ? `${(n / 1024 ** 2).toFixed(1)} MiB` : `${(n / 1024 ** 3).toFixed(1)} GiB`; + +// Danger → Delete, plan first (release 28 M9): Delete asks for the plan — +// what goes, what stays, what refuses — and nothing is removed until Confirm. +// A plan refused only for reasons force answers (a deploy target, a deploy on +// record, reports of its own) offers force behind its own confirmation; any +// other refusal offers nothing. export function DeleteSiteButton({ siteId }: { siteId: string }) { const router = useRouter(); const [pending, start] = useTransition(); const [error, setError] = useState<string | null>(null); + const [plan, setPlan] = useState<SiteDeletePlan | null>(null); + const [forceOk, setForceOk] = useState(false); + const blocked = (force: boolean) => !!plan && plan.refusals.some((r) => !force || !r.forceable); + const run = (force: boolean) => + start(async () => { + setError(null); + const res = await deleteSiteAction(siteId, { force }); + if (!res.ok) { + setError(res.error); + if (res.plan) setPlan(res.plan); + } else { + setPlan(null); + router.refresh(); + } + }); return ( - <span className="flex items-center gap-2"> - <button - type="button" - disabled={pending} - onClick={() => { - if (!confirm(`Delete site "${siteId}"? This cannot be undone.`)) return; - start(async () => { - const res = await deleteSiteAction(siteId); - if (!res.ok) setError(res.error); - else router.refresh(); - }); - }} - className="px-2 py-1 rounded border border-destructive/30 text-xs text-destructive disabled:opacity-50" - > - {pending ? "Deleting…" : "Delete"} - </button> - {error && <span className="text-xs text-destructive">{error}</span>} + <span className="flex flex-col items-end gap-2"> + <span className="flex items-center gap-2"> + <button + type="button" + disabled={pending} + aria-expanded={!!plan} + onClick={() => + start(async () => { + setError(null); + setForceOk(false); + const res = await planSiteDeleteAction(siteId); + if (res.ok) setPlan(res.plan); + else setError(res.error); + }) + } + className="px-2 py-1 rounded border border-destructive/30 text-xs text-destructive disabled:opacity-50" + > + {pending && !plan ? "Planning…" : "Delete"} + </button> + {error && <span className="text-xs text-destructive">{error}</span>} + </span> + {plan && ( + <div + role="region" + aria-label={`delete site ${siteId}`} + data-site-delete-plan={siteId} + className="w-full max-w-xl rounded border border-destructive/40 bg-destructive/5 p-3 text-xs" + > + <p className="font-medium" data-plan-summary=""> + Delete site <code>{siteId}</code>: {plan.remove.length} path{plan.remove.length === 1 ? "" : "s"}, {size(plan.bytes)} in {plan.files} file + {plan.files === 1 ? "" : "s"} + </p> + {plan.refusals.length > 0 && ( + <ul className="mt-1 list-disc pl-4 text-destructive" aria-label="refusals"> + {plan.refusals.map((r) => ( + <li key={r.reason} data-refusal={r.forceable ? "forceable" : "final"}> + {r.reason} + {r.forceable ? " (force answers it)" : " (force does not)"} + </li> + ))} + </ul> + )} + <ul className="mt-1 list-disc pl-4" aria-label="removed"> + {plan.remove.map((e) => ( + <li key={e.path} data-remove={e.label}> + <code>{e.label}</code> — {e.what}, {e.kind === "link" ? "a link" : `${size(e.bytes)} in ${e.files} file${e.files === 1 ? "" : "s"}`} + </li> + ))} + </ul> + <ul className="mt-1 list-disc pl-4 text-muted-foreground" aria-label="kept"> + {plan.kept.map((k) => ( + <li key={k.what}> + keeps {k.what}: {k.why} + </li> + ))} + </ul> + <div className="mt-2 flex flex-wrap items-center gap-2"> + {!blocked(false) && ( + <button + type="button" + disabled={pending} + onClick={() => run(false)} + className="px-2 py-1 rounded bg-destructive text-white disabled:opacity-50" + > + {pending ? "Deleting…" : "Confirm delete"} + </button> + )} + {blocked(false) && !blocked(true) && ( + <> + <label className="flex items-center gap-1"> + <input type="checkbox" checked={forceOk} onChange={(e) => setForceOk(e.target.checked)} /> + I understand: the refusals above are overridden, and nothing deployed is undeployed + </label> + <button + type="button" + disabled={pending || !forceOk} + onClick={() => run(true)} + className="px-2 py-1 rounded bg-destructive text-white disabled:opacity-50" + > + {pending ? "Deleting…" : "Delete with force"} + </button> + </> + )} + <button type="button" disabled={pending} onClick={() => setPlan(null)} className="px-2 py-1 rounded border border-border"> + Cancel + </button> + </div> + </div> + )} </span> ); } diff --git a/editor/e2e/site-delete.spec.ts b/editor/e2e/site-delete.spec.ts @@ -0,0 +1,63 @@ +import { test, expect } from "@playwright/test"; +import { mkdir, writeFile } from "node:fs/promises"; +import { join } from "node:path"; +import { pathExists, resetData, testPaths, writeSite } from "./helpers"; + +// Danger → Delete on /sites, plan first (release 28 M9, through H5's +// publish/siteDelete.ts): Delete shows what goes (sites/<id>/, its publish +// state and bundle, compose's staging), what stays and what refuses; nothing +// is removed until Confirm. A site with a deploy target is refused unless +// forced, and force has its own confirmation. Temp sites in the fixture +// corpus only. + +const sitesDir = () => join(testPaths().transcriptsDir, "sites"); + +test("Delete shows the plan; Cancel removes nothing; Confirm removes the site and its build state", async ({ page }) => { + await resetData("empty"); + await writeSite("scratch", { siteTitle: "Scratch Site" }); + // Its build state, as a publish leaves it. + const builds = join(testPaths().transcriptsDir, ".export-builds", "scratch"); + await mkdir(join(builds, "out"), { recursive: true }); + await writeFile(join(builds, "out", "index.html"), "<p>scratch</p>"); + await writeFile(join(builds, "built.json"), "{}"); + + await page.goto("/sites"); + const row = page.getByRole("listitem").filter({ hasText: "Scratch Site" }); + await row.getByRole("button", { name: /^delete$/i }).click(); + const plan = page.getByRole("region", { name: "delete site scratch" }); + await expect(plan).toBeVisible(); + await expect(plan.locator("[data-plan-summary]")).toContainText("Delete site scratch: 2 paths"); + await expect(plan.locator("[data-remove='sites/scratch/']")).toBeVisible(); + await expect(plan.locator("[data-remove='export/.export-builds/scratch/']")).toContainText("2 files"); + await expect(plan.getByRole("list", { name: "kept" })).toContainText("every channel's data"); + await expect(plan.locator("[data-refusal]")).toHaveCount(0); + + await plan.getByRole("button", { name: "Cancel" }).click(); + await expect(plan).toHaveCount(0); + expect(await pathExists(join(sitesDir(), "scratch", "site.json"))).toBe(true); + + await row.getByRole("button", { name: /^delete$/i }).click(); + await page.getByRole("region", { name: "delete site scratch" }).getByRole("button", { name: "Confirm delete" }).click(); + await expect(page.getByRole("link", { name: /Scratch Site/ })).toHaveCount(0); + expect(await pathExists(join(sitesDir(), "scratch"))).toBe(false); + expect(await pathExists(builds)).toBe(false); +}); + +test("a site with a deploy target is refused; force, behind its own confirmation, deletes it", async ({ page }) => { + await resetData("empty"); + await writeSite("deployed", { siteTitle: "Deployed Site", cloudflareProject: "deployed-pages" }); + + await page.goto("/sites"); + const row = page.getByRole("listitem").filter({ hasText: "Deployed Site" }); + await row.getByRole("button", { name: /^delete$/i }).click(); + const plan = page.getByRole("region", { name: "delete site deployed" }); + await expect(plan.locator("[data-refusal='forceable']")).toContainText('it deploys to the Cloudflare Pages project "deployed-pages" (force answers it)'); + await expect(plan.getByRole("list", { name: "kept" })).toContainText('the Pages project "deployed-pages"'); + await expect(plan.getByRole("button", { name: "Confirm delete" })).toHaveCount(0); + const force = plan.getByRole("button", { name: "Delete with force" }); + await expect(force).toBeDisabled(); + await plan.getByRole("checkbox", { name: /I understand/ }).check(); + await force.click(); + await expect(page.getByRole("link", { name: /Deployed Site/ })).toHaveCount(0); + expect(await pathExists(join(sitesDir(), "deployed"))).toBe(false); +}); diff --git a/editor/e2e/sites-crud.spec.ts b/editor/e2e/sites-crud.spec.ts @@ -128,8 +128,9 @@ test("delete removes the site config", async ({ page }) => { await writeSite("doomed", { siteTitle: "Doomed" }); await page.goto("/sites"); - page.once("dialog", (d) => d.accept()); - await page.getByRole("button", { name: /delete/i }).click(); + // Plan first (release 28 M9): nothing goes until Confirm. + await page.getByRole("button", { name: /^delete$/i }).click(); + await page.getByRole("region", { name: "delete site doomed" }).getByRole("button", { name: "Confirm delete" }).click(); await expect(page.getByText("Doomed")).toHaveCount(0); expect(await pathExists(`${testPaths().transcriptsDir}/sites/doomed/site.json`)).toBe(