Repository navigation
fix(api): accept an issue report from an API client - #1089
Conversation
Every atlas issue report was refused with "The following field is invalid: System > Form". The form-builder plugin proves a submission's form exists with `findByID` on the caller's req and no `select`; for an API client that read trips the select-required client gate, the plugin catches the 400, and reports the form as missing. Production logs show the gate's warning immediately before each refusal. It was hidden until now behind the CORS preflight that dropped every atlas POST (#1085). `perTypeForm` now runs its own existence check: the same `findByID` on the caller's req, so a client still cannot cite a form it may not read, with a one-column `select` that satisfies the gate. No spec could see this because the test harness registered `usagePlugin` before `formsPlugin`, the reverse of payload.config.ts, so `forms` and `user-submissions` never received the client read gates under test. The harness now mirrors production, and a new case submits a report as the atlas client through the write guard: it failed with the production error before the fix and passes after. Refs sydevs/SahajAtlasWeb#259 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🚅 Deployed to the SahajCloud-pr-1089 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diagnosis is right, and the harness reorder is the most valuable part — it is why the next such regression fails a spec. Scope is clean: three files, nothing smuggled in.
The fix writes own code where the repo already holds the mechanism. asTrustedReq lets an internal read forward the caller's req with no select, and five modules call it. Using it keeps the plugin the single owner of its existence check, and deletes the duplicated string and the catch-all.
The docblock rewrite also dropped the src/collections/AGENTS.md pointer: supplying validate replaces Payload's default. That is why relationshipValidation is composed at all.
Findings
- should-fix —
fields.ts:260: rebuilds the plugin's existence check. Pass the plugin's validator a trustedreqinstead. - should-fix —
atlas-report-issue-form.int.spec.ts:223:toThrow(/Form/)matches the wrapper message, so the negative case passes against the bug too. - consider —
fields.ts:270: the barecatchreports any failure as a missing form, and logs nothing.
What was checked
- Read whole:
UserSubmissions/fields.ts,plugins/usage/hooks.ts, the spec,tests/utils/testHelpers.ts. - Ladder:
extractIDis the platform's.FORM_MISSINGduplicates the plugin's string, and thefindByIDduplicates its validator. - Traced the gate.
validateClientQueryParamsHookreturns onskipClientQueryValidation;validateClientOriginHookdoes not. A trusted req relaxes shape, not origin. asTrustedReqcallers:deliverRegistration,upsertUserByEmail,fullness,regionTree,atlas/sitemap.- No
## Previewlinks. The Railway preview reports Success. NocontractSyncconsumer reads this field. - Not checked: the plugin's validator source.
node_modulesis absent in this clone, so its behaviour is taken from the PR body.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The form-builder plugin already owns the form-exists check. Rebuilding it here duplicated the plugin's refusal string, the `extractID` cast and a bare `catch` that reported a dropped connection as a missing form. `asTrustedReq` is this repo's opt-out for an internal read forwarding the caller's `req` with no `select`, which five modules already use. The plugin stays the single owner of its check, and origin enforcement still applies to the forwarded read. Trade: the plugin's read passes no `select` and runs at the default depth, so it is heavier than a one-column one. Restores the `src/collections/AGENTS.md` pointer the earlier docblock rewrite dropped: supplying `validate` replaces Payload's default, which is why `relationshipValidation` is composed at all. Addresses #1089 (comment) Addresses #1089 (comment) Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjV2RHc4z2qB8cRpKq7
`toThrow(/Form/)` matched the wrapper, `The following field is invalid: System > Form`, so it would pass on any refusal naming that field. The case now reads `data.errors` and pins the field's own sentence, as `user-submissions-create` and `forms-action-type` do. This does not make the case discriminate the defect, and nothing can: the plugin catches both a genuinely missing form and the select gate's 400, and returns the same sentence for each. The accept case beside it is the regression test — reproduced against the old validator, it fails with the production `System > Form`. Addresses #1089 (comment) Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjV2RHc4z2qB8cRpKq7
|
All three review threads addressed, in two commits, relayed for Actions to land. Adopted
Corrected
Docs checked, nothing stale. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
400 The following field is invalid: System > Form, reported 2026-11-05 right after fix(api): allow the Turnstile token header through CORS preflight #1085 unblocked the atlas forms. The widget shows "Your report wasn't sent".formvalidator proves the form exists withpayload.findByID({ collection: 'forms', id, req }), using the caller'sreqand noselect. For an API client, that read trips the select-required client gate (src/plugins/usage/hooks.ts). The plugin catches the 400 and calls the form missing.Client query validation rejected: select missing or wrong shapefor client 8.perTypeForm(src/collections/UserSubmissions/fields.ts) hands the plugin's own validator a trustedreq—asTrustedReq, this repo's opt-out for an internal read that forwards the caller'sreqwith noselect, which five other modules already use.asTrustedReqrelaxes the query-shape gate only: origin enforcement still reaches the forwarded read, and the shared count cell keeps the create at one metered request.payload.findByIDdefaultsoverrideAccess: true, so forwardingreqnever enforced it — this body claimed otherwise before2eb5ad9.usagePluginbeforeformsPlugin, the reverse ofpayload.config.ts. A plugin only wraps collections that exist when it runs, soformsanduser-submissionsnever got the client read gates under test.tests/utils/testHelpers.tsnow mirrors production.eventfield has no existence check that reads as the client.Refs sydevs/SahajAtlasWeb#259 (criterion 4: a test report from the live site).
Test results
tests/int/atlas-report-issue-form.int.spec.tsadds two cases that submit a report as the atlas client through the write guard: one accepts the configured form, one refuses an unknown form id.ValidationError: The following field is invalid: System > Form). With the fix it passes, 13/13.data.errorsand asserts the field's own sentence. It cannot discriminate the defect under any assertion — the plugin returns that sentence for the select-gate 400 as well — so the accept case is the regression test and this one pins the wording.2eb5ad9and88d5112, one command at a time:atlas-report-issue-form13/13,user-submissions-create+forms-action-type68/68,usage-tracking-dedup+client-query-validation72/72..claude/skills/pr-prep/check.shpasses: lint, format, both typechecks, 239 unit files / 3,084 tests.securityReview.triggerPattern.Manual verification
After deploy: send an issue report from sahajatlas.com. It should show the thank-you screen and arrive at the general contact inbox.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Mg9rjV2RHc4z2qB8cRpKq7