test(serverless): avoid pinning header validation order#4896
test(serverless): avoid pinning header validation order#4896NathanFlurry merged 1 commit intomainfrom
Conversation
|
PR 4896 Review - test(serverless): avoid pinning header validation order
Overview This PR fixes two related issues: the Rust fallback logic for the deprecated x-rivet-runner-name header was producing a misleading error message when neither header was present, and the test was brittle because it pinned a specific header validation order. Rust change (rivetkit-core/src/serverless.rs) Root cause fixed: The old chain used required_header().or_else(|_| required_header()), which meant when neither header was present, the error came from the fallback call and said "x-rivet-runner-name header is required" instead of the canonical "x-rivet-pool-name header is required". The new code always surfaces the canonical name. Correct fix. Suggestion - simplify to idiomatic Option::or_else: The match block can be replaced with an optional_header().or_else().ok_or_else() chain. This avoids explicit match arms and is more idiomatic Rust for "try A, fall back to B, error if neither." Test change (tests/driver/serverless-handler.test.ts) Indentation issue: The closing }); for toMatchObject and the subsequent expect call are both indented one level too deep, at the object-content level rather than the call level. This is syntactically valid but visually implies the second expect is nested inside the first. Consider re-indenting for clarity. Optional chaining on a required field: body.metadata?.reason uses ?. on metadata, which should always be present in an invalid_request response. If metadata is absent, expect(undefined).toMatch(regex) fails with "received value must be a string" rather than a clear missing-field error. Prefer body.metadata.reason. Regex scope is appropriate: Matching any of the three possible required header names avoids pinning to a specific validation order, which is exactly the goal of this PR. Summary
The core logic fix is correct. The suggestions above are minor style and quality improvements. |
1000bc4 to
afafe22
Compare
c9ab192 to
6ddb158
Compare
afafe22 to
7cff899
Compare
6ddb158 to
44367cd
Compare
44367cd to
20f0389
Compare
7cff899 to
5ffa0d0
Compare
7cff899 to
5ffa0d0
Compare

Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context.
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
Checklist: