Skip to content

refactor: dedupe layout-type/answer-format logic; test rate-limit & captcha#59

Merged
Musiker15 merged 1 commit into
mainfrom
refactor/dedup-and-tests
Jun 20, 2026
Merged

refactor: dedupe layout-type/answer-format logic; test rate-limit & captcha#59
Musiker15 merged 1 commit into
mainfrom
refactor/dedup-and-tests

Conversation

@Musiker15

Copy link
Copy Markdown
Member

Maintainability follow-up from the multi-agent review (PR B of the cluster).

Changes

Deduplicate layout-type checks

Shared answer formatter

  • Extracted a framework-agnostic formatAnswerValue(field, value, labels) into @msk-forms/shared. Used by both the reviewer/status AnswerSummary and 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.
  • Added a vitest server-only stub alias so server-side libs are unit-testable.

Validation

pnpm typecheck, pnpm lint, pnpm test (web now 27 tests), pnpm build — all green.

…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.
@Musiker15 Musiker15 merged commit af519ed into main Jun 20, 2026
3 checks passed
@Musiker15 Musiker15 deleted the refactor/dedup-and-tests branch June 20, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant