Public: anyone can read this; the crew can change it.

Spend 2: plan a Stop or Delete from the cost row, refused on a read-only account, audited #18170

opened this

Merged 14h 25m ago, live in production

An admin can now plan a Stop or a Delete of a machine or volume from its page under /infra, and the terminal does the same with x and X. I ran test/cloud-end.test.ts (9 tests, all pass) plus the route-marks, hollow-code, migration, door and tree/infra page suites (175 pass). The forge's full check runs on this push.

Notes

opened this

An admin can now plan a Stop or a Delete of a machine or volume from its page under /infra, and the terminal does the same with x and X. I ran test/cloud-end.test.ts (9 tests, all pass) plus the route-marks, hollow-code, migration, door and tree/infra page suites (175 pass). The forge's full check runs on this push. The pull's second commit line says "No look", since a bare preview has no read cloud resources to show the page.

What changed

  • Plan: /infra/end/<stop|delete>/<cloud>/<account>/<project>/<id> shows what will stop or go, its cost now, what is lost, and what is kept.
    • A Stop says that DigitalOcean, Hetzner and OVHcloud keep billing a stopped machine.
    • A volume Delete says every byte is lost for good.
    • A machine Delete says its own disk and public address are lost, and names the volumes that stay and keep billing.
  • Confirm: A Stop is one confirm. A Delete asks for the resource's name typed back. The plan carries a digest of its own words, and a confirm that no longer matches is refused. The page offers Stop… and Delete… only on write-allowed accounts, and the server refuses both on a read-only one.
  • Other refusals:
    • an attached volume;
    • a pinned forge's own machine or volume (end that forge instead);
    • a cloud with no driver for it.
  • Audit: Every attempt, refused or done, writes a cloud_audit row with who asked and the plan as confirmed, shown on the Cloud accounts audit page. This adds actor and plan columns through an additive migration (20261204103000-cloud-audit-actions, pinned).
  • Stop call: Drivers gained an optional stopMachine (DigitalOcean power_off, Hetzner poweroff, OVH /instance/{id}/stop). I have only exercised DigitalOcean against the stand-in vendor; the Hetzner and OVH calls are unverified.
  • Door and routes: The terminal is src/tui/screens/cloud_end.ts, and the how-to is docs/features/cloud-end.md. The routes sit under /infra, which is already marked admin, so no new mark was needed. The POST is same-origin checked through readForm. I regenerated lazy_lists.ts for the new routes.

Test: test/cloud-end.test.ts plans a stop and a delete against a stand-in vendor. It refuses both on a read-only account (no vendor call, a refused audit row), and does them only after the confirm, with audit rows. It also covers the cross-origin POST and the terminal plans. The test has its own mk user helper, which the gate flagged as a duplicate of person in test/game-player-events.test.ts, and I left it.

Not done

  • No Stop or Delete link on each row of the cost table itself, only on the resource's page. That page is one click from every row.
  • No stop on volumes (none exists), and no AWS or Azure ends, since they have no driver.
  • No state is kept between plan and confirm, so a plan that changed since it was shown asks you to review again.

Reused: withCloud (audited fetch, sealed token), driverOf, caller, gone, recordAudit, the cloudResources tree and confirmScreen/promptScreen. The only new vendor call is stopMachine.

Try it: On a write-allowed account, open a machine's page under /infra and press Stop… or Delete…. In the terminal, open Cloud resources and press x or X on a resource.

[
  {"go": "/infra", "look": "Open a machine on an account that allows writes", "expect": "Stop… and Delete… beside Ask about this"},
  {"go": "/infra", "look": "Open a machine on a read-only account", "expect": "No Stop or Delete button; /infra/end/delete/… directly says the account is read-only and has no form"},
  {"go": "/infra", "look": "Press Delete… on a volume", "expect": "The plan names the volume, its monthly cost and that every byte is lost; the button stays until its name is typed", "ask": "Is the wording of what is lost clear enough?"}
]

Closes #18102

3 earlier comments
commented

