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

Making a forge from an unknown template answers 404 and names the known templates, on the page and the API #13414

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A mistyped template id (a string that isn't blank, starter or an owner/name repo) now gets a 404 instead of a 422, on the page and the API. I ran the new test and the two existing template suites (11 tests, all pass), plus tsc and design-lint; bun scripts/gate.ts --fix printed nothing.

Notes

shipped production is serving it deploy 59903fa

opened this

A mistyped template id (a string that isn't blank, starter or an owner/name repo) now gets a 404 instead of a 422, on the page and the API. I ran the new test and the two existing template suites (11 tests, all pass), plus tsc and design-lint; bun scripts/gate.ts --fix printed nothing. I did not run the full suite — the forge's check does that on push.

What changed

  • API: the spawn door in src/spawn/door.ts now answers 404 unknown_template. The message is "There is no such template; the known ones are blank and starter, or the owner/name of a template repository." The body also carries templates: [{id, title}]. The same door serves POST /api/v1/forges, the MCP spawn tool and the page. I did not touch server.ts.
  • Page: posting /forges/new with a bad template returns 404 with that sentence in the form's error spot. Below it is the list of known templates, each a link to /forges/new?template=<id>.
  • Preselect: that URL now opens the form with the template already selected when the id is valid. The links needed it.
  • Escaping: the bad id is never echoed back anywhere. The test sends <script>alert(1)</script> and checks it is absent from the page and the JSON.
  • Tests: test/template-unknown.test.ts covers the API (dry run and real), the page, and the link preselect. I changed one existing assertion in test/spawn-template-api.test.ts: "nope" used to expect 422 and that case moved to the new test. Non-string values such as 7 or ["starter"] still answer 422.

What I left out

  • A repo-shaped id like someone/missing keeps its existing path: 404 when the repo isn't there or isn't readable. Only the known built-in ids are listed in the 404, not the marked template repos.
  • bun scripts/design-lint.ts passed, but I added no styling. The links use the existing list class.

Try it: curl -X POST $URL/api/v1/forges -H 'authorization: Bearer …' -d '{"name":"kid","template":"nope"}', or post the /forges/new form with a mistyped template. The first push was refused by a pre-push hook that wants a commit message starting Try:, so the branch has an extra empty commit for that.

Closes #13389

4 earlier comments · 1 event
commented

A mistyped template id (a string that isn't blank, starter or an owner/name repo) now gets a 404 instead of a 422, on the page and the API. I ran the new test and the two existing template suites (11 tests, all pass), plus tsc and design-lint; bun scripts/gate.ts --fix printed nothing. I did not run the full suite — the forge's check does that on push.

What changed

  • API: the spawn door in src/spawn/door.ts now answers 404 unknown_template. The message is "There is no such template; the known ones are blank and starter, or the owner/name of a template repository." The body also carries templates: [{id, title}]. The same door serves POST /api/v1/forges, the MCP spawn tool and the page. I did not touch server.ts.
  • Page: posting /forges/new with a bad template returns 404 with that sentence in the form's error spot. Below it is the list of known templates, each a link to /forges/new?template=<id>.
  • Preselect: that URL now opens the form with the template already selected when the id is valid. The links needed it.
  • Escaping: the bad id is never echoed back anywhere. The test sends <script>alert(1)</script> and checks it is absent from the page and the JSON.
  • Tests: test/template-unknown.test.ts covers the API (dry run and real), the page, and the link preselect. I changed one existing assertion in test/spawn-template-api.test.ts: "nope" used to expect 422 and that case moved to the new test. Non-string values such as 7 or ["starter"] still answer 422.

What I left out

  • A repo-shaped id like someone/missing keeps its existing path: 404 when the repo isn't there or isn't readable. Only the known built-in ids are listed in the 404, not the marked template repos.
  • bun scripts/design-lint.ts passed, but I added no styling. The links use the existing list class.

Try it: curl -X POST $URL/api/v1/forges -H 'authorization: Bearer …' -d '{"name":"kid","template":"nope"}', or post the /forges/new form with a mistyped template. The first push was refused by a pre-push hook that wants a commit message starting Try:, so the branch has an extra empty commit for that.

commented

An unknown template id now answers 404 with the message and the list of known templates, on the new-forge page and on the API. The gate is satisfied by two notes in a commit message, not by new terminal or look changes.

What changed

  • POST /forges/new with a mistyped template re-renders the form with the error and a list of the known templates. Each one links to /forges/new?template=<id>.
  • /forges/new?template=<id> preselects that template when it is known, and falls back to the default otherwise.
  • The spawn door in src/spawn/door.ts returns unknown_template for an id it doesn't know.

The failed check The check failed on the "both doors" rule and the "before/after looks" rule. I did not add a terminal change or a look page. The gate now passes locally with an empty commit carrying two lines:

  • No door: — the terminal already shows the API's 404 message, which names the known templates. Only the page's link list is new.
  • No look: — the 404 shows only after posting a mistyped template, which no app.looks page can reach.

I first tried a docs/features/unknown-template.md how-to plus a Looks: /forges/new line. That tripped two other rules instead: /forges/new is not in app.looks, and a new feature file counts as a feature with no pipeline change. So I dropped it.

What I ran

  • scripts/gate.ts passes.
  • tsc --noEmit is clean.
  • test/template-unknown.test.ts and test/spawn-template-api.test.ts pass (8 tests).
  • scripts/fast.ts named 2331 test files for this diff, so I did not run them here. The forge's check runs the full suite on the push.

To try it

  1. Open /forges/new?template=starter.
  2. Post the form with a mistyped template to see the 404 and the links.
commented

An unknown template id now answers 404 with unknown_template, a sentence naming the known templates, and their ids. This holds on the new-forge page and on the API (POST /api/v1/spawn).

Fixed this push: two older tests still expected the previous behaviour, a 422 with "template must be blank, starter or…". Those tests were out of date, not the code, so I changed them:

  • test/new-forge.test.ts expects 404, the new message, and the link to /forges/new?template=starter.
  • test/tui-newforge.test.ts expects the new message beside the Template field.

Tests: these two files and test/template-unknown.test.ts pass here (38 tests), and gate.ts passes. I did not run the three other failures from the check, because none touches this pull's code:

  • started-from-line is red on main too.
  • The engine-stream test is flaky.
  • The idle-previews test is unrelated.

What changed

  • Posting the new-forge form with a mistyped template re-renders it with the error and a list of the known templates, each linking to /forges/new?template=<id>.
  • /forges/new?template=<id> preselects a known template and falls back to the default for an unknown one.
  • The error does not echo the id that was asked for.
  • A template field of the wrong type (not a string) is still a 422 from the plan.

Not done: no change under src/tui/ and no app.looks page. The commit carries No door: and No look: lines saying why, because the terminal already shows the API's message and no look page can reach the 404.

To try it: open /forges/new?template=starter, then post the form with a mistyped template to see the 404 and the links.

commented

I merged main into the branch and pushed; the merge commit is 1653fc1a2. The only conflict was in src/web/pages/new-forge.ts.

The conflict. main added an askedTemplate(ctx) helper that does what my inline ?template= check did: use the asked template if it is known, otherwise the default. I kept main's helper and dropped my inline version. My 404 re-render and the known-templates link list are untouched.

Checks run after the merge:

  • gate.ts is clean.
  • tsc --noEmit is clean.
  • Four test files pass (43 tests): new-forge, tui-newforge, template-unknown and spawn-template-api.

I did not run the full suite; the forge's check does that on the push.

To try it: open /forges/new?template=starter, then post the form with a mistyped template to see the 404 and the links.

Changes requested — before the latest push

Works in the preview: POST /api/v1/forges with template "nope" answers 404 unknown_template, the sentence, and the known ids, and the id is not echoed. Changes needed, in one round:

  1. (first) The how-to is stale. docs/features/new-forge-template.md still says an unknown template answers 422 and does not mention the 404, the list or the links. Update that file (not README).
  2. Both doors: the terminal only shows the sentence; the page also gets a list of known templates as links. Say in the how-to what the terminal does instead (its Templates screen lists them), or show the list there too.
  3. The MCP spawn door lost its test: the old assertion on the 'nope' case was deleted and nothing replaces it. Add one for mcp spawn with an unknown string template.
  4. The page test posts as a stranger, so it never proves the signed-in form. Post as alice and assert the 404 with the links and that the form keeps the name. Also drop the pointless /forges/templates fetch.
  5. Principle 1/8: the sentence ends with 'or the owner/name of a template repository' while the page repeats the ids as a list below it; say it once.
  6. Small: knownTemplates builds its list inline with a long line and ad-hoc 'muted small' span; reuse the /templates row markup (templateList) so the two lists cannot drift.
commented

All six points are addressed. The two earlier pushes had a red test/new-forge.test.ts while I was still fixing it; the latest push is green for the suites below.

  1. How-to: docs/features/new-forge-template.md now says that a string that is no template answers 404 unknown_template, with the sentence and the built-in ids in templates, and that the id is never echoed. It also says other wrong types stay 422, that the page re-renders the form with the /templates rows, and what the terminal does (see 2).
  2. Terminal: it still shows the sentence only. The how-to now says its Templates screen is where the list is, rather than repeating the list there.
  3. MCP test: test/template-unknown.test.ts now calls spawn with template "nope" over /mcp. It asserts the sentence and unknown_template, and that the payload is not echoed.
  4. Page test: it now signs in as alice at /signin, posts the form with the hostile template, and asserts the 404, the sentence and the rows. It also asserts the name kid stays in the form and the payload is not echoed. The /forges/templates fetch is gone.
  5. One sentence: the message is now just "There is no such template." The ids are carried by the page's list and by templates in the API body.
  6. Shared rows: templateRows(rows) is extracted from src/web/pages/templates.ts and used by both /templates and the 404 page. The 404 page reads templateList, so a signed-in maker also sees readable template repositories there. knownTemplates is deleted.

Because the rows are buttons, not links, test/new-forge.test.ts and test/tui-newforge.test.ts were updated for the shorter sentence and the row markup. Those were assertions on the old wording, not behaviour changes.

tsc and the design lint are clean. These suites pass: template-unknown, spawn-template-api, templates-page, new-forge, tui-newforge. gate.ts --fix ran with no output.

Approved

Earlier asks (how-to updated, one sentence, shared templateRows, MCP and page tests that sign in and assert the 404, id never echoed) are all met in the diff since 1653fc1a. The 404 is on the API, MCP and page; other wrong types stay 422; README is untouched; the how-to lives in docs/features/new-forge-template.md.

Next two things, both non-blocking:

  1. Non-blocking (design: anything that navigates is an <a>): templateRows renders each row as a GET form with a button. It matches the existing /templates page, so it is not new, but a link per row would be lighter on a phone and in the terminal-free path.
  2. Non-blocking: the long inline page() call in newForgeSubmit (src/web/pages/new-forge.ts) is hard to read; pull the 404 view into a small helper.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs