diff --git a/CHANGELOG.md b/CHANGELOG.md index 768e661..f7e13c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ The package version runs on its own semver; the schema it is generated from is ` ## Unreleased +## 0.160.0 (2026-11-30) + +- **The schema pin is v0.34.1-dist.150** (canonical 00.34.01 unchanged). The folder format is 0.3.26, so `FORMAT_VERSION` and a new folder's `format_version` say `0.3.26`; a folder stamped 0.3.25 is read as before. 0.3.26 writes down how a writer names and refuses element files, rules `write_folder` already keeps: the id tail, an id whose `.json` is not one file name, and two file names that are one once folded. The schema distribution now carries their cases in `fixtures/folder-writer/` (9 id tails; 24 ids refused and 5 written; 16 sets of elements refused and 10 written), and the tests run those files, which the npm SDK's tests read too, in place of their own copies. + ## 0.159.1 (2026-11-30) - **Fixed: a folder `write_folder` writes always packs into a world file.** `write_folder`, and so `export_world` and the import doors, now also refuse an element id whose `.json` the world file's name check refuses (folder spec 3.2): one holding `<`, `>`, `"`, `|`, `?` or `*`, a control character from U+007F to U+009F, or a Windows device name such as `con`. Before, such an id was written (on Windows, `a?b.json` stopped the write part-way with an OSError), and `world_file_bytes` then refused the folder. The refusal says why in the archive's words, `as "a?b.json" it holds a reserved or control character`. An id ending in a dot or a space is still written, since its file name ends in `.json`. The shared cases (`tests/fixtures/unsafe-ids.cases.json`, the same bytes as the npm SDK's) move with it: 22 refused, 5 written. diff --git a/codegen/schema-dist/MANIFEST.json b/codegen/schema-dist/MANIFEST.json index 2e1d8e0..4bc318a 100644 --- a/codegen/schema-dist/MANIFEST.json +++ b/codegen/schema-dist/MANIFEST.json @@ -39,6 +39,9 @@ "example/hyperion/world.json": "e888457dec6710c6492b18ebae9470618552a3d3c557e22b99fc76ed0e21a9f5", "example/world-export.json": "dfd36ff98b7d835e2bd4b022205dfc7424b367693e2f96416a79ca9b53c089b9", "fixtures/file-names.fixture.json": "0da1846641e116b2ff39269261779854e794db117388bd912e5aff68a243a91d", + "fixtures/folder-writer/case-collide.cases.json": "6458bd08ad90de5dbc8c2f1fd4c52dca415cdd04bdd646555f4a00c787d0fd48", + "fixtures/folder-writer/id-tail.cases.json": "9684866ecf54bbf19901bc8579cc4b05f0b5bf3e1bbeb5036b609edfeb7bf06c", + "fixtures/folder-writer/unsafe-ids.cases.json": "de446111fbd89ab923d2450859f6f8b6020ca88770153c3b0d4045c29f4d484c", "fixtures/owworld/CaseFolding-15.1.0.txt": "4e55acfdc32825a22e87670e9056a3bf94ad7c5400065778e9e10f8314372bcf", "fixtures/owworld/CompositionExclusions-15.1.0.txt": "59d2d9e3dfdf0a999cf9dae11d594f053631222679a2f5710315ea07f7fe82af", "fixtures/owworld/fail-OW-1-json-export.owworld": "f6159d0ae98ef51f9a9d920143e2c0b69bba08192d4d65a632dbd229443e8696", @@ -207,7 +210,7 @@ "profiles/spine.md": "6bd367c3f4b101878fbc54a3c8c806630b7760173f24fef995db801b6103d92e", "profiles/strand.fixture.json": "7bc2d2dae11c0722b1db987c070b249ddcbc55b81683c4bfa26900c7ffe0fc53", "profiles/strand.md": "2a9bd36814a0de80a68180d2d75d3ef9d2539b9dcd52165f20b8ef0821575488", - "README.md": "a396419a8556d7b343a43742bb411e082413a6f9ae93462dd1d9740001c8d120", + "README.md": "49cf6e3f0ebc1542b4bf70c3f1ac3085a40e95e0fc614c5354281ad85a006eff", "schema/ability.yaml": "af185b2d22a5985ac323e6227a95df287fffaae0e5fca502976a02c2754f71b2", "schema/base_properties.yaml": "ec3724ceb2faca973e431a2e2ff946e55bfb55b6b8d78689b6b22d0cfb7c9a2e", "schema/character.yaml": "dc291b206121bd23c69cb89e01a0523eb2f71b4a247116dd6a1fa4bc227ff145", @@ -234,10 +237,10 @@ "schema/zone.yaml": "cca04ee498fb813fa18b96f1ac99816e7f1a8ae1fb9e21c48b37620dbb674856", "schema.json": "581dc7b5e890acc06b1c89b0d7bdcc2f20f54f52d5a3b4af8c5a184e1e6fd48c", "SECURITY.md": "939ee364b06f0b749bdd4cbe66b2fe49322c95abe732650ec4ef062a0c03820a", - "VERSION": "d2108320c93281b51981fb5d76e8db69b4f2051a135ad33898d1b0ea8fa763e3", + "VERSION": "0894baa5604e5f005a5daba8118f795b40cdd626ebd092b28dd62bfb7cb80a34", "views.fixture.json": "f9a2713b26639d1cb2c792b9f28f95c57e576f8e6c123b5ad3eac2a2507dfcf8", "views.json": "f4d06ee16bd6c66fc28cf27146b8d199c85164e5deecabafc23af53408746fe0", - "walk/lint_folder.py": "ddd7d28e7fbc5e8fb4494c2b2eda23daefc1b3708840a93b6cdffe12a3af88bd", + "walk/lint_folder.py": "7d28ed84263f5c91034f39f33c55c2c7b229baa40f68a98e0e7d6e9d286a9506", "walk/rulings.yaml": "1fb87ce4012d160b809e0aac50688c62405d2a5e6e303a57df84b98c249374ca", "walk/schema_walk.py": "e4a490dda5133e3961252cd8675eb39e5b214df68f6a661fa8601ccd69e6aed0" } diff --git a/codegen/schema-dist/README.md b/codegen/schema-dist/README.md index 35bd9ba..22aad0a 100644 --- a/codegen/schema-dist/README.md +++ b/codegen/schema-dist/README.md @@ -23,6 +23,9 @@ Each serial (one numbered publication of these files, tagged `v- | `walk/lint_folder.py` | the folder check: run it on a world folder and it names every key that is not a field of its type, every link that does not resolve or points at the wrong type, every value of the wrong shape, and a `world.json` that carries an `api` block while git tracks it (a linked folder is never committed, folder spec 4.6 d). The example world passes it at every publish | | `fixtures/owworld/` | the `.owworld` conformance set (folder spec 4.7): 120 zips, one per check and one cause each, with `verdicts.json` saying what a reader must answer for every one (accept, or refuse with its cause from the one list, and for some the files it leaves out of the world it reads, by reason, in `left_out`) and what a writer may emit. A world-file reader in any language runs the set and compares. `generate.py` rewrites every zip byte for byte (`python fixtures/owworld/generate.py --out fixtures/owworld`); `CaseFolding-15.1.0.txt` is Unicode's file as published, the C and S rows every reader folds names by, never a runtime's own fold | | `fixtures/file-names.fixture.json` | how a writer makes the name part of an element's file name, the rule under "The example world": 38 element names and the name part each gives (`""` where a name leaves none, so the file is named by the full id). A writer in any language runs them and compares | +| `fixtures/folder-writer/id-tail.cases.json` | the id tail in an element's file name, the rule under "The example world": 9 ids, each an element named Bob written alone, and the path each is written to | +| `fixtures/folder-writer/unsafe-ids.cases.json` | the ids a writer does not write, the rule under "The example world": 24 cases a writer does not write and 5 it writes, with the path of each | +| `fixtures/folder-writer/case-collide.cases.json` | the elements of one type a writer does not write because their file names are one name once folded, and those it writes, the rule under "The example world": 16 cases a writer does not write and 10 it writes, with every path | | `VERSION` | three `key: value` lines: the canonical schema version, the dist serial, the publish date | | `MANIFEST.json` | the sha256 of every file above (not of itself) | @@ -47,7 +50,9 @@ Only `id` and `name` are required. Element bodies read from the API also carry k ## The example world -`example/hyperion/` is a world folder: `world.json` for the world, and one JSON file per element at `elements//--.json`. The `id` inside a file is the element's identity; the filename is only for people. Its name part is made one way, so that two writers give an element the same name part: the element's name is put in Unicode's NFKD form; every code point from U+0300 to U+036F is dropped, and no other mark; the rest is lowercased by Unicode's default case mapping, in no locale; every run of characters outside `a` to `z` and `0` to `9` becomes one hyphen; hyphens at the start and the end are dropped; a name part longer than 40 characters is cut at 40, and hyphens at its new end are dropped; the forms and the case mapping are those of Unicode 11.0, and a code point Unicode assigned after 11.0 is promised nothing. A name that leaves nothing gives a file named by the full id (`.json`). A reader never leans on any of it: it reads the `id`. `fixtures/file-names.fixture.json` holds the cases. It needs no account or key: load it, check it against `schema.json`, and you have tested your reader on real data. The format is described at [World Folders](https://onlyworlds.github.io/docs/schema/folders). The folder format is at 0.3.25 (the spec's own version line); a folder stamps `format_version` from it. +`example/hyperion/` is a world folder: `world.json` for the world, and one JSON file per element at `elements//--.json`. The `id` inside a file is the element's identity; the filename is only for people. Its name part is made one way, so that two writers give an element the same name part: the element's name is put in Unicode's NFKD form; every code point from U+0300 to U+036F is dropped, and no other mark; the rest is lowercased by Unicode's default case mapping, in no locale; every run of characters outside `a` to `z` and `0` to `9` becomes one hyphen; hyphens at the start and the end are dropped; a name part longer than 40 characters is cut at 40, and hyphens at its new end are dropped; the forms and the case mapping are those of Unicode 11.0, and a code point Unicode assigned after 11.0 is promised nothing. A name that leaves nothing gives a file named by the full id (`.json`). A reader never leans on any of it: it reads the `id`. `fixtures/file-names.fixture.json` holds the cases. It needs no account or key: load it, check it against `schema.json`, and you have tested your reader on real data. The format is described at [World Folders](https://onlyworlds.github.io/docs/schema/folders). The folder format is at 0.3.26 (the spec's own version line); a folder stamps `format_version` from it. + +The id tail is the id's last eight code points. An id of eight code points or fewer is its own tail, dashes and all. When the last eight code points of a longer id begin with `-` or hold `--`, the tail is cut instead from the id with every `-` removed: the last eight code points of what is left, or all of it when eight or fewer are left. A writer writes an element only when `.json` is one file name that a world file's name check passes (folder spec 4.7, OW-22, with its cases in `fixtures/owworld/`), whatever the element's name. That check refuses a name that holds any of `<`, `>`, `:`, `"`, `|`, `?`, `*` or a control character (U+0000 to U+001F, U+007F to U+009F), a name that ends in a dot or a space, and a name whose part before its first dot is, in any letter case, `CON`, `PRN`, `AUX`, `NUL`, `COM1` to `COM9` or `LPT1` to `LPT9`. The name checked ends in `.json`, so no id is refused for ending in a dot or a space. An element whose id is empty, holds `/` or a backslash, or is `.` or `..` is never written. The id check comes first, each element alone; names are then made among the elements that pass it. When elements of one type would get file names that are one name once folded, by the fold below, the one whose id comes first in code point order keeps its name, and each later one is named with its full id in place of the tail. An element whose name leaves nothing is named `.json` either way. When two or more elements of one type still have file names that are one name once folded after that renaming, none of them is written. The fold is NFC as Unicode 15.1 has it, from `fixtures/owworld/UnicodeData-15.1.0.txt` and `fixtures/owworld/CompositionExclusions-15.1.0.txt`, then simple case folding by the C and S rows of `fixtures/owworld/CaseFolding-15.1.0.txt`, never a runtime's own. A writer that meets an element it does not write either leaves it out and writes the rest, or writes nothing. It names the id it reports, or the ids of the pair; in a folder with several such elements, not every one need be named. `fixtures/folder-writer/` holds the cases, each a folder written from the elements it lists. A writer passes a written case when it writes exactly the paths the case gives, and a refused case when it writes no file for the ids the case names and names those ids, in words of its own. An element file, in a world folder or in a world file (`.owworld`), in which an object or array sits more than 200 levels deep is not read. The count is made in the file's text, as each object or array opens: objects and arrays both count, an empty one too, the file's top object is level 1, a plain value inside an object or array at level 200 is read, and a key written twice counts with each of its values. A reader leaves such a file out of the world it reads, for the reason `too_deep`, and names it where it names the files it left out; the rest of the world is read as it stands. If the file is also broken in another way, it is still left out, and the reader may name either fault. The world's own `world.json` is counted the same way, and one past 200 is a `world.json` the reader cannot read (a world file holding one is refused, `not_a_world`). A file at 200 levels or fewer is not left out for depth. `fixtures/owworld/` holds the cases (OW-25). diff --git a/codegen/schema-dist/VERSION b/codegen/schema-dist/VERSION index 0d3f297..7022fa4 100644 --- a/codegen/schema-dist/VERSION +++ b/codegen/schema-dist/VERSION @@ -1,3 +1,3 @@ canonical: 00.34.01 -serial: 149 -published: 2026-11-27 +serial: 150 +published: 2026-11-30 diff --git a/tests/fixtures/case-collide.cases.json b/codegen/schema-dist/fixtures/folder-writer/case-collide.cases.json similarity index 100% rename from tests/fixtures/case-collide.cases.json rename to codegen/schema-dist/fixtures/folder-writer/case-collide.cases.json diff --git a/codegen/schema-dist/fixtures/folder-writer/id-tail.cases.json b/codegen/schema-dist/fixtures/folder-writer/id-tail.cases.json new file mode 100644 index 0000000..887dda7 --- /dev/null +++ b/codegen/schema-dist/fixtures/folder-writer/id-tail.cases.json @@ -0,0 +1,51 @@ +{ + "about": "Element ids and the path a world folder writer writes each to: the cases for the tail of the id in --.json (the name part is made as the README's \"The example world\" says). The tail is the last eight code points of the id. An id of eight code points or fewer is its own tail, as it stands, dashes kept. When the last eight code points of a longer id begin with - or hold --, the tail is cut instead from the id with every - removed: the last eight code points of what is left, or all of it when eight or fewer are left. Each case is one element of type character, written alone into an empty folder; it passes when the writer writes exactly the path given. Cases written by hand.", + "version": 1, + "written": [ + { + "id": "a1234567๐Ÿ˜€", + "name": "Bob", + "path": "elements/character/bob--1234567๐Ÿ˜€.json" + }, + { + "id": "a๐Ÿ˜€1234567", + "name": "Bob", + "path": "elements/character/bob--๐Ÿ˜€1234567.json" + }, + { + "id": "ab-cd-ef-gh1", + "name": "Bob", + "path": "elements/character/bob--d-ef-gh1.json" + }, + { + "id": "abcd-efghijk", + "name": "Bob", + "path": "elements/character/bob--defghijk.json" + }, + { + "id": "abc--defghij", + "name": "Bob", + "path": "elements/character/bob--cdefghij.json" + }, + { + "id": "a--b", + "name": "Bob", + "path": "elements/character/bob--a--b.json" + }, + { + "id": "-a", + "name": "Bob", + "path": "elements/character/bob---a.json" + }, + { + "id": "zzzza--bcdef", + "name": "Bob", + "path": "elements/character/bob--zzabcdef.json" + }, + { + "id": "ab------cdef", + "name": "Bob", + "path": "elements/character/bob--abcdef.json" + } + ] +} diff --git a/tests/fixtures/unsafe-ids.cases.json b/codegen/schema-dist/fixtures/folder-writer/unsafe-ids.cases.json similarity index 100% rename from tests/fixtures/unsafe-ids.cases.json rename to codegen/schema-dist/fixtures/folder-writer/unsafe-ids.cases.json diff --git a/codegen/schema-dist/walk/lint_folder.py b/codegen/schema-dist/walk/lint_folder.py index e97d61a..7770109 100644 --- a/codegen/schema-dist/walk/lint_folder.py +++ b/codegen/schema-dist/walk/lint_folder.py @@ -59,7 +59,12 @@ # The folder format's version this lint was written against: the folder spec's # own version line, the one source. It moves when the spec's version moves, and -# publish_dist.py writes the dist README's version sentence from it. 0.3.25 +# publish_dist.py writes the dist README's version sentence from it. 0.3.26 +# (2026-11-30, serial 150) says how a writer names and refuses element files: the id tail is +# the id's last eight code points, cut from the id with its dashes removed when that cut begins +# with `-` or holds `--`; an id whose `.json` is not one file name a world file's name check +# passes is not written; two elements of one type whose file names are one name once folded are +# not written; this lint names no files and gained no check. 0.3.25 # (2026-11-25, serial 148) says an element file in which an object or array sits more than 200 # levels deep is not read, `too_deep`; this lint counts the depth itself (_too_deep). 0.3.24 # (2026-11-14, serial 128) says a multi-link names each element once: a reader served a @@ -70,7 +75,7 @@ # this lint reads no prose and gained no check. 0.3.22 (2026-11-12) says what a draft # world is and that a writer adds no `world` key to an element file (already reported # as no field of its type). -FORMAT_VERSION = "0.3.25" +FORMAT_VERSION = "0.3.26" # Keys an element body carries that the schema does not declare: the type # slug and the server-managed fields (elements/serialize.py READONLY_FIELDS diff --git a/codegen/schema-pin.json b/codegen/schema-pin.json index 8d0dae0..b79bab4 100644 --- a/codegen/schema-pin.json +++ b/codegen/schema-pin.json @@ -2,15 +2,20 @@ "_what": "The recorded pin for the vendored OnlyWorlds schema distribution (codegen/schema-dist/, copied byte-exact). Do not edit by hand; re-vendor from the pinned tag and review the diff. Kept equal to the npm SDK's pin (github.com/OnlyWorlds/sdk, codegen/schema-pin.json) on purpose: two clients, one schema.", "_why_manifest_sha256": "Verifying the tree against its own MANIFEST.json only proves internal consistency. If the tag moved, the manifest moved with it. The hash recorded here is the one first accepted, which is what makes a moved tag visible.", "repo": "https://github.com/OnlyWorlds/schema-dist", - "tag": "v0.34.1-dist.149", - "commit": "67929605d43c5d27c71cad0c21488bf81a897793", - "manifest_sha256": "5d71d4c9bae2c8e7b55ada9c88093769059d677f56e08c6aaa5e4c063c599dda", + "tag": "v0.34.1-dist.150", + "commit": "3cca6b5ba1f5ff7a548abda9de45330545de0478", + "manifest_sha256": "6f3d6733bb1c46707b1545188306931d31419f71901998ea29dc9276bf4c6b8f", "canonical_version": "00.34.01", - "dist_serial": 149, - "published": "2026-11-27", - "pinned_at": "2026-11-27", - "pinned_by": "The maintainer: tree from `git archive` of the tag in a schema-dist checkout (241 files: the 240 the MANIFEST lists, and MANIFEST.json itself); files re-hashed against MANIFEST.json by verify_dist.py; MANIFEST self-hash matched against the raw file GitHub serves at the tag, whose ref resolves to the commit above.", + "dist_serial": 150, + "published": "2026-11-30", + "pinned_at": "2026-11-30", + "pinned_by": "The maintainer: tree from `git archive` of the tag in a schema-dist checkout (244 files: the 243 the MANIFEST lists, and MANIFEST.json itself); files re-hashed against MANIFEST.json by verify_dist.py; MANIFEST self-hash matched against the raw file GitHub serves at the tag, whose ref resolves to the commit above.", "previous_pins": [ + { + "tag": "v0.34.1-dist.149", + "manifest_sha256": "5d71d4c9bae2c8e7b55ada9c88093769059d677f56e08c6aaa5e4c063c599dda", + "note": "the cases for a tool that writes world folders (fixtures/folder-writer/), folder format 0.3.26" + }, { "tag": "v0.34.1-dist.148", "manifest_sha256": "4cbe4d923e47d9f1899d9a3f865d3b0169dede546921dfc89557bce215577c1a", diff --git a/src/onlyworlds/__init__.py b/src/onlyworlds/__init__.py index d4018cf..28cd098 100644 --- a/src/onlyworlds/__init__.py +++ b/src/onlyworlds/__init__.py @@ -1,6 +1,6 @@ """OnlyWorlds for Python: the world folder (read, write, push), its archive (``.owworld``) and a client for the v2 API. -Folder format: v0.3.25 (``FORMAT_VERSION``). Schema: generated from the pinned +Folder format: v0.3.26 (``FORMAT_VERSION``). Schema: generated from the pinned schema distribution (``SCHEMA_DIST_TAG``, ``SCHEMA_VERSION``); the package version runs on its own semver. """ diff --git a/src/onlyworlds/_schema.py b/src/onlyworlds/_schema.py index 5a0cb99..4d627e1 100644 --- a/src/onlyworlds/_schema.py +++ b/src/onlyworlds/_schema.py @@ -1,13 +1,13 @@ # GENERATED by codegen/generate_schema.py from the vendored schema distribution. Do not hand-edit. # Regenerate: python codegen/generate_schema.py (CI/test: --check) -# Source: https://github.com/OnlyWorlds/schema-dist @ v0.34.1-dist.149 (67929605d43c5d27c71cad0c21488bf81a897793) +# Source: https://github.com/OnlyWorlds/schema-dist @ v0.34.1-dist.150 (3cca6b5ba1f5ff7a548abda9de45330545de0478) """Schema provenance, the 22 element types and their fields, from the pinned schema distribution.""" -SCHEMA_DIST_TAG = "v0.34.1-dist.149" +SCHEMA_DIST_TAG = "v0.34.1-dist.150" SCHEMA_VERSION = "00.34.01" -SCHEMA_DIST_SERIAL = 149 -SCHEMA_MANIFEST_SHA256 = "5d71d4c9bae2c8e7b55ada9c88093769059d677f56e08c6aaa5e4c063c599dda" +SCHEMA_DIST_SERIAL = 150 +SCHEMA_MANIFEST_SHA256 = "6f3d6733bb1c46707b1545188306931d31419f71901998ea29dc9276bf4c6b8f" # Canonical order, as the walk declares it. ELEMENT_TYPES: tuple[str, ...] = ( diff --git a/src/onlyworlds/_version.py b/src/onlyworlds/_version.py index d762f74..36947cd 100644 --- a/src/onlyworlds/_version.py +++ b/src/onlyworlds/_version.py @@ -1 +1 @@ -__version__ = "0.159.1" +__version__ = "0.160.0" diff --git a/src/onlyworlds/_walk/lint_folder.py b/src/onlyworlds/_walk/lint_folder.py index e97d61a..7770109 100644 --- a/src/onlyworlds/_walk/lint_folder.py +++ b/src/onlyworlds/_walk/lint_folder.py @@ -59,7 +59,12 @@ # The folder format's version this lint was written against: the folder spec's # own version line, the one source. It moves when the spec's version moves, and -# publish_dist.py writes the dist README's version sentence from it. 0.3.25 +# publish_dist.py writes the dist README's version sentence from it. 0.3.26 +# (2026-11-30, serial 150) says how a writer names and refuses element files: the id tail is +# the id's last eight code points, cut from the id with its dashes removed when that cut begins +# with `-` or holds `--`; an id whose `.json` is not one file name a world file's name check +# passes is not written; two elements of one type whose file names are one name once folded are +# not written; this lint names no files and gained no check. 0.3.25 # (2026-11-25, serial 148) says an element file in which an object or array sits more than 200 # levels deep is not read, `too_deep`; this lint counts the depth itself (_too_deep). 0.3.24 # (2026-11-14, serial 128) says a multi-link names each element once: a reader served a @@ -70,7 +75,7 @@ # this lint reads no prose and gained no check. 0.3.22 (2026-11-12) says what a draft # world is and that a writer adds no `world` key to an element file (already reported # as no field of its type). -FORMAT_VERSION = "0.3.25" +FORMAT_VERSION = "0.3.26" # Keys an element body carries that the schema does not declare: the type # slug and the server-managed fields (elements/serialize.py READONLY_FIELDS diff --git a/src/onlyworlds/campfire.py b/src/onlyworlds/campfire.py index e3e9440..0aa7dd9 100644 --- a/src/onlyworlds/campfire.py +++ b/src/onlyworlds/campfire.py @@ -73,7 +73,7 @@ A second element of one type and name gets ``:`` on its key and is named in the report; an exact copy folds into one. ``producer`` is ``{"tool": "onlyworlds", "version": ..., "input": "campfire-export"}`` (``PRODUCER_INPUT``, on the folder spec's ยง4.2 list since v0.3.18; the -folder's ``format_version`` is the package's ``FORMAT_VERSION``, 0.3.25 since 0.155.0). +folder's ``format_version`` is the package's ``FORMAT_VERSION``, 0.3.26 since 0.160.0). From the command line: exit 0 written (or planned), 2 on bad arguments (no ``--file``, a missing file, an OUT-DIR that is not empty, a blank ``--project``, a file that is not a Campfire export). diff --git a/src/onlyworlds/folder.py b/src/onlyworlds/folder.py index c9ca84d..61839b6 100644 --- a/src/onlyworlds/folder.py +++ b/src/onlyworlds/folder.py @@ -1,6 +1,6 @@ """The OnlyWorlds world folder: filenames, the writer, the reader. -Spec: OnlyWorlds Folder Format v0.3.25. +Spec: OnlyWorlds Folder Format v0.3.26. Section numbers below are that document's. :: @@ -65,7 +65,7 @@ ] #: The spec version this module writes and reads against (ยง4.2 ``format_version``). -FORMAT_VERSION = "0.3.25" +FORMAT_VERSION = "0.3.26" #: ยง4.4 (v0.3.10): the stub marker. keel hands a guest an element it reaches only #: through its own Character's sheet as a stub, ``known_of: true``: these keys, its type's public @@ -198,7 +198,8 @@ def _unsafe_id_why(element_id: str) -> str | None: character (U+0000 to U+001F), ``.`` or ``..``, then whatever a world file's name check refuses for the one segment ``.json`` (folder spec 3.2: ``<>"|?*``, every other control character, a Windows device name), so a folder that writes always packs. The npm SDK's writer refuses the same ids in the same - words (tests/fixtures/unsafe-ids.cases.json). ``_inside`` is the second guard, on the path itself.""" + words (the schema distribution's fixtures/folder-writer/unsafe-ids.cases.json). ``_inside`` is the second + guard, on the path itself.""" from .worldfile import _segment_fault # worldfile imports this module at load if not element_id: @@ -280,7 +281,7 @@ def _refuse_case_collisions(etype: str, names: Mapping[str, str]) -> None: 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).""" + packages name the same pair (the schema distribution's fixtures/folder-writer/case-collide.cases.json).""" from .worldfile import _fold_name # worldfile imports this module seen: dict[str, str] = {} diff --git a/tests/test_case_collide.py b/tests/test_case_collide.py index c2b1878..a56b298 100644 --- a/tests/test_case_collide.py +++ b/tests/test_case_collide.py @@ -1,8 +1,8 @@ """``write_folder`` refuses two elements of one type whose file names, once the collision rule (folder spec 3.2) has chosen them, are one name under OW-18's fold (NFC, then simple case folding): a case-insensitive disk may keep one file for both. The shared -cases (``tests/fixtures/case-collide.cases.json``, the same bytes as the npm SDK's -``test/fixtures/case-collide.cases.json``; both suites hold its sha256): each refused case is a ValueError in the +cases (the schema distribution's ``fixtures/folder-writer/case-collide.cases.json``, vendored in +``codegen/schema-dist/``; both suites hold its sha256): each refused case is a ValueError in the case's words and nothing is written, in either input order; each written case gives its paths.""" from __future__ import annotations @@ -18,7 +18,7 @@ from onlyworlds import write_folder -FIXTURE = Path(__file__).resolve().parent / "fixtures" / "case-collide.cases.json" +FIXTURE = Path(__file__).resolve().parents[1] / "codegen/schema-dist/fixtures/folder-writer/case-collide.cases.json" FIXTURE_SHA256 = "6458bd08ad90de5dbc8c2f1fd4c52dca415cdd04bdd646555f4a00c787d0fd48" W = {"id": "w-1", "name": "W"} diff --git a/tests/test_export.py b/tests/test_export.py index d97ee44..8662358 100644 --- a/tests/test_export.py +++ b/tests/test_export.py @@ -106,7 +106,7 @@ def test_an_export_carries_the_servers_origin_beside_its_own_lines( def test_world_json_says_where_it_came_from(tmp_path: Path, make_client: Callable[..., Client]) -> None: w, _ = _export(tmp_path, make_client, jresp(200, _me("owner", "owner"))) - assert w["format_version"] == "0.3.25" == FORMAT_VERSION + assert w["format_version"] == "0.3.26" == FORMAT_VERSION src = w["source"] assert isinstance(src, dict) and list(src) == ["server", "world", "at"] assert src["server"] == "https://www.onlyworlds.com" # the API origin, not the /api/v2 base diff --git a/tests/test_id_tail.py b/tests/test_id_tail.py index 8a8b6c9..34bba6c 100644 --- a/tests/test_id_tail.py +++ b/tests/test_id_tail.py @@ -1,33 +1,43 @@ -"""An element file's id tail is the last 8 code points of its id (folder spec 3.2): an id with a character above -U+FFFF in its tail, or at the cut, names its file as the npm SDK names it, and dashes are kept unless the cut of -eight begins with one or holds two, when the tail is cut from the id with every dash removed. The five cases are the -folder spec's own and the same as the npm SDK's ``test/id-tail.test.mjs``; ``write_folder`` writes each name to -disk.""" +"""An element file's id tail (folder spec 3.2): the last 8 code points of its id, never UTF-16 units, and dashes kept +unless the cut of eight begins with one or holds two, when the tail is cut from the id with every dash removed. The +cases are the schema distribution's ``fixtures/folder-writer/id-tail.cases.json``, vendored in ``codegen/schema-dist/``, +which the npm SDK runs too: each is one element of type character written alone into an empty folder, and +``write_folder`` writes exactly the path given.""" from __future__ import annotations +import hashlib +import json from pathlib import Path +from typing import Any import pytest from onlyworlds import write_folder from onlyworlds.folder import element_filename -E = chr(0x1F600) - - -@pytest.mark.parametrize( - ("element_id", "name"), - [ - (f"a1234567{E}", f"bob--1234567{E}.json"), - (f"a{E}1234567", f"bob--{E}1234567.json"), - ("ab-cd-ef-gh1", "bob--d-ef-gh1.json"), - ("abcd-efghijk", "bob--defghijk.json"), - ("abc--defghij", "bob--cdefghij.json"), - ], -) -def test_the_tail_of_eight_code_points(tmp_path: Path, element_id: str, name: str) -> None: - assert element_filename(element_id, "Bob") == name +FIXTURE = Path(__file__).resolve().parents[1] / "codegen/schema-dist/fixtures/folder-writer/id-tail.cases.json" +FIXTURE_SHA256 = "9684866ecf54bbf19901bc8579cc4b05f0b5bf3e1bbeb5036b609edfeb7bf06c" + + +def _cases() -> list[dict[str, str]]: + data: dict[str, Any] = json.loads(FIXTURE.read_bytes()) + cases: list[dict[str, str]] = data["written"] + return cases + + +def test_the_cases_file_is_the_pinned_bytes() -> None: + assert hashlib.sha256(FIXTURE.read_bytes()).hexdigest() == FIXTURE_SHA256 + data = json.loads(FIXTURE.read_bytes()) + assert data["version"] == 1 + assert len(data["written"]) == 9 + + +@pytest.mark.parametrize("case", _cases(), ids=lambda c: c["id"]) +def test_the_tail_of_eight_code_points(tmp_path: Path, case: dict[str, str]) -> None: + folder, _, name = case["path"].rpartition("/") + assert folder == "elements/character" + assert element_filename(case["id"], case["name"]) == name out = tmp_path / "world" - write_folder(out, {"id": "w-1", "name": "W"}, {"character": [{"id": element_id, "name": "Bob"}]}) + write_folder(out, {"id": "w-1", "name": "W"}, {"character": [{"id": case["id"], "name": case["name"]}]}) assert [p.name for p in (out / "elements" / "character").iterdir()] == [name] diff --git a/tests/test_known_of.py b/tests/test_known_of.py index ad293f2..995f555 100644 --- a/tests/test_known_of.py +++ b/tests/test_known_of.py @@ -71,7 +71,7 @@ def dev_file(root: Path) -> dict[str, Any]: def test_the_kept_keys_are_keels() -> None: assert frozenset(KEPT) == KNOWN_OF_KEEPS - assert FORMAT_VERSION == "0.3.25" + assert FORMAT_VERSION == "0.3.26" def test_is_known_of_only_for_true() -> None: diff --git a/tests/test_unsafe_ids.py b/tests/test_unsafe_ids.py index a17dd16..e851596 100644 --- a/tests/test_unsafe_ids.py +++ b/tests/test_unsafe_ids.py @@ -1,5 +1,5 @@ """``write_folder`` refuses an element id that cannot name a file. The shared cases -(``tests/fixtures/unsafe-ids.cases.json``, the same bytes as the npm SDK's ``test/fixtures/unsafe-ids.cases.json``; +(the schema distribution's ``fixtures/folder-writer/unsafe-ids.cases.json``, vendored in ``codegen/schema-dist/``; both suites hold its sha256): an id that holds ``/``, ``\\`` or a control character, or is ``.`` or ``..``, is refused whatever the name, since ``.json`` would leave its type folder, with a ValueError naming the type, the id as JSON text and the case's why, and nothing is written (the target is not made, an empty one is left as it @@ -24,7 +24,7 @@ from onlyworlds.http import Response from onlyworlds.okf import write_bundle -FIXTURE = Path(__file__).resolve().parent / "fixtures" / "unsafe-ids.cases.json" +FIXTURE = Path(__file__).resolve().parents[1] / "codegen/schema-dist/fixtures/folder-writer/unsafe-ids.cases.json" FIXTURE_SHA256 = "de446111fbd89ab923d2450859f6f8b6020ca88770153c3b0d4045c29f4d484c" W = {"id": "w-1", "name": "W"}