Repository navigation
fix: merge partial route options with global options - #397
Vinayak1337 wants to merge 2 commits into
Conversation
0487e7a to
64e54e5
Compare
|
👋 I just closed #398 in favor of this one (it hadn't surfaced in my issue-thread search). One small suggestion if you take another pass: this regression also affects the compress-side onUnsupportedEncoding hook (not just the decompress hooks), and the current test coverage here doesn't exercise that path. A minimal test sketch: Full version on my closed PR if useful: https://github.com/fastify/fastify-compress/pull/398/files |
|
Thanks for catching this, @ranjeetcao. That path was a real coverage gap. I added a focused regression test for the route-level I also re-ran:
Appreciate the pointer. |
There was a problem hiding this comment.
Pull request overview
This PR fixes option resolution precedence so that partial route-level compress/decompress option objects inherit from processed global plugin options first, and only fall back to plugin defaults when neither route nor global provided a value (fixing #340).
Changes:
- Refactored option processing to support
process*Params(routeOpts, globalParams)merging without re-expanding missing route values to plugin defaults. - Added regression tests to ensure partial route overrides preserve global handlers/settings (
onInvalidRequestPayload,removeContentLengthHeader: false).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
index.js |
Refactors compress/decompress parameter processing to properly merge route-level partial options with processed global options. |
test/routes-decompress.test.js |
Adds coverage ensuring a partial route decompress override preserves the global onInvalidRequestPayload handler. |
test/routes-compress.test.js |
Adds coverage ensuring a partial route compress override preserves global removeContentLengthHeader: false (and adds a related partial-options test). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
index.js:262
baseParams.encodingsmay already have been narrowed to the globalforceRequestEncodingbelow. Consequently, with global{ requestEncodings: ['gzip', 'deflate'], forceRequestEncoding: 'gzip' }, a route override{ forceRequestEncoding: 'deflate' }inherits only['gzip']and rejects every request, althoughdeflateis allowed by the global list. Preserve the unforced request-encoding list separately and narrow only the effective route list after resolving its force option; this case should also have regression coverage.
encodings: encodingsOrBase(opts, 'requestEncodings', baseParams),
forceEncoding: forceEncodingOrBase(opts, baseParams)
}
if (params.forceEncoding && params.encodings.includes(params.forceEncoding)) {
params.encodings = [params.forceEncoding]
4ba2e6d to
4155222
Compare
|
Thanks @Fdawgs — I simplified the implementation to follow the approach in #398: raw global and route options are merged first, then passed through the existing processor once. The processor refactor and merge commit are gone, and the branch is rebased onto current I also trimmed the tests to the minimum focused coverage: the issue #340 invalid-payload-handler case, compression-handler inheritance, Local validation:
The fresh GitHub Actions run is currently marked |
4155222 to
99df941
Compare
|
@Fdawgs as soon as you have time, could you review the latest changes? If everything looks good to you, we'll merge it. |
There was a problem hiding this comment.
🟡 Changes recommended
Explicitly undefined route fields still erase global values, and the request-encoding inheritance test does not exercise inheritance.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Balanced
cdcf98f to
4dd8dce
Compare
Signed-off-by: Vinayak <34209962+Vinayak1337@users.noreply.github.com>
4dd8dce to
e1d295a
Compare
|
Good catches, I missed the explicit I have fixed the option merge, updated the regression tests, and rebased the branch onto the latest I also checked the earlier review feedback again and added coverage for both allowed and rejected route-level force encoding cases. Local tests, lint, TypeScript checks, coverage, and |
|
@Fdawgs do you agree with merging this PR? 😄 |
If you'd rather fix it yourself, that's fine with me — otherwise I'd suggest we merge this one. I'll keep this PR open for now so the contributor's work isn't lost either way, and we can close it once your fix lands if you go that route. 😉 |
Fixes #340
What changed
compressanddecompressoptions before processing them once.forceRequestEncodingscenario raised during review.Why
The previous
Object.assign({}, globalParams, processParams(routeOptions))flow allowed defaults andundefinedfields from the processed route object to overwrite configured global values. Processing one coherent{ ...globalOptions, ...routeOptions }object applies the intended route > global > default precedence and follows the simpler approach demonstrated in #398.Tests
node --test test/routes-compress.test.js test/routes-decompress.test.jsnpm run lintnpm testgit diff --checknpm run benchmark --if-present(executed; the harness rejected the measurements because the unchanged control varied by 12% on a busy machine)No documentation or type changes are needed because this fixes existing option precedence without changing the public API.
Checklist
npm run test && npm run benchmark --if-present