Download tests/test_runtime_migration.py from DiabetesCareChatbot/dmChatbotBackend: direct link, hf CLI and curl.
- Browser
- Download file 3.8 kB
-
https://huggingface.co/spaces/DiabetesCareChatbot/dmChatbotBackend/resolve/main/tests/test_runtime_migration.py
- Command line
-
hf download hf://spaces/DiabetesCareChatbot/dmChatbotBackend/tests/test_runtime_migration.py
-
curl -L -o test_runtime_migration.py https://huggingface.co/spaces/DiabetesCareChatbot/dmChatbotBackend/resolve/main/tests/test_runtime_migration.py
3.8 kB
| """Documentation-driven acceptance tests for roadmap phases 6 through 12.""" | |
| from __future__ import annotations | |
| import inspect | |
| import pytest | |
| from src.core.graph import _worker_skill_node | |
| from src.core.policy import PlatformGateService, PolicyEngine | |
| from src.runtime.cdm_runtime import TrendAnalysis | |
| from src.runtime.execution_context import ExecutionContext | |
| from src.runtime.metrics import RuntimeMetrics | |
| from src.runtime.worker_runtime import WorkerRuntime | |
| from src.skills.adapters import LEGACY_WORKER_FACTORIES | |
| from src.skills.registry import default_skill_registry | |
| from src.skills.runtime import SkillRuntime | |
| def test_phase6_registry_contains_all_non_clinical_worker_skills(): | |
| registry = default_skill_registry() | |
| assert { | |
| "caregiver-support", | |
| "diabetes-research", | |
| "diabetes-dietary-coach", | |
| } <= {skill.id for skill in registry.list_active()} | |
| def test_phase7_clinical_manifests_enforce_role_and_intent(): | |
| registry = default_skill_registry() | |
| runtime = SkillRuntime(registry) | |
| runtime.select("clinical-diagnosis-support", role="clinician", intent="diagnosis") | |
| with pytest.raises(PermissionError): | |
| runtime.select("clinical-diagnosis-support", role="patient", intent="diagnosis") | |
| with pytest.raises(PermissionError): | |
| runtime.select("clinical-diagnosis-support", role="clinician", intent="treatment") | |
| def test_phase8_cdm_trend_is_typed_and_survives_worker_flush(): | |
| trend = TrendAnalysis(summary="Glucose is stable.", metrics={"Glucose": {"trend": "stable"}}) | |
| context = ExecutionContext(user_query="Review my trends") | |
| context.metadata["cdm_trend_analysis"] = trend.as_dict() | |
| worker = WorkerRuntime(default_skill_registry()) | |
| worker.load_skill("cdm-health-coach") | |
| worker.flush_and_destroy() | |
| assert context.metadata["cdm_trend_analysis"] == { | |
| "trend_analysis": "Glucose is stable.", | |
| "trend_data": {"Glucose": {"trend": "stable"}}, | |
| } | |
| def test_phase9_failed_gate_cannot_publish_artifact(): | |
| state = {"gates": {"emergency": {"decision": "passed"}, "validation": {"decision": "failed"}, "safety": {"decision": "passed"}}} | |
| assert PlatformGateService.can_publish(state) is False | |
| invalidated = PlatformGateService.invalidate_artifact( | |
| {"response_artifacts": [{"status": "generated"}]}, "validation" | |
| ) | |
| assert invalidated["response_artifacts"][0]["status"] == "invalidated_by_validation" | |
| def test_phase10_graph_worker_surface_is_skill_based(): | |
| source = inspect.getsource(_worker_skill_node) | |
| assert "WorkerRuntime" in source | |
| assert "create_worker_adapter" in source | |
| def test_phase11_has_no_legacy_worker_singletons_in_graph_runtime(): | |
| import src.core.graph as graph | |
| assert "agent_instances" not in inspect.getsource(graph) | |
| def test_phase12_runtime_metrics_capture_lifecycle_and_context_counters(): | |
| metrics = RuntimeMetrics() | |
| metrics.record("runtime.created", runtime="WorkerRuntime") | |
| metrics.record("skill.loaded", runtime="WorkerRuntime", duration_ms=1.2) | |
| metrics.record("skill.executed", prompt_tokens=12, context_tokens=8) | |
| metrics.record("runtime.destroyed", runtime="WorkerRuntime") | |
| snapshot = metrics.snapshot() | |
| assert snapshot["event_count"] == 4 | |
| assert snapshot["durations_ms"]["skill.loaded"] == 1.2 | |
| assert snapshot["active_runtime_slots"] == 0 | |
| def test_policy_emergency_detection_is_deterministic(): | |
| assert PolicyEngine.check_emergency("The patient is unconscious") is True | |
| assert PolicyEngine.check_emergency("The patient wants meal planning") is False | |
| def test_phase6_compatibility_factories_are_explicitly_scoped(): | |
| assert set(LEGACY_WORKER_FACTORIES) >= { | |
| "caregiver-support", | |
| "diabetes-research", | |
| "diabetes-dietary-coach", | |
| } |