diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d44e81..72faa2a 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.155.0 (2026-11-26) + +- **The schema pin is v0.34.1-dist.148** (canonical 00.34.01 unchanged). The folder format is 0.3.25, so `FORMAT_VERSION` and a new folder's `format_version` say `0.3.25`; the vendored folder check counts depth itself, the same on every Python, and refuses a `world.json` past 200 levels. The `.owworld` set holds 120 archives, nine new for the depth rule, every one read as its verdict says. +- **`date_labels` is never sent by `push`.** The MCP server on onlyworlds.com gives a date in the words of the world's calendar as `date_labels` beside the numbers, and a write that carries the key is refused (422); a body copied from it into a folder now pushes as if the key were not there. +- **Depth is counted in a file's text, before the parse** (folder format, serial 148), as the npm SDK counts it. Text this package did not write is past 200 levels when it opens an object or array deeper than 200, so each value of a repeated key counts and a file past the line is refused as nested too deep whatever else is wrong with it. Brackets inside a string are not counted, and a string left open runs to the end of the text. Before, the depth was read from the parsed value: a repeated key's plain value hid a deep one, and a file broken and deep was refused as not JSON. + ## 0.154.1 (2026-11-26) - **A calendar's era walk is linear in its eras**, as the npm SDK's is. Each era's domain looked for the next up era in a slice of the rest of the sorted list, so the walk was quadratic: one `format_step` label took 331 ms under 15,000 eras; now 101 ms, the same labels. diff --git a/codegen/schema-dist/MANIFEST.json b/codegen/schema-dist/MANIFEST.json index 4ae0adf..b49a1e0 100644 --- a/codegen/schema-dist/MANIFEST.json +++ b/codegen/schema-dist/MANIFEST.json @@ -107,6 +107,7 @@ "fixtures/owworld/fail-OW-23-share-carries-twin.owworld": "3d14536c777e1b9b53832479d4b6aee06036063f70aa590279e0afe5200cb566", "fixtures/owworld/fail-OW-23-share-carries-unread.owworld": "3f1b2e7f7ca3e411f519e869c1ae3a8849ff2bdd7626ee28c55f09be68b205e9", "fixtures/owworld/fail-OW-23-share-carries-untyped.owworld": "8a4ea219edac7fc018cb14d82f5457a0f5c2e77367d0b456eb33f388530adb0f", + "fixtures/owworld/fail-OW-25-world-json-too-deep.owworld": "cf8aae17d3080df240b06c89f58e84078c7fab26d6d3438fc9e16c3ab463f8a4", "fixtures/owworld/fail-OW-3-array.owworld": "6cededb313e38bb73474890587d10cda608440030eef5ad27f487060fa638ff6", "fixtures/owworld/fail-OW-3-blank-id.owworld": "19189cba558889eba5c5f7d5b7133668ec845d08b7dcea3cd6b26e0b027fbb0c", "fixtures/owworld/fail-OW-3-no-id.owworld": "0c26aca58f7f89f41b5c466de544b4f0a06d52b3eee94e325f901b1df60883b6", @@ -125,7 +126,7 @@ "fixtures/owworld/fail-OW-8-producer-meta-dropped.owworld": "4fa8e3a1f0ba92f38db1e29223ae1bd3c6df5346c34bb6b6eb1e4cf1a8d20259", "fixtures/owworld/fail-OW-8-records-missing.owworld": "128fff91a82385acca5a23eb7dcc7605d19aac1a4349bfcb7134e3136aa69e32", "fixtures/owworld/fail-OW-8-records-reencoded.owworld": "128261249c08c26ea19a54872c02c313d8492ca17586f295e83fb40e9126a96c", - "fixtures/owworld/generate.py": "329e386406a90cd2da11b04788e2b67722e9214dd87bf57839cd9d5b763a72b5", + "fixtures/owworld/generate.py": "e118a05b58e7c48dd4f5c75e10a2967d6206ea1df7827dff6784d559a43fa557", "fixtures/owworld/pass-good.owworld": "11a577b054b87cc8e7d66f8070d791d413f3ab7527d4de82a9d19abbf5d1e856", "fixtures/owworld/pass-OW-1-renamed.zip": "11a577b054b87cc8e7d66f8070d791d413f3ab7527d4de82a9d19abbf5d1e856", "fixtures/owworld/pass-OW-10-api.owworld": "2304fcdaeb1ce7cbcc9aec2222716ba1219f347296d87d26df3e02273955fe1a", @@ -142,6 +143,14 @@ "fixtures/owworld/pass-OW-23-share-leaves-unread-out.owworld": "11a577b054b87cc8e7d66f8070d791d413f3ab7527d4de82a9d19abbf5d1e856", "fixtures/owworld/pass-OW-24-spatial-type-case.owworld": "51e50436e02ccd8bd2978380fb64ea5688da32ee7fc697fc7adb480ab39e5be1", "fixtures/owworld/pass-OW-24-spatial-untyped.owworld": "cc39ecd74848be036925a5aeb12bfa0390b470525baf0a7d87cf3b6fc160379d", + "fixtures/owworld/pass-OW-25-brackets-in-string-read.owworld": "1869a10b261c7d605389358cbd198a7ded58080a57763adc0814fba95e972369", + "fixtures/owworld/pass-OW-25-depth-200-read.owworld": "faabbd23cbcd4bf4502ef10b438e36566f97e43244e9d2f91b7e6d0986b99c5d", + "fixtures/owworld/pass-OW-25-depth-201-left-out.owworld": "a5dffe6d0f68f5ab277176b330388030fed7210c69422a5ecbd340fe5d53f6a4", + "fixtures/owworld/pass-OW-25-dup-key-deep-first-left-out.owworld": "9784b98f18dd4e855e81b5b35d26d8aeade6b96b0ffab5cf1178f3b6f8cb42fd", + "fixtures/owworld/pass-OW-25-dup-key-deep-last-left-out.owworld": "683857a8d8d073f1613b90438d356d9095292a6af03fc72daa4c4649a41105bb", + "fixtures/owworld/pass-OW-25-empty-array-at-201-left-out.owworld": "7d2c9d67ac769610b7ccccd8b0f140b6caec9f0fabd9601b881941b3949a4136", + "fixtures/owworld/pass-OW-25-empty-object-at-201-left-out.owworld": "def2a965df80ef83e3913accfd18306bc418bda27569ac314e38d8509143d6f8", + "fixtures/owworld/pass-OW-25-escaped-backslash-then-deep-left-out.owworld": "f0f2edf04efc91e36d75fd09b427b4392db2bb2840f93390fd78aa08204ef138", "fixtures/owworld/pass-OW-4-archive-junk.owworld": "b7ca25bda4354a71dfaf5202dfea97dec3079167b31622a343a55fad372bcde2", "fixtures/owworld/pass-OW-4-readme.owworld": "8985f68a3336787042eb61127507f5fa41c95fa8188c39c1769ee7ce2860667b", "fixtures/owworld/pass-OW-4-tool-folder.owworld": "424b5f898d0db6b38d73abca6e03bbf7d8e74f707af7f0096b11c04f86c5b315", @@ -154,7 +163,7 @@ "fixtures/owworld/pass-OW-9-roundtrip.owworld": "ea5a1087df2b0006aa7230ca75de69f491238bff3a565114e0037ad8eb6d5c2f", "fixtures/owworld/pass-OW-9-unknown.owworld": "f220915504a75e7f8f644188d8868c6b7ce05834e24b6f47cea24890b9159eca", "fixtures/owworld/UnicodeData-15.1.0.txt": "2fc713e6a31a87c4850a37fe2caffa4218180fadb5de86b43a143ddb4581fb86", - "fixtures/owworld/verdicts.json": "c21b4ec6c355902a9cde1c45bd7f057e9833e31a3c6032a963cec9b801961693", + "fixtures/owworld/verdicts.json": "282fcf2162b16cde398d8f877b12bef3dc5d7a18a66aeae58b93258f0e069a04", "LICENSE": "3235f6ccc2b72375c517c1fdeef87954e8bfda17c5b1b485b98b5c2b4a1026d1", "pairs.json": "18a9918a2a3581a09c584b02aa418c926a613bc1c75d526b6bc9a4ad0cd89021", "presentation.json": "af84662c29628b6e90b923c9541f68f5924563adce397cebbadfdbf0f06e5f18", @@ -198,7 +207,7 @@ "profiles/spine.md": "6bd367c3f4b101878fbc54a3c8c806630b7760173f24fef995db801b6103d92e", "profiles/strand.fixture.json": "7bc2d2dae11c0722b1db987c070b249ddcbc55b81683c4bfa26900c7ffe0fc53", "profiles/strand.md": "2a9bd36814a0de80a68180d2d75d3ef9d2539b9dcd52165f20b8ef0821575488", - "README.md": "e186fda7a396568825d31c2b45bf43657eb4f402bc72fed7c7140b2ede2a8fc3", + "README.md": "a396419a8556d7b343a43742bb411e082413a6f9ae93462dd1d9740001c8d120", "schema/ability.yaml": "af185b2d22a5985ac323e6227a95df287fffaae0e5fca502976a02c2754f71b2", "schema/base_properties.yaml": "ec3724ceb2faca973e431a2e2ff946e55bfb55b6b8d78689b6b22d0cfb7c9a2e", "schema/character.yaml": "dc291b206121bd23c69cb89e01a0523eb2f71b4a247116dd6a1fa4bc227ff145", @@ -225,10 +234,10 @@ "schema/zone.yaml": "cca04ee498fb813fa18b96f1ac99816e7f1a8ae1fb9e21c48b37620dbb674856", "schema.json": "581dc7b5e890acc06b1c89b0d7bdcc2f20f54f52d5a3b4af8c5a184e1e6fd48c", "SECURITY.md": "939ee364b06f0b749bdd4cbe66b2fe49322c95abe732650ec4ef062a0c03820a", - "VERSION": "c8b12547293e2ef371d2e669607c8beef4ad4760116d921aa8644faa7770bc2b", + "VERSION": "8fc2b957179cd0ccdc2cda9f3f51187091764c1a8d556d28083a0ac987923603", "views.fixture.json": "f9a2713b26639d1cb2c792b9f28f95c57e576f8e6c123b5ad3eac2a2507dfcf8", "views.json": "f4d06ee16bd6c66fc28cf27146b8d199c85164e5deecabafc23af53408746fe0", - "walk/lint_folder.py": "2c456cb917d692e3199f87bc6f7918bb20b91d6943d33feb0db0ac99519e1e87", + "walk/lint_folder.py": "ddd7d28e7fbc5e8fb4494c2b2eda23daefc1b3708840a93b6cdffe12a3af88bd", "walk/rulings.yaml": "1fb87ce4012d160b809e0aac50688c62405d2a5e6e303a57df84b98c249374ca", "walk/schema_walk.py": "e4a490dda5133e3961252cd8675eb39e5b214df68f6a661fa8601ccd69e6aed0" } diff --git a/codegen/schema-dist/README.md b/codegen/schema-dist/README.md index 0ba6a01..35bd9ba 100644 --- a/codegen/schema-dist/README.md +++ b/codegen/schema-dist/README.md @@ -21,7 +21,7 @@ Each serial (one numbered publication of these files, tagged `v- | `walk/schema_walk.py` | the reference decoder, in Python: reads the YAML and returns each type's fields. `schema.json` is its output. One module; its only dependency is PyYAML | | `walk/rulings.yaml` | rulings the YAML cannot carry (nullability, empty strings, extension fields). Code in any language should follow these rows | | `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): 111 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 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/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 | | `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 +47,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.24 (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.25 (the spec's own version line); a folder stamps `format_version` from it. + +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). ## Using the walk (Python) @@ -77,7 +79,7 @@ Pass a `note` sink. A field type the walk does not know is skipped, and with the python walk/lint_folder.py path/to/world-folder ``` -One line per problem (`elements/creature/x.json: `characters` is not a field of creature`), then the count of the element files it checked, a file not read not among them. A file is not read when the Python running the check cannot hold its JSON (nested too deep, or a number too long for it): it gets one line saying so, and the check goes on. A link to an element in a file not read is still reported as not in the folder. Exit 0 when clean, 1 with problems, 2 when the path is not a world folder, 3 when nothing it read has a problem and some files were not read; which files go unread can change with the Python running it. Server keys, the folder format's own keys (`local_updated_at`, `server_updated_at`, `image_media_id`) and extension prefixes pass; any other undeclared key does not. A string may be null on disk (read as the unset string). It decodes the YAML through the walk beside it, so its view of the schema is the walk's; `--schema DIR` points it at another copy. +One line per problem (`elements/creature/x.json: `characters` is not a field of creature`), then the count of the element files it checked, a file not read not among them. An element file is not read when an object or array in it sits more than 200 levels deep, counted as under "The example world" (its line says `too_deep`), and a file, `world.json` among them, when it holds a number too long for the Python running the check: it gets one line saying so, and the check goes on. A `world.json` that deep is a problem, in the same words. A link to an element in a file not read is still reported as not in the folder. Exit 0 when clean, 1 with problems, 2 when the path is not a world folder, 3 when nothing it read has a problem and some files were not read; which files go unread for a long number can change with the Python running it, and which go unread for depth cannot. Server keys, the folder format's own keys (`local_updated_at`, `server_updated_at`, `image_media_id`) and extension prefixes pass; any other undeclared key does not. A string may be null on disk (read as the unset string). It decodes the YAML through the walk beside it, so its view of the schema is the walk's; `--schema DIR` points it at another copy. ## Versions diff --git a/codegen/schema-dist/VERSION b/codegen/schema-dist/VERSION index 7406ea1..3ab2a7b 100644 --- a/codegen/schema-dist/VERSION +++ b/codegen/schema-dist/VERSION @@ -1,3 +1,3 @@ canonical: 00.34.01 -serial: 147 -published: 2026-11-25 +serial: 148 +published: 2026-11-26 diff --git a/codegen/schema-dist/fixtures/owworld/fail-OW-25-world-json-too-deep.owworld b/codegen/schema-dist/fixtures/owworld/fail-OW-25-world-json-too-deep.owworld new file mode 100644 index 0000000..78ec2d4 Binary files /dev/null and b/codegen/schema-dist/fixtures/owworld/fail-OW-25-world-json-too-deep.owworld differ diff --git a/codegen/schema-dist/fixtures/owworld/generate.py b/codegen/schema-dist/fixtures/owworld/generate.py index fac8549..de9fada 100644 --- a/codegen/schema-dist/fixtures/owworld/generate.py +++ b/codegen/schema-dist/fixtures/owworld/generate.py @@ -1015,6 +1015,94 @@ def hidden_world(drop=()): "elements and no Pin. What a reader says about a folder it does not read is its own. A copy carries " "the file as written; a share leaves it out as unread. No side: the writer verdict is a copy's.") + # -- OW-25: an element file nested more than 200 deep is not read, too_deep (ruled 2026-11-25) -- + # Depth counts objects and arrays both, the file's top object at 1; a file is not read when any object or array + # sits past 200, and a plain value inside the 200th is read. Both cases nest an object and an array in turn under + # one x_ key, so a reader that counts only objects reads the 201 file and fails; `left_out` names what a reader + # leaves out of the world it reads, by reason. + def nested_element(n, name, depth): + value = 1 + for level in range(depth, 1, -1): # levels depth..2 under the element's own object, level 1 + value = {"a": value} if level % 2 else [value] + return element(n, name, x_depth=value) + + deep_file = "elements/character/deep--0000ab0e.json" + add("pass-OW-25-depth-200-read.owworld", build_zip(base(extra=[(deep_file, nested_element(0xe, "The Deep", 200))])), + test="OW-25", left_out={"too_deep": []}, + rule="A Character whose x_depth nests an array and an object in turn so its deepest one sits at 200, the " + "element's own object at 1, a plain value inside it: read whole. The world read holds the base's three " + "elements and this one, nothing cut or flattened.") + add("pass-OW-25-depth-201-left-out.owworld", build_zip(base(extra=[(deep_file, nested_element(0xe, "The Deep", 201))])), + test="OW-25", left_out={"too_deep": [deep_file]}, + rule="The same Character one level deeper, its deepest array or object at 201: the file is not read, reason " + "too_deep, and is named among the files the reader left out; the world is accepted and holds the base's " + "three elements. A reader that counts only objects reads it and fails. A writer may emit it: only a " + "reader leaves it out.") + + # The rulings of 2026-11-25: the count is made in the file's text as each + # object or array opens, so every value of a repeated key counts; an empty object or array at 201 is past; the + # world's own file is counted the same way. No case carries a second fault. + dup = nested_element(0xe, "The Deep", 201) + assert dup.endswith(b"\n}\n") + dup = dup[:-3] + b',\n "x_depth": 1\n}\n' # the same key again, plain: a parser keeps this one, the text count does not + add("pass-OW-25-dup-key-deep-first-left-out.owworld", build_zip(base(extra=[(deep_file, dup)])), + test="OW-25", left_out={"too_deep": [deep_file]}, + rule="The 201 Character with its x_depth key given twice, the deep value first and a plain 1 after it: the " + "count is made in the file's text as each object or array opens, so every value of a repeated key " + "counts and the file is not read, too_deep. A reader that parses first keeps the last value, depth 1, " + "reads it and fails.") + last = nested_element(0xe, "The Deep", 201) + assert last.count(b'\n "x_depth": [') == 1 + last = last.replace(b'\n "x_depth": [', b'\n "x_depth": 1,\n "x_depth": [') # plain first, deep last + add("pass-OW-25-dup-key-deep-last-left-out.owworld", build_zip(base(extra=[(deep_file, last)])), + test="OW-25", left_out={"too_deep": [deep_file]}, + rule="The 201 Character with its x_depth key given twice, a plain 1 first and the deep value last: every " + "value of a repeated key counts, so the file is not read, too_deep. A reader that parses first and " + "keeps the first value reads it and fails.") + + # Counted in the text means counted outside strings: brackets inside a string are no level, and a string's end is + # found past its escapes, an escaped backslash included. + in_string = "[{" * 100 # 200 brackets: a counter blind to strings reaches 201 + add("pass-OW-25-brackets-in-string-read.owworld", + build_zip(base(extra=[(deep_file, element(0xe, "The Deep", x_note=in_string))])), + test="OW-25", left_out={"too_deep": []}, + rule="A Character whose x_note is a string of 200 brackets, [ and { in turn, and nothing nested: a bracket " + "inside a string opens no object or array, so the file is at 1 and read whole. A reader that counts " + "brackets without knowing strings leaves it out and fails.") + escaped = element(0xe, "The Deep", x_note="C:\\", x_depth=0) + assert escaped.count(b'"C:\\\\"') == 1 and escaped.count(b'"x_depth": 0') == 1 + deep_value = nested_element(0xe, "The Deep", 201).split(b'"x_depth": ', 1)[1].rsplit(b"\n}", 1)[0] + escaped = escaped.replace(b'"x_depth": 0', b'"x_depth": ' + deep_value) + add("pass-OW-25-escaped-backslash-then-deep-left-out.owworld", build_zip(base(extra=[(deep_file, escaped)])), + test="OW-25", left_out={"too_deep": [deep_file]}, + rule="A Character whose x_note ends in an escaped backslash (C:\\ as a value), then x_depth nested to 201: " + "the string ends at its quote, so the levels after it count and the file is not read, too_deep. A " + "reader that takes a quote after a backslash as escaped stays inside the string, reads the file and " + "fails.") + + def empty_at(depth, empty): + value = empty + for level in range(depth - 1, 1, -1): # the empty one at `depth`, then levels depth-1..2 around it + value = {"a": value} if level % 2 else [value] + return element(0xe, "The Deep", x_depth=value) + + for slug, empty, what in [("array", [], "an empty array"), ("object", {}, "an empty object")]: + add("pass-OW-25-empty-%s-at-201-left-out.owworld" % slug, + build_zip(base(extra=[(deep_file, empty_at(201, empty))])), + test="OW-25", left_out={"too_deep": [deep_file]}, + rule="A Character whose deepest container is %s at 201, nothing inside it: an object or array past 200 " + "is past whether or not it holds anything, so the file is not read, too_deep." % what) + + world_value = 1 + for level in range(201, 1, -1): # world.json's own object at 1 + world_value = {"a": world_value} if level % 2 else [world_value] + add("fail-OW-25-world-json-too-deep.owworld", world_with(dict(WORLD, x_depth=world_value)), test="OW-25", + reader="refuse", reason="not_a_world", + rule="world.json nested past 200, an object or array at 201, its own object at 1: counted as an element file " + "is, it is a world.json the reader cannot read, so the world is refused as fail-OW-3-unparseable is, " + "not a world. A writer refuses it for the same reason: it emits no world whose world.json a reader " + "cannot read.") + return F @@ -1041,7 +1129,8 @@ def hidden_world(drop=()): ] # Spec 4.7 (line 229): the TypeScript reader's six (world-file.ts, as that reader names them) plus six, and 4.8's -# name_case (2026-11-25: one fixed name alone in another case). +# name_case (2026-11-25: one fixed name alone in another case). The words for a refused archive only: OW-25's +# too_deep names an element file left out, and a world.json past 200 is refused as not_a_world (ruled 2026-11-25). READER_REASONS = ["unsafe_path", "too_big", "too_many", "not_a_world", "more_than_one", "not_openable", "duplicate", "collision", "link", "method", "name", "marker", "name_case"] @@ -1053,7 +1142,8 @@ def verdicts_doc(entries): "generated_by": "generate.py", "spec": "folder format spec section 4.7, the archive (drafted 2026-10-22), on 0.3.12; tests OW-1..OW-22; " "OW-23, the share, section 4.8 (ruled 2026-11-23); OW-24, which folders under spatial/ a reader serves, " - "section 4.8 (ruled 2026-11-25)", + "section 4.8 (ruled 2026-11-25); OW-25, an element file nested past 200 not read " + "(ruled 2026-11-25)", "notes": [ "reader: what a reader does with the file (accept, or refuse with `reason`). Every reader runner checks " "this field.", @@ -1088,6 +1178,10 @@ def verdicts_doc(entries): "left_out: on the share side a writer emits, the two sets of paths its report names, inside the world: " "`hidden` and, counted apart, `unread`. A writer runner compares its own report with it; the shape of " "each writer's report stays its own.", + "left_out on a reader case (OW-25): the element files a reader leaves out of the world it reads, by " + "reason, inside the world (`too_deep`: any object or array past 200, the file's top object at 1); an " + "empty list says the reader leaves none out for that reason. A reader runner compares the files it " + "left out with it; the world is accepted either way.", ], "reasons": READER_REASONS, "floor": {"entries": FLOOR_ENTRIES, "bytes": FLOOR_BYTES}, diff --git a/codegen/schema-dist/fixtures/owworld/pass-OW-25-brackets-in-string-read.owworld b/codegen/schema-dist/fixtures/owworld/pass-OW-25-brackets-in-string-read.owworld new file mode 100644 index 0000000..571320f Binary files /dev/null and b/codegen/schema-dist/fixtures/owworld/pass-OW-25-brackets-in-string-read.owworld differ diff --git a/codegen/schema-dist/fixtures/owworld/pass-OW-25-depth-200-read.owworld b/codegen/schema-dist/fixtures/owworld/pass-OW-25-depth-200-read.owworld new file mode 100644 index 0000000..440e5e6 Binary files /dev/null and b/codegen/schema-dist/fixtures/owworld/pass-OW-25-depth-200-read.owworld differ diff --git a/codegen/schema-dist/fixtures/owworld/pass-OW-25-depth-201-left-out.owworld b/codegen/schema-dist/fixtures/owworld/pass-OW-25-depth-201-left-out.owworld new file mode 100644 index 0000000..484944e Binary files /dev/null and b/codegen/schema-dist/fixtures/owworld/pass-OW-25-depth-201-left-out.owworld differ diff --git a/codegen/schema-dist/fixtures/owworld/pass-OW-25-dup-key-deep-first-left-out.owworld b/codegen/schema-dist/fixtures/owworld/pass-OW-25-dup-key-deep-first-left-out.owworld new file mode 100644 index 0000000..17ed6b2 Binary files /dev/null and b/codegen/schema-dist/fixtures/owworld/pass-OW-25-dup-key-deep-first-left-out.owworld differ diff --git a/codegen/schema-dist/fixtures/owworld/pass-OW-25-dup-key-deep-last-left-out.owworld b/codegen/schema-dist/fixtures/owworld/pass-OW-25-dup-key-deep-last-left-out.owworld new file mode 100644 index 0000000..d894614 Binary files /dev/null and b/codegen/schema-dist/fixtures/owworld/pass-OW-25-dup-key-deep-last-left-out.owworld differ diff --git a/codegen/schema-dist/fixtures/owworld/pass-OW-25-empty-array-at-201-left-out.owworld b/codegen/schema-dist/fixtures/owworld/pass-OW-25-empty-array-at-201-left-out.owworld new file mode 100644 index 0000000..968f8e9 Binary files /dev/null and b/codegen/schema-dist/fixtures/owworld/pass-OW-25-empty-array-at-201-left-out.owworld differ diff --git a/codegen/schema-dist/fixtures/owworld/pass-OW-25-empty-object-at-201-left-out.owworld b/codegen/schema-dist/fixtures/owworld/pass-OW-25-empty-object-at-201-left-out.owworld new file mode 100644 index 0000000..5f9d608 Binary files /dev/null and b/codegen/schema-dist/fixtures/owworld/pass-OW-25-empty-object-at-201-left-out.owworld differ diff --git a/codegen/schema-dist/fixtures/owworld/pass-OW-25-escaped-backslash-then-deep-left-out.owworld b/codegen/schema-dist/fixtures/owworld/pass-OW-25-escaped-backslash-then-deep-left-out.owworld new file mode 100644 index 0000000..f16de98 Binary files /dev/null and b/codegen/schema-dist/fixtures/owworld/pass-OW-25-escaped-backslash-then-deep-left-out.owworld differ diff --git a/codegen/schema-dist/fixtures/owworld/verdicts.json b/codegen/schema-dist/fixtures/owworld/verdicts.json index b2f3a77..433b3f5 100644 --- a/codegen/schema-dist/fixtures/owworld/verdicts.json +++ b/codegen/schema-dist/fixtures/owworld/verdicts.json @@ -1,7 +1,7 @@ { "set": "owworld-conformance", "generated_by": "generate.py", - "spec": "folder format spec section 4.7, the archive (drafted 2026-10-22), on 0.3.12; tests OW-1..OW-22; OW-23, the share, section 4.8 (ruled 2026-11-23); OW-24, which folders under spatial/ a reader serves, section 4.8 (ruled 2026-11-25)", + "spec": "folder format spec section 4.7, the archive (drafted 2026-10-22), on 0.3.12; tests OW-1..OW-22; OW-23, the share, section 4.8 (ruled 2026-11-23); OW-24, which folders under spatial/ a reader serves, section 4.8 (ruled 2026-11-25); OW-25, an element file nested past 200 not read (ruled 2026-11-25)", "notes": [ "reader: what a reader does with the file (accept, or refuse with `reason`). Every reader runner checks this field.", "writer: whether the file is one a conforming writer may emit as a portable .owworld, checked against `source` (every source file present byte-exact) and the writer's MUST rules (only the folder's parts, a marker only in its shape, no api, 1980 stamps, UTF-8 byte order, methods 0 and 8). A SHOULD never makes it refuse; `should` names one a fixture breaks. Only a reference checker checks it; the role says which side the test is about.", @@ -13,7 +13,8 @@ "source: a fixture's writer verdict is checked against `source` unless it names one of `sources` (the private case's world, OW-8). A source's `private` lists producers marked private in its RECORDS.json (section 4.5 rule 11): each one's directory is present whole and byte-exact, or absent whole; the manifest itself travels byte-exact either way.", "side: on the private case, which side of the export the file is: `default` (private records left out) or `asked` (the caller asked for them). Both are files a conforming writer emits; which one depends on the call, not the bytes.", "side, on the share case (OW-23, section 4.8, source `hidden`): `share` (includeHidden false) or `copy` (the default). A source's `hidden` and `unread` are the two sets of paths a share leaves out whole: the hidden ones for their mark, the unread ones because the folder reader would not serve them as an element (it could not read them, or they are no element file) or a second file holds the same id. On a `share` side each is absent; on a `copy` side each is present byte-exact.", - "left_out: on the share side a writer emits, the two sets of paths its report names, inside the world: `hidden` and, counted apart, `unread`. A writer runner compares its own report with it; the shape of each writer's report stays its own." + "left_out: on the share side a writer emits, the two sets of paths its report names, inside the world: `hidden` and, counted apart, `unread`. A writer runner compares its own report with it; the shape of each writer's report stays its own.", + "left_out on a reader case (OW-25): the element files a reader leaves out of the world it reads, by reason, inside the world (`too_deep`: any object or array past 200, the file's top object at 1); an empty list says the reader leaves none out for that reason. A reader runner compares the files it left out with it; the world is accepted either way." ], "reasons": [ "unsafe_path", @@ -1345,6 +1346,133 @@ "sha256": "51e50436e02ccd8bd2978380fb64ea5688da32ee7fc697fc7adb480ab39e5be1", "bytes": 2649 }, + { + "file": "pass-OW-25-depth-200-read.owworld", + "test": "OW-25", + "role": "reader", + "reader": "accept", + "writer": "accept", + "rule": "A Character whose x_depth nests an array and an object in turn so its deepest one sits at 200, the element's own object at 1, a plain value inside it: read whole. The world read holds the base's three elements and this one, nothing cut or flattened.", + "left_out": { + "too_deep": [] + }, + "sha256": "faabbd23cbcd4bf4502ef10b438e36566f97e43244e9d2f91b7e6d0986b99c5d", + "bytes": 83968 + }, + { + "file": "pass-OW-25-depth-201-left-out.owworld", + "test": "OW-25", + "role": "reader", + "reader": "accept", + "writer": "accept", + "rule": "The same Character one level deeper, its deepest array or object at 201: the file is not read, reason too_deep, and is named among the files the reader left out; the world is accepted and holds the base's three elements. A reader that counts only objects reads it and fails. A writer may emit it: only a reader leaves it out.", + "left_out": { + "too_deep": [ + "elements/character/deep--0000ab0e.json" + ] + }, + "sha256": "a5dffe6d0f68f5ab277176b330388030fed7210c69422a5ecbd340fe5d53f6a4", + "bytes": 84779 + }, + { + "file": "pass-OW-25-dup-key-deep-first-left-out.owworld", + "test": "OW-25", + "role": "reader", + "reader": "accept", + "writer": "accept", + "rule": "The 201 Character with its x_depth key given twice, the deep value first and a plain 1 after it: the count is made in the file's text as each object or array opens, so every value of a repeated key counts and the file is not read, too_deep. A reader that parses first keeps the last value, depth 1, reads it and fails.", + "left_out": { + "too_deep": [ + "elements/character/deep--0000ab0e.json" + ] + }, + "sha256": "9784b98f18dd4e855e81b5b35d26d8aeade6b96b0ffab5cf1178f3b6f8cb42fd", + "bytes": 84795 + }, + { + "file": "pass-OW-25-dup-key-deep-last-left-out.owworld", + "test": "OW-25", + "role": "reader", + "reader": "accept", + "writer": "accept", + "rule": "The 201 Character with its x_depth key given twice, a plain 1 first and the deep value last: every value of a repeated key counts, so the file is not read, too_deep. A reader that parses first and keeps the first value reads it and fails.", + "left_out": { + "too_deep": [ + "elements/character/deep--0000ab0e.json" + ] + }, + "sha256": "683857a8d8d073f1613b90438d356d9095292a6af03fc72daa4c4649a41105bb", + "bytes": 84795 + }, + { + "file": "pass-OW-25-brackets-in-string-read.owworld", + "test": "OW-25", + "role": "reader", + "reader": "accept", + "writer": "accept", + "rule": "A Character whose x_note is a string of 200 brackets, [ and { in turn, and nothing nested: a bracket inside a string opens no object or array, so the file is at 1 and read whole. A reader that counts brackets without knowing strings leaves it out and fails.", + "left_out": { + "too_deep": [] + }, + "sha256": "1869a10b261c7d605389358cbd198a7ded58080a57763adc0814fba95e972369", + "bytes": 2879 + }, + { + "file": "pass-OW-25-escaped-backslash-then-deep-left-out.owworld", + "test": "OW-25", + "role": "reader", + "reader": "accept", + "writer": "accept", + "rule": "A Character whose x_note ends in an escaped backslash (C:\\ as a value), then x_depth nested to 201: the string ends at its quote, so the levels after it count and the file is not read, too_deep. A reader that takes a quote after a backslash as escaped stays inside the string, reads the file and fails.", + "left_out": { + "too_deep": [ + "elements/character/deep--0000ab0e.json" + ] + }, + "sha256": "f0f2edf04efc91e36d75fd09b427b4392db2bb2840f93390fd78aa08204ef138", + "bytes": 84799 + }, + { + "file": "pass-OW-25-empty-array-at-201-left-out.owworld", + "test": "OW-25", + "role": "reader", + "reader": "accept", + "writer": "accept", + "rule": "A Character whose deepest container is an empty array at 201, nothing inside it: an object or array past 200 is past whether or not it holds anything, so the file is not read, too_deep.", + "left_out": { + "too_deep": [ + "elements/character/deep--0000ab0e.json" + ] + }, + "sha256": "7d2c9d67ac769610b7ccccd8b0f140b6caec9f0fabd9601b881941b3949a4136", + "bytes": 83969 + }, + { + "file": "pass-OW-25-empty-object-at-201-left-out.owworld", + "test": "OW-25", + "role": "reader", + "reader": "accept", + "writer": "accept", + "rule": "A Character whose deepest container is an empty object at 201, nothing inside it: an object or array past 200 is past whether or not it holds anything, so the file is not read, too_deep.", + "left_out": { + "too_deep": [ + "elements/character/deep--0000ab0e.json" + ] + }, + "sha256": "def2a965df80ef83e3913accfd18306bc418bda27569ac314e38d8509143d6f8", + "bytes": 83969 + }, + { + "file": "fail-OW-25-world-json-too-deep.owworld", + "test": "OW-25", + "role": "reader", + "reader": "refuse", + "writer": "refuse", + "rule": "world.json nested past 200, an object or array at 201, its own object at 1: counted as an element file is, it is a world.json the reader cannot read, so the world is refused as fail-OW-3-unparseable is, not a world. A writer refuses it for the same reason: it emits no world whose world.json a reader cannot read.", + "reason": "not_a_world", + "sha256": "cf8aae17d3080df240b06c89f58e84078c7fab26d6d3438fc9e16c3ab463f8a4", + "bytes": 84540 + }, { "file": "fail-OW-14-count.owworld", "test": "OW-14", diff --git a/codegen/schema-dist/walk/lint_folder.py b/codegen/schema-dist/walk/lint_folder.py index 15db2e1..e97d61a 100644 --- a/codegen/schema-dist/walk/lint_folder.py +++ b/codegen/schema-dist/walk/lint_folder.py @@ -28,14 +28,16 @@ (`x_spine_depends_on`, `x_lens_leads_to`: the lens profile's closed table), that names one element more than once gets one warning line per element, with how many times, never a problem (each names each element once; a reader reads a repeat once, in its first place); -entries are compared as written, so `[a, A]` is no repeat. A `world.json` or an element -file whose JSON this Python cannot hold (nested deeper than its parser goes, or a number -longer than it converts) gets one line saying it was not read, and the check goes on: -a third verdict beside clean and a problem, since a newer Python on another system may read -the same file. The last line is the count it checked, so an empty -report is a result and not a silence. Exit 0 clean, 1 with problems, 2 when -the folder is not a world folder, 3 when nothing it read has a problem but a file was not -read. +entries are compared as written, so `[a, A]` is no repeat. An element file in which an +object or array sits more than 200 levels deep (objects and arrays both count, the file's +top object at 1) is not read, and its line says so with the reason `too_deep`; a `world.json` +that deep is a problem in the same words, as one that does not parse is. The check counts +the depth in the text itself, so the verdict is the same on every Python. A file with a number longer than this Python converts is not read either, and +a newer Python on another system may read it. Either way the file gets one line saying it was +not read, and the check goes on: a third verdict beside clean and a problem. The last line is +the count it checked, so an empty report is a result and not a silence. Exit 0 clean, 1 +with problems, 2 when the folder is not a world folder, 3 when nothing it read has a problem +but a file was not read. The same function gates the published example world (publish_dist.py), so the check a stranger runs is the check the dist itself passed. Decoding goes @@ -57,7 +59,9 @@ # 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.24 +# publish_dist.py writes the dist README's version sentence from it. 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 # list that names one element twice reads it once, in its first place, a writer served # one writes it back as served, and a writer that builds a list builds it with each @@ -66,7 +70,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.24" +FORMAT_VERSION = "0.3.25" # Keys an element body carries that the schema does not declare: the type # slug and the server-managed fields (elements/serialize.py READONLY_FIELDS @@ -118,7 +122,7 @@ class Report: def __init__(self) -> None: self.problems: list[str] = [] self.warnings: list[str] = [] # printed, never counted: the exit code is the problems' - # Files this Python could not parse (serial 146): neither clean nor a problem. + # Files not read (serial 146; depth by the count, serial 148): neither clean nor a problem. self.unread: list[str] = [] self.files = 0 self.types: set[str] = set() @@ -143,22 +147,71 @@ def is_uuid(value) -> bool: return True -# A file whose JSON the Python running the check cannot hold is neither an element nor a -# problem: another Python may read it (serial 146). Two causes: nested deeper than its parser -# goes (RecursionError, which is no ValueError), or a number longer than it converts (a bare -# ValueError, which is no JSONDecodeError). A file that is not JSON or not UTF-8 is a problem. -NOT_READ = ("not read: the Python running this check cannot hold its JSON (nested too deep, " - "or a number too long for it), so nothing is said about it here") +# A file that is not read is neither an element nor a problem (serial 146). Two causes, each +# with its own words. Depth (serial 148): an object or array more than MAX_DEPTH levels deep, +# objects and arrays both counted and the file's top object at 1, counted in the text before +# any parse, so the verdict is the number's and never this Python's. A number longer than this +# Python converts (a bare ValueError, which is no JSONDecodeError): another Python may read it. +# A file that is not JSON or not UTF-8 is a problem. +MAX_DEPTH = 200 +TOO_DEEP = ("not read, too_deep: an object or array in it sits more than 200 levels deep " + "(its top object at 1), so nothing is said about it here") +NOT_READ = ("not read: the Python running this check cannot hold a number in it (a number too " + "long for it), so nothing is said about it here") + + +def _too_deep(text: str) -> bool: + """Whether any object or array in `text` sits past MAX_DEPTH, the top one at 1. One pass + over the characters, with no recursion: a bracket inside a string is not counted, and a + backslash in a string takes the character after it, so an escaped quote does not end the + string.""" + depth = 0 + in_string = escaped = False + for c in text: + if in_string: + if escaped: + escaped = False + elif c == "\\": + escaped = True + elif c == '"': + in_string = False + elif c == '"': + in_string = True + elif c in "[{": + depth += 1 + if depth > MAX_DEPTH: + return True + elif c in "]}": + depth -= 1 + return False + + +def _parse(text: str) -> object: + """json.loads with room for MAX_DEPTH levels above wherever the recursion limit was set: a + decoder written in Python spends frames on each level, and a limit set low must not turn a + file of 200 levels into one not read. The limit is put back after.""" + limit = sys.getrecursionlimit() + sys.setrecursionlimit(limit + 4 * MAX_DEPTH) + try: + return json.loads(text) + finally: + sys.setrecursionlimit(limit) def _load(path: Path) -> tuple[str, object]: """Read one JSON file: ("ok", value), ("problem", the line's words) or ("unread", the line's words).""" try: - return "ok", json.loads(path.read_text(encoding="utf-8")) - except (json.JSONDecodeError, UnicodeDecodeError) as e: + text = path.read_text(encoding="utf-8") + except UnicodeDecodeError as e: + return "problem", f"not JSON ({e})" + if _too_deep(text): + return "unread", TOO_DEEP + try: + return "ok", _parse(text) + except json.JSONDecodeError as e: return "problem", f"not JSON ({e})" - except (ValueError, RecursionError): + except ValueError: return "unread", NOT_READ @@ -226,6 +279,11 @@ def lint_folder(src: Path, decoded: dict) -> Report: if kind == "problem": report.add(f"world.json: {world}") world = {} + elif kind == "unread" and world == TOO_DEEP: + # Serial 148: a world.json past 200 is one the check cannot read, as one that does not + # parse, so it is a problem, in the words an element file's line uses. + report.add(f"world.json: {world}") + world = {} elif kind == "unread": report.unread.append(f"world.json: {world}") world = {} diff --git a/codegen/schema-pin.json b/codegen/schema-pin.json index 0e7de68..4e30f0a 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.147", - "commit": "9d7fb973fd4842c68c7d39111003b7f3dbcfc9a1", - "manifest_sha256": "beaa7093c2ae47b4f47afd8ce3672223f72015f3d014f7a890af5ebb15fecc8f", + "tag": "v0.34.1-dist.148", + "commit": "93e7232e2814579947720e17b008377b802e67f9", + "manifest_sha256": "4cbe4d923e47d9f1899d9a3f865d3b0169dede546921dfc89557bce215577c1a", "canonical_version": "00.34.01", - "dist_serial": 147, - "published": "2026-11-25", - "pinned_at": "2026-11-25", - "pinned_by": "The maintainer: tree from `git archive` of the tag in a schema-dist checkout (232 files: the 231 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": 148, + "published": "2026-11-26", + "pinned_at": "2026-11-26", + "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.", "previous_pins": [ + { + "tag": "v0.34.1-dist.147", + "manifest_sha256": "beaa7093c2ae47b4f47afd8ce3672223f72015f3d014f7a890af5ebb15fecc8f", + "note": "superseded by v0.34.1-dist.148 (an element file past 200 levels is too_deep, counted in the text; world.json the same; folder format 0.3.25; 120 owworld archives)" + }, { "tag": "v0.34.1-dist.146", "manifest_sha256": "1d948463a5e8c13026ac069dd4ae91c22ba3f5fc4ba81508a7d08a600638f367", diff --git a/src/onlyworlds/__init__.py b/src/onlyworlds/__init__.py index 7de3aa2..d4018cf 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.24 (``FORMAT_VERSION``). Schema: generated from the pinned +Folder format: v0.3.25 (``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/_outside_json.py b/src/onlyworlds/_outside_json.py index da4e21a..64e28a7 100644 --- a/src/onlyworlds/_outside_json.py +++ b/src/onlyworlds/_outside_json.py @@ -22,7 +22,9 @@ import json import math +import re import sys +from itertools import accumulate from typing import Any #: The deepest nesting read: a value at the top is depth 0, an object or array there depth 1, what it holds @@ -50,21 +52,26 @@ def _int(text: str) -> int: return int(text) -def _too_deep(value: Any) -> bool: - """Whether any object or array sits deeper than ``MAX_DEPTH``. A loop with its own stack, never recursion.""" - stack: list[tuple[Any, int]] = [(value, 1)] - while stack: - item, depth = stack.pop() - if isinstance(item, dict): - children: Any = item.values() - elif isinstance(item, list): - children = item - else: - continue - if depth > MAX_DEPTH: - return True - stack.extend((child, depth + 1) for child in children if isinstance(child, (dict, list))) - return False +#: A whole JSON string: a backslash escapes the character after it. +_STRING = re.compile(r'"[^"\\]*(?:\\.[^"\\]*)*"', re.DOTALL) +_BRACKET = re.compile(r"[\[\]{}]") +_STEP = {"[": 1, "{": 1, "]": -1, "}": -1} + + +def _text_too_deep(text: str) -> bool: + """Whether the text opens an object or array deeper than ``MAX_DEPTH``, counted in the text itself as each + one opens, before any parse (the folder format's rule since serial 148): so each value of a repeated key + counts, and a text past the line is too deep whatever else is wrong with it. Brackets inside a string are + not counted; a string left open runs to the end of the text, as the npm SDK's scan reads it.""" + outside = _STRING.sub("", text) + open_quote = outside.find('"') + if open_quote >= 0: + outside = outside[:open_quote] + brackets = "".join(_BRACKET.findall(outside)) + # No text can open more levels than it has opening brackets. + if brackets.count("[") + brackets.count("{") <= MAX_DEPTH: + return False + return max(accumulate(_STEP[b] for b in brackets)) > MAX_DEPTH def loads(text: str, **kwargs: Any) -> Any: @@ -72,10 +79,10 @@ def loads(text: str, **kwargs: Any) -> Any: kwargs.setdefault("parse_int", _int) kwargs.setdefault("parse_float", _float) kwargs.setdefault("parse_constant", _constant) + if _text_too_deep(text): + raise ValueError(_TOO_DEEP) try: value = json.loads(text, **kwargs) except RecursionError: raise ValueError(_TOO_DEEP) from None - if _too_deep(value): - raise ValueError(_TOO_DEEP) return value diff --git a/src/onlyworlds/_schema.py b/src/onlyworlds/_schema.py index 7eac337..9d095f4 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.147 (9d7fb973fd4842c68c7d39111003b7f3dbcfc9a1) +# Source: https://github.com/OnlyWorlds/schema-dist @ v0.34.1-dist.148 (93e7232e2814579947720e17b008377b802e67f9) """Schema provenance, the 22 element types and their fields, from the pinned schema distribution.""" -SCHEMA_DIST_TAG = "v0.34.1-dist.147" +SCHEMA_DIST_TAG = "v0.34.1-dist.148" SCHEMA_VERSION = "00.34.01" -SCHEMA_DIST_SERIAL = 147 -SCHEMA_MANIFEST_SHA256 = "beaa7093c2ae47b4f47afd8ce3672223f72015f3d014f7a890af5ebb15fecc8f" +SCHEMA_DIST_SERIAL = 148 +SCHEMA_MANIFEST_SHA256 = "4cbe4d923e47d9f1899d9a3f865d3b0169dede546921dfc89557bce215577c1a" # Canonical order, as the walk declares it. ELEMENT_TYPES: tuple[str, ...] = ( diff --git a/src/onlyworlds/_version.py b/src/onlyworlds/_version.py index dfd0203..81d2cdc 100644 --- a/src/onlyworlds/_version.py +++ b/src/onlyworlds/_version.py @@ -1 +1 @@ -__version__ = "0.154.1" +__version__ = "0.155.0" diff --git a/src/onlyworlds/_walk/lint_folder.py b/src/onlyworlds/_walk/lint_folder.py index 15db2e1..e97d61a 100644 --- a/src/onlyworlds/_walk/lint_folder.py +++ b/src/onlyworlds/_walk/lint_folder.py @@ -28,14 +28,16 @@ (`x_spine_depends_on`, `x_lens_leads_to`: the lens profile's closed table), that names one element more than once gets one warning line per element, with how many times, never a problem (each names each element once; a reader reads a repeat once, in its first place); -entries are compared as written, so `[a, A]` is no repeat. A `world.json` or an element -file whose JSON this Python cannot hold (nested deeper than its parser goes, or a number -longer than it converts) gets one line saying it was not read, and the check goes on: -a third verdict beside clean and a problem, since a newer Python on another system may read -the same file. The last line is the count it checked, so an empty -report is a result and not a silence. Exit 0 clean, 1 with problems, 2 when -the folder is not a world folder, 3 when nothing it read has a problem but a file was not -read. +entries are compared as written, so `[a, A]` is no repeat. An element file in which an +object or array sits more than 200 levels deep (objects and arrays both count, the file's +top object at 1) is not read, and its line says so with the reason `too_deep`; a `world.json` +that deep is a problem in the same words, as one that does not parse is. The check counts +the depth in the text itself, so the verdict is the same on every Python. A file with a number longer than this Python converts is not read either, and +a newer Python on another system may read it. Either way the file gets one line saying it was +not read, and the check goes on: a third verdict beside clean and a problem. The last line is +the count it checked, so an empty report is a result and not a silence. Exit 0 clean, 1 +with problems, 2 when the folder is not a world folder, 3 when nothing it read has a problem +but a file was not read. The same function gates the published example world (publish_dist.py), so the check a stranger runs is the check the dist itself passed. Decoding goes @@ -57,7 +59,9 @@ # 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.24 +# publish_dist.py writes the dist README's version sentence from it. 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 # list that names one element twice reads it once, in its first place, a writer served # one writes it back as served, and a writer that builds a list builds it with each @@ -66,7 +70,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.24" +FORMAT_VERSION = "0.3.25" # Keys an element body carries that the schema does not declare: the type # slug and the server-managed fields (elements/serialize.py READONLY_FIELDS @@ -118,7 +122,7 @@ class Report: def __init__(self) -> None: self.problems: list[str] = [] self.warnings: list[str] = [] # printed, never counted: the exit code is the problems' - # Files this Python could not parse (serial 146): neither clean nor a problem. + # Files not read (serial 146; depth by the count, serial 148): neither clean nor a problem. self.unread: list[str] = [] self.files = 0 self.types: set[str] = set() @@ -143,22 +147,71 @@ def is_uuid(value) -> bool: return True -# A file whose JSON the Python running the check cannot hold is neither an element nor a -# problem: another Python may read it (serial 146). Two causes: nested deeper than its parser -# goes (RecursionError, which is no ValueError), or a number longer than it converts (a bare -# ValueError, which is no JSONDecodeError). A file that is not JSON or not UTF-8 is a problem. -NOT_READ = ("not read: the Python running this check cannot hold its JSON (nested too deep, " - "or a number too long for it), so nothing is said about it here") +# A file that is not read is neither an element nor a problem (serial 146). Two causes, each +# with its own words. Depth (serial 148): an object or array more than MAX_DEPTH levels deep, +# objects and arrays both counted and the file's top object at 1, counted in the text before +# any parse, so the verdict is the number's and never this Python's. A number longer than this +# Python converts (a bare ValueError, which is no JSONDecodeError): another Python may read it. +# A file that is not JSON or not UTF-8 is a problem. +MAX_DEPTH = 200 +TOO_DEEP = ("not read, too_deep: an object or array in it sits more than 200 levels deep " + "(its top object at 1), so nothing is said about it here") +NOT_READ = ("not read: the Python running this check cannot hold a number in it (a number too " + "long for it), so nothing is said about it here") + + +def _too_deep(text: str) -> bool: + """Whether any object or array in `text` sits past MAX_DEPTH, the top one at 1. One pass + over the characters, with no recursion: a bracket inside a string is not counted, and a + backslash in a string takes the character after it, so an escaped quote does not end the + string.""" + depth = 0 + in_string = escaped = False + for c in text: + if in_string: + if escaped: + escaped = False + elif c == "\\": + escaped = True + elif c == '"': + in_string = False + elif c == '"': + in_string = True + elif c in "[{": + depth += 1 + if depth > MAX_DEPTH: + return True + elif c in "]}": + depth -= 1 + return False + + +def _parse(text: str) -> object: + """json.loads with room for MAX_DEPTH levels above wherever the recursion limit was set: a + decoder written in Python spends frames on each level, and a limit set low must not turn a + file of 200 levels into one not read. The limit is put back after.""" + limit = sys.getrecursionlimit() + sys.setrecursionlimit(limit + 4 * MAX_DEPTH) + try: + return json.loads(text) + finally: + sys.setrecursionlimit(limit) def _load(path: Path) -> tuple[str, object]: """Read one JSON file: ("ok", value), ("problem", the line's words) or ("unread", the line's words).""" try: - return "ok", json.loads(path.read_text(encoding="utf-8")) - except (json.JSONDecodeError, UnicodeDecodeError) as e: + text = path.read_text(encoding="utf-8") + except UnicodeDecodeError as e: + return "problem", f"not JSON ({e})" + if _too_deep(text): + return "unread", TOO_DEEP + try: + return "ok", _parse(text) + except json.JSONDecodeError as e: return "problem", f"not JSON ({e})" - except (ValueError, RecursionError): + except ValueError: return "unread", NOT_READ @@ -226,6 +279,11 @@ def lint_folder(src: Path, decoded: dict) -> Report: if kind == "problem": report.add(f"world.json: {world}") world = {} + elif kind == "unread" and world == TOO_DEEP: + # Serial 148: a world.json past 200 is one the check cannot read, as one that does not + # parse, so it is a problem, in the words an element file's line uses. + report.add(f"world.json: {world}") + world = {} elif kind == "unread": report.unread.append(f"world.json: {world}") world = {} diff --git a/src/onlyworlds/campfire.py b/src/onlyworlds/campfire.py index fff1325..e3e9440 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.24 since 0.126.0). +folder's ``format_version`` is the package's ``FORMAT_VERSION``, 0.3.25 since 0.155.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 228d103..3c76bb2 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.24. +Spec: OnlyWorlds Folder Format v0.3.25. Section numbers below are that document's. :: @@ -64,7 +64,7 @@ ] #: The spec version this module writes and reads against (§4.2 ``format_version``). -FORMAT_VERSION = "0.3.24" +FORMAT_VERSION = "0.3.25" #: §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 diff --git a/src/onlyworlds/push.py b/src/onlyworlds/push.py index bb53b0f..1afdf8f 100644 --- a/src/onlyworlds/push.py +++ b/src/onlyworlds/push.py @@ -114,6 +114,7 @@ "doors", "known_of", "x_served_trimmed", # the message and lens profiles: served only, kept in the file, never sent + "date_labels", # the MCP server's words for a date, served beside the numbers; a write carrying it is 422 "hidden", "local_updated_at", "server_updated_at", diff --git a/tests/test_export.py b/tests/test_export.py index c21705a..d97ee44 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.24" == FORMAT_VERSION + assert w["format_version"] == "0.3.25" == 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_known_of.py b/tests/test_known_of.py index 57a68e8..ad293f2 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.24" + assert FORMAT_VERSION == "0.3.25" def test_is_known_of_only_for_true() -> None: diff --git a/tests/test_outside_json.py b/tests/test_outside_json.py index b02dda4..eddb68d 100644 --- a/tests/test_outside_json.py +++ b/tests/test_outside_json.py @@ -73,6 +73,38 @@ def nest(depth: int, open_: str, close: str) -> str: _outside_json.loads('{"a": ' + nest(200, "[", "]") + "}") +NEST_200 = "[" * 200 + "]" * 200 # as a field's value in an element object, it reaches 201 + + +@pytest.mark.parametrize( + ("text", "deep"), + [ + # Counted in the text as each object or array opens (serial 148): what the parse keeps does not decide it. + ('{"x": ' + NEST_200 + ', "x": 1}', True), + ('{"x": , ' + NEST_200 + "}", True), + ('{"x": ' + "[" * 199 + "{}" + "]" * 199 + "}", True), + ('{"x": ' + json.dumps("[" * 300) + "}", False), + ('{"x": "a\\"' + "{" * 300 + '"}', False), + ('{"x": ["\\\\", ' + "[" * 199 + "]" * 199 + "]}", True), + ('{"x": "open ' + "[" * 300, False), + ], + ids=[ + "a repeated key, its deep value first", + "broken JSON before a part past the line", + "an empty object at 201", + "brackets inside a string", + "an escaped quote, then brackets still inside the string", + "an escaped backslash, then a real bracket at 201", + "a string left open runs to the end", + ], +) +def test_the_depth_is_counted_in_the_text_before_the_parse(text: str, deep: bool) -> None: + assert _outside_json._text_too_deep(text) is deep + if deep: + with pytest.raises(ValueError, match="nested more than 200 deep"): + _outside_json.loads(text) + + def test_text_that_is_not_json_is_still_a_decode_error() -> None: with pytest.raises(json.JSONDecodeError): _outside_json.loads('{"id": ') diff --git a/tests/test_push.py b/tests/test_push.py index 72de3f3..42a595f 100644 --- a/tests/test_push.py +++ b/tests/test_push.py @@ -153,6 +153,22 @@ def test_the_served_trimmed_mark_is_never_sent(tmp_path: Path) -> None: assert [(p.id, p.fields) for p in plan.patches] == [(C2, {"name": "B2"})] +def test_date_labels_are_never_sent(tmp_path: Path) -> None: + """A body copied from the MCP server can carry date_labels, and keel refuses a write that carries it.""" + base, edit = folders( + tmp_path, + {"character": [wire_char(C1, "A"), wire_char(C2, "B")]}, + { + "character": [ + wire_char(C1, "A", date_labels={"birth_date": "Year 3"}), + wire_char(C2, "B2", date_labels={"birth_date": "Year 4"}), + ] + }, + ) + plan = plan_push(base, edit) + assert [(p.id, p.fields) for p in plan.patches] == [(C2, {"name": "B2"})] + + def test_changed_by_and_changed_via_are_never_sent(tmp_path: Path) -> None: """The last write's author and door are read-only like created_by, and every push restamps them.""" base, edit = folders( diff --git a/tests/test_worldfile.py b/tests/test_worldfile.py index c15560d..ceac429 100644 --- a/tests/test_worldfile.py +++ b/tests/test_worldfile.py @@ -132,7 +132,7 @@ def test_the_owworld_fixture_set_every_verdict_and_every_cause(tmp_path: Path) - print(f" disagrees: {d}") assert diffs == [] # After the verdicts, so a red count never hides a disagreeing fixture. - assert run == len(on_disk) == 111, f"the set holds {run} fixtures" # serial 147: two OW-18 fold cases + assert run == len(on_disk) == 120, f"the set holds {run} fixtures" # serial 148: nine OW-25 depth cases # Serial 58's three cases (ruled 2026-10-24), named on their own: the deflate stream read to its