refactor: dedupe layout-type/answer-format logic; test rate-limit & captcha#59
Merged
Conversation
…aptcha Maintainability follow-up from the review (PR B): - Replace the three copies of the full layout-type list (submit route, field-input, answer-summary) with the shared `isLayoutField`. Rename the builder's narrower subset to `BUILDER_LAYOUT_TYPES` to make clear it is a different concept (only the layout types the builder offers). - Extract a framework-agnostic `formatAnswerValue` into @msk-forms/shared and use it from both the reviewer/status answer summary and the bot review-embed preview, so the two formatters can't drift. - Add unit tests for `rateLimit` (fail-open: no Redis / command error / limit boundaries) and `verifyCaptcha` (pass-through when off, fail-closed on missing token / failure / HTTP error / thrown fetch). A vitest `server-only` stub alias makes these server-side libs testable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Maintainability follow-up from the multi-agent review (PR B of the cluster).
Changes
Deduplicate layout-type checks
field-input.tsx,answer-summary.tsx). All now use the sharedisLayoutField/LAYOUT_FIELD_TYPES(introduced in harden: file delivery, submit metadata, client IP, status idempotency, answer validation #58).BUILDER_LAYOUT_TYPES— a different concept (only the layout types the builder currently offers).Shared answer formatter
formatAnswerValue(field, value, labels)into@msk-forms/shared. Used by both the reviewer/statusAnswerSummaryand the bot review-embed preview (buildPreview), so the two renderings can't drift.Tests for fail-open / fail-closed services
rateLimit: fails open with no Redis and on command error; correct allow/block at the limit boundary; TTL fallback.verifyCaptcha: passes through when unconfigured; fails closed on missing token, Cloudflare failure, non-OK HTTP, and thrown fetch.server-onlystub alias so server-side libs are unit-testable.Validation
pnpm typecheck,pnpm lint,pnpm test(web now 27 tests),pnpm build— all green.