Public: anyone can read this; the crew can change it.
The remaining copies of the origin, app and report refusals import src/actions/origin_app_words.ts #16930
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/5692-the-remaining-copies-of-the-origin-app-a → main 0 commits fork
9 files
changed +39
−16
- src/actions/migrate.ts
- src/contract/openapi/routes/getApiV1UserOriginsIdRepos.ts
- src/contract/openapi/routes/postApiV1ReposOwnerNameMakeItYours.ts
- src/contract/openapi/routes/postApiV1UserOriginsIdBrowseOwnerNameContribute.ts
- src/contract/openapi/routes/postApiV1UserOriginsIdFork.ts
- src/contract/openapi/shared.ts
- src/origins/mirror.ts
- src/tui/screens/common.ts
- test/origin-app-words.test.ts
src/actions/migrate.ts +2 −1
| @@ -35,6 +35,7 @@ | ||
| 35 | 35 | * checksums, on both sides (`apps/dump_import.ts`). |
| 36 | 36 | */ |
| 37 | 37 | |
| 38 | import { ORIGIN_UNREACHABLE } from "./origin_app_words.ts"; | |
| 38 | 39 | import { NOT_A_MEMBER } from "../core/roles.ts"; |
| 39 | 40 | import { requireVerified } from "./verify.ts"; |
| 40 | 41 | import type { App } from "../app.ts"; |
| @@ -757,7 +758,7 @@ async function afterWords( | ||
| 757 | 758 | done.error.error === "unauthorized" || |
| 758 | 759 | done.error.error === "not_found" |
| 759 | 760 | ? `. ${source.label} was not archived: the connected account lacks admin rights there. Archive it on the origin yourself` |
| 760 | : `. ${source.label} was not archived: the origin could not be reached`; | |
| 761 | : `. ${source.label} was not archived: ${ORIGIN_UNREACHABLE}`; | |
| 761 | 762 | } |
| 762 | 763 | const tips: Record<string, string> = {}; |
| 763 | 764 | for (const [ref, oid] of refs) if (ref.startsWith("refs/heads/")) tips[ref] = oid; |
src/contract/openapi/routes/getApiV1UserOriginsIdRepos.ts +2 −1
| @@ -1,3 +1,4 @@ | ||
| 1 | import { ORIGIN_UNREACHABLE } from "../../../actions/origin_app_words.ts"; | |
| 1 | 2 | import type { Route } from "../shared.ts"; |
| 2 | 3 | |
| 3 | 4 | const U = "no valid credentials were sent"; |
| @@ -17,7 +18,7 @@ export const route: Route = { | ||
| 17 | 18 | forbidden: F, |
| 18 | 19 | not_found: NF, |
| 19 | 20 | invalid_group: "422, group is yours, shared or public", |
| 20 | origin_unreachable: "502, the origin could not be reached and nothing is cached", | |
| 21 | origin_unreachable: `502, ${ORIGIN_UNREACHABLE} and nothing is cached`, | |
| 21 | 22 | }, |
| 22 | 23 | refuses: [401, 404], |
| 23 | 24 | }; |
src/contract/openapi/routes/postApiV1ReposOwnerNameMakeItYours.ts +2 −1
| @@ -1,3 +1,4 @@ | ||
| 1 | import { APP_ALREADY_YOURS } from "../../../actions/origin_app_words.ts"; | |
| 1 | 2 | import { PROVE_FIRST } from "../../../actions/verify_words.ts"; |
| 2 | 3 | import { REPO, type Route } from "../shared.ts"; |
| 3 | 4 | import { VISIBILITY_WORDS } from "../../../core/arg_words.ts"; |
| @@ -14,7 +15,7 @@ export const route: Route = { | ||
| 14 | 15 | body: { dryRun: "boolean", name: "string", visibility: "string" }, |
| 15 | 16 | refusals: { |
| 16 | 17 | invalid: `422: ${VISIBILITY_WORDS}`, |
| 17 | own: "409: this app is already yours", | |
| 18 | own: `409: ${APP_ALREADY_YOURS}`, | |
| 18 | 19 | unverified: `403: ${PROVE_FIRST}`, |
| 19 | 20 | limit: "429: at most so many copies a day; { resetsAt }", |
| 20 | 21 | repository_limit: "403: at the repository limit", |
src/contract/openapi/routes/postApiV1UserOriginsIdBrowseOwnerNameContribute.ts +2 −1
| @@ -1,3 +1,4 @@ | ||
| 1 | import { ORIGIN_UNREACHABLE } from "../../../actions/origin_app_words.ts"; | |
| 1 | 2 | import { PROVE_FIRST } from "../../../actions/verify_words.ts"; |
| 2 | 3 | import { BROWSE, type Route } from "../shared.ts"; |
| 3 | 4 | |
| @@ -15,7 +16,7 @@ export const route: Route = { | ||
| 15 | 16 | refusals: { |
| 16 | 17 | not_found: "404: no such origin of yours, or no such repository there", |
| 17 | 18 | unverified: `403: ${PROVE_FIRST}`, |
| 18 | origin_unreachable: "422: the origin could not be reached", | |
| 19 | origin_unreachable: `422: ${ORIGIN_UNREACHABLE}`, | |
| 19 | 20 | invalid_branch: "422: that branch is not one this forge can use", |
| 20 | 21 | unknown_base: "422: that base branch is not one this forge can use", |
| 21 | 22 | fork_timeout: "504: the origin took the fork and it has not appeared yet; try again shortly", |
src/contract/openapi/routes/postApiV1UserOriginsIdFork.ts +2 −1
| @@ -1,3 +1,4 @@ | ||
| 1 | import { ORIGIN_UNREACHABLE } from "../../../actions/origin_app_words.ts"; | |
| 1 | 2 | import type { Route } from "../shared.ts"; |
| 2 | 3 | |
| 3 | 4 | export const route: Route = { |
| @@ -11,7 +12,7 @@ export const route: Route = { | ||
| 11 | 12 | status: 202, |
| 12 | 13 | refusals: { |
| 13 | 14 | not_found: "404: no such origin of yours", |
| 14 | origin_unreachable: "422: the origin could not be reached", | |
| 15 | origin_unreachable: `422: ${ORIGIN_UNREACHABLE}`, | |
| 15 | 16 | fork_timeout: "504: the origin took the fork and it has not appeared yet; try again shortly", |
| 16 | 17 | mirror_failed: "502: a local copy of the fork could not be made", |
| 17 | 18 | }, |
src/origins/mirror.ts +2 −1
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | * leave a mirror you can retry, not a half-created nothing. |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | import { ORIGIN_UNREACHABLE } from "../actions/origin_app_words.ts"; | |
| 14 | 15 | import { lacks, NOT_A_MEMBER } from "../core/roles.ts"; |
| 15 | 16 | import type { App } from "../app.ts"; |
| 16 | 17 | import { |
| @@ -339,7 +340,7 @@ export function mirrorMessage(error: MirrorError): string { | ||
| 339 | 340 | case "dir_in_the_way": |
| 340 | 341 | return "a folder on disk already holds that name, with no repository behind it"; |
| 341 | 342 | case "unreachable": |
| 342 | return "the origin could not be reached"; | |
| 343 | return ORIGIN_UNREACHABLE; | |
| 343 | 344 | case "repository_limit": |
| 344 | 345 | return "this account is at the forge's repositories limit"; |
| 345 | 346 | case "storage_limit": |
src/tui/screens/common.ts +2 −1
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * of them. Nothing here knows about repos or issues — that is the point. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { ORIGIN_UNREACHABLE } from "../../actions/origin_app_words.ts"; | |
| 10 | 11 | import { DELETING_SAYS } from "../../core/repo_deleting.ts"; |
| 11 | 12 | import { CHECK_STALE_REFUSAL } from "../../checks/stale.ts"; |
| 12 | 13 | import { DRAFT_REFUSAL } from "../../core/pulls.ts"; |
| @@ -1053,7 +1054,7 @@ const MESSAGES: Record<string, string> = { | ||
| 1053 | 1054 | origin_read_only: "this account was connected read-only; nothing is written through it", |
| 1054 | 1055 | origin_paused: "this connection is not verified yet; writes are paused", |
| 1055 | 1056 | origin_protected: "the operator protects this repository at its origin: nothing is pushed to it from here; propose the change from your fork", |
| 1056 | origin_unreachable: "the origin could not be reached; nothing changed", | |
| 1057 | origin_unreachable: `${ORIGIN_UNREACHABLE}; nothing was changed`, | |
| 1057 | 1058 | already_connected: ORIGIN_ALREADY_CONNECTED, |
| 1058 | 1059 | already_mirrored: "that repository is already mirrored here", |
| 1059 | 1060 | unknown_host: "that does not look like a forge", |
test/origin-app-words.test.ts +22 −7
| @@ -38,7 +38,20 @@ const SENTENCES = { | ||
| 38 | 38 | REPORT_ALREADY_DECIDED: "this report was already decided", |
| 39 | 39 | } as const; |
| 40 | 40 | |
| 41 | const DOORS = ["src/http/api.ts", "src/http/mcp.ts"] as const; | |
| 41 | // Each door and the sentences it says; the API and the MCP say all three. | |
| 42 | const ALL = Object.keys(SENTENCES) as (keyof typeof SENTENCES)[]; | |
| 43 | const DOORS: Record<string, readonly (keyof typeof SENTENCES)[]> = { | |
| 44 | "src/http/api.ts": ALL, | |
| 45 | "src/http/mcp.ts": ALL, | |
| 46 | "src/origins/mirror.ts": ["ORIGIN_UNREACHABLE"], | |
| 47 | "src/actions/migrate.ts": ["ORIGIN_UNREACHABLE"], | |
| 48 | "src/tui/screens/common.ts": ["ORIGIN_UNREACHABLE"], | |
| 49 | "src/contract/openapi/shared.ts": ["ORIGIN_UNREACHABLE"], | |
| 50 | "src/contract/openapi/routes/postApiV1UserOriginsIdFork.ts": ["ORIGIN_UNREACHABLE"], | |
| 51 | "src/contract/openapi/routes/postApiV1UserOriginsIdBrowseOwnerNameContribute.ts": ["ORIGIN_UNREACHABLE"], | |
| 52 | "src/contract/openapi/routes/getApiV1UserOriginsIdRepos.ts": ["ORIGIN_UNREACHABLE"], | |
| 53 | "src/contract/openapi/routes/postApiV1ReposOwnerNameMakeItYours.ts": ["APP_ALREADY_YOURS"], | |
| 54 | }; | |
| 42 | 55 | |
| 43 | 56 | describe("origin, app and report refusals live in one module", () => { |
| 44 | 57 | test("the module says each sentence, word for word", () => { |
| @@ -49,14 +62,16 @@ describe("origin, app and report refusals live in one module", () => { | ||
| 49 | 62 | }).toEqual(SENTENCES); |
| 50 | 63 | }); |
| 51 | 64 | |
| 52 | for (const door of DOORS) { | |
| 65 | for (const [door, names] of Object.entries(DOORS)) { | |
| 53 | 66 | test(`${door} imports the sentences and types none of them out`, () => { |
| 54 | 67 | const text = read(door); |
| 55 | expect(importsFrom(text, "actions/origin_app_words.ts")).toBe(true); | |
| 56 | for (const [name, sentence] of Object.entries(SENTENCES)) { | |
| 57 | expect(text).toContain(name); | |
| 58 | expect(text).not.toContain(sentence); | |
| 59 | } | |
| 68 | // A module inside src/actions/ imports its sibling as "./origin_app_words.ts". | |
| 69 | const imported = door.startsWith("src/actions/") | |
| 70 | ? text.includes('from "./origin_app_words.ts"') | |
| 71 | : importsFrom(text, "actions/origin_app_words.ts"); | |
| 72 | expect(imported).toBe(true); | |
| 73 | for (const name of names) expect(text).toContain(name); | |
| 74 | for (const sentence of Object.values(SENTENCES)) expect(text).not.toContain(sentence); | |
| 60 | 75 | }); |
| 61 | 76 | } |
| 62 | 77 | }); |
new above
offline