From cec9249e207a5b55e02911efd6b5c1b7b9d2ed24 Mon Sep 17 00:00:00 2001 From: Ray Walker Date: Mon, 14 Sep 2026 13:45:30 +1000 Subject: [PATCH] test(cachekit): pin {"ttl": null} decoding of TtlResponse (LAB-3593) The server answers 200 {"ttl": null} for a live key with no expiry. TtlResponse must keep decoding that to None; without a test, changing the field to a bare u64 passes CI and turns every such key into a client-side parse error. Also pins deny_unknown_fields. --- crates/cachekit/src/backend/cachekitio_ttl.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/cachekit/src/backend/cachekitio_ttl.rs b/crates/cachekit/src/backend/cachekitio_ttl.rs index 57dac77..1bbf832 100644 --- a/crates/cachekit/src/backend/cachekitio_ttl.rs +++ b/crates/cachekit/src/backend/cachekitio_ttl.rs @@ -95,4 +95,15 @@ mod tests { _assert_ttl_inspectable(backend); } } + + /// The server answers `{"ttl": null}` for a live key with no expiry. + /// That must decode to `None`, never a parse error. + #[test] + fn ttl_response_decodes_null_ttl_as_none() { + let decode = |json: &str| serde_json::from_str::(json).map(|r| r.ttl); + + assert!(matches!(decode(r#"{"ttl":null}"#), Ok(None))); + assert!(matches!(decode(r#"{"ttl":42}"#), Ok(Some(42)))); + assert!(decode(r#"{"ttl":null,"extra":1}"#).is_err()); + } }