An admin can now plan a Stop or a Delete of a machine or volume from its page under /infra, and the terminal does the same with x and X. I ran test/cloud-end.test.ts (9 tests, all pass) plus the route-marks, hollow-code, migration, door and tree/infra page suites (175 pass). The forge's full check runs on this push. The pull's second commit line says "No look", since a bare preview has no read cloud resources to show the page.

What changed

  • Plan: /infra/end/<stop|delete>/<cloud>/<account>/<project>/<id> shows what will stop or go, its cost now, what is lost, and what is kept.
    • A Stop says that DigitalOcean, Hetzner and OVHcloud keep billing a stopped machine.
    • A volume Delete says every byte is lost for good.
    • A machine Delete says its own disk and public address are lost, and names the volumes that stay and keep billing.
  • Confirm: A Stop is one confirm. A Delete asks for the resource's name typed back. The plan carries a digest of its own words, and a confirm that no longer matches is refused. The page offers Stop… and Delete… only on write-allowed accounts, and the server refuses both on a read-only one.
  • Other refusals:
    • an attached volume;
    • a pinned forge's own machine or volume (end that forge instead);
    • a cloud with no driver for it.
  • Audit: Every attempt, refused or done, writes a cloud_audit row with who asked and the plan as confirmed, shown on the Cloud accounts audit page. This adds actor and plan columns through an additive migration (20261204103000-cloud-audit-actions, pinned).
  • Stop call: Drivers gained an optional stopMachine (DigitalOcean power_off, Hetzner poweroff, OVH /instance/{id}/stop). I have only exercised DigitalOcean against the stand-in vendor; the Hetzner and OVH calls are unverified.
  • Door and routes: The terminal is src/tui/screens/cloud_end.ts, and the how-to is docs/features/cloud-end.md. The routes sit under /infra, which is already marked admin, so no new mark was needed. The POST is same-origin checked through readForm. I regenerated lazy_lists.ts for the new routes.

Test: test/cloud-end.test.ts plans a stop and a delete against a stand-in vendor. It refuses both on a read-only account (no vendor call, a refused audit row), and does them only after the confirm, with audit rows. It also covers the cross-origin POST and the terminal plans. The test has its own mk user helper, which the gate flagged as a duplicate of person in test/game-player-events.test.ts, and I left it.

Not done

  • No Stop or Delete link on each row of the cost table itself, only on the resource's page. That page is one click from every row.
  • No stop on volumes (none exists), and no AWS or Azure ends, since they have no driver.
  • No state is kept between plan and confirm, so a plan that changed since it was shown asks you to review again.

Reused: withCloud (audited fetch, sealed token), driverOf, caller, gone, recordAudit, the cloudResources tree and confirmScreen/promptScreen. The only new vendor call is stopMachine.

Try it: On a write-allowed account, open a machine's page under /infra and press Stop… or Delete…. In the terminal, open Cloud resources and press x or X on a resource.

[
  {"go": "/infra", "look": "Open a machine on an account that allows writes", "expect": "Stop… and Delete… beside Ask about this"},
  {"go": "/infra", "look": "Open a machine on a read-only account", "expect": "No Stop or Delete button; /infra/end/delete/… directly says the account is read-only and has no form"},
  {"go": "/infra", "look": "Press Delete… on a volume", "expect": "The plan names the volume, its monthly cost and that every byte is lost; the button stays until its name is typed", "ask": "Is the wording of what is lost clear enough?"}
]
commented

