From 6000130566bddc726cb86fc0170f73fd8f23781b Mon Sep 17 00:00:00 2001 From: Titus Date: Wed, 25 Nov 2026 01:30:40 +0100 Subject: [PATCH] 0.150.2: a world file keeps a file whose integer no double holds as written world_file_bytes rewrote such a file exact when it left the author fields out, while the npm SDK rewrote it rounded (9007199254740993 as ...992): one input, two answers. A file holding an integer no double holds, or one too large for a double at all, now travels byte for byte, the five with it; one past 2**53 that a double holds exactly is rewritten as before. The shared author-fields fixture gains case 8, the same bytes as the SDK's. Watched failing: case 8 red without the check; the whole suite 2435 passed, 45 skipped. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 6 ++++++ src/onlyworlds/_version.py | 2 +- src/onlyworlds/worldfile.py | 24 ++++++++++++++++++++++- tests/fixtures/author-fields.fixture.json | 14 +++++++++++++ tests/test_worldfile.py | 4 ++-- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e23ff98..f84a468 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ The package version runs on its own semver; the schema it is generated from is ` ## Unreleased +## 0.150.2 (2026-11-25) + +### Fixed + +- **A world file keeps a file whose integer no double holds as written.** `world_file_bytes` and `write_world_file` rewrote such a file exact when they left the author fields out, while the npm SDK rewrote it rounded (`9007199254740993` as `...992`): one input, two answers. A file holding an integer a double cannot hold, or one too large for a double at all, now travels byte for byte, its author fields with it, in both packages. An integer past 2**53 that a double holds exactly (`9007199254740994`) is rewritten as before. The shared author-fields fixture's case 8 pins it. + ## 0.150.1 (2026-11-24) ### Fixed diff --git a/src/onlyworlds/_version.py b/src/onlyworlds/_version.py index 9cf5b53..f269d2a 100644 --- a/src/onlyworlds/_version.py +++ b/src/onlyworlds/_version.py @@ -1 +1 @@ -__version__ = "0.150.1" +__version__ = "0.150.2" diff --git a/src/onlyworlds/worldfile.py b/src/onlyworlds/worldfile.py index 2691826..f34519d 100644 --- a/src/onlyworlds/worldfile.py +++ b/src/onlyworlds/worldfile.py @@ -888,6 +888,28 @@ def _unread_object(src: Path | bytes) -> dict[str, Any] | None: return doc if isinstance(doc, dict) else None +def _holds_unheld_integer(value: Any) -> bool: + """Whether a read file holds an integer no double holds (``9007199254740993``, which the npm + SDK and every JavaScript reader read as ``...992``; an integer too large for a double at all): + rewriting it would leave the five readers with five answers, so the file travels byte for + byte, its author fields with it (the author-fields fixture's case 8). One past 2**53 that a + double holds exactly (``9007199254740994``) does not count. ``bool`` is no integer here.""" + stack = [value] + while stack: + v = stack.pop() + if isinstance(v, dict): + stack.extend(v.values()) + elif isinstance(v, list): + stack.extend(v) + elif isinstance(v, int) and not isinstance(v, bool) and not -(2**53) <= v <= 2**53: + try: + if float(v) != v: + return True + except OverflowError: + return True + return False + + def _without_author_fields(body: dict[str, Any] | None) -> bytes | None: """An element-folder file's object (``_element_files``, else ``_unread_object``) without its author fields, in the folder's own form (``_jsonfmt.encode``: two-space indent, a trailing @@ -981,7 +1003,7 @@ def in_private(rel: str) -> bool: body = elements.get(rel) if body is None and not include_author_fields and _under_element_folders(rel): body = _unread_object(files[rel]) - bare = None if include_author_fields else _without_author_fields(body) + bare = None if include_author_fields or _holds_unheld_integer(body) else _without_author_fields(body) plan.append((rel, files[rel] if bare is None else bare)) return top, plan diff --git a/tests/fixtures/author-fields.fixture.json b/tests/fixtures/author-fields.fixture.json index 23a1bc7..650c5a5 100644 --- a/tests/fixtures/author-fields.fixture.json +++ b/tests/fixtures/author-fields.fixture.json @@ -114,6 +114,20 @@ "elements/character/Spaced.JSON": "{\"id\":\"sp\", \"x_note\":{\"created_by\":\"kept, an extension's own\"}}" }, "stripped": 0 + }, + { + "name": "an integer no double holds (9007199254740993, which a double reads as ...992) keeps the file's bytes, the five with them, in an element read as an element too; one past 2^53 that a double holds exactly (9007199254740994) is rewritten", + "files": { + "world.json": "{\n \"id\": \"0192a000-aaaa-7bbb-8ccc-000000000001\",\n \"name\": \"W\"\n}\n", + "elements/object/held--o2.json": "{\"id\":\"o2\",\"name\":\"Held\",\"x_ref\":9007199254740994,\"created_by\":\"u\"}", + "elements/object/unheld--o3.json": "{\"id\":\"o3\",\"name\":\"Unheld\",\"x_ref\":9007199254740993,\"created_by\":\"u\"}" + }, + "default": { + "world.json": "{\n \"id\": \"0192a000-aaaa-7bbb-8ccc-000000000001\",\n \"name\": \"W\"\n}\n", + "elements/object/held--o2.json": "{\n \"id\": \"o2\",\n \"name\": \"Held\",\n \"x_ref\": 9007199254740994\n}\n", + "elements/object/unheld--o3.json": "{\"id\":\"o3\",\"name\":\"Unheld\",\"x_ref\":9007199254740993,\"created_by\":\"u\"}" + }, + "stripped": 1 } ] } diff --git a/tests/test_worldfile.py b/tests/test_worldfile.py index a9107a8..0475eaf 100644 --- a/tests/test_worldfile.py +++ b/tests/test_worldfile.py @@ -801,8 +801,8 @@ def test_a_share_carries_under_the_element_folders_only_what_the_reader_serves(t # The same bytes as the npm SDK's test/fixtures/author-fields.fixture.json (both suites hold its sha256). AUTHOR_FIXTURE = REPO / "tests" / "fixtures" / "author-fields.fixture.json" -AUTHOR_FIXTURE_SHA256 = "6943ce5a8c2cd7bf69f82facb6f1d545d87d68f5ea0104cc4d711d94e035898a" -AUTHOR_CASES = 7 +AUTHOR_FIXTURE_SHA256 = "33835ede8b407868da8fef2857699c53e763879ad4bef7909376c75b31c48645" +AUTHOR_CASES = 8 AUTHOR_FIELDS = ["created_by", "changed_by", "changed_via", "changed_client", "doors"]