Fourth review round (ADR-023): encode_payload typed (Codec), numeric-argument domains pinned by kind, plain-path SQLite open (URI flag dropped, D-29), watcher cadence posture — waves-1-2 general-review findings
This commit is contained in:
1 parent
ee7871d25d
commit
44637eea5b
11 files changed
+502
-22
No files matched your search
@@ -19,8 +19,15 @@ use crate::Error;
|
||||
/// stream event row are, contract-pinned, the serde_json serialization
|
||||
/// of the `Value` the call carried. Cross-engine byte equality falls
|
||||
/// out — the same `Value` serializes identically on both engines.
|
||||
pub fn encode_payload(value: &serde_json::Value) -> Vec<u8> {
|
||||
serde_json::to_vec(value).unwrap_or_else(|_| Vec::new())
|
||||
///
|
||||
/// Fallible per ADR-023 §1: serialization failure is
|
||||
/// [`Error::Codec`](crate::Error::Codec), typed at this helper — no
|
||||
/// silent fallback form exists (an empty-byte store would decode to
|
||||
/// `Null`, silent data corruption). Unreachable for `serde_json::Value`
|
||||
/// in practice (its variants all serialize), pinned against an
|
||||
/// encoding posture change.
|
||||
pub fn encode_payload(value: &serde_json::Value) -> Result<Vec<u8>, Error> {
|
||||
serde_json::to_vec(value).map_err(|e| Error::Codec(e.to_string()))
|
||||
}
|
||||
|
||||
/// Decode stored payload bytes into a concrete target type.
|
||||
|
||||
@@ -86,7 +86,7 @@ fn sample_event(payload: Vec<u8>) -> StreamEvent {
|
||||
#[test]
|
||||
fn payload_as_round_trips_json_value_through_job() {
|
||||
let v = json!({"id": 9, "nested": {"ok": [true, null, 1.5]}, "s": "ünï"});
|
||||
let bytes = crate::encode_payload(&v);
|
||||
let bytes = crate::encode_payload(&v).unwrap_or_else(|e| panic!("encode failed: {e}"));
|
||||
assert_eq!(bytes, serde_json::to_vec(&v).unwrap_or_default());
|
||||
let job = sample_job(bytes);
|
||||
let decoded: Value = job
|
||||
@@ -98,7 +98,8 @@ fn payload_as_round_trips_json_value_through_job() {
|
||||
#[test]
|
||||
fn event_payload_as_round_trips() {
|
||||
let v = json!([1, 2, 3, {"x": "y"}]);
|
||||
let event = sample_event(crate::encode_payload(&v));
|
||||
let bytes = crate::encode_payload(&v).unwrap_or_else(|e| panic!("encode failed: {e}"));
|
||||
let event = sample_event(bytes);
|
||||
let decoded: Value = event
|
||||
.payload_as()
|
||||
.unwrap_or_else(|e| panic!("decode failed: {e}"));
|
||||
@@ -108,7 +109,8 @@ fn event_payload_as_round_trips() {
|
||||
#[test]
|
||||
fn payload_as_concrete_typed_targets() {
|
||||
let v = json!({"alpha": 1, "beta": 2});
|
||||
let job = sample_job(crate::encode_payload(&v));
|
||||
let bytes = crate::encode_payload(&v).unwrap_or_else(|e| panic!("encode failed: {e}"));
|
||||
let job = sample_job(bytes);
|
||||
let decoded: HashMap<String, i64> = job.payload_as().unwrap_or_else(|e| panic!("decode: {e}"));
|
||||
assert_eq!(
|
||||
decoded,
|
||||
@@ -119,7 +121,8 @@ fn payload_as_concrete_typed_targets() {
|
||||
#[test]
|
||||
fn payload_as_undecodable_target_yields_codec() {
|
||||
let v = json!({"name": "x"});
|
||||
let job = sample_job(crate::encode_payload(&v));
|
||||
let bytes = crate::encode_payload(&v).unwrap_or_else(|e| panic!("encode failed: {e}"));
|
||||
let job = sample_job(bytes);
|
||||
let r: crate::Result<String> = job.payload_as();
|
||||
match r {
|
||||
Err(crate::Error::Codec(msg)) => assert!(!msg.is_empty()),
|
||||
@@ -130,6 +133,13 @@ fn payload_as_undecodable_target_yields_codec() {
|
||||
assert!(matches!(r2, Err(crate::Error::Codec(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn encode_payload_success_carries_exact_serialization() {
|
||||
let v = json!({"k": [1, 2, 3]});
|
||||
let bytes = crate::encode_payload(&v).unwrap_or_else(|e| panic!("encode failed: {e}"));
|
||||
assert_eq!(bytes, serde_json::to_vec(&v).unwrap_or_default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stop_token_cancel_flips_all_clones() {
|
||||
let token = StopToken::new();
|
||||
|
||||
Reference in new issue
Block a user