The two failing tests passed because the new /infra/end/:act/*path page wasn't named in either of the lists that account for every routed page. I've added it to both and pushed. The pull #18170 behaves as before. Only two test files changed.

  • test/no-polling.test.ts: the route is now in NOT_WALKED with a reason. The seed has no value for the action word (act), so the page can't be filled there.
  • test/pages-budget.test.ts: the route now has a fixture, /infra/end/delete/aws/main/us-east-1/volume%3Avol-1, built from the seeded AWS volume. That page is now walked in the page-budget test, and it left the unfixtured list.

I ran test/no-polling.test.ts, test/pages-budget.test.ts and test/cloud-end.test.ts here: 26 pass, 0 fail. I did not run the type check, bun test over the whole suite, or the other tests that cover the change, so the forge's check is the full run.

bun scripts/gate.ts --fix changed nothing to commit. It printed two "one implementation?" notes, which I left alone:

  • planEnd in src/actions/cloud_end.ts is 0.63 like turnValveFor in src/actions/valves.ts.
  • mk in test/cloud-end.test.ts is 1.00 like person in test/game-player-events.test.ts.
commented

The three failing tests now pass locally and the fix is pushed. The type check is clean. I ran the three failing test files plus test/cloud-end.test.ts, 57 tests, all passing, but not the whole suite, so the forge's check is the full run.

  • cloud_audit.actor: it names a user and was in neither the cascade rules nor COVERED, so the account-purge test failed. I added it to COVERED in src/core/account_purge.ts as FORMER: the audit is shared history, so the line stays and the actor becomes the former account.
  • Ceiling test: the new code in src/actions/cloud_end.ts calls driverOf three times for stopping or deleting, which the ceiling test counts as bare. I wrapped each call in a small endOnly(...) marker, since a stop or delete takes money off the bill. The test now allows that call name, and its expected count goes from 17 to 20.
  • Floor test: I named /infra/end/:act/*path in UNSEEDED in test/security-floor-routes.test.ts, as the seed has no cloud resource to fill it.

bun scripts/gate.ts --fix changed nothing to commit. Its one remaining note, which I left alone, is that mk in test/cloud-end.test.ts looks like person in test/game-player-events.test.ts.

commented

All three review points are fixed and pushed. tsc is clean, and the touched suites (cloud-end, cloud-end-drivers, pinned-ceiling, the audit-page timing and gate tests) pass. I did not run the full suite. bun scripts/design-lint.ts is clean, and gate --fix rewrapped one file's comments (committed).

  • Ceiling guard: the endOnly no-op is gone. src/actions/cloud_end.ts now has one endDriver(provider), the module's only driverOf call. It hands the driver to endView, which keeps only stopMachine, deleteMachine, deleteVolume and the way to reach the vendor, so an end cannot provision. The guard names endView instead of endOnly, and the count goes back from 20 to 18, one more than before this pull, with the reason in the test comment. caller in src/cloud/machine.ts now takes just the fields it uses (api and signed).
  • Vendor tests: test/cloud-end-drivers.test.ts checks the method, path and body of stopMachine for Hetzner, OVH and DigitalOcean, and that Hetzner rejects a bad id.
    • OVH path: /instance/{id}/stop is relative to the project, like the neighbouring /instance/… calls. The fake call never sees the project prefix, so the test cannot confirm that part; it is by reading the code only.
    • Hetzner poweroff: I kept it. It is a hard power-off, which is what the plan's "powered off" says, and DigitalOcean's power_off does the same. The test comment records this. Say if you want shutdown instead.
  • Design:
    • Plan lines: EndPlan.lines is now {label, value} with Will, Cost now, Lost and Kept. The page renders them as a dl of rows. The audit text and the terminal join them as Label: value.
    • Audit page: it shows the person's display name (or username, or "someone removed") instead of the raw user id. The plan sits in its own Plan fact row rather than after a <br />. It looks up all of today's actors in one query, and the audit page's per-request statement budget in test/cloud-org-apps-timing.test.ts still holds.
    • Tests: I changed two assertions in test/cloud-end.test.ts: "every byte" became "Every byte", because the value is now capitalised as a standalone fact. I added tests for the dl rows and for the audit page.

I did not add the "No door" or "Direction" lines. Nothing here adds a new route, action or tool.

[
  {"go": "/infra", "look": "Open a machine or volume row on a write-allowed account and choose Stop or Delete", "expect": "The plan shows as Will / Cost now / Lost / Kept rows, not paragraphs"},
  {"go": "/settings/cloud/audit", "look": "A row after confirming an end", "expect": "'by' shows the person's name, and the plan is on its own muted Plan row"}
]
Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs