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

As code: infra.json in a repo, written by the UI, reconciled on merge (#16696) #17089

opened this

Parked 44h 28m ago

This is the first two steps of phase 4: the infra.json schema and a read-only diff of it against what runs. The page writing the file as commits, and reconciling on merge to main, are not done.

Notes

opened this

This is the first two steps of phase 4: the infra.json schema and a read-only diff of it against what runs. The page writing the file as commits, and reconciling on merge to main, are not done.

What changed

  • Schema: an app's repo may hold infra.json at its root on the main branch, as {"version":1,"machines":[{name, account, place, host?, lifetimeDays?}]}.
    • Every machine in it runs that app, and the file never names an app, so it cannot touch another repo's machines.
    • The schema is closed: an unknown key is refused, so a typo is not read as "no host". It is capped at 64 KiB and 50 machines.
    • Every problem is reported with its path, for example machines[0].host.
  • Diff: pure code in src/cloud/infra_file.ts marks each machine as add, change, remove or same. Retired machines count as not there. Only the declaring app's own running machines can be marked remove, and a name already used by another app is flagged.
  • Where you see it: src/cloud/infra_read.ts reads the file from each app's repo and feeds all four doors.
    • Web: an "As code" block on /infra.
    • Terminal: rows on the Infrastructure screen, loaded after the first paint.
    • API: GET /api/v1/admin/infra/code.
    • MCP: an infra tool action code.
    • All are admin-only. The how-to is a new section in docs/features/infra.md.
  • Tests: test/infra-file.test.ts covers the schema, the diff and each door. bun x tsc --noEmit is clean. I ran the infra, Talk, own-source, unused-exports, doorless and feature-doors tests; all pass. I did not run the full suite.
  • Gate: I ran bun scripts/gate.ts (it names no remaining failure) and bun scripts/design-lint.ts (clean). I added a "No door" line because the "both doors" rule counts only new files, and the terminal screen and how-to are extended, not new.
  • Reused: parseInfra and the plan code reuse NAME from core/pinned.ts. The page reuses row, rowList and the settings-block section.

Left out

  • Writing infra.json from the UI as a commit.
  • Reconcile on merge to main.
  • Applying anything: nothing here makes or ends machines.
  • Other kinds, such as firewalls and buckets, which phases 2 and 3 will add.

Try it: commit an infra.json to an app's main branch, then open /infra as an admin. You can also call GET /api/v1/admin/infra/code, or infra with {action:"code"}.

Review block:

[{"go":"/infra","look":"As code block under the running list, one per repo with infra.json","expect":"'1 to add' and a row 'add shop-1 at <place>'; a malformed file shows 'infra.json is refused: <path>: <why>'"}]

Closes #17075

Show 5 earlier items

7 earlier comments
commented

I merged main into the branch and pushed it as e27d153c7.

Both conflicts were in imports, so I kept both sides:

  • src/http/infra_routes.ts: infraCode from this branch, plus machineOf and the snapshot actions from main.
  • src/web/pages/infra.ts: the CodeFile type from this branch, plus the snapshot imports from main.

bun x tsc --noEmit is clean. I ran 88 tests across 10 files (the infra, OpenAPI operation-id and route-timing tests) and all pass. I didn't run the rest of the suite, so the forge's check on this push is the full run.

commented

<!-- look-pages e27d153c76e9 --> Look pages for e27d153, from the gate:

  • look pages (named): this pull changes src/web/pages/infra.ts; a commit names /settings/security/controls
commented

I pushed an empty commit, 2ce9275db, to answer the look-pages note. Its message has the line No look: /infra is not a page of app.looks in forge.json, and the owner's look seed has no cloud/ directory to read. I haven't seen the forge re-run the look-pages check on this push yet.

The note said the pull changes src/web/pages/infra.ts while the only look page a commit names is /settings/security/controls. The gate's rule wants either Looks: <path> naming a page in app.looks, or No look: <why>. /infra isn't in app.looks, so I used No look: rather than add a page to the look list. If you want a look for the code section, say so and I'll add /infra to app.looks and the owner's list.

The four recurring refusals you listed don't apply to this change. Nothing here adds a dead export, uses as never, or leaves a job untimed. The route is already in the untimed list from an earlier commit. The rest of the gate still ran after my commit and printed no failures. The unrelated duplicate-function note about codeSays in src/cloud/infra_read.ts is only a note, and I left it.

commented

All six findings are addressed and pushed. bun x tsc --noEmit, the gate, bun scripts/design-lint.ts and the infra, route-timing and dead-code tests pass. The forge's full check has not run yet.

What changed

  1. Page cost. infraCode (in src/cloud/infra_read.ts) reads all apps in parallel. The parsed file is cached per (repo dir, tip oid), capped at 1000 entries. An unchanged tip costs one ref lookup and no blob read. The "unchanged tip gives the same answer" test checks the result only, not that the cache is hit.
  2. Tests.
    • A guest gets 404 from the API.
    • A non-admin gets 403 not_admin from the API and from /infra.
    • A non-admin gets no "As code" block, no tool code result and no terminal rows.
    • A malformed file shows infra.json is refused: machines[0].typo: … on the page and in the API.
    • A repo with no infra.json yields nothing.
  3. blocked kind. A name already used by another app is now blocked. It is counted in the tally and is never something to apply.
  4. Wording. The OpenAPI summary and detail and the route-timing reason now say the file is read from each app's repo main branch. codeSays now uses a new countLine in src/core/gate_triage.ts, and tallyLine uses it too.
  5. Design. Each file is an <h3> with the app name, and its changes are rows. A file that matches what runs gets one muted line. With no files, the block is left out. No new component class.
  6. Look. /infra is in app.looks in forge.json. I did not use No look.

I also updated docs/features/infra.md.

Disagreement. You asked for 404 for a non-admin on the API. The route has role: "admin", so the router refuses a non-admin with 403 not_admin before the handler runs. The handler's own 404 is only reached by a guest. I kept the router's existing behaviour and pinned it in the test. Both refuse, and neither leaks any data.

Not done

  • The page and the terminal still show nothing when the read fails. The read only fails when the viewer is not an admin, and those doors are already refused earlier, so there is no admin-visible failure to surface.
  • Applying the file and writing it from the UI remain out of scope, as before.

To try it: sign in as an admin, put an infra.json at the root of an app's repo on main, and open /infra. The same data is at GET /api/v1/admin/infra/code and in the infra tool's code action.

[
 {"go":"/infra","look":"As code block, one heading per app, rows per change","expect":"No paragraph repeating the rows; a matching file shows one muted line"},
 {"go":"/infra","look":"A repo whose infra.json has an unknown key","expect":"Row reads 'infra.json is refused: machines[0].typo: not a key of a machine'"}
]
commented

The preview deploy failed because my last push put 33 paths in app.looks, one over the cap of 32. I took /infra back out and pushed. app.looks is back to 32 paths, and the forge-looks and infra-file tests pass (19 pass, 0 fail). The deploy itself has not been re-run yet.

That undoes the /infra look you asked for in item 6 of the earlier review. The 32 slots are all taken. /infra is already named in NOT_A_PAGE in test/forge-looks.test.ts as "no picture: app.looks is at its 32 paths", and every other top-level page must stay in app.looks. Adding /infra would mean dropping another page's look, which is a person's call. The commit carries a No look: line with this reason, and the page is covered by test/infra-page.test.ts and test/infra-file.test.ts.

Everything else in the earlier change is unchanged. The page is still a heading with rows for the changes. The read is still parallel and cached per tip. blocked is still its own kind. The tests still pin the gates.

commented

I merged main into the branch and pushed it, so #17089 should merge cleanly again. I haven't seen the forge's check verdict on this push yet.

Two files conflicted, and I kept both sides in each:

  • src/http/mcp/tools/infra.ts: the infra tool's action list now has code from this pull and price and bind from the buckets work on main.
  • docs/features/infra.md: it now has both the "As code" section and the "Buckets" section.

bun x tsc --noEmit passes. I ran only the three infra and bucket test files the merge touched (23 pass, 0 fail), not the full suite. bun scripts/gate.ts --fix rewrapped nothing, and it noted five files with comment lines over 100 columns that the nightly rewrap will handle on main.

commented

I fixed the module-state failure and pushed; the keymap failure is not this pull's and I left it alone.

  • Module-state test: src/cloud/infra_read.ts kept its per-tip read cache in a module-level Map, which the rule refuses. The cache is now a WeakMap keyed by the app, so each forge has its own. test/module-state.test.ts and test/infra-file.test.ts pass (14 tests), and bun x tsc --noEmit is clean.
  • Keymap test: "every screen that binds r…" is red on main too, per the check log, and the check didn't count it against this pull.

I haven't seen the forge's check on this push yet.

commented

Closed by the crew: main moved under it 2 times and the branch could not be brought up to date. Conflicting files: docs/features/infra.md, src/http/api/admin.ts, src/http/mcp/tools/infra.ts, src/tui/screens/infra.ts.

Sign in to join this conversation.

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

Keyboard shortcuts

Docs