Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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)

- **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).
Expand Down
2 changes: 1 addition & 1 deletion src/onlyworlds/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.158.6"
__version__ = "0.159.0"
16 changes: 10 additions & 6 deletions src/onlyworlds/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand All @@ -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
Expand Down
38 changes: 37 additions & 1 deletion tests/fixtures/case-collide.cases.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down Expand Up @@ -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"
]
}
]
}
4 changes: 2 additions & 2 deletions tests/test_case_collide.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}


Expand Down Expand Up @@ -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"])
Expand Down
Loading