From 9c78a847d71852e15c4dd004ab321f4fa765b1b2 Mon Sep 17 00:00:00 2001 From: Titus Date: Sat, 28 Nov 2026 20:32:25 +0100 Subject: [PATCH 1/2] The folder collision rule compares short names by the folder format's fold resolve_filenames bucketed short file names (slug and id tail) by str.lower(). It now buckets them by _fold_name, NFC then simple case folding at Unicode 15.1, the fold the archive reader compares names by and the refusal of two names that fold to one already uses: one fold for folder spec 3.2. A name changes only for an id whose lowercase and fold differ, all of them beyond ASCII: two elements named Bob with ids a1234567 and b1234567 kept two short names that the refusal joined, and are now written, the higher id under its full id. No ASCII id and no UUID changes. The shared cases add that pair and one with the Kelvin sign in a tail, each with its two file names (tests/fixtures/case-collide.cases.json, the same bytes as the npm SDK's; the sha256 pin moves). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 ++ src/onlyworlds/folder.py | 16 +++++++---- tests/fixtures/case-collide.cases.json | 38 +++++++++++++++++++++++++- tests/test_case_collide.py | 4 +-- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06adc66..5a67950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ The package version runs on its own semver; the schema it is generated from is ` ## Unreleased +- **Changed: the folder writer's collision rule compares names by the folder format's fold.** `resolve_filenames`, and so `write_folder`, the import doors and `export_world`, give two elements of one type whose short file names (slug and id tail) land on one name the id-ascending rule of folder spec §3.2: the lowest id keeps the short name, every other takes its full id. "One name" was `str.lower()` and is now the fold the archive reader compares names by (NFC, then simple case folding, Unicode 15.1), the same fold 0.158.6's refusal uses. So a few ids beyond ASCII now get the full-id name where before they were refused or lowercased apart: two elements named Bob with ids `a1234567ς` and `b1234567σ` kept the short names `bob--1234567ς.json` and `bob--1234567σ.json`, which the refusal joined, and are now written as `bob--1234567ς.json` and `bob--b1234567σ.json`. No ASCII id and no UUID changes its file name. The npm SDK's folder writer names them alike (`tests/fixtures/case-collide.cases.json`). + ## 0.158.6 (2026-11-28) - **Fixed: two elements whose file names differ only in case are refused, where one of them was lost.** `write_folder` names a file from the element's id, and when two ids of one type differ only in case (`Ab1` and `ab1`, unnamed or both named `Bob`) it gave them file names that also differ only in case. A case-insensitive disk (Windows, macOS) keeps one file for both, so the folder held one element where the world had two. It now raises `ValueError` before anything is written, once the collision rule has chosen every name in a type folder, when two of them are one name under the folder format's name fold (NFC, then simple case folding, as the archive reader compares names): `character element ids "Ab1" and "ab1" give the file names "Ab1.json" and "ab1.json", which are one name once folded (NFC, then simple case folding), so a case-insensitive disk (NTFS, APFS) may keep one file for both.` The same refusal holds an unnamed id `bob--x` beside an element `x` named `Bob`, which were both written as `bob--x.json` on any disk. So are ids that differ as `Ä1` and `ä1`, `Σ1` and `σ1`, `Dž1` and `dž1`, the Kelvin sign `K1` and `k1`, or by normalization alone; `İ1` and `i1`, and `ß1` and `ss1`, stay two files. Ids in two types, and names whose slugs differ, are written as before, and every other folder keeps its bytes. The import doors and `export_world` write through `write_folder` and refuse alike. The npm SDK's folder writer refuses the same pairs in the same words (`tests/fixtures/case-collide.cases.json`, the same bytes in both). diff --git a/src/onlyworlds/folder.py b/src/onlyworlds/folder.py index 1d1b4c3..0e0b330 100644 --- a/src/onlyworlds/folder.py +++ b/src/onlyworlds/folder.py @@ -245,18 +245,21 @@ def _name_of(body: Mapping[str, Any]) -> str | None: def resolve_filenames(elements: Iterable[tuple[str, str | None]]) -> dict[str, str]: """★ The writer collision rule (§3.2, MUST): id -> filename for ONE type directory. - Two elements whose short names would land on one path (compared case-folded, - because NTFS and APFS resolve them to one file) are resolved id-ascending: - the lowest id keeps the short form, every other claimant takes the full id. - Deterministic across writers and re-runs, whatever order the elements came in. + Two elements whose short names would land on one path (compared by the folder + format's one fold, NFC then simple case folding, ``_fold_name``, because NTFS and + APFS resolve such names to one file) are resolved id-ascending: the lowest id keeps + the short form, every other claimant takes the full id. Deterministic across + writers and re-runs, whatever order the elements came in. """ + from .worldfile import _fold_name # worldfile imports this module + names: dict[str, str | None] = {} buckets: dict[str, list[str]] = {} for element_id, name in elements: if element_id in names: raise ValueError(f"duplicate id {element_id!r} in one type directory") names[element_id] = name - buckets.setdefault(element_filename(element_id, name).lower(), []).append(element_id) + buckets.setdefault(_fold_name(element_filename(element_id, name)), []).append(element_id) out: dict[str, str] = {} for ids in buckets.values(): for i, element_id in enumerate(sorted(ids)): @@ -268,7 +271,8 @@ def resolve_filenames(elements: Iterable[tuple[str, str | None]]) -> dict[str, s def _refuse_case_collisions(etype: str, names: Mapping[str, str]) -> None: """Raise ValueError when two of one type folder's final file names are one name under OW-18's fold (``_fold_name``: NFC, then simple case folding; the npm SDK's ``foldName``): a case-insensitive disk may - keep one file for both. The collision rule's own buckets still lowercase. + keep one file for both (the collision rule buckets by the same fold, so what is left is a full-id name that + folds onto another's name, or two ids that fold alike). The ids are walked in code point order and the first pair found is named, the lower id first, so both packages name the same pair (tests/fixtures/case-collide.cases.json).""" from .worldfile import _fold_name # worldfile imports this module diff --git a/tests/fixtures/case-collide.cases.json b/tests/fixtures/case-collide.cases.json index 104edd7..5c6c690 100644 --- a/tests/fixtures/case-collide.cases.json +++ b/tests/fixtures/case-collide.cases.json @@ -1,5 +1,5 @@ { - "about": "Pairs of elements a world folder writer refuses, and pairs it writes: the npm SDK's folder writer (folderFiles, so worldFolderFiles and convertKanka) and the Python package's write_folder. The same bytes in both repositories; both suites hold its sha256. After the collision rule (folder spec 3.2) has named every file in one type folder, two final file names that are one name under OW-18's fold (NFC, then simple case folding, both at Unicode 15.1: the SDK's foldName, the Python package's _fold_name) are refused, since a case-insensitive disk may keep one file for both: the refusal names the type, the two ids in code point order and their file names as JSON text, in the words given here (a TypeError in the SDK, a ValueError in Python), and no file is written. A written case gives every file's path but world.json, in code point order. Cases written by hand.", + "about": "Pairs of elements a world folder writer refuses, and pairs it writes: the npm SDK's folder writer (folderFiles, so worldFolderFiles and convertKanka) and the Python package's write_folder. The same bytes in both repositories; both suites hold its sha256. After the collision rule (folder spec 3.2) has named every file in one type folder, two final file names that are one name under OW-18's fold (NFC, then simple case folding, both at Unicode 15.1: the SDK's foldName, the Python package's _fold_name; the collision rule compares short names by the same fold) are refused, since a case-insensitive disk may keep one file for both: the refusal names the type, the two ids in code point order and their file names as JSON text, in the words given here (a TypeError in the SDK, a ValueError in Python), and no file is written. A written case gives every file's path but world.json, in code point order. Cases written by hand.", "version": 1, "refused": [ { @@ -339,6 +339,42 @@ "elements/character/bob--ss1.json", "elements/character/bob--ß1.json" ] + }, + { + "elements": [ + { + "type": "character", + "id": "b1234567σ", + "name": "Bob" + }, + { + "type": "character", + "id": "a1234567ς", + "name": "Bob" + } + ], + "paths": [ + "elements/character/bob--1234567ς.json", + "elements/character/bob--b1234567σ.json" + ] + }, + { + "elements": [ + { + "type": "character", + "id": "b1234567k", + "name": "Bob" + }, + { + "type": "character", + "id": "a1234567K", + "name": "Bob" + } + ], + "paths": [ + "elements/character/bob--1234567K.json", + "elements/character/bob--b1234567k.json" + ] } ] } diff --git a/tests/test_case_collide.py b/tests/test_case_collide.py index c9225f9..c8a1698 100644 --- a/tests/test_case_collide.py +++ b/tests/test_case_collide.py @@ -19,7 +19,7 @@ from onlyworlds import write_folder FIXTURE = Path(__file__).resolve().parent / "fixtures" / "case-collide.cases.json" -FIXTURE_SHA256 = "e3992a35b1389188edd6c95aec24a727920644d01fff802eb243c01f0ff9f427" +FIXTURE_SHA256 = "7fec915c2207aa654c01587076883fbdd693dc9f2c5e604733360573ff838b12" W = {"id": "w-1", "name": "W"} @@ -48,7 +48,7 @@ def test_the_cases_file_is_the_pinned_bytes() -> None: data = _data() assert data["version"] == 1 assert len(data["refused"]) == 14 - assert len(data["written"]) == 7 + assert len(data["written"]) == 9 @pytest.mark.parametrize("reverse", [False, True], ids=["given", "reversed"]) From f23a7d47cc15b7836bebf8bb3d2c4a4168d3ad65 Mon Sep 17 00:00:00 2001 From: Titus Date: Sat, 28 Nov 2026 20:33:41 +0100 Subject: [PATCH 2/2] 0.159.0: the collision rule compares file names by the folder format's fold Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 ++ src/onlyworlds/_version.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a67950..e212192 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ The package version runs on its own semver; the schema it is generated from is ` ## Unreleased +## 0.159.0 (2026-11-28) + - **Changed: the folder writer's collision rule compares names by the folder format's fold.** `resolve_filenames`, and so `write_folder`, the import doors and `export_world`, give two elements of one type whose short file names (slug and id tail) land on one name the id-ascending rule of folder spec §3.2: the lowest id keeps the short name, every other takes its full id. "One name" was `str.lower()` and is now the fold the archive reader compares names by (NFC, then simple case folding, Unicode 15.1), the same fold 0.158.6's refusal uses. So a few ids beyond ASCII now get the full-id name where before they were refused or lowercased apart: two elements named Bob with ids `a1234567ς` and `b1234567σ` kept the short names `bob--1234567ς.json` and `bob--1234567σ.json`, which the refusal joined, and are now written as `bob--1234567ς.json` and `bob--b1234567σ.json`. No ASCII id and no UUID changes its file name. The npm SDK's folder writer names them alike (`tests/fixtures/case-collide.cases.json`). ## 0.158.6 (2026-11-28) diff --git a/src/onlyworlds/_version.py b/src/onlyworlds/_version.py index 2c37e0f..812fce7 100644 --- a/src/onlyworlds/_version.py +++ b/src/onlyworlds/_version.py @@ -1 +1 @@ -__version__ = "0.158.6" +__version__ = "0.159.0"