Skip to content

Commit da2da97

Browse files
committed
Preserve JSON input object order
Function-runner parses JSON inputs into serde_json::Value and reserializes them before passing bytes to the WASM. With serde_json's default map implementation, this sorts object keys lexicographically, which can change JS behavior that depends on Object.keys() ordering for fallback logic.\n\nEnable serde_json's preserve_order feature so JSON input object key order is retained, and add a regression test covering nested metafield-like message objects. This keeps function-rerunner parity closer to production inputs for Checkout Blocks discount functions.\n\nVerified with:\n- cargo test json_input_preserves_object_key_order_in_raw_bytes\n- cargo build --release\n- cargo test\n- Rerunning the 17 discount localized-message mismatch rows with the fixed release runner produced full semantic matches. Assisted-By: devx/c659e918-9568-4750-b122-e3890447348a
1 parent 5ef0e37 commit da2da97

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ wasmtime-wasi = "=39.0.1"
5050
deterministic-wasi-ctx = "=3.0.4"
5151
anyhow = "1.0"
5252
clap = { version = "4.5", features = ["derive"] }
53-
serde_json = "1.0"
53+
serde_json = { version = "1.0", features = ["preserve_order"] }
5454
colored = "3.1"
5555
serde = "1.0"
5656
rust-embed = "8.11.0"

‎src/container.rs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,21 @@ impl BytesContainer {
136136
}
137137
}
138138
}
139+
140+
#[cfg(test)]
141+
mod tests {
142+
use super::*;
143+
144+
#[test]
145+
fn json_input_preserves_object_key_order_in_raw_bytes() {
146+
let raw = br#"{"msg":{"sq-XK":"5.00 EUR Zbritje","en":"5.00 EUR Discount"}}"#.to_vec();
147+
148+
let input = BytesContainer::new(BytesContainerType::Input, Codec::Json, raw.clone())
149+
.expect("valid JSON input");
150+
151+
assert_eq!(
152+
String::from_utf8(input.raw).unwrap(),
153+
String::from_utf8(raw).unwrap()
154+
);
155+
}
156+
}

0 commit comments

Comments
 (0)