Public: anyone can read this; the crew can change it.
Tick up to 20 of an account's repositories on /migrate and start them all with one "Migrate selected" #17381
Merged 37h 38m ago, live in production
scout/forge:scout/6408-tick-up-to-20-of-an-account-s-repositori → main 0 commits fork 5 threads · 5 unresolved
10 files
changed +339
−6
README.md +2 −2
| @@ -16,8 +16,8 @@ Your code stays in ordinary git repositories. The forge's state is one SQLite | ||
| 16 | 16 | file, in one data directory you can restore on another machine. Clone your |
| 17 | 17 | repositories and leave whenever you want. Yours to keep. |
| 18 | 18 | |
| 19 | Pull work in from GitHub, Forgejo, Gitea or another forge. Do it with the crew | |
| 20 | and send a clean pull request back. | |
| 19 | Pull work in from GitHub, Forgejo, Gitea or another forge, with the crew, and send a clean pull request back. | |
| 20 | [](docs/features/migrate-selected.md) brings up to 20 at once: tick them on `/migrate`, or in the terminal tick with space and start with `m`. | |
| 21 | 21 | |
| 22 | 22 | The forge is part of [](https://www.open-platform.sh) and open |
| 23 | 23 | source under AGPL-3.0. Run it yourself, or use a hosted forge. |
docs/design/areas/migrate.md added +5
| @@ -0,0 +1,5 @@ | ||
| 1 | # Migrate | |
| 2 | ||
| 3 | `/migrate` (`src/web/pages/migrate.ts`): each connected account lists its newest repositories as `row()`s. | |
| 4 | ||
| 5 | - `.mig-tick` — a row's tick box for **Migrate selected** (#6408): a label wrapping the plain checkbox, 44px each way, so the whole lead is the tap target on a 360px phone. The form submits with no script. |
docs/features/migrate-selected.md added +11
| @@ -0,0 +1,11 @@ | ||
| 1 | --- | |
| 2 | topic: Your apps | |
| 3 | row: Migrate selected: bring several repositories in at once | |
| 4 | --- | |
| 5 | # Migrate selected: bring several repositories in at once | |
| 6 | ||
| 7 | On `/migrate`, each connected account lists its newest repositories, each with a tick box. Tick up to 20 and press **Migrate selected**. One migration starts per ticked repository, through the same path a single pick takes: the same validation and the same repository limit. Each keeps its own name under the owner chosen in the Destination block; the crew, visibility and "after" choices there apply to all. | |
| 8 | ||
| 9 | You land on a page listing each job with its link. A repository that is refused (a name already taken, the repository limit) is named with its reason, and the rest still start. Ticking more than 20 is refused with a 422 before anything starts. | |
| 10 | ||
| 11 | In the terminal, `M` opens the same list: **space** ticks the row under the cursor (it shows `✓ ticked`) and **m** starts every ticked repository the filter shows, up to 20 (a tick the filter hides is named, not started), as private repositories of yours with each source's name. The terminal has no destination block, so use the web page to choose an owner, crew or "after" for the batch. |
src/actions/migrate_multi.ts added +9
| @@ -0,0 +1,9 @@ | ||
| 1 | /** | |
| 2 | * "Migrate selected": the limit and the two refusals both the page and the terminal speak (#6408). | |
| 3 | */ | |
| 4 | ||
| 5 | /** The most repositories one "Migrate selected" starts. */ | |
| 6 | export const MULTI_MAX = 20; | |
| 7 | ||
| 8 | export const MULTI_TOO_MANY = `Tick at most ${MULTI_MAX} repositories at a time: ${MULTI_MAX} is the limit. Nothing was started.`; | |
| 9 | export const MULTI_NONE = "Tick at least one repository."; |
src/tui/screens/migrate.ts +61 −1
| @@ -19,6 +19,7 @@ import { | ||
| 19 | 19 | migrateRepo, |
| 20 | 20 | type MigrateSource, |
| 21 | 21 | } from "../../actions/migrate.ts"; |
| 22 | import { MULTI_MAX, MULTI_NONE, MULTI_TOO_MANY } from "../../actions/migrate_multi.ts"; | |
| 22 | 23 | import { |
| 23 | 24 | listRemoteRepos, |
| 24 | 25 | listUserOrigins, |
| @@ -98,6 +99,9 @@ export function migrateScreen(f: Session, ctx: Ctx): Screen { | ||
| 98 | 99 | let unreachable: string[] = []; |
| 99 | 100 | let publicOnly: PublicOnly[] = []; |
| 100 | 101 | let self: Screen; |
| 102 | // Ticked rows, as `<origin id>/<full name>`: the web's checkboxes. | |
| 103 | const ticks = new Set<string>(); | |
| 104 | const tickKey = (r: Row): string => `${r.originId}/${r.repo.fullName}`; | |
| 101 | 105 | |
| 102 | 106 | const shown = (): Row[] => |
| 103 | 107 | rows.filter((r) => repoMatches(r.repo, filter.query)); |
| @@ -163,6 +167,46 @@ export function migrateScreen(f: Session, ctx: Ctx): Screen { | ||
| 163 | 167 | }); |
| 164 | 168 | }; |
| 165 | 169 | |
| 170 | const hiddenWords = (n: number): string => | |
| 171 | `${n} ticked ${n === 1 ? "repository is" : "repositories are"} hidden by the filter and not started.`; | |
| 172 | ||
| 173 | /** "Migrate selected": each tick through `migrateRepo`, as the web's button does. */ | |
| 174 | const migrateTicked = (): void => { | |
| 175 | if (user === undefined) return; | |
| 176 | // Only what the filter shows starts: a tick the filter hides is named, not started. | |
| 177 | const chosen = shown().filter((r) => ticks.has(tickKey(r))); | |
| 178 | const hidden = ticks.size - chosen.length; | |
| 179 | if (chosen.length === 0) return void ctx.toast(hidden > 0 ? `${MULTI_NONE} ${hiddenWords(hidden)}` : MULTI_NONE, "danger"); | |
| 180 | if (chosen.length > MULTI_MAX) return void ctx.toast(MULTI_TOO_MANY, "danger"); | |
| 181 | runAsync(ctx, async () => { | |
| 182 | let started = 0; | |
| 183 | const refused: string[] = []; | |
| 184 | for (const r of chosen) { | |
| 185 | const done = await migrateRepo(f.app, user, { | |
| 186 | source: { originId: r.originId, fullName: r.repo.fullName }, | |
| 187 | owner: user.username, | |
| 188 | name: r.repo.fullName.split("/").pop() ?? "", | |
| 189 | visibility: "private", | |
| 190 | after: "leave", | |
| 191 | }); | |
| 192 | if (done.ok) { | |
| 193 | started++; | |
| 194 | ticks.delete(tickKey(r)); | |
| 195 | } else | |
| 196 | refused.push( | |
| 197 | `${r.repo.fullName}: ${migrateMessage(done.error, repositoryLimitMessage(f.app, user))}`, | |
| 198 | ); | |
| 199 | } | |
| 200 | if (started > 0) | |
| 201 | ctx.toast( | |
| 202 | `Started ${started} ${started === 1 ? "migration" : "migrations"}; they run in the background.${hidden > 0 ? ` ${hiddenWords(hidden)}` : ""}`, | |
| 203 | "success", | |
| 204 | ); | |
| 205 | if (refused.length > 0) ctx.toast(`Not started: ${refused.join(" ")}`, "danger"); | |
| 206 | ctx.invalidate(); | |
| 207 | }); | |
| 208 | }; | |
| 209 | ||
| 166 | 210 | const pasteUrl = (): void => { |
| 167 | 211 | ctx.push( |
| 168 | 212 | promptScreen(ctx, self, { |
| @@ -229,6 +273,8 @@ export function migrateScreen(f: Session, ctx: Ctx): Screen { | ||
| 229 | 273 | return [ |
| 230 | 274 | binding(["j", "k"], "move"), |
| 231 | 275 | binding(["enter"], "pick branch"), |
| 276 | binding(["space"], "tick"), | |
| 277 | binding(["m"], `migrate selected${ticks.size === 0 ? "" : ` (${ticks.size})`}`), | |
| 232 | 278 | binding(["/"], "filter"), |
| 233 | 279 | binding(["u"], "paste a URL"), |
| 234 | 280 | ...(publicOnly.length > 0 ? [binding(["t"], "replace token")] : []), |
| @@ -328,7 +374,9 @@ export function migrateScreen(f: Session, ctx: Ctx): Screen { | ||
| 328 | 374 | state, |
| 329 | 375 | items.map((r) => ({ |
| 330 | 376 | title: r.repo.fullName, |
| 331 | secondary: r.repo.private ? "private" : "", | |
| 377 | secondary: [ticks.has(tickKey(r)) ? "✓ ticked" : "", r.repo.private ? "private" : ""] | |
| 378 | .filter((p) => p !== "") | |
| 379 | .join(" · "), | |
| 332 | 380 | meta: [ |
| 333 | 381 | r.origin, |
| 334 | 382 | r.repo.pushedAt === null ? "" : `pushed ${ago(r.repo.pushedAt)}`, |
| @@ -353,6 +401,18 @@ export function migrateScreen(f: Session, ctx: Ctx): Screen { | ||
| 353 | 401 | ctx.pop(); |
| 354 | 402 | return true; |
| 355 | 403 | } |
| 404 | if (e.key === "m") { | |
| 405 | migrateTicked(); | |
| 406 | return true; | |
| 407 | } | |
| 408 | if (e.key === " ") { | |
| 409 | const row = shown()[state.index]; | |
| 410 | if (row !== undefined) { | |
| 411 | const k = tickKey(row); | |
| 412 | if (!ticks.delete(k)) ticks.add(k); | |
| 413 | } | |
| 414 | return true; | |
| 415 | } | |
| 356 | 416 | if (e.key === "u") { |
| 357 | 417 | pasteUrl(); |
| 358 | 418 | return true; |
src/web/migrate-multi.ts added +80
| @@ -0,0 +1,80 @@ | ||
| 1 | /** | |
| 2 | * "Migrate selected": the ticked repositories of /migrate, each started through the same | |
| 3 | * `migrateRepo` a single pick takes (same validation, same repository limit) (#6408). | |
| 4 | */ | |
| 5 | ||
| 6 | import { migrateMessage, migrateRepo, type MigrateInput } from "../actions/migrate.ts"; | |
| 7 | import type { Ctx } from "../http/context.ts"; | |
| 8 | import { forbiddenPage, NOT_YOURS_TO_DO, pageHead } from "./chrome.ts"; | |
| 9 | import type { Form } from "./form.ts"; | |
| 10 | import { html } from "./html.ts"; | |
| 11 | import { page } from "./layout.ts"; | |
| 12 | import { btn, row, rowList } from "./ui.ts"; | |
| 13 | ||
| 14 | /** The distinct, bounded `picks` of a form, in the order ticked. */ | |
| 15 | export function ticked(form: Form): string[] { | |
| 16 | const seen = new Set<string>(); | |
| 17 | for (const v of form.getAll("picks")) | |
| 18 | if (typeof v === "string" && v.length > 0 && v.length <= 400) seen.add(v); | |
| 19 | return [...seen]; | |
| 20 | } | |
| 21 | ||
| 22 | /** `<origin id>/<owner>/<name>` split as the page's pick is; undefined when it is not one. */ | |
| 23 | function split(value: string): { originId: string; fullName: string } | undefined { | |
| 24 | const slash = value.indexOf("/"); | |
| 25 | return slash <= 0 ? undefined : { originId: value.slice(0, slash), fullName: value.slice(slash + 1) }; | |
| 26 | } | |
| 27 | ||
| 28 | type Rest = Omit<MigrateInput, "source" | "name">; | |
| 29 | ||
| 30 | /** | |
| 31 | * Start one migration per pick; a refusal names its repository and the rest still start. Returns | |
| 32 | * the page of jobs, or undefined when none started (the caller shows the first refusal at 422). | |
| 33 | */ | |
| 34 | export async function migrateSelected( | |
| 35 | ctx: Ctx, | |
| 36 | picks: readonly string[], | |
| 37 | rest: Rest, | |
| 38 | limitWords: string, | |
| 39 | ): Promise<{ response: Response } | { refusal: string }> { | |
| 40 | const user = ctx.auth.user!; | |
| 41 | const jobs: { id: string; fullName: string }[] = []; | |
| 42 | const refused: { fullName: string; why: string }[] = []; | |
| 43 | for (const pick of picks) { | |
| 44 | const source = split(pick); | |
| 45 | if (source === undefined) { | |
| 46 | refused.push({ fullName: pick, why: migrateMessage("no_such_origin") }); | |
| 47 | continue; | |
| 48 | } | |
| 49 | const started = await migrateRepo(ctx.app, user, { | |
| 50 | ...rest, | |
| 51 | source, | |
| 52 | name: source.fullName.split("/").pop() ?? "", | |
| 53 | }); | |
| 54 | if (started.ok) jobs.push({ id: started.value.job.id, fullName: source.fullName }); | |
| 55 | else if (started.error === "forbidden_owner" || started.error === "unauthorized") | |
| 56 | return { response: forbiddenPage(ctx, NOT_YOURS_TO_DO) }; | |
| 57 | else refused.push({ fullName: source.fullName, why: migrateMessage(started.error, limitWords) }); | |
| 58 | } | |
| 59 | if (jobs.length === 0) return { refusal: refused.map((r) => `${r.fullName}: ${r.why}`).join(" ") }; | |
| 60 | const what = `Migrating ${jobs.length} ${jobs.length === 1 ? "repository" : "repositories"}`; | |
| 61 | return { | |
| 62 | response: page({ | |
| 63 | ctx, | |
| 64 | title: what, | |
| 65 | body: html`${pageHead(what)} | |
| 66 | <div class="narrow-wide" id="migrate-batch"> | |
| 67 | ${rowList( | |
| 68 | jobs.map((j) => row({ href: `/migrate/jobs/${j.id}`, title: html`<span class="mono">${j.fullName}</span>` })), | |
| 69 | )} | |
| 70 | ${refused.length === 0 | |
| 71 | ? null | |
| 72 | : html`<h2 class="mb">Not started</h2> | |
| 73 | <div id="migrate-batch-refused"> | |
| 74 | ${rowList(refused.map((r) => row({ title: html`<span class="mono">${r.fullName}</span>`, meta: html`${r.why}` })))} | |
| 75 | </div>`} | |
| 76 | <p>${btn("Back to Migrate", { href: "/migrate", variant: "outline" })}</p> | |
| 77 | </div>`, | |
| 78 | }), | |
| 79 | }; | |
| 80 | } |
src/web/pages/migrate.ts +49 −3
| @@ -50,7 +50,10 @@ import { | ||
| 50 | 50 | import type { Ctx } from "../../http/context.ts"; |
| 51 | 51 | import type { MirrorJob, MirrorStage } from "../../origins/jobs.ts"; |
| 52 | 52 | import { notFoundPage, pageHead, signInFirst, NOT_YOURS_TO_DO, forbiddenPage } from "../chrome.ts"; |
| 53 | import { field, readForm } from "../form.ts"; | |
| 53 | import { field, readForm, type Form } from "../form.ts"; | |
| 54 | import { compact } from "../compact.ts"; | |
| 55 | import { MULTI_MAX, MULTI_NONE, MULTI_TOO_MANY } from "../../actions/migrate_multi.ts"; | |
| 56 | import { migrateSelected, ticked } from "../migrate-multi.ts"; | |
| 54 | 57 | import { html, raw, type Html } from "../html.ts"; |
| 55 | 58 | import { blockedWay } from "../blocked.ts"; |
| 56 | 59 | import { noAgentsBlocked } from "../../actions/blocked_words.ts"; |
| @@ -382,7 +385,7 @@ function account(origin: OriginChoices, values: MigrateValues, withCrew: boolean | ||
| 382 | 385 | /> |
| 383 | 386 | ${btn("Search", { variant: "outline", type: "submit", icon: "search" })} |
| 384 | 387 | </form>`} |
| 385 | <ul class="list" data-pick-rows> | |
| 388 | ${compact(html`<ul class="list" data-pick-rows> | |
| 386 | 389 | ${shown.map((remote) => { |
| 387 | 390 | const value = pickValue(origin.id, remote.fullName); |
| 388 | 391 | const size = formatKib(remote.sizeKb); |
| @@ -394,6 +397,7 @@ function account(origin: OriginChoices, values: MigrateValues, withCrew: boolean | ||
| 394 | 397 | return row({ |
| 395 | 398 | data: { q: `${remote.fullName} ${remote.description}`.toLowerCase() }, |
| 396 | 399 | current: values.source === value, |
| 400 | lead: html`<label class="mig-tick"><input type="checkbox" name="picks" value="${value}" form="migrate-form" aria-label="Tick ${remote.fullName}"></label>`, | |
| 397 | 401 | title: html`<span class="mono">${remote.fullName}</span> |
| 398 | 402 | ${remote.private ? badge("private") : null}`, |
| 399 | 403 | meta: html`${size === "" ? null : html`${size} · `}${remote.description}`, |
| @@ -408,7 +412,12 @@ function account(origin: OriginChoices, values: MigrateValues, withCrew: boolean | ||
| 408 | 412 | })}`, |
| 409 | 413 | }); |
| 410 | 414 | })} |
| 411 | </ul> | |
| 415 | </ul>`)} | |
| 416 | ${shown.length === 0 | |
| 417 | ? null | |
| 418 | : html`<p class="mb"> | |
| 419 | ${btn("Migrate selected", { size: "sm", variant: "outline", type: "submit", name: "multi", value: "1", form: "migrate-form" })} | |
| 420 | </p>`} | |
| 412 | 421 | ${matches.length === 0 && origin.repos.length > 0 |
| 413 | 422 | ? html`<p class="muted small">Nothing matches.</p>` |
| 414 | 423 | : null} |
| @@ -818,6 +827,8 @@ export async function migrateSubmit(ctx: Ctx): Promise<Response> { | ||
| 818 | 827 | const again = async (message: string): Promise<Response> => |
| 819 | 828 | show(ctx, values, await originChoices(ctx), message, 422); |
| 820 | 829 | |
| 830 | if (field(form, "multi") !== "") return migrateTicked(ctx, form, values, again); | |
| 831 | ||
| 821 | 832 | const picked = values.source === "" ? undefined : parsePick(values.source); |
| 822 | 833 | if (picked !== undefined && values.url !== "") |
| 823 | 834 | return again( |
| @@ -862,6 +873,41 @@ export async function migrateSubmit(ctx: Ctx): Promise<Response> { | ||
| 862 | 873 | return redirect(`/migrate/jobs/${started.value.job.id}`); |
| 863 | 874 | } |
| 864 | 875 | |
| 876 | /** "Migrate selected": every ticked row through the one path a single pick takes. */ | |
| 877 | async function migrateTicked( | |
| 878 | ctx: Ctx, | |
| 879 | form: Form, | |
| 880 | values: MigrateValues, | |
| 881 | again: (message: string) => Promise<Response>, | |
| 882 | ): Promise<Response> { | |
| 883 | const picks = ticked(form); | |
| 884 | if (picks.length === 0) return again(MULTI_NONE); | |
| 885 | if (picks.length > MULTI_MAX) return again(MULTI_TOO_MANY); | |
| 886 | if (ctx.auth.scope === undefined || !scopeAllows(ctx.auth.scope, "admin")) | |
| 887 | return forbiddenPage(ctx, "This token is not allowed to do this."); | |
| 888 | const user = ctx.auth.user!; | |
| 889 | const done = await migrateSelected( | |
| 890 | ctx, | |
| 891 | picks, | |
| 892 | { | |
| 893 | owner: values.owner, | |
| 894 | visibility: values.visibility === "public" ? "public" : "private", | |
| 895 | ...(values.agent === "" | |
| 896 | ? {} | |
| 897 | : { | |
| 898 | crew: { | |
| 899 | agent: values.agent, | |
| 900 | autonomous: values.autonomous, | |
| 901 | ...(values.migration ? { mode: "migration" as const } : {}), | |
| 902 | }, | |
| 903 | }), | |
| 904 | after: values.after, | |
| 905 | }, | |
| 906 | repositoryLimitMessage(ctx.app, user), | |
| 907 | ); | |
| 908 | return "response" in done ? done.response : again(done.refusal); | |
| 909 | } | |
| 910 | ||
| 865 | 911 | const STAGES: { name: MirrorStage; label: string }[] = [ |
| 866 | 912 | { name: "creating", label: "Creating the repository" }, |
| 867 | 913 | { name: "fetching", label: "Cloning every branch and tag" }, |
src/web/style/components.ts +3
| @@ -1451,6 +1451,9 @@ ul.list { overflow-anchor: none; } | ||
| 1451 | 1451 | white-space: normal; overflow-wrap: anywhere; |
| 1452 | 1452 | } |
| 1453 | 1453 | :is(#crew-now, #next-steps) .input { max-width: 100%; box-sizing: border-box; } |
| 1454 | /* A /migrate row's tick: the label is the 44px target around the box (docs/design/areas/migrate.md). */ | |
| 1455 | .mig-tick { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; cursor: pointer; } | |
| 1456 | .mig-tick input { margin: 0; accent-color: var(--accent); } | |
| 1454 | 1457 | /* Under a finger, 44px each way (docs/design/areas/touch.md). */ |
| 1455 | 1458 | @media (pointer: coarse) { |
| 1456 | 1459 | /* The bar's height follows its tallest control: the search's 44px box and its 1px border each side, in 8px of padding. */ |
test/migrate-multi.test.ts added +84
| @@ -0,0 +1,84 @@ | ||
| 1 | /** | |
| 2 | * "Migrate selected" on /migrate: up to 20 ticked repositories, one migration each, through the | |
| 3 | * same path a single pick takes (#6408). | |
| 4 | */ | |
| 5 | ||
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { getRepo } from "../src/core/repos.ts"; | |
| 8 | import { settled } from "../src/origins/jobs.ts"; | |
| 9 | import { quietLogs } from "./helpers/globals.ts"; | |
| 10 | import { startMigrateForge, type MigrateForge } from "./support/migrate-forge.ts"; | |
| 11 | ||
| 12 | quietLogs(); | |
| 13 | ||
| 14 | describe("migrate: selected", () => { | |
| 15 | let forge: MigrateForge; | |
| 16 | beforeAll(async () => { | |
| 17 | forge = await startMigrateForge(); | |
| 18 | }, 30_000); | |
| 19 | afterAll(() => forge.stop()); | |
| 20 | ||
| 21 | const post = (cookie: string, picks: string[], extra: Record<string, string> = {}, origin?: string) => | |
| 22 | fetch(`${forge.base}/migrate`, { | |
| 23 | method: "POST", | |
| 24 | redirect: "manual", | |
| 25 | headers: { | |
| 26 | cookie, | |
| 27 | origin: origin ?? new URL(forge.base).origin, | |
| 28 | "content-type": "application/x-www-form-urlencoded", | |
| 29 | }, | |
| 30 | body: new URLSearchParams([ | |
| 31 | ["multi", "1"], | |
| 32 | ["owner", "alice"], | |
| 33 | ["visibility", "private"], | |
| 34 | ...Object.entries(extra), | |
| 35 | ...picks.map((p) => ["picks", p] as [string, string]), | |
| 36 | ]), | |
| 37 | }); | |
| 38 | ||
| 39 | test("each row has a tick box and the account one Migrate selected", async () => { | |
| 40 | const html = await (await forge.browser(forge.aliceCookie, "/migrate")).text(); | |
| 41 | expect(html).toContain(`name="picks" value="${forge.originId}/octo/secret-widgets"`); | |
| 42 | expect(html).toContain("Migrate selected"); | |
| 43 | // The tick is a 44px label around the box, and the button carries no second explanation. | |
| 44 | expect(html).toMatch(/<label class="mig-tick"\s*><input type="checkbox" name="picks"/); | |
| 45 | expect(html).not.toContain("each keeps its name"); | |
| 46 | }); | |
| 47 | ||
| 48 | test("3 picks start 3 jobs, each linked; the rest start when one is refused", async () => { | |
| 49 | const names = ["secret-widgets", "arm", "hush"]; | |
| 50 | const r = await post(forge.aliceCookie, names.map((n) => `${forge.originId}/octo/${n}`)); | |
| 51 | expect(r.status).toBe(200); | |
| 52 | const body = await r.text(); | |
| 53 | const ids = [...body.matchAll(/href="\/migrate\/jobs\/([^"]+)"/g)].map((m) => m[1]!); | |
| 54 | expect(ids).toHaveLength(3); | |
| 55 | expect(body).toContain("<title>Migrating 3 repositories"); | |
| 56 | for (const id of ids) await settled(id); | |
| 57 | for (const n of names) expect(getRepo(forge.app.db, "alice", n)).toBeDefined(); | |
| 58 | ||
| 59 | // Again: all three names are taken, so each is named and refused. | |
| 60 | const again = await post(forge.aliceCookie, [`${forge.originId}/octo/arm`]); | |
| 61 | expect(again.status).toBe(422); | |
| 62 | expect(await again.text()).toContain("octo/arm"); | |
| 63 | }); | |
| 64 | ||
| 65 | test("21 ticked start none, and the 422 says the limit", async () => { | |
| 66 | const picks = Array.from({ length: 21 }, (_, i) => `${forge.originId}/octo/r${i}`); | |
| 67 | const r = await post(forge.aliceCookie, picks, { owner: "alice" }); | |
| 68 | expect(r.status).toBe(422); | |
| 69 | expect(await r.text()).toContain("at most 20"); | |
| 70 | expect(getRepo(forge.app.db, "alice", "r0")).toBeUndefined(); | |
| 71 | }); | |
| 72 | ||
| 73 | test("an origin that is not the caller's is refused like a single pick", async () => { | |
| 74 | const r = await post(forge.bobCookie, [`${forge.originId}/octo/hush`], { owner: "bob" }); | |
| 75 | expect(r.status).toBe(422); | |
| 76 | expect(await r.text()).toContain("not one you have connected"); | |
| 77 | expect(getRepo(forge.app.db, "bob", "hush")).toBeUndefined(); | |
| 78 | }); | |
| 79 | ||
| 80 | test("the mutation keeps the same-origin check", async () => { | |
| 81 | const r = await post(forge.aliceCookie, [`${forge.originId}/octo/hush`], {}, "https://evil.example"); | |
| 82 | expect(r.status).toBe(403); | |
| 83 | }); | |
| 84 | }); |
test/tui-migrate.test.ts +35
| @@ -209,6 +209,41 @@ describe("migrate from the terminal", () => { | ||
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | test("space ticks rows and m starts them all, as the web's Migrate selected does; m with none ticked says so", () => | |
| 213 | withTui(alice, async ({ tui, terminal }) => { | |
| 214 | terminal.feed("M"); | |
| 215 | await settleApp(tui); | |
| 216 | terminal.feed("m"); | |
| 217 | await settleApp(tui); | |
| 218 | expect(tui.screen.toText()).toContain("Tick at least one repository."); | |
| 219 | terminal.feed("/octo/e\r"); // filter to octo/empty | |
| 220 | await settleApp(tui); | |
| 221 | terminal.feed(" "); | |
| 222 | await settleApp(tui); | |
| 223 | expect(tui.screen.toText()).toContain("✓ ticked"); | |
| 224 | terminal.feed("m"); | |
| 225 | await until(() => getRepo(app.db, "alice", "empty") !== undefined); | |
| 226 | await settleApp(tui); | |
| 227 | expect(tui.screen.toText()).toContain("Started 1 migration"); | |
| 228 | })); | |
| 229 | ||
| 230 | test("m starts only the ticked rows the filter shows, and names the hidden ones", () => | |
| 231 | withTui(alice, async ({ tui, terminal }) => { | |
| 232 | terminal.feed("M"); | |
| 233 | await settleApp(tui); | |
| 234 | terminal.feed("/gears\r"); // octo/widgets | |
| 235 | await settleApp(tui); | |
| 236 | terminal.feed(" "); | |
| 237 | await settleApp(tui); | |
| 238 | terminal.feed("/zzz\r"); // "gearszzz": nothing shows | |
| 239 | await settleApp(tui); | |
| 240 | terminal.feed("m"); | |
| 241 | await settleApp(tui); | |
| 242 | const text = tui.screen.toText(); | |
| 243 | expect(text).toContain("1 ticked repository is hidden by the filter"); | |
| 244 | expect(text).not.toContain("Started"); | |
| 245 | })); | |
| 246 | ||
| 212 | 247 | test("u pastes a URL: an empty address is told so, the name comes from the URL, the branch step is skipped, and a blank name keeps the source's", () => |
| 213 | 248 | withTui(alice, async ({ tui, terminal }) => { |
| 214 | 249 | terminal.feed("Mu"); |
new above
offline
The title says 'repositories' even for 1 while the heading pluralises. Build the phrase once (const what =
${n} ${n === 1 ? "repository" : "repositories"}) and use it for both title and pageHead.