From 8c998caba2badf63557c199055a9f2613462f042 Mon Sep 17 00:00:00 2001 From: Titus Date: Fri, 27 Nov 2026 11:21:02 +0100 Subject: [PATCH] 0.157.0: the Kanka door reads Kanka 4.0's exports (a dead status, a family's pivotMembers) 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 family's pivotMembers is kept with its reason on any module. Races and families read as proven; the report names an export version other than 3.15 or 4.0. A made fixture, the first export with 4.0's two changes, holds both packages to it. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 5 ++ src/onlyworlds/_version.py | 2 +- src/onlyworlds/convert/kanka.json | 8 +- src/onlyworlds/kanka.py | 48 ++++++++---- tests/fixtures/kanka/kanka-4-made.zip | Bin 0 -> 9144 bytes tests/fixtures/kanka/make_kanka_4_made.py | 64 ++++++++++++++++ tests/test_kanka.py | 87 +++++++++++++++++++++- tests/test_made_names.py | 5 +- 8 files changed, 199 insertions(+), 20 deletions(-) create mode 100644 tests/fixtures/kanka/kanka-4-made.zip create mode 100644 tests/fixtures/kanka/make_kanka_4_made.py 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 0000000000000000000000000000000000000000..c54ac738542005383c3f5e993f4779e99f562457 GIT binary patch literal 9144 zcmbVx1yq!4*ETVPw1jj@jC6O3bPY&%It(!6&>-F2At{p5B^@Fyp&%WKq?EMuH^+0{ z*CXG1{`G$U%zD;5&#ZM{_qzAB_kQ-?7f1;iK!|{VfDXUBjX31XuchF3s_^R`{DRm& zb6~e|aj<`_J*4`6ST&kMiH&*m{n*o54ek#-ppWW`6~F-w=59Q8b_G^u1r>Gp|J;!lsG}JKZ2xnwkOURg z9!|WFs=#MGeNw8Ck>6aZk!Xi2inrurDLomJ%f2lp5PYo1N7}zy_dfDQJv8NSm}=3+ zGYT^`O*_#2qLW*ziEQzFHOykDI|vC!8WWWf8Hf(qKnjeIMlU1D&U>TUC0X#oRcpIU zul*Zw-CX*`xkB7NHX&B~EvC_O-emKs{z_7MBcZ%%Bg~kk3%K?M&}EH+2BWHLKe~w* zd#3s!#Kh3K3#b2Gk_F8$@NvzW-eHrwbo`?uEu)enWzAa$o?fW)>{Gkl1fM949oCt+ zAa%lM=V{TD$bD)IQ75_go83D`rfr6Vc=MAM6lk=KzD3Cj)&Z%=P&HG2tIiYW2!j!e zu5;m|nIw&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3b3YAzU3~9=OEM)Rb zjpCagZs(WBvZ@Lm2Y9ZM zmE&$4X)MX|ryW zTIQgS@Owja;$_Z*pSs4|H}_kua!griwzA1nTol zw{*rT%@o_DY#+UQ1*84KjK^S5OBml!=hWuYdBoBLZGA$ZfFJ_az04=2hlz1vCsf(5}n`p!JzpZlu2uy>2pU$Dx=e~10gCF@n`ryn&B6&1=;^!1#x$WyKlr_J8Y2upWcsmf$wJdU%+;h|6R@p VDWRbLu?iRdeFIk^x2gVk`X6mYddUC) literal 0 HcmV?d00001 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