fix: preserve PDF fallback text and load live-test env#1082
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
📝 WalkthroughWalkthroughThe live-test runner loads Next.js environment configuration before permission checks. JavaScript PDF fallback extraction validates image entries, skips unusable images, preserves page text, and reports malformed-image pages. ChangesLive-test runner environment
PDF fallback image safety
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/pdf-extraction-budget.test.ts (1)
245-268: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winCover invalid dimensions in the fallback regression test.
This test verifies missing image data only. Add cases for zero, negative, non-finite, and fractional dimensions so every validation branch is protected and malformed entries remain skipped.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/pdf-extraction-budget.test.ts` around lines 245 - 268, Add invalid-dimension cases to the “skips malformed image entries returned by the JavaScript fallback” test by including image entries with zero, negative, non-finite, and fractional width or height values alongside the missing-data entry. Keep the extraction assertions verifying all malformed images are skipped and valid page text remains preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lib/extractors/document.ts`:
- Around line 59-73: Update isUsableFallbackPdfImage to require image.width and
image.height to be positive integers, matching extractedImageSchema; retain the
existing data presence and finite-value checks for otherwise valid fallback
images.
---
Nitpick comments:
In `@tests/pdf-extraction-budget.test.ts`:
- Around line 245-268: Add invalid-dimension cases to the “skips malformed image
entries returned by the JavaScript fallback” test by including image entries
with zero, negative, non-finite, and fractional width or height values alongside
the missing-data entry. Keep the extraction assertions verifying all malformed
images are skipped and valid page text remains preserved.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: f68dd447-0b5e-4769-b55c-933aa97bff5a
📒 Files selected for processing (4)
scripts/run-live-tests.mjssrc/lib/extractors/document.tstests/pdf-extraction-budget.test.tstests/test-runner-safety.test.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 068f0197d9
ℹ️ 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".
|
@codex resolve actionable Codex review findings for this pull request and current head using the repository instructions. This is the pull request's single automatic repair pass: do not perform a fresh review, create new standalone findings, or request another review. Work only the existing unresolved Codex threads on the current head. Always fix P0 and P1 findings. For P2 and lower findings, fix only clear, scoped, low-risk issues; otherwise disposition them with a concise reason. After fixing or dispositioning a thread, reply in that thread with as the first line, followed by a concise summary; that marker authorizes the workflow to close that exact thread. If human input or new authorization is required, do not use the marker and leave the thread open with the blocker. Finish only after every actionable thread is fixed or dispositioned and closed, or explicitly left open for a human decision. Do not update the branch from main, address unrelated reviews, broaden scope, or create more than one scoped fix commit. Do not use external APIs, paid services, credentials, dependency changes, or broad refactors unless explicitly authorized. Add targeted tests where behavior changes and run the narrowest relevant validation. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 068f0197d9
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8f46a4c814
ℹ️ 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".
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lib/extractors/document.ts`:
- Around line 337-339: Update the image-counting logic near the page.images loop
in the document extraction flow so imageCountByPage only includes entries that
pass isUsableFallbackPdfImage(image). Ensure pages containing only malformed or
unusable records are not marked needsOcr, while preserving counting and emission
for usable images.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 70d8dad7-692c-4e45-824b-b33871d463e1
📒 Files selected for processing (4)
scripts/run-live-tests.mjssrc/lib/extractors/document.tstests/pdf-extraction-budget.test.tstests/test-runner-safety.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- tests/pdf-extraction-budget.test.ts
- tests/test-runner-safety.test.ts
- scripts/run-live-tests.mjs
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eca5af958d
ℹ️ 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 vitestBin = path.join(projectRoot, "node_modules", "vitest", "vitest.mjs"); | ||
| const { loadEnvConfig } = nextEnv; | ||
| const providerTestPermission = process.env.ALLOW_PROVIDER_TESTS; | ||
| loadEnvConfig(projectRoot); |
There was a problem hiding this comment.
Set test mode before loading live-test env files
When ALLOW_PROVIDER_TESTS=true npm run test:live is run from a normal shell, this call happens before the script sets NODE_ENV: "test" for Vitest, so Next's env loader resolves the non-test mode and can load .env.production.local/.env.production values into lock.environment before passing them to the test child. In a checkout that keeps production Supabase/OpenAI credentials in those files, the explicit live-test approval can therefore run the provider suite against production-shaped configuration instead of the intended test configuration; set the intended mode before loadEnvConfig (or pass the appropriate dev/test loading mode) so the env files match the test process.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/lib/extractors/document.ts (1)
353-353: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winRecord filtered image entries in
malformedImagePages.When
getImagereturns an invalid image object, Line [353] skips it without marking the page. Themalformed_fallback_imageswarning therefore omits this malformed-record case. AddmalformedImagePages.add(page.pageNumber)before continuing.Proposed fix
- if (!isUsableFallbackPdfImage(image)) continue; + if (!isUsableFallbackPdfImage(image)) { + malformedImagePages.add(page.pageNumber); + continue; + }Also applies to: 392-396
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/lib/extractors/document.ts` at line 353, Update the image filtering branches in the document extraction flow, including the check around isUsableFallbackPdfImage and the corresponding logic near the additional referenced range, to add page.pageNumber to malformedImagePages before continuing when getImage returns an invalid image object.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/lib/extractors/document.ts`:
- Line 353: Update the image filtering branches in the document extraction flow,
including the check around isUsableFallbackPdfImage and the corresponding logic
near the additional referenced range, to add page.pageNumber to
malformedImagePages before continuing when getImage returns an invalid image
object.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: f9a58417-412c-4721-b553-9958fbf72312
📒 Files selected for processing (2)
src/lib/extractors/document.tstests/pdf-extraction-budget.test.ts
Summary
RAG impact: no retrieval behaviour change — only malformed PDF image tolerance and live-test environment setup changed.
Verification
npm exec vitest run tests/pdf-extraction-budget.test.ts tests/test-runner-safety.test.ts— 2 expected failures (undefined image data; missing Next env initialization).npm exec vitest run tests/pdf-extraction-budget.test.ts tests/test-runner-safety.test.ts tests/private-client-auth.test.ts— 37 passed.npm run verify:cheap— passed; 360 files, 3,203 passed / 1 skipped.npm run verify:pr-local -- --files scripts/run-live-tests.mjs,src/lib/extractors/document.ts,tests/pdf-extraction-budget.test.ts,tests/test-runner-safety.test.ts— passed; format, lint, typecheck, full unit suite, production build, client-secret scan, offline RAG fixtures.npm run check:production-readiness— local configuration gate reached; expected failure because this isolated worktree intentionally has no.env.local, Supabase service key, or OpenAI key.Verification not run: live provider tests, Supabase operations, Railway operations, browser matrix, and live RAG evaluation were not needed for these two guards.
Risk and rollout
ALLOW_PROVIDER_TESTS=true.068f0197d97d119d32f37dcb08c9b74007bf1673.Clinical Governance Preflight
Clinical KB Database(sjrfecxgysukkwxsowpy)Notes
Note
Low Risk
Ingestion tolerance and test-runner env ordering only; live tests still require explicit ALLOW_PROVIDER_TESTS=true and retrieval behavior is unchanged.
Overview
JavaScript PDF fallback no longer fails the whole extraction when
pdf-parsereturns bad image records (missingdata, non-integer dimensions). Invalid entries are skipped viaisUsableFallbackPdfImage; text and valid images still go through the existing budget path. Per-page image counts forneedsOcrare taken from the parser’s image list (including skipped entries), so short text plus reported images still flags image-only pages.Live provider test runner calls Next’s
loadEnvConfigso repo-local env files can supply credentials, whileALLOW_PROVIDER_TESTSis captured before that load and passed intorequireProviderTestPermissionso permission cannot be granted only from a persisted env file.Tests cover malformed fallback images and assert the snapshot → load env → permission-check ordering in
run-live-tests.mjs.Reviewed by Cursor Bugbot for commit f3380b0. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
Bug Fixes
Tests