|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from sourceos_syncd.policy import PolicyRequest, decision_counts, evaluate_policy, evaluate_report_policy |
| 4 | +from sourceos_syncd.store_reports import init_store, snapshot_from_store |
| 5 | + |
| 6 | + |
| 7 | +def test_secure_lane_agent_access_is_denied(): |
| 8 | + decision = evaluate_policy(PolicyRequest(action="agent_access", lane="secure")) |
| 9 | + assert decision.status == "denied" |
| 10 | + assert decision.reason == "secure_lane_requires_explicit_grant" |
| 11 | + |
| 12 | + |
| 13 | +def test_secure_lane_indexing_is_redacted(): |
| 14 | + decision = evaluate_policy(PolicyRequest(action="index", lane="secure")) |
| 15 | + assert decision.status == "redacted" |
| 16 | + assert decision.reason == "secure_lane_indexing_requires_redaction" |
| 17 | + |
| 18 | + |
| 19 | +def test_unknown_action_is_deferred(): |
| 20 | + decision = evaluate_policy(PolicyRequest(action="unknown", lane="normal")) |
| 21 | + assert decision.status == "deferred" |
| 22 | + assert decision.reason == "unknown_action" |
| 23 | + |
| 24 | + |
| 25 | +def test_report_policy_counts_include_all_statuses(): |
| 26 | + lanes = [{"name": "normal"}, {"name": "secure"}, {"name": "repair"}, {"name": "ephemeral"}] |
| 27 | + decisions = evaluate_report_policy(lanes) |
| 28 | + counts = decision_counts(decisions) |
| 29 | + assert counts["allowed"] > 0 |
| 30 | + assert counts["denied"] > 0 |
| 31 | + assert counts["redacted"] > 0 |
| 32 | + assert counts["deferred"] > 0 |
| 33 | + |
| 34 | + |
| 35 | +def test_store_backed_snapshot_includes_policy_summary(tmp_path): |
| 36 | + init_store(tmp_path) |
| 37 | + report = snapshot_from_store(tmp_path) |
| 38 | + assert report["policy"]["policy_engine"] == "policy-fabric-local-stub" |
| 39 | + assert report["policy"]["policy_version"] == "v0.1.0-local-stub" |
| 40 | + assert report["diagnosis"]["policy"]["engine"] == "policy-fabric-local-stub" |
| 41 | + assert report["diagnosis"]["policy"]["counts"]["allowed"] > 0 |
0 commit comments