mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-08-18 00:47:23 +02:00
ci: add strict test evidence gates
This commit is contained in:
@@ -2,12 +2,37 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import socket
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
|
||||
_EXTERNAL_MARKERS = ("network", "download", "remote")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def offline_test_environment(request, monkeypatch):
|
||||
"""Fail accidental network access and force offline Hugging Face behavior."""
|
||||
if any(request.node.get_closest_marker(name) for name in _EXTERNAL_MARKERS):
|
||||
return
|
||||
|
||||
monkeypatch.setenv("HF_DATASETS_OFFLINE", "1")
|
||||
monkeypatch.setenv("HF_HUB_DISABLE_TELEMETRY", "1")
|
||||
monkeypatch.setenv("HF_HUB_OFFLINE", "1")
|
||||
monkeypatch.setenv("TRANSFORMERS_OFFLINE", "1")
|
||||
|
||||
def reject_network(*_args, **_kwargs):
|
||||
raise RuntimeError(
|
||||
"unmarked tests may not access the network; add an explicit "
|
||||
"network, download, or remote marker",
|
||||
)
|
||||
|
||||
monkeypatch.setattr(socket, "create_connection", reject_network)
|
||||
monkeypatch.setattr(socket.socket, "connect", reject_network)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Fixtures
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -1067,7 +1067,12 @@ class TestAttentionHeadSurgery:
|
||||
# SOTA technique #6: SAE feature-level abliteration
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@pytest.mark.filterwarnings(
|
||||
"ignore:SAE held-out reconstruction MSE.*:UserWarning",
|
||||
)
|
||||
class TestSAEAbliteration:
|
||||
"""Exercise deliberately undertrained SAEs without weakening global warnings."""
|
||||
|
||||
def test_sae_train_and_reconstruct(self):
|
||||
"""SAE should train and reconstruct activations."""
|
||||
from obliteratus.analysis.sae_abliteration import train_sae
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
"""Tests for the separate line/branch coverage policy gate."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
SCRIPT = Path(__file__).parents[1] / "scripts" / "check_coverage_thresholds.py"
|
||||
SPEC = importlib.util.spec_from_file_location("check_coverage_thresholds", SCRIPT)
|
||||
assert SPEC is not None and SPEC.loader is not None
|
||||
MODULE = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(MODULE)
|
||||
|
||||
|
||||
def _report(line: float = 49.0, branch: float = 36.0) -> dict[str, object]:
|
||||
return {
|
||||
"totals": {
|
||||
"percent_statements_covered": line,
|
||||
"percent_branches_covered": branch,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_validate_coverage_accepts_exact_floors():
|
||||
assert MODULE.validate_coverage(
|
||||
_report(), min_line=49.0, min_branch=36.0,
|
||||
) == []
|
||||
|
||||
|
||||
def test_validate_coverage_reports_each_regression():
|
||||
failures = MODULE.validate_coverage(
|
||||
_report(line=48.9, branch=35.9), min_line=49.0, min_branch=36.0,
|
||||
)
|
||||
|
||||
assert failures == [
|
||||
"line coverage 48.90% is below the 49.00% floor",
|
||||
"branch coverage 35.90% is below the 36.00% floor",
|
||||
]
|
||||
|
||||
|
||||
def test_validate_coverage_rejects_malformed_totals():
|
||||
assert MODULE.validate_coverage(
|
||||
{}, min_line=49.0, min_branch=36.0,
|
||||
) == ["coverage report is missing the totals object"]
|
||||
@@ -369,7 +369,12 @@ class TestActivationPatcher:
|
||||
# Tests: Enhanced SAE Decomposition Pipeline
|
||||
# ===========================================================================
|
||||
|
||||
@pytest.mark.filterwarnings(
|
||||
"ignore:SAE held-out reconstruction MSE.*:UserWarning",
|
||||
)
|
||||
class TestSAEDecompositionPipeline:
|
||||
"""Use small training budgets while keeping unrelated warnings fatal."""
|
||||
|
||||
def test_basic_pipeline(self):
|
||||
harmful, harmless, _ = _make_activations(hidden_dim=16, n_per_class=30, separation=2.0)
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
"""Executable contracts for the mandatory CPU/offline pytest policy."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import socket
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def test_unmarked_tests_run_with_offline_hugging_face_policy():
|
||||
assert os.environ["HF_DATASETS_OFFLINE"] == "1"
|
||||
assert os.environ["HF_HUB_DISABLE_TELEMETRY"] == "1"
|
||||
assert os.environ["HF_HUB_OFFLINE"] == "1"
|
||||
assert os.environ["TRANSFORMERS_OFFLINE"] == "1"
|
||||
|
||||
|
||||
def test_unmarked_tests_cannot_open_network_connections():
|
||||
with pytest.raises(RuntimeError, match="unmarked tests may not access the network"):
|
||||
socket.create_connection(("example.invalid", 443))
|
||||
Reference in New Issue
Block a user