66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
import numpy as np
|
|
import pytest
|
|
|
|
from validate_historical_oracle_acceptance import array_digest, validate
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
def test_validate_uses_runner_semantic_array_digest(tmp_path):
|
|
output_dir = tmp_path / "run"
|
|
checkpoints = output_dir / "checkpoints"
|
|
checkpoints.mkdir(parents=True)
|
|
values = np.array([1.0, 2.0], dtype=np.float64)
|
|
status = {
|
|
"artifact": "HISTORICAL_FEATURE_ORACLE_FULL_STATUS_V1",
|
|
"status": "PASS",
|
|
"completed_features": 711,
|
|
"checkpoints": [
|
|
{
|
|
"request_id": f"feature-{index}",
|
|
"path": f"feature-{index}.npy",
|
|
"dtype": "<f8",
|
|
"shape": [2],
|
|
"sha256": array_digest(values),
|
|
}
|
|
for index in range(711)
|
|
],
|
|
}
|
|
for checkpoint in status["checkpoints"]:
|
|
np.save(checkpoints / checkpoint["path"], values, allow_pickle=False)
|
|
(output_dir / "final_status.json").write_text(json.dumps(status), encoding="utf-8")
|
|
|
|
assert validate(output_dir)["status"] == "PASS"
|
|
|
|
|
|
def test_validate_rejects_raw_npy_file_digest(tmp_path):
|
|
output_dir = tmp_path / "run"
|
|
checkpoints = output_dir / "checkpoints"
|
|
checkpoints.mkdir(parents=True)
|
|
values = np.array([1.0], dtype=np.float64)
|
|
np.save(checkpoints / "feature.npy", values, allow_pickle=False)
|
|
status = {
|
|
"artifact": "HISTORICAL_FEATURE_ORACLE_FULL_STATUS_V1",
|
|
"status": "PASS",
|
|
"completed_features": 711,
|
|
"checkpoints": [
|
|
{
|
|
"request_id": f"feature-{index}",
|
|
"path": f"feature-{index}.npy",
|
|
"dtype": "<f8",
|
|
"shape": [1],
|
|
"sha256": "0" * 64,
|
|
}
|
|
for index in range(711)
|
|
],
|
|
}
|
|
for checkpoint in status["checkpoints"]:
|
|
np.save(checkpoints / checkpoint["path"], values, allow_pickle=False)
|
|
(output_dir / "final_status.json").write_text(json.dumps(status), encoding="utf-8")
|
|
|
|
with pytest.raises(ValueError, match="semantic digest mismatch"):
|
|
validate(output_dir)
|