Replace Pdf loader spec with behavior-first contract tests#4948
Replace Pdf loader spec with behavior-first contract tests#4948Austin-s-h with Copilot wants to merge 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4948 +/- ##
===========================================
+ Coverage 46.50% 91.21% +44.70%
===========================================
Files 832 17 -815
Lines 34090 660 -33430
Branches 5833 0 -5833
===========================================
- Hits 15854 602 -15252
+ Misses 16237 58 -16179
+ Partials 1999 0 -1999
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Austin-s-h
left a comment
There was a problem hiding this comment.
@copilot consider the current PR branch target and perform a review of before and after your spec redesign. This should result in comparison of the spec in both branches.
Compared against the PR target branch ( Before (target branch): 11 tests, including several implementation-rederived checks (manual extension ternaries, substring URL assertions).
I also fixed a CI portability issue discovered during this branch-aware review ( |
Description
This PR replaces
catalog/app/components/Preview/loaders/Pdf.spec.tswith a stronger, behavior-oriented suite targetingPdf.jsruntime contracts throughLoader. It removes tautological tests and increases coverage where regressions are most likely (request contract + 403 mapping split).Behavior over implementation detail
endsWith('.pptx') ? 'pptx' : 'pdf'style tests with loader-driven assertions.logicalKeyprecedence by observing real request behavior (input=pptx), not re-deriving branch logic in the test.Request contract assertions
/thumbnailrequest shape vianew URL(...)and explicit query param checks (url,input,size,countPages), instead of substring matching.Error-path coverage
PreviewError.Archived.PreviewError.Forbidden.Loader wiring + async cardinality
pendingcardinality / call counts).useErrorHandlingis called with{ handle, retry: data.fetch }and that children receive the wrapped value.CI/runtime compatibility follow-up
Blobrealm mismatch in CI while still validating the returned blob payload shape and non-empty content.TODO
optipngon any new PNGsbuild.pyfor new docstringsOriginal prompt
Create a new pull request against
masterinquiltdata/quiltthat replacescatalog/app/components/Preview/loaders/Pdf.spec.tswith a stronger version of the spec.Context:
catalog/app/components/Preview/loaders/Pdf.spec.ts.Repository context discovered from the current codebase:
catalog/app/components/Preview/loaders/Pdf.js.detectisutils.extIn(['.pdf', '.pptx']).loadPdfsigns the handle, derivestypefrom(handle.logicalKey || handle.key).toLowerCase().endsWith('.pptx') ? 'pptx' : 'pdf', fetches/thumbnailwithurl,input,size, andcountPages, parsesX-Quilt-Info.page_count, and mapsHTTPError403s to eitherPreviewError.Archived({ handle })when the glacier regex matches orPreviewError.Forbidden({ handle })otherwise.LoadercallsAWS.Signer.useS3Signer(),Data.use(loadPdf, { sign, handle }), and wraps the result withutils.useErrorHandling(data.result, { handle, retry: data.fetch }).Problems in the currently proposed spec from PR #4937:
determines type as pptx for .pptx keys,determines type as pdf for .pdf keys,uses logicalKey over key when available for type detection).stringContainingfragments instead of asserting the full request contract.PreviewError.Forbiddenpath even though the production code explicitly supports it.pending[0]only) or direct invocation ofuseErrorHandling.Loaderover tests that restate implementation details.What to change:
catalog/app/components/Preview/loaders/Pdf.spec.tswith a stronger test suite.detectaccepts.pdfand.pptxcase-insensitively and rejects non-matching names.new URL(...)rather than only substring checkspendinglength / call counts)useErrorHandlingis called with{ handle, retry: data.fetch }PreviewError.ForbiddenendsWith('.pptx') ? 'pptx' : 'pdf'outside the production code.Expectations for the resulting PR:
If you need to inspect the existing file path, use
catalog/app/components/Preview/loaders/Pdf.spec.tsandcatalog/app/components/Preview/loaders/Pdf.js.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Perform an adversarial review of my new PDF spec and provide suggestions to improve it.
Assistant: This spec is a good start but too implementation-coupled, and an adversarial review would push for fewer tautological tests, stronger behavioral assertions, and better failure-shape coverage.
Main concerns
1. Several tests duplicate the implementation instead of validating behavior
These tests are weak because they restate the branching logic inline:
determines type as pptx for .pptx keysdetermines type as pdf for .pdf keysuses logicalKey over key when available for type detectionThey don’t exercise
Loaderor a real exported helper; they just compute:That means they can pass even if the production code regresses elsewhere.
Suggestion: remove or replace them with tests that verify observable behavior through
Loader, e.g. that the request includesinput=pptxorinput=pdffor representative handles.2. The happy-path test does not validate enough of the returned payload
In `fetches thumbnail with correct parameters for ...
This pull request was created from Copilot chat.