feat: integrate minute rectification safeguards

This commit is contained in:
Jesse_Chen
2026-07-22 09:58:32 +08:00
parent d5453681ad
commit d7d9703364
16 changed files with 639 additions and 36 deletions
+3 -2
View File
@@ -1570,6 +1570,7 @@ def test_capability_audit_scans_registry_and_local_sources() -> None:
assert audit['surfaces']['app_routes'] == ['admin/codes', 'home', 'login']
assert set(audit['surfaces']['app_visible_topics']) == {
'Birth Rectification',
'Case Validation',
'Synastry 16-factor',
}
assert '/api/deep_varga_avastha' in audit['surfaces']['api_endpoints']
@@ -1599,14 +1600,14 @@ def test_capability_audit_scans_registry_and_local_sources() -> None:
assert all('ux_next_action' in row for row in ux['next_queue'])
ux_by_id = {row['id']: row for row in ux['rows']}
assert ux_by_id['birth_time_rectifier']['ux_level'] in {'excellent', 'usable'}
assert ux_by_id['case_validator']['ux_level'] == 'excellent'
assert ux_by_id['synastry_16factor']['ux_level'] == 'excellent'
for technique_id in [
'ashtakavarga_pav',
'ashtakavarga_sodhita',
'bhava_bala',
'career_engine',
'case_validator',
'deep_varga_avastha',
'deep_varga_avastha',
'divisional_yoga',
'kakshya',
'kp_system',
@@ -25,3 +25,6 @@ def test_scanner_reports_real_divisional_transitions(monkeypatch):
assert report["transitions"]
assert report["pending_layers"] == ["UL", "A7", "A10", "KP_cusp"]
assert report["rows"][0]["divisional_ascendants"]["D9"] in {"Aries", "Taurus"}
assert report["input_contract"]["settings"]["node_mode"] == "mean"
assert report["rows"][0]["input_fingerprint"] != report["rows"][1]["input_fingerprint"]
assert report["stability_contract"]["minute_confirmation_allowed"] is False
@@ -0,0 +1,73 @@
import hashlib
import json
from copy import deepcopy
from pathlib import Path
from scripts.minute_rectification_holdout_intake import DEFAULT_INTAKE, append_case
from scripts.minute_rectification_holdout_validator import DEFAULT_MANIFEST
def _reviewed_case() -> dict:
case = deepcopy(json.loads(DEFAULT_MANIFEST.read_text(encoding="utf-8"))["cases"][0])
case["case_id"] = "new-reviewed-case"
case["adjudicator"] = "independent-reviewer"
case["independent_human_reviewed"] = True
case["frozen_before_scoring"] = True
case["false_minute_commitments"] = [
{
"offset_minutes": offset,
"commitment_hash": hashlib.sha256(f"control:{offset}".encode()).hexdigest(),
}
for offset in case["false_minute_offsets"]
]
return case
def _queue(path: Path) -> None:
path.write_text(json.dumps({
"schema_version": "minute-rectification-holdout-v4-intake",
"minimum_gate": {
"events_per_case": 3,
"domains_per_case": 2,
"independent_event_sources_per_case": 2,
"negative_minutes_per_case": 4,
"day_precision_events_per_case": 3,
},
"cases": [],
}), encoding="utf-8")
def test_intake_appends_reviewed_case_but_keeps_release_blocked(tmp_path: Path) -> None:
path = tmp_path / "intake.json"
_queue(path)
report = append_case(path, _reviewed_case())
data = json.loads(path.read_text(encoding="utf-8"))
assert report["appended"] is True
assert report["verified_minute_claim_allowed"] is False
assert data["production_tuning_allowed"] is False
assert data["verified_minute_claim_allowed"] is False
assert data["cases"][0]["ingested_at"].endswith("Z")
def test_intake_rejects_missing_review_and_commitments(tmp_path: Path) -> None:
path = tmp_path / "intake.json"
_queue(path)
case = _reviewed_case()
case["independent_human_reviewed"] = False
case["false_minute_commitments"] = []
report = append_case(path, case)
assert report["appended"] is False
assert "independent_review_not_attested" in report["errors"]
assert "false_minute_commitments_do_not_match_offsets" in report["errors"]
def test_default_intake_is_non_production_and_empty() -> None:
data = json.loads(DEFAULT_INTAKE.read_text(encoding="utf-8"))
assert data["cases"] == []
assert data["production_tuning_allowed"] is False
assert data["verified_minute_claim_allowed"] is False
@@ -1,3 +1,4 @@
import hashlib
import json
from copy import deepcopy
from pathlib import Path
@@ -49,6 +50,52 @@ def test_v3_validator_requires_content_source_audit_before_freeze(tmp_path: Path
assert report["status"] == "blocked_awaiting_public_aa_cases"
def _add_v4_review_safeguards(manifest: dict) -> None:
manifest["schema_version"] = "minute-rectification-holdout-v4"
manifest["source_audit_status"] = "passed_before_freeze"
manifest["minimum_gate"]["day_precision_events_per_case"] = 3
for case in manifest["cases"]:
case["adjudicator"] = "independent-reviewer"
case["independent_human_reviewed"] = True
case["frozen_before_scoring"] = True
case["false_minute_commitments"] = [
{
"offset_minutes": offset,
"commitment_hash": hashlib.sha256(
f"{case['case_id']}:{offset}:sealed".encode()
).hexdigest(),
}
for offset in case["false_minute_offsets"]
]
def test_v4_validator_accepts_reviewed_cases_with_committed_false_minutes(tmp_path: Path) -> None:
manifest = deepcopy(_manifest())
_add_v4_review_safeguards(manifest)
path = tmp_path / "v4.json"
path.write_text(json.dumps(manifest), encoding="utf-8")
report = validate(path)
assert report["manifest_errors"] == []
assert report["invalid_case_details"] == []
def test_v4_validator_rejects_unreviewed_or_uncommitted_cases(tmp_path: Path) -> None:
manifest = deepcopy(_manifest())
_add_v4_review_safeguards(manifest)
case = manifest["cases"][0]
case["independent_human_reviewed"] = False
case["false_minute_commitments"].pop()
path = tmp_path / "invalid-v4.json"
path.write_text(json.dumps(manifest), encoding="utf-8")
errors = validate(path)["invalid_case_details"][0]["errors"]
assert "independent_review_not_attested" in errors
assert "false_minute_commitments_do_not_match_offsets" in errors
def test_validator_rejects_tuning_case_and_non_independent_event_source(tmp_path: Path) -> None:
manifest = deepcopy(_manifest())
case = manifest["cases"][0]
@@ -0,0 +1,24 @@
import json
from pathlib import Path
from scripts.minute_rectification_source_audit import build_source_audit
def test_source_audit_supports_current_holdout_shape_and_counts_day_precision(tmp_path: Path) -> None:
source = tmp_path / "cases.json"
source.write_text(json.dumps({"cases": [{
"case_id": "public-case",
"subject_label": "Public case",
"birth": {"source": {"rodden_rating": "AA", "url": "https://example.test/birth"}},
"events": [
{"date": "2001-01-01"},
{"date": "2002"},
],
}]}), encoding="utf-8")
report = build_source_audit([source])
assert report["public_aa_case_count"] == 1
assert report["cases"][0]["existing_day_precision_event_count"] == 1
assert report["cases"][0]["additional_day_precision_events_required"] == 2
assert report["production_tuning_allowed"] is False
@@ -0,0 +1,47 @@
from scripts.rectification_input_contract import (
candidate_input_fingerprint,
canonical_birth_input,
semantic_evidence_hash,
stability_probe_contract,
)
CASE = {
"year": 1990,
"month": 1,
"day": 1,
"hour": 12,
"minute": 0,
"lat": 0.0,
"lon": 0.0,
"tz": 0.0,
}
def test_contract_uses_deployed_mean_node_default_and_stable_identity() -> None:
reordered = {key: CASE[key] for key in reversed(CASE)}
assert canonical_birth_input(CASE)["node_mode"] == "mean"
assert candidate_input_fingerprint(CASE) == candidate_input_fingerprint(reordered)
assert candidate_input_fingerprint(CASE) == candidate_input_fingerprint({**CASE, "nodeMode": "MEAN"})
def test_candidate_fingerprint_changes_with_calculation_input() -> None:
assert candidate_input_fingerprint(CASE) != candidate_input_fingerprint({**CASE, "minute": 1})
assert candidate_input_fingerprint(CASE) != candidate_input_fingerprint({**CASE, "node_mode": "true"})
def test_stability_contract_records_adjacent_probes_without_confirming() -> None:
contract = stability_probe_contract(CASE)
assert [probe["offset_minutes"] for probe in contract["probes"]] == [-5, -2, -1, 1, 2, 5]
assert contract["minute_confirmation_allowed"] is False
assert contract["status"] == "pending_score_comparison"
def test_semantic_hash_normalizes_only_known_order_insensitive_lists() -> None:
left = {"aspects": {"gives": ["Mars", "Saturn"]}, "ordered_scores": [2, 1]}
reordered_aspects = {"ordered_scores": [2, 1], "aspects": {"gives": ["Saturn", "Mars"]}}
reordered_scores = {"ordered_scores": [1, 2], "aspects": {"gives": ["Saturn", "Mars"]}}
assert semantic_evidence_hash(left) == semantic_evidence_hash(reordered_aspects)
assert semantic_evidence_hash(left) != semantic_evidence_hash(reordered_scores)
@@ -1,6 +1,5 @@
from scripts.rectification_three_engine_packet import build_packet, case_hash
CASE = {"year": 1990, "month": 1, "day": 1, "hour": 12, "minute": 0, "lat": 0.0, "lon": 0.0, "tz": 0.0}
@@ -10,6 +9,8 @@ def test_packet_is_private_and_never_confirms(monkeypatch) -> None:
monkeypatch.setattr("scripts.rectification_three_engine_packet._jyotishganit_d1", lambda _: {"Sun": "Aries"})
packet = build_packet(CASE)
assert packet["case_hash"] == case_hash(CASE)
assert packet["input_contract_hash"] == packet["case_hash"]
assert packet["stability_contract"]["minute_confirmation_allowed"] is False
assert "year" not in str(packet)
assert packet["can_confirm"] is False
assert packet["vedastro"]["status"] == "requires_gateway_raw_archive"