Slides: scene data keeps every digit an agent sent, so versions agree
An agent works a scene's version out from the data it sent (docs/api.md), but the core read op JSON with serde_json's default float parser, which can land one bit off: 427.20000000000005 came back as 427.2000000000001, and the HalfStack world's stills were refused as stale. serde_json's float_roundtrip reads every number as JSON.parse does. A version vector with seventeen-digit numbers holds core, fixtures and Go to it; the embedded wasm is rebuilt and restamped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+29
−3
core/Cargo.toml+4 −1core/tests/scenes.rs+17 −0fixtures/vectors/scene-version.json+6 −0internal/slides/core/testdata/slides_core.wasmbinaryinternal/slides/core/testdata/slides_core.wasm.stamp+2 −2
diff --git a/core/Cargo.toml b/core/Cargo.toml| index fbb5452..e6ba8bf 100644 |
| --- a/core/Cargo.toml |
| +++ b/core/Cargo.toml |
| @@ -10,8 +10,11 @@ crate-type = ["cdylib", "rlib"] |
| yrs = "=0.23.5" |
| # The op batch and the view both cross the ABI as JSON. Pinned exact, |
| # like yrs, so a build is the same build everywhere the lockfile goes. |
| +# float_roundtrip: every number reads back as the double that was sent, as |
| +# JSON.parse reads it; the default parser can land one bit off, and a scene's |
| +# version (scene.rs) is worked out by agents from the numbers they sent. |
| serde = { version = "=1.0.229", features = ["derive"] } |
| -serde_json = "=1.0.151" |
| +serde_json = { version = "=1.0.151", features = ["float_roundtrip"] } |
| # Only used by the __getrandom_v03_custom hook in src/lib.rs, which is |
| # itself cfg(target_arch = "wasm32") — the custom getrandom backend has no |
diff --git a/core/tests/scenes.rs b/core/tests/scenes.rs| index 8e10d9f..c0ea2d8 100644 |
| --- a/core/tests/scenes.rs |
| +++ b/core/tests/scenes.rs |
| @@ -248,6 +248,23 @@ fn data_up_to_960_kib_of_canonical_json_is_taken() { |
| apply_ops(&d, &spaced).expect("spaces in the op are not the data's size"); |
| } |
| +#[test] |
| +fn data_numbers_keep_every_digit_an_agent_sent() { |
| + // An agent works a scene's version out from the data it sent (docs/api.md), |
| + // so the document must hold exactly those numbers: a double that takes |
| + // seventeen digits to write reads back as the same double, not its |
| + // neighbour. |
| + let d = deck(17); |
| + let sent = "[[427.20000000000005,-15.599999999999994],[54.400000000000006,0.30000000000000004]]"; |
| + apply_ops( |
| + &d, |
| + &format!(r#"[{{"op": "set_scene", "id": "worldsceneaa", "data": {sent}}}]"#), |
| + ) |
| + .expect("the data applies"); |
| + assert_eq!(view(&d)["scenes"]["worldsceneaa"]["data"].to_string(), sent); |
| + assert!(view_json(&d).contains(sent), "the view as written: {}", view_json(&d)); |
| +} |
| + |
| #[test] |
| fn a_scene_block_names_a_scene_and_two_of_its_states() { |
| let d = deck(9); |
diff --git a/fixtures/vectors/scene-version.json b/fixtures/vectors/scene-version.json| index 3735281..a9d6d79 100644 |
| --- a/fixtures/vectors/scene-version.json |
| +++ b/fixtures/vectors/scene-version.json |
| @@ -58,5 +58,11 @@ |
| "scene": {"code": "1111111111111111111111111111111111111111111111111111111111111111", "data": null, "words": {}}, |
| "canonical": "{\"code\":\"1111111111111111111111111111111111111111111111111111111111111111\",\"data\":null,\"words\":{}}", |
| "version": "8b56238f8abd76bb42728fada630446b2727f12f5d31fce5e47a1cb523e64952" |
| + }, |
| + { |
| + "name": "numbers JSON.stringify writes with seventeen digits keep every one", |
| + "scene": {"code": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", "data": {"pieces": [[427.20000000000005, -15.599999999999994], [54.400000000000006, 0.30000000000000004]]}, "words": {}}, |
| + "canonical": "{\"code\":\"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"data\":{\"pieces\":[[427.20000000000005,-15.599999999999994],[54.400000000000006,0.30000000000000004]]},\"words\":{}}", |
| + "version": "e2ec4a0d6a99f5f217fa4545d78957af412955863de03914c8b245bb407cf06d" |
| } |
| ] |
diff --git a/internal/slides/core/testdata/slides_core.wasm b/internal/slides/core/testdata/slides_core.wasm| index 59aeeaa..65907ee 100755 |
| Binary files a/internal/slides/core/testdata/slides_core.wasm and b/internal/slides/core/testdata/slides_core.wasm differ |
diff --git a/internal/slides/core/testdata/slides_core.wasm.stamp b/internal/slides/core/testdata/slides_core.wasm.stamp| index 38e5a7b..664caa1 100644 |
| --- a/internal/slides/core/testdata/slides_core.wasm.stamp |
| +++ b/internal/slides/core/testdata/slides_core.wasm.stamp |
| @@ -1,3 +1,3 @@ |
| # Written by scripts/build-wasm.sh; checked by scripts/wasm-stamp.sh check slides_core. |
| -inputs ebea011c8c0075a5816a7f43a0152b668c75271c38ee31dc157cf9d09a36b696 |
| -wasm 2981b2252e3c4f6753c589892d0002586d275793d70f45bb55e6739e56d90c33 |
| +inputs b78c9f3b9f77dc2bc163bb210562ba6b146115ff05ae792f6cddf4e2bc27b82a |
| +wasm 14309a357166822d6b8670adc9762701f23bb0bbf5492506ed5ec00784eb2491 |