Add translation fallback tests#618
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughBatch translation now falls back to per-string single-text translations when batch AI responses are invalid or exhausted; new parsing/stripping helpers, retry logic, tests and a test script were added, and Changes
Sequence DiagramsequenceDiagram
participant Client as Client
participant Worker as Translation Worker
participant AI as AI.run
participant Validator as Validator
participant Cache as Translation Cache
Client->>Worker: Submit translation job (batch)
Worker->>AI: Request batch translation (array)
AI-->>Worker: Non-JSON / malformed response
Worker->>Worker: Log error, begin fallback
loop per input string
Worker->>AI: Request single-text translation (stricter prompt)
alt AI returns usable text
AI-->>Worker: Raw translation (various shapes)
Worker->>Validator: plainTranslationFromUnknown (strip/unquote)
Validator-->>Worker: Parsed translated text
else AI returns invalid / throws
AI-->>Worker: Error / malformed
Worker->>Worker: Retry (up to TRANSLATION_SINGLE_TEXT_ATTEMPTS)
end
end
Worker->>Validator: assertTranslatedBatch
Validator-->>Worker: Validated results
Worker->>Cache: Store translations (update cache/version)
Worker-->>Client: Return 200 + translated HTML (set X-Capgo-Translation-Cache)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Review rate limit: 2/5 reviews remaining, refill in 26 minutes and 19 seconds. Comment |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/translation-worker/test/index.test.ts`:
- Around line 94-103: The test setup replaces globalThis.caches in beforeEach
but never restores it; save the original caches reference at the top of the test
file (e.g., const originalCaches = (globalThis as any).caches) before beforeEach
runs, and in afterEach restore it (set (globalThis as any).caches =
originalCaches) alongside the existing restoration of originalWarn and
originalError; update the beforeEach/afterEach blocks that reference
globalThis.caches, MemoryCache, originalWarn, and originalError to use this
saved originalCaches so other tests aren't affected.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a672dce8-cb68-4ce9-bab9-ec8cb2ece2a3
📒 Files selected for processing (4)
apps/translation-worker/package.jsonapps/translation-worker/src/index.tsapps/translation-worker/test/index.test.tspackage.json
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/translation-worker/test/index.test.ts (1)
131-132: ⚡ Quick winAvoid pinning the exact batch retry count here.
This assertion couples the test to the current retry policy rather than the fallback behavior. If the worker still falls back correctly but changes the number of batch attempts, this test will fail for an unrelated reason.
[details>
♻️ Suggested tweak
- expect(calls.filter((input) => Array.isArray(lastUserPayload(input).texts))).toHaveLength(3) + expect(calls.some((input) => Array.isArray(lastUserPayload(input).texts))).toBe(true) expect(calls.some((input) => typeof lastUserPayload(input).text === 'string')).toBe(true)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/translation-worker/test/index.test.ts` around lines 131 - 132, The test currently asserts an exact number of batched retry attempts by expecting calls.filter(...).toHaveLength(3), which couples it to the retry policy; change this to assert behavior instead of count—e.g., verify at least one payload contains an array of texts (use a "greater than 0" or "not empty" assertion on calls.filter((input) => Array.isArray(lastUserPayload(input).texts)) ) and keep the existing assertion that some payload has a string (calls.some((input) => typeof lastUserPayload(input).text === 'string')). This removes dependence on the exact batch retry count while still validating fallback behavior in the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/translation-worker/test/index.test.ts`:
- Around line 131-132: The test currently asserts an exact number of batched
retry attempts by expecting calls.filter(...).toHaveLength(3), which couples it
to the retry policy; change this to assert behavior instead of count—e.g.,
verify at least one payload contains an array of texts (use a "greater than 0"
or "not empty" assertion on calls.filter((input) =>
Array.isArray(lastUserPayload(input).texts)) ) and keep the existing assertion
that some payload has a string (calls.some((input) => typeof
lastUserPayload(input).text === 'string')). This removes dependence on the exact
batch retry count while still validating fallback behavior in the test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0515ef2d-b5de-496b-ad5a-7507a0e371e6
📒 Files selected for processing (1)
apps/translation-worker/test/index.test.ts
|



Summary
Validation
Summary by CodeRabbit
Tests
Bug Fixes
Chores