61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
import uuid
|
|
|
|
from tht.decisions import DecisionInput
|
|
from tht.phase import current_phase, cte_plan, next_cte
|
|
from tht.session.filesystem_repository import FilesystemSessionRepository
|
|
from tht.session.models import PrincipalContext, SessionManifest
|
|
from tht.session.store import persist_verified_finalization
|
|
|
|
|
|
def _manifest(session_id: str) -> SessionManifest:
|
|
return SessionManifest(
|
|
id=session_id,
|
|
created_at="2026-07-16T10:00:00Z",
|
|
question="Which patients had an ablation?",
|
|
database="testdb",
|
|
schema="public",
|
|
)
|
|
|
|
|
|
def test_phase_helpers_fold_the_repository_snapshot_not_a_session_path(tmp_path):
|
|
repository = FilesystemSessionRepository(
|
|
tmp_path / "home", "demo", PrincipalContext(issuer="local", subject="alice")
|
|
)
|
|
session_id = str(uuid.uuid4())
|
|
repository.create(_manifest(session_id))
|
|
repository.write_artifact(session_id, "cte_plan", '["base_patients"]')
|
|
repository.append_decisions(
|
|
session_id,
|
|
[
|
|
DecisionInput(type="phase_approved", subject="phase:1"),
|
|
DecisionInput(type="phase_auto_approved", subject="phase:2"),
|
|
DecisionInput(type="cte_approved", subject="base_patients"),
|
|
],
|
|
)
|
|
|
|
snapshot = repository.get(session_id)
|
|
|
|
assert current_phase(snapshot) == 3
|
|
assert cte_plan(snapshot) == ["base_patients"]
|
|
assert next_cte(snapshot) is None
|
|
|
|
|
|
def test_verified_finalization_commits_report_evidence_and_status_through_repository(tmp_path):
|
|
repository = FilesystemSessionRepository(
|
|
tmp_path / "home", "demo", PrincipalContext(issuer="local", subject="alice")
|
|
)
|
|
session_id = str(uuid.uuid4())
|
|
repository.create(_manifest(session_id))
|
|
|
|
persist_verified_finalization(
|
|
repository,
|
|
session_id,
|
|
validation_report="# Validation\n\nverified against DWH\n",
|
|
evidence='[{"source":"review"}]\n',
|
|
)
|
|
|
|
snapshot = repository.get(session_id)
|
|
assert snapshot.manifest.status == "finalized"
|
|
assert snapshot.artifacts["validation_report"] == "# Validation\n\nverified against DWH\n"
|
|
assert snapshot.artifacts["evidence"] == '[{"source":"review"}]\n'
|