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.148.1 (2026-11-24)

- **Fixed: `read_world_file` no longer refuses a world file whose world holds a tool's own `world.json` under a dot-folder** (`abbey/.atlas/world.json`, or deeper, `abbey/elements/character/.trash/world.json`). A dot-folder is never a world, wherever it sits, as the folder reader already had it: `read_folder` never reads a dot-folder. So the same world now opens as a file and as a folder. Only the check for a second `world.json` inside the world skips those paths; every other check still runs on their entries (paths, names, duplicates, collisions, size and count), and they are still returned in `entries`. A nested `world.json` outside a dot-folder and outside `records/` (`abbey/inner/world.json`) is still refused. This follows a ruling on the world-file conformance checks OW-4 and OW-5; the conformance case comes with the next schema distribution serial.

## 0.148.0 (2026-11-24)

- **Added: `pins_known_to(pins, served)`**: which of a map's Pins one reader knows, for a map drawn as one Character sees it. A Pin is known when the element it places is among `served`, the elements as that reader was served them (a list read with the reader's own key, or the owner's read with `view_as`); the function reads nothing else, so it cannot show a reader more than the world told them. The answer is `{"known", "unknown", "out"}`: `known` lists each known Pin as `{"pin", "map", "element_type", "element_id", "how"}` by Pin id in code point order, where `how` is `"whole"` or, when the element reached the reader as a stub it only knows of (`known_of` exactly `True`), `"known_of"`, so a drawing can tell a place heard of from a place known; `unknown` counts the Pins that place an element the reader was not served, as a number and never as ids; `out["no_link"]` counts the Pins that place nothing. The type and the id are compared as written, the last of two served rows with one type and id decides, and the answer carries no name or body of any element. It does not ask whether a Pin has a point or its Map exists: `map_space` reads that, and a drawing keeps the Pins both name. `pins` may be a whole world's list: only its rows of type `pin` are read. The Pins are the caller's to bring, from whichever read holds the map (an open world's, the owner's): a reader's own list need not hold them. A list or a tuple is taken for either argument; anything else is a `TypeError`. A rule of this package and the npm SDK (`pinsKnownTo` in `@onlyworlds/sdk` 4.200.0), not of the standard: the two run the same 31 cases and 8 refusals (`tests/fixtures/pins-known-to.cases.json`). Types `PinsKnownTo`, `PinKnown`.
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.148.0"
__version__ = "0.148.1"
11 changes: 8 additions & 3 deletions src/onlyworlds/worldfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
- ``marker`` (OW-6): a root ``mimetype`` entry with other bytes than the media type.
A marker is never required.
- ``not_a_world``, ``more_than_one`` (OW-2, OW-3, OW-5): no world, two worlds, a second
``world.json`` inside the world (one under ``records/`` is a producer's data), a
``world.json`` that will not parse or has no string id.
``world.json`` inside the world (one under ``records/`` is a producer's data; one under a
dot-folder is a tool's, since a dot-folder is never a world), a ``world.json`` that will not
parse or has no string id.

Files beside the world's folder and archive junk (``__MACOSX``, ``.DS_Store``,
``Thumbs.db``) are ignored (OW-4), still checked and counted. An ``api`` block in
Expand Down Expand Up @@ -711,10 +712,14 @@ def read_world_file(
if len(roots) > 1:
_refuse("more_than_one", f"The file holds worlds in {', '.join(roots)}.")
prefix = roots[0]
# OW-5: no world.json inside the world but its own, except a producer's under records/.
# OW-5: no world.json inside the world but its own, except a producer's under records/. A dot-folder is
# never a world, wherever it sits: a tool's own world.json under one is not looked at here, as a folder
# reader never reads it. Only this check skips those paths; every check above ran on them.
inside = {n for n in candidates if n.startswith(prefix)}
for n in sorted(inside):
rel = n[len(prefix) :]
if any(seg.startswith(".") for seg in rel.split("/")[:-1]):
continue
if rel != WORLD_FILE and rel.endswith(f"/{WORLD_FILE}") and not rel.startswith("records/"):
_refuse("more_than_one", f"A second world.json sits inside the world: {n}.")

Expand Down
81 changes: 81 additions & 0 deletions tests/test_worldfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,87 @@ def test_to_folder_writes_every_entry_byte_for_byte_and_never_over_a_folder(tmp_
assert not (tmp_path / "evil.json").exists() and not (tmp_path / "forged").exists()


# A dot-folder is never a world, wherever it sits: OW-5 does not look under one. The same five
# cases, in the same order, are in the npm SDK's test/world-file.test.mjs.
ABBEY = "0192a000-aaaa-7bbb-8ccc-0000000000ab"
ADA = "0192a000-aaaa-7bbb-8ccc-0000000000a1"
ELSEWHERE = encode({"id": "0192a000-aaaa-7bbb-8ccc-0000000000ef", "name": "Elsewhere"})


def abbey_tree(more: dict[str, bytes] | None = None) -> dict[str, bytes]:
"""Abbey's world folder, path -> bytes: its world.json, one character, and ``more``."""
return {
"world.json": encode({"id": ABBEY, "name": "Abbey"}),
"elements/character/ada.json": encode({"id": ADA, "name": "Ada"}),
**(more or {}),
}


def abbey_zip(files: dict[str, bytes]) -> bytes:
"""The tree zipped under one top-level folder ``abbey/``, built here: the writer never emits a
dot-folder unprompted."""
return zip_of({f"abbey/{rel}": data for rel, data in files.items()})


def folder_view(root: Path) -> dict[str, Any]:
"""What ``read_folder`` makes of a folder, every path relative to it."""
folder = read_folder(root)

def rel(p: Path) -> str:
return p.relative_to(root).as_posix()

return {
"world": folder.world,
"elements": sorted(
(el.layout, rel(el.path), el.id, el.type, encode(el.body)) for el in folder.all_elements().values()
),
"skipped": [(rel(s.path), s.reason) for s in folder.skipped],
"duplicates": [(d.id, rel(d.kept), rel(d.ignored)) for d in folder.duplicates],
"ignored_dirs": [rel(p) for p in folder.ignored_dirs],
}


def reads_as_its_folder(files: dict[str, bytes], tmp_path: Path) -> None:
"""The file is accepted as abbey, carries every entry, and reads to exactly what the folder reads to."""
r = read_world_file(abbey_zip(files))
assert (r.world_id, r.name, r.top) == (ABBEY, "Abbey", "abbey")
assert list(r.entries) == sorted(files)
from_file = folder_view(r.to_folder(tmp_path / "from-file"))
assert [e[1] for e in from_file["elements"]] == ["elements/character/ada.json"]
assert from_file == folder_view(make_folder(tmp_path / "folder", files))


def test_ow5_a_tools_world_json_in_a_dot_folder_at_the_root_is_no_second_world(tmp_path: Path) -> None:
reads_as_its_folder(
abbey_tree({".atlas/world.json": ELSEWHERE, ".atlas/world-prefs.json": encode({"zoom": 2})}), tmp_path
)


def test_ow5_a_dot_folder_deeper_in_the_world_is_no_second_world_either(tmp_path: Path) -> None:
reads_as_its_folder(abbey_tree({"elements/character/.trash/world.json": ELSEWHERE}), tmp_path)


def test_ow5_a_name_that_is_dots_and_more_is_a_dot_folder_name(tmp_path: Path) -> None:
reads_as_its_folder(abbey_tree({"..atlas/world.json": ELSEWHERE}), tmp_path)


def test_ow5_still_refused_each_by_its_own_reason() -> None:
refuses("more_than_one", abbey_zip(abbey_tree({"inner/world.json": ELSEWHERE})))
refuses("unsafe_path", abbey_zip(abbey_tree({"inner/.atlas/../world.json": ELSEWHERE})))
refuses("unsafe_path", abbey_zip(abbey_tree({".atlas/./world.json": ELSEWHERE})))
# Only a folder's name counts: the dot-folder beside it is skipped, inner/world.json is not, and a
# dot file is no folder.
for beside in ({"inner/.hidden/world.json": ELSEWHERE}, {"inner/.hidden": b"x"}):
error = refuses("more_than_one", abbey_zip(abbey_tree({**beside, "inner/world.json": ELSEWHERE})))
assert str(error) == "A second world.json sits inside the world: abbey/inner/world.json."


def test_ow5_records_is_still_excepted() -> None:
r = read_world_file(abbey_zip(abbey_tree({"records/lab/world.json": ELSEWHERE})))
assert r.world_id == ABBEY
assert list(r.entries) == ["elements/character/ada.json", "records/lab/world.json", "world.json"]


# --- the writer --------------------------------------------------------------------------------


Expand Down
Loading