Repository navigation
Prevent demo requests from silently targeting Mexico - #65
Conversation
The public demo endpoint defaulted any request without a dialect field to es-MX. That made alternate client contracts such as targetLocale look like model failures and produced Mexican/neutral output for Puerto Rican test cases. The server now accepts common target-dialect aliases and rejects missing dialects with a client error before touching providers. Documentation counts were also refreshed after the research MCP tool and new regression tests. Constraint: Browser UI already sends dialect, but external/API testers commonly send targetLocale or targetDialect. Rejected: Keep es-MX fallback | hides contract mistakes and misdiagnoses dialect quality. Confidence: high Scope-risk: narrow Directive: Do not reintroduce default dialects on public translation endpoints; force explicit target dialects or aliases. Tested: node --test scripts/__tests__/demo-server.test.mjs Tested: pnpm build Tested: pnpm test Tested: pnpm audit --audit-level low
a9a0960 to
fd7940a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a9a09607bb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const candidate = body?.dialect ?? body?.targetDialect ?? body?.targetLocale ?? body?.locale; | ||
| if (candidate === undefined || candidate === null || String(candidate).trim() === "") { | ||
| throw new Error("Target dialect is required. Send dialect, targetDialect, or targetLocale, for example es-PR."); |
There was a problem hiding this comment.
Treat blank dialect as missing before alias fallback
readDialect uses nullish coalescing (??), so a present-but-empty dialect value short-circuits alias lookup and causes a 400 even when targetDialect/targetLocale/locale is valid. A request like { "dialect": "", "targetLocale": "es-PR" } now fails with “Target dialect is required” instead of using the alias, which breaks clients that always send an empty dialect field.
Useful? React with 👍 / 👎.
| const status = /No provider configured|No translation providers|Provider not available/i.test(message) | ||
| ? 503 | ||
| : /Invalid|No input|too large/i.test(message) | ||
| : /Invalid|No input|required|too large/i.test(message) |
There was a problem hiding this comment.
Avoid classifying all 'required' errors as HTTP 400
The new /required/ check in the status mapper turns unrelated server-side failures into client errors. In this codebase, translation failures can include messages like Missing required semantic trait... (from the quality-judge path), so valid requests are now returned as 400 instead of 5xx/503, which misclassifies provider/output failures and can break client retry and alerting behavior.
Useful? React with 👍 / 👎.
Summary
/api/translateso missingdialectno longer silently defaults toes-MX.dialect,targetDialect,targetLocale,locale.Root cause
Live/browser testing with
dialect: "es-PR"works for Puerto Rico examples, but API-style requests usingtargetLocale: "es-PR"were ignored and silently routed ases-MX. That made the system look like it was failing regional semantics when the real bug was an unsafe endpoint default.Verification
node --test scripts/__tests__/demo-server.test.mjspnpm buildpnpm testpnpm audit --audit-level low