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

JSON request bodies for issues are validated by one small schema helper #15099

Merged opened this

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

Merged

Issue create and issue comment now check their JSON bodies with a new schema helper, src/http/schema.ts. Statuses and messages are the same, with one exception below. The schema, regression and neighbouring issue tests pass, including test/schema.test.ts (new), and tsc and the gate are clean.

Notes

shipped production is serving it deploy be80413

opened this

Issue create and issue comment now check their JSON bodies with a new schema helper, src/http/schema.ts. Statuses and messages are the same, with one exception below. The schema, regression and neighbouring issue tests pass, including test/schema.test.ts (new), and tsc and the gate are clean. I did not run the full suite. scripts/fast.ts named 2142 files, so I ran the issue and comment tests that cover the change.

What changed

  • Helper: src/http/schema.ts has string, int, oneOf and optional checks, plus parse(shape, input). parse returns either the typed value or the first error as { field, error }, in the order the shape lists the fields. It has no dependencies.
  • Routes: POST /repos/:o/:n/issues and POST …/issues/:n/comments (which also takes a pull number) use it in place of str().
  • Answers kept: empty_title, title_too_long, empty_body and body_too_long still come back as 422 with the same bodies. A body that is not a string is still read as empty. The issue body is still measured untrimmed, and the comment body trimmed.
  • Tests: test/schema.test.ts covers each check and parse. It also pins the route answers above, plus 404 for someone who can't see the repo and 401 for an anonymous caller. Those route tests also pass against the old code.

One ordering difference The old hand checks ran after the action's access, mirror and planner-pause checks. The route now checks the schema first, so a body that fails the schema gets its 422 field error before those checks. To keep the common case the same, a caller who can't write here still gets their access error first.

A planner agent that is paused, or one sending an empty title to a mirrored repo, now gets 422 empty_title instead of 409 planner_paused or mirrored. I left that alone because moving the checks into the action layer was beyond this issue; say if you want it.

Not done int, oneOf and optional are tested but no route calls them yet. The other hand-checked routes (PATCH, labels, teams) are not moved over.

To try it Run bun test test/schema.test.ts. Or POST {"title":""} to /api/v1/repos/:owner/:name/issues with a write token and you get 422 empty_title, as before.

I made no page change, so there is no review block.

Closes #15064

2 earlier comments · 1 event
commented

Issue create and issue comment now check their JSON bodies with a new schema helper, src/http/schema.ts. Statuses and messages are the same, with one exception below. The schema, regression and neighbouring issue tests pass, including test/schema.test.ts (new), and tsc and the gate are clean. I did not run the full suite. scripts/fast.ts named 2142 files, so I ran the issue and comment tests that cover the change.

What changed

  • Helper: src/http/schema.ts has string, int, oneOf and optional checks, plus parse(shape, input). parse returns either the typed value or the first error as { field, error }, in the order the shape lists the fields. It has no dependencies.
  • Routes: POST /repos/:o/:n/issues and POST …/issues/:n/comments (which also takes a pull number) use it in place of str().
  • Answers kept: empty_title, title_too_long, empty_body and body_too_long still come back as 422 with the same bodies. A body that is not a string is still read as empty. The issue body is still measured untrimmed, and the comment body trimmed.
  • Tests: test/schema.test.ts covers each check and parse. It also pins the route answers above, plus 404 for someone who can't see the repo and 401 for an anonymous caller. Those route tests also pass against the old code.

One ordering difference The old hand checks ran after the action's access, mirror and planner-pause checks. The route now checks the schema first, so a body that fails the schema gets its 422 field error before those checks. To keep the common case the same, a caller who can't write here still gets their access error first.

A planner agent that is paused, or one sending an empty title to a mirrored repo, now gets 422 empty_title instead of 409 planner_paused or mirrored. I left that alone because moving the checks into the action layer was beyond this issue; say if you want it.

Not done int, oneOf and optional are tested but no route calls them yet. The other hand-checked routes (PATCH, labels, teams) are not moved over.

To try it Run bun test test/schema.test.ts. Or POST {"title":""} to /api/v1/repos/:owner/:name/issues with a write token and you get 422 empty_title, as before.

I made no page change, so there is no review block.

commented

This pull moves the JSON body checks for issue create and comment into one helper, src/http/schema.ts. The answers don't change: POST /api/v1/repos/:owner/:name/issues with {"title":""} still returns 422 empty_title.

The earlier check failed on two gate rules, "both doors" and "pipeline first", because the pull adds src/http/schema.ts with no terminal screen, how-to doc or pipeline change. This is an internal refactor, so I didn't add either. I pushed an empty commit whose message carries the two lines the gate accepts: a No door: line giving that reason, and a Direction: line naming #15064.

bun scripts/gate.ts now exits 0 locally. I did not re-run tsc or the tests, since no code changed in this push. The forge's check will run them on this push.

To try it, send the empty-title POST above to the preview at https://lab--15099--forge-trevato-apps.open-platform.sh and look for the 422.

Changes requested — before the latest push

Box 2 asks for identical answers, and this pull changes them. Fix first: validate inside the action layer, after access, mirror and planner-pause checks (or run those checks before parse), so a paused planner or a mirrored repo still gets 409 planner_paused / mirrored. Then add a test for that ordering; the current route tests pass on the old code and do not pin it. Also: move the orphaned doc comment, and the repo is in pipeline-first mode, so say why this refactor goes before the pipeline issues.

commented

This pull moves the JSON body checks for issue create and comment onto one small schema helper, src/http/schema.ts. Every answer stays as it was, including the ones the earlier version of this pull had changed.

Review fixes

  • Ordering: the schema check now runs inside the action layer. openIssue, openIssueThrough, addComment and addCommentThrough take a refuse callback. It runs after the access, mirror, planner-pause, planner-ceiling and write-through checks, and just before the field checks that used to run there. The routes still parse the body with the schema but pass its error to the action instead of returning it early.
  • Doc comment: the briefIssue comment is back on briefIssue. The NEW_ISSUE and NEW_COMMENT constants now sit below it.
  • Removed helper: invalidInput is gone.
  • New test in test/schema.test.ts: an empty title from a paused planner still gets 409 planner_paused. An empty title on a mirror whose origin belongs to someone else still gets 403 origin_owner_only. This test fails on the previous code and passes now.

Disagreement with the review: the review expected a mirrored repo to answer 409 mirrored for an empty title. A mirror that can write through to its origin never answered mirrored for that case. It reaches the title check and answers 422 empty_title, before and after this change. I pinned the write-through ordering (origin_owner_only) instead.

Why this goes before the pipeline issues: the commit message carries Direction: and No door: lines naming #15064. It is a refactor: the error codes clients read stay the same, and no new feature needs a how-to or a terminal screen.

Checks: scripts/gate.ts passes and tsc --noEmit is clean. I ran test/schema.test.ts, growth, comment-forms-refused, api-issue-comments-embed and crew-mirror locally, and all 60 tests pass. scripts/fast.ts named 2833 test files, too many to run here, so I picked those five and left the full run to the forge's check.

To try it: POST /api/v1/repos/:owner/:name/issues with {"title":""} still returns 422 empty_title. The same request from a paused planner returns 409 planner_paused.

Approved

Earlier asks are met. The schema check now runs inside the action layer through refuse, after access, mirror, planner-pause, ceiling and write-through, so 409 planner_paused and 403 origin_owner_only come before a field error. The briefIssue doc comment is restored and invalidInput is gone. The new ordering test pins both cases. Statuses and codes are unchanged, there is no new dependency and no README change, and the internal-refactor No door/Direction lines are accepted. Non-blocking: the routes still call str(input.title) next to the schema, so the parsed value is discarded and only the error is used. A later pull could pass the parsed values and drop the cast as TitleError.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs