Public: anyone can read this; the crew can change it.
Revert "The API refuses a read-only mirror with 409 and the same sentence as every door (#16434)" #16469
Check · Review · Land · Live — No review yet.
revert-16450 → main 1 commit
3 files
changed +6
−19
src/actions/branch_words.ts +1
| @@ -49,6 +49,7 @@ export const DELETE_ERRORS: Record<string, string> = { | ||
| 49 | 49 | "That branch moved while the page was open, so nothing was deleted. Reload and look again.", |
| 50 | 50 | }; |
| 51 | 51 | |
| 52 | ||
| 52 | 53 | /** |
| 53 | 54 | * The one sentence a refused branch create says on every door (page, Talk and MCP, the terminal): |
| 54 | 55 | * on a mirror its person may only read, where to change it instead (`copyWords`, from |
src/http/api.ts +5 −9
| @@ -87,7 +87,7 @@ import { | ||
| 87 | 87 | ORIGIN_ALREADY_CONNECTED, |
| 88 | 88 | } from "../actions/origins.ts"; |
| 89 | 89 | import { |
| 90 | createBranchSaying, | |
| 90 | createBranch, | |
| 91 | 91 | deleteBranch as deleteBranchAction, |
| 92 | 92 | } from "../actions/branches.ts"; |
| 93 | 93 | import { editFiles, type EditFile } from "../actions/contents.ts"; |
| @@ -753,7 +753,7 @@ export const NOTHING_TO_CHANGE = () => | ||
| 753 | 753 | * caller's own request being wrong. |
| 754 | 754 | */ |
| 755 | 755 | function branchStatus(error: string): number { |
| 756 | if (error === "exists" || error === "branch_moved" || error === "mirror_read_only") return 409; | |
| 756 | if (error === "exists" || error === "branch_moved") return 409; | |
| 757 | 757 | if (error === "default_branch") return 409; |
| 758 | 758 | if (error === "unknown_branch") return 404; |
| 759 | 759 | return 422; |
| @@ -1933,16 +1933,12 @@ export function apiRoutes(router: Router<Handler>, isPage: (path: string) => boo | ||
| 1933 | 1933 | const repo = loadRepo(ctx); |
| 1934 | 1934 | if (!repo) return notFound(); |
| 1935 | 1935 | const input = await body(ctx.request); |
| 1936 | const created = await createBranchSaying(ctx.app, ctx.auth.user, repo, { | |
| 1936 | const created = await createBranch(ctx.app, ctx.auth.user, repo, { | |
| 1937 | 1937 | name: str(input.name), |
| 1938 | 1938 | from: str(input.from), |
| 1939 | 1939 | }); |
| 1940 | if (!created.ok) { | |
| 1941 | const { code, words } = created.error; | |
| 1942 | // The sentence every door says: where to change a read-only mirror, or the origin's reason. | |
| 1943 | if (code === "mirror_read_only" || code === "origin_refused") return apiError(code, 409, words); | |
| 1944 | return originAware(code, branchStatus(code)); | |
| 1945 | } | |
| 1940 | if (!created.ok) | |
| 1941 | return originAware(created.error, branchStatus(created.error)); | |
| 1946 | 1942 | return json(created.value, 201); |
| 1947 | 1943 | }); |
| 1948 | 1944 |
test/mirror-write-copy.test.ts −10
| @@ -168,16 +168,6 @@ describe("a change asked of a mirror", () => { | ||
| 168 | 168 | expect(wrote.text).toContain(SAID); |
| 169 | 169 | }); |
| 170 | 170 | |
| 171 | test("the API answers 409 with the same sentence, for a branch and for the contents route", async () => { | |
| 172 | const headers = { "content-type": "application/json", authorization: `Bearer ${token}` }; | |
| 173 | const branch = await fetch(`${homeServers.url}/api/v1/repos/gina/voxel/branches`, { method: "POST", headers, body: JSON.stringify({ name: "via-api", from: "main" }) }); | |
| 174 | expect(branch.status).toBe(409); | |
| 175 | expect(await branch.json()).toMatchObject({ error: "mirror_read_only", message: SAID }); | |
| 176 | const contents = await fetch(`${homeServers.url}/api/v1/repos/gina/voxel/contents`, { method: "POST", headers, body: JSON.stringify({ branch: "main", message: "x", files: [{ path: "a.txt", content: "a\n" }] }) }); | |
| 177 | expect(contents.status).toBe(409); | |
| 178 | expect(await contents.json()).toMatchObject({ error: "mirror_read_only", message: SAID }); | |
| 179 | }); | |
| 180 | ||
| 181 | 171 | test("the actions refuse it for every door: the page's branch create says the same sentence", async () => { |
| 182 | 172 | const mirror = getRepo(home.db, "gina", "voxel")!; |
| 183 | 173 | expect(await createBranch(home, gina, mirror, { name: "via-action" })).toEqual({ ok: false, error: "mirror_read_only" }); |
new above
offline