"""D6 ยง5.2: the manifest's new fields are actually written (not just declared). The reference bug: author/summary/updated_at/updated_by/schema_version existed on the model but no code ever populated them. These tests pin that create_session fills them and that mutations (set_question, touch_manifest) bump updated_at/updated_by. """ from tht.config import DatabaseConfig from tht.session.store import create_session, load_session, set_question, touch_manifest def _db() -> DatabaseConfig: return DatabaseConfig(host="h", port=5432, database="dw", user="u", password="p", schema="dwh") def test_create_session_populates_new_fields(tmp_path, monkeypatch): monkeypatch.setenv("THT_AUTHOR", "alice@psd") m = create_session("Quanti ricoveri per ablazione nel 2024?", _db(), tmp_path) assert m.author == "alice@psd" assert m.updated_by == "alice@psd" assert m.summary and m.summary.startswith("Quanti ricoveri") assert m.created_at is not None assert m.updated_at == m.created_at assert m.schema_version is not None # from workflow.yaml def test_default_author_when_env_absent(tmp_path, monkeypatch): monkeypatch.delenv("THT_AUTHOR", raising=False) m = create_session("x", _db(), tmp_path) assert m.author == "dev@local" def test_touch_manifest_bumps_updated(tmp_path, monkeypatch): monkeypatch.setenv("THT_AUTHOR", "alice@psd") m = create_session("domanda", _db(), tmp_path) created = m.updated_at monkeypatch.setenv("THT_AUTHOR", "bob@psd") set_question(m.id, "domanda riscritta", [], tmp_path) reloaded = load_session(m.id, tmp_path) assert reloaded.updated_by == "bob@psd" assert reloaded.updated_at >= created # touch_manifest helper is reachable and updates the field touch_manifest(m.id, tmp_path, updated_by="carol@psd") assert load_session(m.id, tmp_path).updated_by == "carol@psd"