diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f097c2..cdf1db4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ The package version runs on its own semver; the schema it is generated from is ` ## Unreleased +## 0.157.0 (2026-11-27) + +- **The Kanka door reads Kanka 4.0's exports.** A Character whose `entity.status_id` is 3, the `dead` row of the character statuses every Kanka campaign shares, gets `[Deceased] ` before `physicality`, as `is_dead` does; neither the 3.15 nor the 4.0 export writes `is_dead`. A campaign's own statuses are not in the export, so only the shared one reads as dead, and a `status_id` that is set is still kept as `x_kanka_status_id`. A family's `pivotMembers`, where 4.0 lists its people, is kept as `x_kanka_pivot_members` with its reason in the report, on any module. Races and families now read as proven on a real export, and the report names an export version other than 3.15 or 4.0. Exports of 3.15 come out as before. +- `tests/fixtures/kanka/kanka-4-made.zip`, made by `make_kanka_4_made.py` from the first fixture with 4.0's two changes, is the case both packages are held to; the npm SDK's `convertKanka` writes the same folder and report on it. + ## 0.156.5 (2026-11-27) - **The two deprecations say since which release and that they leave in onlyworlds 1.0**: `calendar.resolve_calendar_lens` (since 0.69.0; its warning now names the release) and the `version` key of `KindLayout` and `AroundLayout` (since 0.133.0), which said it would leave with the npm SDK. diff --git a/src/onlyworlds/_version.py b/src/onlyworlds/_version.py index e676b0c..317612e 100644 --- a/src/onlyworlds/_version.py +++ b/src/onlyworlds/_version.py @@ -1 +1 @@ -__version__ = "0.156.5" +__version__ = "0.157.0" diff --git a/src/onlyworlds/convert/kanka.json b/src/onlyworlds/convert/kanka.json index 5865d74..6c31316 100644 --- a/src/onlyworlds/convert/kanka.json +++ b/src/onlyworlds/convert/kanka.json @@ -21,10 +21,11 @@ "journals": "narrative", "maps": "map" }, - "proven_modules": ["characters", "locations", "organisations", "notes"], + "proven_modules": ["characters", "locations", "organisations", "notes", "races", "families"], "story_modules": ["notes", "quests", "journals"], "starter_window": 5.0, - "proven_export_version": "3.15", + "proven_export_versions": ["3.15", "4.0"], + "dead_status_ids": [3], "parent_fields": { "location": "parent_location", "institution": "parent_institution", @@ -49,7 +50,7 @@ "organisations": "organisations", "row_handled": [ "id", "name", "entry", "type", "is_private", "entity", "location_id", "race_id", "is_dead", "character_traits", - "character_families", "character_races", "organisation_memberships", "members", "is_personality_visible", "image_uuid" + "character_families", "character_races", "organisation_memberships", "members", "pivotMembers", "is_personality_visible", "image_uuid" ], "entity_handled": [ "id", "entity_id", "parent_id", "name", "type", "entry", "is_private", "is_attributes_private", "posts", "relationships", @@ -102,6 +103,7 @@ "untyped_type": "a module with no OnlyWorlds type keeps its own type", "entry_differs": "the row's entry differs from the entity's (kept as written)", "members_elsewhere": "members on a module that is not organisations", + "pivot_members": "who belongs, as Kanka 4.0 writes it; a Character's own family link comes from its character_families", "parent_not_id": "not an entity id", "parent_missing": "its parent is not in the folder", "posts_meta": "a post's layout, place, pins or visibility have no field", diff --git a/src/onlyworlds/kanka.py b/src/onlyworlds/kanka.py index 2a9f79c..d81fe51 100644 --- a/src/onlyworlds/kanka.py +++ b/src/onlyworlds/kanka.py @@ -36,11 +36,18 @@ own text names the visibility it was set to). Each comes in as its own hidden Narrative, the Character visible: the hidden-post rule below, read on a real file. -**Believed**, not yet seen in a file: the folders ``families/``, ``races/``, ``items/``, -``creatures/``, ``events/``, ``abilities/``, ``quests/``, ``journals/``, ``maps/`` and every other -module; the shapes of ``character_families``, ``character_races`` and -``organisation_memberships`` items (``family_id``, ``race_id``, ``organisation_id``), of an -organisation's ``members`` (``character_id``), of ``is_dead``, of ``[entity:N|text]``, of a +**And on a fourth** (Kanka 4.0, ``export_version`` ``"4.0"``, a new campaign made 2026-11-27; not +committed, as it carries the account's ids): ``races/`` and ``families/``; a Character's +``character_races``, ``character_families`` and ``organisation_memberships`` items (``race_id``, +``family_id``, ``organisation_id``); an organisation's ``members`` (``character_id``, a ``role`` +on one). Two keys this door was built for are not written: a dead Character carries no ``is_dead`` +but ``entity.status_id`` 3, and a family holds its people under ``pivotMembers`` (``character_id``, ``family_id``), not +``members``. ``tests/fixtures/kanka/kanka-4-made.zip`` is the first export with those two +changes made by hand, the case both packages are held to. + +**Believed**, not yet seen in a file: the folders ``items/``, ``creatures/``, ``events/``, +``abilities/``, ``quests/``, ``journals/``, ``maps/`` and every other module; the shapes of +``is_dead`` (which neither the 3.15 nor the 4.0 export writes), of a family's ``members``, of ``[entity:N|text]``, of a campaign's ``entry``; that ``character_traits`` section 1 is appearance and 2 personality (Kanka's own API names them so, read live on 2026-07-18; the export carries the number only). @@ -94,10 +101,12 @@ file name. - **A character's traits**: appearance (section 1) to ``physicality`` and personality (section 2) to ``mentality``, one ``Name: entry`` line each; another section is kept as ``x_kanka_traits``. - ``is_dead`` puts ``[Deceased] `` before ``physicality`` (the schema skill's convention for a - dead Character until a status field lands). ``status_id`` (1 on the two characters made in - the editor, null on the starters) is kept as ``x_kanka_status_id``: what its numbers mean is - not in the file. + A dead Character, ``is_dead`` set or ``entity.status_id`` 3, gets + ``[Deceased] `` before ``physicality`` (the schema skill's convention for a dead Character + until a status field lands). The 3 is the ``dead`` row of the character statuses every + campaign shares (Kanka's API documents them under ``category_statuses``: 1 ``alive``, 2 + ``missing``, 3 ``dead``); a campaign's own statuses are not in the export. A ``status_id`` + that is set is kept as ``x_kanka_status_id``, whatever it says. - **Attributes** (``entityAttributes``): one whose name, lowercased with spaces as underscores, is a field of the type fills it when the value fits (text; a whole number for an integer; only mentions, of the linked type, for a link); every other is kept as ``x_kanka_`` with its @@ -252,8 +261,13 @@ #: Seconds after the campaign's ``created_at`` within which an entity is named possible starter content. STARTER_WINDOW = float(_DATA["starter_window"]) -#: The export version this door was proven on; another is named in the report. -_PROVEN_VERSION: str = _DATA["proven_export_version"] +#: The export versions this door was proven on; another is named in the report. +_PROVEN_VERSIONS: tuple[str, ...] = tuple(_DATA["proven_export_versions"]) + +#: Kanka's own character statuses that read as dead: an entity's ``status_id`` names a row of the +#: ``category_statuses`` every campaign shares (id 3, key ``dead``, on characters). Neither the 3.15 +#: nor the 4.0 export writes ``is_dead``. A campaign's own statuses are not in the export. +_DEAD_STATUS_IDS = frozenset(_DATA["dead_status_ids"]) #: An element type -> its own parent field, which takes a parent of the same type. _PARENT_FIELD: dict[str, str] = dict(_DATA["parent_fields"]) @@ -850,7 +864,11 @@ def collect(self) -> None: version = info.get("export_version") self.report.notes.append( _NOTE["version"].format(kanka_version=info.get("kanka_version"), version=version) - + ("" if str(version) == _PROVEN_VERSION else _NOTE["version_unproven"].format(proven=_PROVEN_VERSION)) + + ( + "" + if str(version) in _PROVEN_VERSIONS + else _NOTE["version_unproven"].format(proven=" and ".join(_PROVEN_VERSIONS)) + ) ) born = _when(campaign.get("created_at")) plans: dict[str, int] = {} @@ -1047,6 +1065,8 @@ def _fill(self, item: _Item) -> None: self._attributes(item) if item.folder != _ORGANISATIONS and not _empty(row.get("members")): # organisations: _memberships self._keep(item, "members", row.get("members"), _WHY["members_elsewhere"]) + if not _empty(row.get("pivotMembers")): + self._keep(item, "pivotMembers", row.get("pivotMembers"), _WHY["pivot_members"]) self._generic(item) def _parent(self, item: _Item) -> None: @@ -1205,7 +1225,9 @@ def _character(self, item: _Item) -> None: sections.setdefault(section, []).append(line) else: other.append({"name": t.get("name"), "entry": t.get("entry"), "section_id": t.get("section_id")}) - dead = _on(row.get("is_dead")) + ent = row.get("entity") + status = _int_id(ent.get("status_id")) if isinstance(ent, dict) else None + dead = _on(row.get("is_dead")) or status in _DEAD_STATUS_IDS for section, to in _TRAIT_SECTIONS.items(): text = "\n".join(sections.get(section, [])) if dead and to["field"] == _DECEASED_FIELD: diff --git a/tests/fixtures/kanka/kanka-4-made.zip b/tests/fixtures/kanka/kanka-4-made.zip new file mode 100644 index 0000000..c54ac73 Binary files /dev/null and b/tests/fixtures/kanka/kanka-4-made.zip differ diff --git a/tests/fixtures/kanka/make_kanka_4_made.py b/tests/fixtures/kanka/make_kanka_4_made.py new file mode 100644 index 0000000..f7c6904 --- /dev/null +++ b/tests/fixtures/kanka/make_kanka_4_made.py @@ -0,0 +1,64 @@ +"""Make ``kanka-4-made.zip``: the first real export with Kanka 4.0's two changes made by hand. + +A real 4.0 export (made 2026-11-27) carries the account's ids, so it is not committed. This makes the +case both packages are held to from the first fixture, every file's bytes kept but three: + +- ``info.json`` names Kanka 4.0 and export version 4.0; +- Mara Voss is dead the 4.0 way: ``entity.status_id`` 3 (the shared ``dead`` row), no ``is_dead``; +- a family, The Voss line, holds her under ``pivotMembers``, as 4.0 writes a family's people. + +Run from the repository: ``uv run python tests/fixtures/kanka/make_kanka_4_made.py``. The same bytes come out +each time (every member's date is fixed); the npm SDK's copy is this file's output, byte for byte. +""" + +from __future__ import annotations + +import zipfile +from pathlib import Path + +HERE = Path(__file__).parent +SOURCE = HERE / "quay-export-world_20261023_074706.zip" +OUT = HERE / "kanka-4-made.zip" +WHEN = (2026, 11, 27, 0, 0, 0) + +FAMILY = "families/the-voss-line_10074650.json" +FAMILY_BODY = ( + b'{"name":"The Voss line","id":2607510,"is_private":0,"entity":{"id":10074650,"entity_id":2607510,' + b'"parent_id":null,"type_id":2,"name":"The Voss line","type":"Family","entry":"

Route planners for ' + b'three generations.<\\/p>","is_private":false,"tooltip":null,"is_template":false,' + b'"is_attributes_private":false,"focus_x":null,"focus_y":null,"created_at":"2026-10-23T07:44:00.000000Z",' + b'"updated_at":"2026-10-23T07:44:00.000000Z","created_by":900001,"updated_by":null,"image_path":null,' + b'"image_uuid":null,"header_image":null,"header_uuid":null,"marketplace_uuid":null,"status_id":null},' + b'"pivotMembers":[{"character_id":2607497,"family_id":2607510}]}' +) + + +def changed(name: str, raw: bytes) -> bytes: + """One member's bytes as the made export has them; each replacement must match exactly once.""" + subs: list[tuple[bytes, bytes]] = [] + if name == "info.json": + subs = [ + (b'"kanka_version":"3.15"', b'"kanka_version":"4.0"'), + (b'"export_version":"3.15"', b'"export_version":"4.0"'), + ] + elif name == "characters/mara-voss_10074603.json": + subs = [(b'"status_id":1,', b'"status_id":3,')] + for old, new in subs: + if raw.count(old) != 1: + raise SystemExit(f"{name}: {old!r} found {raw.count(old)} times, not once") + raw = raw.replace(old, new) + return raw + + +def main() -> None: + with zipfile.ZipFile(SOURCE) as src: + members = [(n, changed(n, src.read(n))) for n in src.namelist()] + members.append((FAMILY, FAMILY_BODY)) + with zipfile.ZipFile(OUT, "w", zipfile.ZIP_DEFLATED) as out: + for name, raw in members: + out.writestr(zipfile.ZipInfo(name, WHEN), raw, zipfile.ZIP_DEFLATED) + print(f"{OUT.name}: {len(members)} files") + + +if __name__ == "__main__": + main() diff --git a/tests/test_kanka.py b/tests/test_kanka.py index 446164f..a600cc8 100644 --- a/tests/test_kanka.py +++ b/tests/test_kanka.py @@ -24,6 +24,12 @@ visibility Kanka's menu offers short of all: Only me (``visibility_id`` 4), Members of the campaign (5) and Admins (2), each post's own text naming the visibility it was set to. The hidden post on a visible element, planted in the first export, read on a real file. + +``fixtures/kanka/kanka-4-made.zip`` is made, not exported: the first export with what a real Kanka 4.0 +export (2026-11-27, not committed: it carries the account's ids) showed in two places, made by hand +by ``fixtures/kanka/make_kanka_4_made.py``. Mara Voss is dead by ``entity.status_id`` 3, and a family +(The Voss line) holds her under ``pivotMembers``; ``info.json`` names 4.0. The npm SDK holds its door +to the Python door's output on it, as on the three real ones. """ from __future__ import annotations @@ -97,6 +103,11 @@ 1577357: ("A note, admins", 2, "Admins"), } +# the fourth: the first export with Kanka 4.0's two changes made by hand (fixtures/kanka/make_kanka_4_made.py) +EXPORT4 = EXPORT.parent / "kanka-4-made.zip" +SHA256_4 = "6ede34b66f2b3114292cc3678c24f3186fcc66c82ebc339d9fd6649aaac2fb65" +VOSS_LINE = 10074650 + # planted in the first export: a tag shaped like the second export's, and gallery uploads KEEPER, KEEPER_ROW, KEEPER_FILE = 10074699, 346600, "tags/keeper_10074699.json" UP1, UP2, UP3 = (f"00000000-0000-7000-8000-00000000000{n}" for n in (1, 2, 3)) @@ -214,7 +225,7 @@ def test_namespace_is_pinned() -> None: #: The door's tables and wording: the same bytes as the npm SDK's ``src/convert/kanka.json``, its test this hash too. -DATA_SHA256 = "53394eee55d8afe0b2b5b5bdc99795a42543600ca085ec282ef1acd66a37106a" +DATA_SHA256 = "ac453c68f54e0d96217e08763169fee7bf53ced6b43f7b24f7054d67f3a8880e" def test_the_data_file_is_the_bytes_the_npm_sdk_reads() -> None: @@ -696,6 +707,80 @@ def test_third_export_deterministic_and_lint_clean(tmp_path: Path) -> None: assert problems == [] and r.returncode == 0, r.stdout + r.stderr +# --- the fourth: Kanka 4.0's shapes, made from the first --------------------------- + + +def test_the_fourth_fixture_is_the_made_file() -> None: + assert hashlib.sha256(EXPORT4.read_bytes()).hexdigest() == SHA256_4 + + +def test_kanka_4_a_dead_status_marks_the_character_deceased(tmp_path: Path) -> None: + """status_id 3, the shared `dead` row, is what is_dead was; 1 (alive) and none mark nothing.""" + out, _ = run(tmp_path, EXPORT4) + people = by_name(out) + assert people["Mara Voss"]["physicality"] == "[Deceased]" + assert people["Mara Voss"]["x_kanka_status_id"] == 3 + assert "physicality" not in people["Ada Okafor"] and people["Ada Okafor"]["x_kanka_status_id"] == 1 + out1, _ = run(tmp_path, EXPORT, name="first") + assert "physicality" not in by_name(out1)["Mara Voss"] + + +def test_kanka_4_a_status_that_is_not_the_shared_dead_marks_nothing(tmp_path: Path) -> None: + """A campaign's own status, or a 3 that is not a whole number, is kept and read as nothing more.""" + for value in (2, 4, 3.0, True, None, "x"): + + def change(doc: dict[str, Any], v: Any = value) -> None: + doc["entity"]["status_id"] = v + + src = variant(tmp_path, change, MARA_FILE, name=f"status-{value!r}.zip") + out, _ = run(tmp_path, src, name=f"status-{value!r}") + assert "physicality" not in by_name(out)["Mara Voss"], value + src = variant(tmp_path, lambda doc: doc["entity"].update(status_id="3"), MARA_FILE, name="status-digits.zip") + out, _ = run(tmp_path, src, name="status-digits") + assert by_name(out)["Mara Voss"]["physicality"] == "[Deceased]" # an id written as digits, as every id here + + +def test_kanka_4_a_familys_pivot_members_are_kept_with_their_reason(tmp_path: Path) -> None: + out, report = run(tmp_path, EXPORT4) + line = by_name(out)["The Voss line"] + assert line["id"] == eid(VOSS_LINE) and line["type"] == "family" + assert line["x_kanka_pivot_members"] == [{"character_id": 2607497, "family_id": 2607510}] + text = report.render() + assert "'The Voss line' / 'pivotMembers': who belongs, as Kanka 4.0 writes it" in text + assert "families/ (1): family; read on a real export" in text + assert "proven on" not in text # 4.0 is a version this door was proven on + + +def test_pivot_members_on_any_module_are_kept_never_dropped(tmp_path: Path) -> None: + """The organisation's members feed its links; a pivotMembers beside them is kept all the same.""" + + def change(doc: dict[str, Any]) -> None: + doc["pivotMembers"] = [{"character_id": 2607497, "organisation_id": 1}] + + src = variant(tmp_path, change, "organisations/the-ferry-guild_10074606.json") + out, _ = run(tmp_path, src) + assert by_name(out)["The Ferry Guild"]["x_kanka_pivot_members"] == [{"character_id": 2607497, "organisation_id": 1}] + + +def test_an_export_version_not_proven_names_both_that_were(tmp_path: Path) -> None: + def change(doc: dict[str, Any]) -> None: + doc["export_version"] = "4.1" + + src = variant(tmp_path, change, "info.json") + _, report = run(tmp_path, src) + assert "(this door was proven on 3.15 and 4.0)" in report.render() + + +def test_fourth_export_deterministic_and_lint_clean(tmp_path: Path) -> None: + run(tmp_path, EXPORT4, name="one") + run(tmp_path, EXPORT4, name="two") + assert tree(tmp_path / "one") == tree(tmp_path / "two") + pytest.importorskip("yaml", reason="the dist's lint decodes the schema YAML") + r = subprocess.run([sys.executable, str(LINT), str(tmp_path / "one")], capture_output=True, text=True) + problems = [line for line in r.stdout.strip().splitlines()[:-1] if not line.startswith("walk note:")] + assert problems == [] and r.returncode == 0, r.stdout + r.stderr + + # --- the gallery, planted ------------------------------------------------------ diff --git a/tests/test_made_names.py b/tests/test_made_names.py index 8014ee9..cf98c86 100644 --- a/tests/test_made_names.py +++ b/tests/test_made_names.py @@ -176,8 +176,9 @@ def name_reads(name: str, src: str) -> str: def test_the_list_holds_every_real_export_in_the_fixtures() -> None: held = {p for _, p, _ in REAL} real = {p for d in DOORS for p in (FIX / d).iterdir() if p.suffix in (".json", ".lk", ".zip", ".html")} - # LegendKeeper's other files are answers of its API, recorded, not exports - real = {p for p in real if p.parent.name != "legendkeeper" or p in (LK3, LK)} + # LegendKeeper's other files are answers of its API, recorded, not exports; a fixture made by hand from a + # real export (its name ends in -made, as kanka-4-made.zip) is not an export either + real = {p for p in real if (p.parent.name != "legendkeeper" or p in (LK3, LK)) and not p.stem.endswith("-made")} assert held == real