-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_kernel.py
More file actions
191 lines (126 loc) · 5.18 KB
/
Copy pathtest_kernel.py
File metadata and controls
191 lines (126 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"""
Smoke tests for src/kernel — one test per engine module.
Each test asserts:
1. The engine class is importable via the package public API.
2. It is a subclass of KernelEngine.
3. It exposes a callable ``process`` method.
4. ``process`` returns a dict when called with a minimal valid context.
"""
import pytest
from kernel import (
KernelEngine,
RegistryEngine,
EventStoreEngine,
WorkflowEngine,
DecisionEngine,
DocumentEngine,
OutcomeEngine,
)
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
def _is_kernel_engine(cls) -> bool:
return issubclass(cls, KernelEngine)
def _has_process(instance) -> bool:
return callable(getattr(instance, "process", None))
# ---------------------------------------------------------------------------
# RegistryEngine
# ---------------------------------------------------------------------------
def test_registry_engine_is_kernel_engine():
assert _is_kernel_engine(RegistryEngine)
def test_registry_engine_has_process():
assert _has_process(RegistryEngine())
def test_registry_engine_process_returns_dict():
result = RegistryEngine().process({"object_type": "user"})
assert isinstance(result, dict)
assert "results" in result
assert "total" in result
def test_registry_engine_name():
assert RegistryEngine().name == "registry"
# ---------------------------------------------------------------------------
# EventStoreEngine
# ---------------------------------------------------------------------------
def test_event_store_engine_is_kernel_engine():
assert _is_kernel_engine(EventStoreEngine)
def test_event_store_engine_has_process():
assert _has_process(EventStoreEngine())
def test_event_store_engine_process_returns_dict():
result = EventStoreEngine().process({"action": "query"})
assert isinstance(result, dict)
assert "events" in result
def test_event_store_engine_name():
assert EventStoreEngine().name == "event_store"
# ---------------------------------------------------------------------------
# WorkflowEngine
# ---------------------------------------------------------------------------
def test_workflow_engine_is_kernel_engine():
assert _is_kernel_engine(WorkflowEngine)
def test_workflow_engine_has_process():
assert _has_process(WorkflowEngine())
def test_workflow_engine_process_returns_dict():
result = WorkflowEngine().process({"workflow_name": "intake"})
assert isinstance(result, dict)
assert "next_steps" in result
assert "updated_state" in result
def test_workflow_engine_name():
assert WorkflowEngine().name == "workflow"
# ---------------------------------------------------------------------------
# DecisionEngine
# ---------------------------------------------------------------------------
def test_decision_engine_is_kernel_engine():
assert _is_kernel_engine(DecisionEngine)
def test_decision_engine_has_process():
assert _has_process(DecisionEngine())
def test_decision_engine_process_returns_dict():
result = DecisionEngine().process(
{"decision_type": "eligibility", "subject": {"id": "abc"}}
)
assert isinstance(result, dict)
assert "choice" in result
assert "rationale" in result
def test_decision_engine_name():
assert DecisionEngine().name == "decision"
# ---------------------------------------------------------------------------
# DocumentEngine
# ---------------------------------------------------------------------------
def test_document_engine_is_kernel_engine():
assert _is_kernel_engine(DocumentEngine)
def test_document_engine_has_process():
assert _has_process(DocumentEngine())
def test_document_engine_process_returns_dict():
result = DocumentEngine().process(
{"action": "create", "document": {"title": "Intake Form", "document_type": "form"}}
)
assert isinstance(result, dict)
assert "document_id" in result
assert "version" in result
assert "storage_ref" in result
def test_document_engine_name():
assert DocumentEngine().name == "document"
# ---------------------------------------------------------------------------
# OutcomeEngine
# ---------------------------------------------------------------------------
def test_outcome_engine_is_kernel_engine():
assert _is_kernel_engine(OutcomeEngine)
def test_outcome_engine_has_process():
assert _has_process(OutcomeEngine())
def test_outcome_engine_process_returns_dict():
result = OutcomeEngine().process(
{
"action": "summarise",
"outcome_type": "employment",
"subject_type": "case",
"subject_id": "xyz",
}
)
assert isinstance(result, dict)
assert "summary" in result
def test_outcome_engine_name():
assert OutcomeEngine().name == "outcome"
# ---------------------------------------------------------------------------
# Package-level: __doc__ smoke test
# ---------------------------------------------------------------------------
def test_kernel_package_docstring_references_engines():
import kernel
assert kernel.__doc__ is not None
assert "RegistryEngine" in kernel.__doc__