Clarify cookie header tests and remove duplicate callback serde test#660
Clarify cookie header tests and remove duplicate callback serde test#660ChristianPavilonis wants to merge 1 commit intomainfrom
Conversation
aram356
left a comment
There was a problem hiding this comment.
Summary
Test-only change closing real coverage gaps; CI is green and production behavior is unchanged. One blocking concern around a brittle assertion in the new UTF-8 test, plus two nitpicks.
Blocking
🔧 wrench
- Brittle assertion on error message text —
cookies.rs:370couples the test to the literal message string set incookies.rs:108. Asserting on the variant alone (InvalidHeaderValue { .. }) is sufficient and survives reasonable message rewording.
Non-blocking
📝 note
- Issue #454 wording is stale — the "Done when" says invalid UTF-8 should return
None, buthandle_request_cookiesactually returnsErr(InvalidHeaderValue)(mapped to400 Bad Requestinerror.rs:111). The PR test correctly exercises the real API; worth mentioning when closing #454 so the discrepancy is documented.
⛏ nitpick
- Explain why the bytes are invalid UTF-8 —
\xF0\x90\x80is a truncated 4-byte sequence; a one-line comment above the literal helps future readers. ts-ec=valid-prefixadds no coverage —to_str()validates the entire byte slice, so a bareb"\xF0\x90\x80"would exercise the same path more clearly.
CI Status
- fmt: PASS
- clippy: PASS
- rust tests: PASS (cookies::tests 25/25, models::tests 10/10 verified locally)
- js tests: PASS
- browser/integration tests: PASS
| if message.contains("invalid UTF-8") | ||
| ), | ||
| "should return invalid header value error for non-UTF-8 cookie header" | ||
| ); |
There was a problem hiding this comment.
🔧 wrench — Brittle assertion: the if message.contains("invalid UTF-8") guard locks this test to the literal string set in cookies.rs:108 ("Cookie header contains invalid UTF-8"). A reasonable rewording of that message (e.g. "Cookie header is not valid UTF-8") would silently break this test even though behavior is unchanged. Production code branches on the variant, not the message — the variant check alone is sufficient.
Fix:
assert!(
matches!(
err.current_context(),
TrustedServerError::InvalidHeaderValue { .. }
),
"should return InvalidHeaderValue for non-UTF-8 cookie header"
);|
|
||
| #[test] | ||
| fn test_handle_request_cookies_invalid_utf8_cookie_header() { | ||
| let invalid_cookie_value = HeaderValue::from_bytes(b"ts-ec=valid-prefix\xF0\x90\x80") |
There was a problem hiding this comment.
⛏ nitpick — \xF0\x90\x80 is a truncated 4-byte UTF-8 sequence: \xF0 introduces a 4-byte code point but only two continuation bytes follow, so to_str() rejects it. A one-line comment above the literal would save future readers a trip to the Unicode tables.
// Truncated 4-byte UTF-8 sequence: `\xF0` starts a 4-byte code point but
// only two continuation bytes follow, so `to_str()` rejects it.
let invalid_cookie_value = HeaderValue::from_bytes(b"ts-ec=valid-prefix\xF0\x90\x80")|
|
||
| #[test] | ||
| fn test_handle_request_cookies_invalid_utf8_cookie_header() { | ||
| let invalid_cookie_value = HeaderValue::from_bytes(b"ts-ec=valid-prefix\xF0\x90\x80") |
There was a problem hiding this comment.
⛏ nitpick — The ts-ec=valid-prefix portion adds no coverage. HeaderValue::to_str() validates the entire byte slice; there is no partial parsing to test. A bare b"\xF0\x90\x80" would exercise the same code path more clearly. Harmless either way.
Summary
Cookieheader path inhandle_request_cookiesChanges
crates/trusted-server-core/src/cookies.rsHeaderValue::from_bytes(...)to exercise the realInvalidHeaderValuebranch.crates/trusted-server-core/src/models.rsCloses
Closes #454
Closes #456
Test plan
cargo test --workspacecargo clippy --workspace --all-targets --all-features -- -D warningscargo fmt --all -- --checkcd crates/js/lib && npx vitest runcd crates/js/lib && npm run formatcd docs && npm run formatcargo build --package trusted-server-adapter-fastly --release --target wasm32-wasip1fastly compute serveChecklist
unwrap()in production code — useexpect("should ...")tracingmacros (notprintln!)