From 68ae82a5e541d860a0050faad774d75023385b09 Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 23 Nov 2026 18:43:48 +0100 Subject: [PATCH 1/2] Load the distribution reference fixture from the API image. Pytest runs inside the backend container, which only contains the backend tree. The reference case lived two directories above that tree, so collection stopped before any test ran. Co-authored-by: Cursor --- .../Shinkan_Lara_Felix_Referenzfall_v1.json | 493 ++++++++++++++++++ backend/tests/test_distribution_contract.py | 5 +- 2 files changed, 495 insertions(+), 3 deletions(-) create mode 100644 backend/tests/fixtures/Shinkan_Lara_Felix_Referenzfall_v1.json diff --git a/backend/tests/fixtures/Shinkan_Lara_Felix_Referenzfall_v1.json b/backend/tests/fixtures/Shinkan_Lara_Felix_Referenzfall_v1.json new file mode 100644 index 0000000..51820e8 --- /dev/null +++ b/backend/tests/fixtures/Shinkan_Lara_Felix_Referenzfall_v1.json @@ -0,0 +1,493 @@ +{ + "fixture_version": 1, + "note": "Synthetische Inhalte ohne produktive Rechte. Die Medienbytes dienen der Testung von Groesse und Hash. Sie sind keine abspielbare Filmdatei.", + "manifest_serialization": "UTF-8, JSON ohne Leerraum, Reihenfolge der Felder aus manifest, kein abschliessender Zeilenumbruch", + "channels": { + "lara_felix": { + "recipient_id": "caa20000-0000-4000-8000-0000000001f5", + "events": [ + { + "event_id": "caa20000-0000-4000-8000-000000000258", + "type": "release.published", + "release_id": "caa20000-0000-4000-8000-0000000000c9", + "occurred_at": "2026-11-23T09:01:00Z", + "source_id": "caa20000-0000-4000-8000-00000000000a", + "revision": 1, + "manifest_sha256": "fcebc8c4db56328a55dc7f350e705822cef19f02392f26625274e68c0abc239c" + }, + { + "event_id": "caa20000-0000-4000-8000-000000000259", + "type": "release.published", + "release_id": "caa20000-0000-4000-8000-0000000000ca", + "occurred_at": "2026-11-23T09:02:00Z", + "source_id": "caa20000-0000-4000-8000-00000000000b", + "revision": 1, + "manifest_sha256": "7dad43afb3077fb2d9fb3aa490bb91daf53f175c06575d648411021d352a1744" + }, + { + "event_id": "caa20000-0000-4000-8000-00000000025a", + "type": "release.published", + "release_id": "caa20000-0000-4000-8000-0000000000cb", + "occurred_at": "2026-11-23T09:03:00Z", + "source_id": "caa20000-0000-4000-8000-00000000000a", + "revision": 2, + "manifest_sha256": "f0c8051cee6feb0e6399f1bc5681e0ef1ecd640c1cbe6b634c5df1c1b1df9ed0" + }, + { + "event_id": "caa20000-0000-4000-8000-00000000025b", + "type": "release.retired", + "release_id": "caa20000-0000-4000-8000-0000000000c9", + "occurred_at": "2026-11-23T09:04:00Z" + }, + { + "event_id": "caa20000-0000-4000-8000-00000000025c", + "type": "asset.withdrawn", + "release_id": "caa20000-0000-4000-8000-0000000000c9", + "occurred_at": "2026-11-23T09:05:00Z", + "target_id": "caa20000-0000-4000-8000-00000000012c", + "reason_code": "rights" + }, + { + "event_id": "caa20000-0000-4000-8000-00000000025d", + "type": "asset.withdrawn", + "release_id": "caa20000-0000-4000-8000-0000000000cb", + "occurred_at": "2026-11-23T09:05:00Z", + "target_id": "caa20000-0000-4000-8000-00000000012c", + "reason_code": "rights" + } + ] + }, + "zweiter_verein": { + "recipient_id": "caa20000-0000-4000-8000-0000000001f6", + "events": [ + { + "event_id": "caa20000-0000-4000-8000-0000000002bc", + "type": "release.published", + "release_id": "caa20000-0000-4000-8000-0000000000cc", + "occurred_at": "2026-11-23T09:03:00Z", + "source_id": "caa20000-0000-4000-8000-00000000000c", + "revision": 1, + "manifest_sha256": "3e34007864d308ac1cf6b555bb7fd00dd6962fb6f396eca16492ace0fec59603" + } + ] + } + }, + "releases": { + "vereinsfassung_1": { + "channel": "lara_felix", + "manifest_sha256": "fcebc8c4db56328a55dc7f350e705822cef19f02392f26625274e68c0abc239c", + "manifest": { + "schema_version": 1, + "resource_type": "exercise", + "release_id": "caa20000-0000-4000-8000-0000000000c9", + "source_id": "caa20000-0000-4000-8000-00000000000a", + "revision": 1, + "publisher_id": "caa20000-0000-4000-8000-00000000177a", + "published_at": "2026-11-23T09:01:00Z", + "exercise": { + "title": "Raum und Wege wahrnehmen", + "audience": "Kursleitungen", + "rights_id": "caa20000-0000-4000-8000-000000000191", + "parts": [ + { + "id": "caa20000-0000-4000-8000-000000000065", + "role": "goal", + "text": "Die Gruppe nimmt freie Wege im Raum wahr.", + "rights_id": "caa20000-0000-4000-8000-000000000191" + }, + { + "id": "caa20000-0000-4000-8000-000000000066", + "role": "instructions", + "text": "Die Kursleitung legt Karten aus und bespricht die freien Wege.", + "rights_id": "caa20000-0000-4000-8000-000000000191" + }, + { + "id": "caa20000-0000-4000-8000-000000000067", + "role": "trainer_notes", + "text": "Vorab genug Platz vorsehen.", + "rights_id": "caa20000-0000-4000-8000-000000000191" + }, + { + "id": "caa20000-0000-4000-8000-000000000068", + "role": "instructions", + "text": "Den kurzen Film ansehen und danach die gezeigten Wege vergleichen.", + "rights_id": "caa20000-0000-4000-8000-000000000191" + } + ], + "assets": [ + { + "id": "caa20000-0000-4000-8000-00000000012c", + "role": "demonstration", + "media_type": "video/mp4", + "size_bytes": 32, + "sha256": "0fb807ef5ec44b003f181dfa9ce317becbcfd5755ebf91a57702d2024df2b915", + "rights_id": "caa20000-0000-4000-8000-000000000192", + "label": "Demonstrationsfilm" + } + ], + "common_part_ids": [ + "caa20000-0000-4000-8000-000000000065", + "caa20000-0000-4000-8000-000000000067" + ], + "common_asset_ids": [], + "variants": [ + { + "id": "caa20000-0000-4000-8000-00000000006b", + "label": "Kartenvariante", + "part_ids": [ + "caa20000-0000-4000-8000-000000000066" + ], + "asset_ids": [] + }, + { + "id": "caa20000-0000-4000-8000-00000000006c", + "label": "Filmvariante", + "part_ids": [ + "caa20000-0000-4000-8000-000000000068" + ], + "asset_ids": [ + "caa20000-0000-4000-8000-00000000012c" + ] + } + ] + }, + "rights": [ + { + "id": "caa20000-0000-4000-8000-000000000191", + "evidence_ref": "test-textrechte", + "actions": [ + "store", + "render", + "grant_customer_use", + "commercial_course_use" + ], + "territories": [ + "DE" + ], + "valid_from": "2026-11-23T09:00:00Z", + "valid_until": null + }, + { + "id": "caa20000-0000-4000-8000-000000000192", + "evidence_ref": "test-filmrechte", + "actions": [ + "store", + "stream", + "course_display", + "grant_customer_use", + "commercial_course_use" + ], + "territories": [ + "DE" + ], + "valid_from": "2026-11-23T09:00:00Z", + "valid_until": null + } + ] + }, + "synthetic_asset_base64_by_id": { + "caa20000-0000-4000-8000-00000000012c": "U2hpbmthbiBkaXN0cmlidXRpb24gZml4dHVyZSB2MQo=" + } + }, + "eigener_bestand": { + "channel": "lara_felix", + "manifest_sha256": "7dad43afb3077fb2d9fb3aa490bb91daf53f175c06575d648411021d352a1744", + "manifest": { + "schema_version": 1, + "resource_type": "exercise", + "release_id": "caa20000-0000-4000-8000-0000000000ca", + "source_id": "caa20000-0000-4000-8000-00000000000b", + "revision": 1, + "publisher_id": "caa20000-0000-4000-8000-00000000177b", + "published_at": "2026-11-23T09:02:00Z", + "exercise": { + "title": "Aufmerksam im Raum ankommen", + "audience": "Kursleitungen", + "rights_id": "caa20000-0000-4000-8000-000000000191", + "parts": [ + { + "id": "caa20000-0000-4000-8000-00000000006f", + "role": "goal", + "text": "Die Gruppe nimmt freie Wege im Raum wahr.", + "rights_id": "caa20000-0000-4000-8000-000000000191" + }, + { + "id": "caa20000-0000-4000-8000-000000000070", + "role": "instructions", + "text": "Die Kursleitung legt Karten aus und bespricht die freien Wege.", + "rights_id": "caa20000-0000-4000-8000-000000000191" + }, + { + "id": "caa20000-0000-4000-8000-000000000071", + "role": "trainer_notes", + "text": "Vorab genug Platz vorsehen.", + "rights_id": "caa20000-0000-4000-8000-000000000191" + } + ], + "assets": [], + "common_part_ids": [ + "caa20000-0000-4000-8000-00000000006f", + "caa20000-0000-4000-8000-000000000071" + ], + "common_asset_ids": [], + "variants": [ + { + "id": "caa20000-0000-4000-8000-000000000075", + "label": "Kartenvariante", + "part_ids": [ + "caa20000-0000-4000-8000-000000000070" + ], + "asset_ids": [] + } + ] + }, + "rights": [ + { + "id": "caa20000-0000-4000-8000-000000000191", + "evidence_ref": "test-textrechte", + "actions": [ + "store", + "render", + "grant_customer_use", + "commercial_course_use" + ], + "territories": [ + "DE" + ], + "valid_from": "2026-11-23T09:00:00Z", + "valid_until": null + } + ] + }, + "synthetic_asset_base64_by_id": {} + }, + "vereinsfassung_2": { + "channel": "lara_felix", + "manifest_sha256": "f0c8051cee6feb0e6399f1bc5681e0ef1ecd640c1cbe6b634c5df1c1b1df9ed0", + "manifest": { + "schema_version": 1, + "resource_type": "exercise", + "release_id": "caa20000-0000-4000-8000-0000000000cb", + "source_id": "caa20000-0000-4000-8000-00000000000a", + "revision": 2, + "publisher_id": "caa20000-0000-4000-8000-00000000177a", + "published_at": "2026-11-23T09:03:00Z", + "exercise": { + "title": "Raum und Wege wahrnehmen", + "audience": "Kursleitungen", + "rights_id": "caa20000-0000-4000-8000-000000000191", + "parts": [ + { + "id": "caa20000-0000-4000-8000-000000000065", + "role": "goal", + "text": "Die Gruppe nimmt freie Wege im Raum wahr.", + "rights_id": "caa20000-0000-4000-8000-000000000191" + }, + { + "id": "caa20000-0000-4000-8000-000000000066", + "role": "instructions", + "text": "Die Kursleitung legt Karten aus und bespricht die freien Wege.", + "rights_id": "caa20000-0000-4000-8000-000000000191" + }, + { + "id": "caa20000-0000-4000-8000-000000000067", + "role": "trainer_notes", + "text": "Vorab genug Platz vorsehen und die Laufwege gemeinsam prüfen.", + "rights_id": "caa20000-0000-4000-8000-000000000191" + }, + { + "id": "caa20000-0000-4000-8000-000000000068", + "role": "instructions", + "text": "Den kurzen Film ansehen und danach die gezeigten Wege vergleichen.", + "rights_id": "caa20000-0000-4000-8000-000000000191" + } + ], + "assets": [ + { + "id": "caa20000-0000-4000-8000-00000000012c", + "role": "demonstration", + "media_type": "video/mp4", + "size_bytes": 32, + "sha256": "0fb807ef5ec44b003f181dfa9ce317becbcfd5755ebf91a57702d2024df2b915", + "rights_id": "caa20000-0000-4000-8000-000000000192", + "label": "Demonstrationsfilm" + } + ], + "common_part_ids": [ + "caa20000-0000-4000-8000-000000000065", + "caa20000-0000-4000-8000-000000000067" + ], + "common_asset_ids": [], + "variants": [ + { + "id": "caa20000-0000-4000-8000-00000000006b", + "label": "Kartenvariante", + "part_ids": [ + "caa20000-0000-4000-8000-000000000066" + ], + "asset_ids": [] + }, + { + "id": "caa20000-0000-4000-8000-00000000006c", + "label": "Filmvariante", + "part_ids": [ + "caa20000-0000-4000-8000-000000000068" + ], + "asset_ids": [ + "caa20000-0000-4000-8000-00000000012c" + ] + } + ] + }, + "rights": [ + { + "id": "caa20000-0000-4000-8000-000000000191", + "evidence_ref": "test-textrechte", + "actions": [ + "store", + "render", + "grant_customer_use", + "commercial_course_use" + ], + "territories": [ + "DE" + ], + "valid_from": "2026-11-23T09:00:00Z", + "valid_until": null + }, + { + "id": "caa20000-0000-4000-8000-000000000192", + "evidence_ref": "test-filmrechte", + "actions": [ + "store", + "stream", + "course_display", + "grant_customer_use", + "commercial_course_use" + ], + "territories": [ + "DE" + ], + "valid_from": "2026-11-23T09:00:00Z", + "valid_until": null + } + ] + }, + "synthetic_asset_base64_by_id": { + "caa20000-0000-4000-8000-00000000012c": "U2hpbmthbiBkaXN0cmlidXRpb24gZml4dHVyZSB2MQo=" + } + }, + "zweiter_verein": { + "channel": "zweiter_verein", + "manifest_sha256": "3e34007864d308ac1cf6b555bb7fd00dd6962fb6f396eca16492ace0fec59603", + "manifest": { + "schema_version": 1, + "resource_type": "exercise", + "release_id": "caa20000-0000-4000-8000-0000000000cc", + "source_id": "caa20000-0000-4000-8000-00000000000c", + "revision": 1, + "publisher_id": "caa20000-0000-4000-8000-00000000177c", + "published_at": "2026-11-23T09:03:00Z", + "exercise": { + "title": "Gemeinsam den Raum erkunden", + "audience": "Kursleitungen", + "rights_id": "caa20000-0000-4000-8000-000000000191", + "parts": [ + { + "id": "caa20000-0000-4000-8000-000000000079", + "role": "goal", + "text": "Die Gruppe nimmt freie Wege im Raum wahr.", + "rights_id": "caa20000-0000-4000-8000-000000000191" + }, + { + "id": "caa20000-0000-4000-8000-00000000007a", + "role": "instructions", + "text": "Die Kursleitung legt Karten aus und bespricht die freien Wege.", + "rights_id": "caa20000-0000-4000-8000-000000000191" + }, + { + "id": "caa20000-0000-4000-8000-00000000007b", + "role": "trainer_notes", + "text": "Vorab genug Platz vorsehen.", + "rights_id": "caa20000-0000-4000-8000-000000000191" + } + ], + "assets": [], + "common_part_ids": [ + "caa20000-0000-4000-8000-000000000079", + "caa20000-0000-4000-8000-00000000007b" + ], + "common_asset_ids": [], + "variants": [ + { + "id": "caa20000-0000-4000-8000-00000000007f", + "label": "Kartenvariante", + "part_ids": [ + "caa20000-0000-4000-8000-00000000007a" + ], + "asset_ids": [] + } + ] + }, + "rights": [ + { + "id": "caa20000-0000-4000-8000-000000000191", + "evidence_ref": "test-textrechte", + "actions": [ + "store", + "render", + "grant_customer_use", + "commercial_course_use" + ], + "territories": [ + "DE" + ], + "valid_from": "2026-11-23T09:00:00Z", + "valid_until": null + } + ] + }, + "synthetic_asset_base64_by_id": {} + } + }, + "plans": { + "plan_a_mit_film": { + "release_id": "caa20000-0000-4000-8000-0000000000c9", + "variant_id": "caa20000-0000-4000-8000-00000000006c" + }, + "plan_b_mit_karten": { + "release_id": "caa20000-0000-4000-8000-0000000000c9", + "variant_id": "caa20000-0000-4000-8000-00000000006b" + }, + "plan_c_mit_film_neuere_fassung": { + "release_id": "caa20000-0000-4000-8000-0000000000cb", + "variant_id": "caa20000-0000-4000-8000-00000000006c" + }, + "plan_d_eigener_bestand": { + "release_id": "caa20000-0000-4000-8000-0000000000ca", + "variant_id": "caa20000-0000-4000-8000-000000000075" + } + }, + "expected": { + "plan_binding_after_revision": { + "release_id": "caa20000-0000-4000-8000-0000000000c9", + "variant_id": "caa20000-0000-4000-8000-00000000006c" + }, + "blocked_plans_after_withdrawal": [ + "plan_a_mit_film", + "plan_c_mit_film_neuere_fassung" + ], + "available_plans_after_withdrawal": [ + "plan_b_mit_karten", + "plan_d_eigener_bestand" + ], + "lara_felix_can_retrieve_after_withdrawal": [ + "caa20000-0000-4000-8000-0000000000ca" + ], + "zweiter_verein_can_retrieve": [ + "caa20000-0000-4000-8000-0000000000cc" + ], + "course_film_allowed": true, + "film_download_allowed": false + } +} diff --git a/backend/tests/test_distribution_contract.py b/backend/tests/test_distribution_contract.py index 2160fdb..76b4447 100644 --- a/backend/tests/test_distribution_contract.py +++ b/backend/tests/test_distribution_contract.py @@ -42,10 +42,9 @@ from main import app from routers.exercises import _assert_can_edit_exercise from tenant_context import TenantContext, get_tenant_context +# Liegt im Backend-Baum, weil Pytest im API-Image läuft und dort kein Repo-docs-Ordner existiert. FIXTURE = json.loads( - (Path(__file__).resolve().parents[2] / "docs" / "architecture" / "distribution" / "Shinkan_Lara_Felix_Referenzfall_v1.json").read_text( - encoding="utf-8" - ) + (Path(__file__).resolve().parent / "fixtures" / "Shinkan_Lara_Felix_Referenzfall_v1.json").read_text(encoding="utf-8") ) From 5ff0cd43ee04a4b51e42a2175644eb649a33c138 Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 23 Nov 2026 22:12:14 +0100 Subject: [PATCH 2/2] Deliver stored exercise HTML on the catalog API. The receiving application needs paragraphs, line breaks, lists and emphasis as stored in Shinkan. The catalog now returns that HTML and marks the text format, while titles and short variant descriptions stay plain text. Co-authored-by: Cursor --- backend/distribution_contract.py | 31 +++++++++++++++------ backend/tests/test_distribution_contract.py | 22 +++++++++++++++ backend/version.py | 11 ++++++-- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/backend/distribution_contract.py b/backend/distribution_contract.py index 8145778..609bb64 100644 --- a/backend/distribution_contract.py +++ b/backend/distribution_contract.py @@ -15,6 +15,8 @@ from datetime import datetime, timezone from html import unescape from typing import Any, Iterable, Optional +from exercise_rich_text import normalize_inline_exercise_media_markup + PART_ROLES = ( "goal", "prerequisites", @@ -235,8 +237,20 @@ def catalog_available(offered: bool, in_scope: bool) -> bool: return bool(offered) and bool(in_scope) +def catalog_html(value: Optional[str]) -> str: + """Gespeichertes Übungs-HTML. Absätze, Umbrüche, Listen und Hervorhebungen bleiben erhalten.""" + if value is None: + return "" + normalized = normalize_inline_exercise_media_markup(str(value)) + return normalized or "" + + def catalog_document(exercise: dict, variants: list[dict], media: list[dict]) -> dict: - """Aktueller Übungsstand. Die Reihenfolge der Varianten und Medien gehört zum Inhalt.""" + """Aktueller Übungsstand. Die Reihenfolge der Varianten und Medien gehört zum Inhalt. + + text_format html gilt für summary, goal, execution, preparation, trainer_notes + und variants.execution_changes. Titel, Variantenbeschreibung und Material bleiben Text. + """ ordered_variants = sorted( variants, key=lambda item: (item.get("sequence_order") is None, item.get("sequence_order") or 0, int(item.get("id") or 0)), @@ -247,12 +261,13 @@ def catalog_document(exercise: dict, variants: list[dict], media: list[dict]) -> ) return { "source_id": str(exercise.get("public_id")), + "text_format": "html", "title": exercise.get("title") or "", - "summary": plaintext(exercise.get("summary")), - "goal": plaintext(exercise.get("goal")), - "execution": plaintext(exercise.get("execution")), - "preparation": plaintext(exercise.get("preparation")), - "trainer_notes": plaintext(exercise.get("trainer_notes")), + "summary": catalog_html(exercise.get("summary")), + "goal": catalog_html(exercise.get("goal")), + "execution": catalog_html(exercise.get("execution")), + "preparation": catalog_html(exercise.get("preparation")), + "trainer_notes": catalog_html(exercise.get("trainer_notes")), "equipment": _equipment_text(exercise) or "", "duration_min": exercise.get("duration_min"), "duration_max": exercise.get("duration_max"), @@ -260,8 +275,8 @@ def catalog_document(exercise: dict, variants: list[dict], media: list[dict]) -> { "id": str(item.get("public_id")), "name": item.get("variant_name") or "", - "description": plaintext(item.get("description")), - "execution_changes": plaintext(item.get("execution_changes")), + "description": (item.get("description") or "").strip(), + "execution_changes": catalog_html(item.get("execution_changes")), "sequence_order": item.get("sequence_order"), } for item in ordered_variants diff --git a/backend/tests/test_distribution_contract.py b/backend/tests/test_distribution_contract.py index 76b4447..a1f51ae 100644 --- a/backend/tests/test_distribution_contract.py +++ b/backend/tests/test_distribution_contract.py @@ -345,6 +345,28 @@ def test_catalog_reports_variant_and_media_order_changes() -> None: ] +def test_catalog_keeps_stored_html() -> None: + exercise = _catalog_exercise() + exercise["execution"] = "

Stand aufrecht.

Drehe die Hüfte.


  • eins
  • zwei
" + exercise["goal"] = "

Sehen

" + variant = [{ + "id": 1, + "public_id": "var-1", + "variant_name": "Karte", + "description": "Kurzer Text", + "execution_changes": "

Langsamer.

Mit Partner.

", + "sequence_order": 1, + }] + document = catalog_document(exercise, variant, []) + assert document["text_format"] == "html" + assert document["execution"] == "

Stand aufrecht.

Drehe die Hüfte.


  • eins
  • zwei
" + assert document["goal"] == "

Sehen

" + assert "