-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_golden_vectors.py
More file actions
58 lines (45 loc) · 1.93 KB
/
test_golden_vectors.py
File metadata and controls
58 lines (45 loc) · 1.93 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
# SPDX-License-Identifier: MIT
"""Golden vector tests — framework for verifying deterministic evaluation.
Each subdirectory under tests/vectors/ contains a vector.json with an inline
ARB model, input facts/timestamps, and expected results.
The same vectors are tested by:
- Python reference evaluator (this file + test_cross_validation.py)
- Generated C runtime under Zephyr
- Blob runtime under Zephyr
NOTE: The comprehensive cross-validation tests are in test_cross_validation.py.
This file is kept for backwards compatibility with the original vector
discovery mechanism.
"""
import json
from pathlib import Path
import pytest
from arbiter.evaluator import ArbiterEvaluator
VECTORS_DIR = Path(__file__).resolve().parent.parent / "vectors"
def _load_vectors():
"""Discover golden vector test cases using vector.json format."""
if not VECTORS_DIR.exists():
return []
vectors = []
for d in sorted(VECTORS_DIR.iterdir()):
if d.is_dir() and (d / "vector.json").exists():
vectors.append(d.name)
return vectors
@pytest.mark.parametrize("vector_name", _load_vectors() or ["placeholder"])
def test_golden_vector(vector_name):
"""Verify golden vector produces expected result via Python evaluator."""
if vector_name == "placeholder":
pytest.skip("No golden vectors yet — add to tests/vectors/")
vector_dir = VECTORS_DIR / vector_name
vec = json.loads((vector_dir / "vector.json").read_text(encoding="utf-8"))
model_data = vec["model"]
expected = vec["expected"]
ev = ArbiterEvaluator(model_data)
for fact_name, value in vec.get("facts", {}).items():
ev.set_fact(fact_name, value)
for fact_name, ms in vec.get("timestamps", {}).items():
ev.set_timestamp(fact_name, ms)
snap_ts = vec.get("snapshot_timestamp_ms", 0)
if snap_ts:
ev.set_snapshot_timestamp(snap_ts)
result = ev.eval()
assert result.fired_rules == expected["fired_rules"]