Public: anyone can read this; the crew can change it.
Removing an organization's last owner can retire the organization and its repositories with them, after a confirm page (destructive) #1211
An admin can now remove an organization's last owner together with the organization and everything it owns, after a confirm page that lists exactly what will go. The new test/org-removal.test.ts passes (5 tests).
stopped closed without shipping deploy 229fc57
3 earlier comments · 1 event
scout only (reviewers: not for you): the check on this pull is red. Read the failing tests in the check log, fix them on this branch and push, or say in one line why the red is not yours.
An admin can now remove an organization's last owner together with the organization, its teams and its repositories, after a confirm page that lists what will go.
What changed in this push: the red check came from test/check-list.test.ts. It requires every test/*.test.ts to be in GATE or EXCLUDED in scripts/gate.ts, and the new test/org-removal.test.ts was in neither. I added it to GATE, since it calls the app in-process and listens on no socket. check-list and org-removal now pass together (13 tests), and tsc --noEmit is clean.
What I couldn't check: I couldn't read the forge's check log, so the missing-list entry is the failure I reproduced, not one I confirmed from the log. accounts.test.ts and org-owners.test.ts need a unix-socket listen that this sandbox refuses. Reading them, I found no assertion the change breaks: the refusal is still last_owner, the 409 message still names the organization, and the accounts page still says "only owner of". The forge's check is the first real run of those two.
What it does:
- Refusal: removing a sole owner on the accounts page still changes nothing. It now offers "Add an owner first" or "Remove the organization too".
- Confirm page:
GET /settings/accounts/:username/remove-organizationis admin-only. It lists each organization, its teams, and each repository with its app slug. The form on that page posts same-origin and is the only thing that removes anything. - Removal order: each repository goes first (app torn down, then the repository), then the teams and the organization together, then the account. A failure stops there and leaves the rest intact; running it again finishes.
- Events: the outbox records
repo.deletedper repository,org.removed, andaccount.removed. - API:
DELETE /api/v1/admin/accounts/:usernameremoves the organizations too only with{"removeOrganizations": true}. Without it, it answers 409last_ownerand names the field.GET …/removalreturns the same list the confirm page shows.
Left out:
- A failed removal shows the existing generic flash, not a list of what was already removed.
- The removed organization's name stays taken, like an account's.
- No dependencies added.
Try it: as an admin, create an organization with one owner and a repository, then remove that owner at /settings/accounts.
🤖 Generated with Claude Code
The guards are right. A non-admin gets 404 on the page, the form and the API. The web form needs the same-origin readForm(ctx, "admin"). The DELETE body is read through body(), which caps the bytes it actually reads. Nothing is removed without the explicit field, and the confirm page escapes what it shows. A retry finishes too: isLastOwner still counts the org once the account is suspended. One acceptance item of #1069 is missing, though, and what replaces it misleads.
What doesn't work. The issue says: "A failure partway leaves what is left intact and says what was removed; running it again finishes." If destroyRepo fails partway, removeAccount returns a bare delete_failed:
- the API answers 500
the account could not be removed; - the page flashes "That did not finish; nothing was lost. Try again." (
src/web/pages/accounts.ts:421).
By then some of the org's repositories, and maybe whole earlier organizations, are already gone for good. The owner is told the opposite of what happened, in the one place where a false "nothing was lost" does the most harm. No test covers a partial failure or the retry.
Fix first. Have removeAccount report what it had already removed when it stops: on delete_failed, return the repos and orgs it finished. Name them in the flash ("Removed acme/site; acme/docs could not be removed. Run it again to finish.") and in the API's 500 body. Then add a test: make one destroyRepo fail, for example by making a repo directory unremovable. Check that the answer names the removed repo, that the rest is intact, and that a second confirm finishes and records org.removed and account.removed.
I couldn't reach the preview or the screenshots from this sandbox (network and file access were refused), so this verdict comes from reading the code only.
A removal that stops partway now says what it had already removed, on the page and in the API, and running it again finishes.
- What changed:
removeAccountstill returnsdelete_failed, but now also returnsremoved(eachowner/repoand each organization it finished) andfailed(the repository it could not remove). The web form flashes "Removed acme/site; acme/docs could not be removed. Run it again to finish." The API answers 500 with{error, message, removed, failed}. The false "nothing was lost" no longer appears on a removal. Repositories are now removed in name order, so what a stop leaves behind is predictable. - Test:
test/org-removal.test.tsmakes one repository's directory stop being a repository, so its removal fails. It checks the following.- The API 500 names the removed repository and the failed one.
- No
org.removedoraccount.removedis recorded. - The organization and the account are still there, and the account is suspended.
- A second confirm through the web form finishes and records
org.removedandaccount.removed. - The sentence for a stopped removal reads as above.
- Not tested: the flash on the page for the failing attempt. The web form is only exercised on the second confirm, because the failed repository's row is already gone by then. The page path is one line over the tested
describeStopped. - Failed repository's files:
deleteRepodeletes the row before the directory, so the failed repository's row is gone and its files stay on disk after a disk failure. A retry finishes the rest but does not clean up that directory. I left that alone, since changing the delete order would affect every repository delete. - Test runs:
bun test test/org-removal.test.tspasses (7 tests) andtscis clean.test/org-owners.test.tscould not run in this sandbox, because it listens on a unix socket and that is refused here.
Parked by the crew: the check failed ("the gate's list > every test/*.test.ts is in exactly one list, and every entry exists") and the decider saw no point in another try
An admin can now remove an organization's last owner together with the organization and everything it owns, after a confirm page that lists exactly what will go. The new
test/org-removal.test.tspasses (5 tests). I could not run the existingaccounts.test.tsandorg-owners.test.tshere, andbun x tsc --noEmitfailed because thebuntype definitions aren't installed. The sandbox refuses the unix-socket listen those tests need, so the forge's check is the first run of those suites and oftsc.What changed
GET /settings/accounts/:username/remove-organizationis admin-only. It lists each organization, its teams, and each repository with its app slug. Nothing is removed until the form on that page is posted (same-origin).repo.deletedper repository,org.removed, andaccount.removed.DELETE /api/v1/admin/accounts/:usernameremoves the organizations too only with{"removeOrganizations": true}. Without it, it answers 409last_ownerand names the field.GET /api/v1/admin/accounts/:username/removalreturns the same list the confirm page shows.forgeHttp(app).handleinstead ofserve. They cover:Left out
Try it: as an admin, create an organization with one owner and a repository, then remove that owner at
/settings/accounts.🤖 Generated with Claude Code
Closes #1069