mirror of
https://github.com/wiltodelta/remove-ai-watermarks.git
synced 2026-10-14 21:40:47 +02:00
Add Perth and PixelSeal benchmark oracles
This commit is contained in:
12 files changed
+1141
-24
No files matched your search
@@ -0,0 +1,31 @@
|
||||
"""Tests for the pinned Perth oracle's pure contract."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
SCRIPTS = Path(__file__).resolve().parents[1] / "scripts"
|
||||
if str(SCRIPTS) not in sys.path:
|
||||
sys.path.insert(0, str(SCRIPTS))
|
||||
|
||||
import perth_oracle # noqa: E402
|
||||
|
||||
|
||||
def test_detection_rule_is_upstream_round_at_one_half() -> None:
|
||||
assert perth_oracle.PerthReading(0.499).detected is False
|
||||
assert perth_oracle.PerthReading(0.5).detected is False
|
||||
assert perth_oracle.PerthReading(0.501).detected is True
|
||||
|
||||
|
||||
def test_checkpoint_and_source_are_immutable_pins() -> None:
|
||||
assert len(perth_oracle.SOURCE_COMMIT) == 40
|
||||
assert len(perth_oracle.CHECKPOINT_SHA256) == 64
|
||||
assert all(char in "0123456789abcdef" for char in perth_oracle.CHECKPOINT_SHA256)
|
||||
|
||||
|
||||
def test_perth_has_no_message_payload_contract() -> None:
|
||||
reading = perth_oracle.PerthReading(0.75)
|
||||
|
||||
assert not hasattr(reading, "decoded_bits")
|
||||
assert not hasattr(perth_oracle, "message_bits")
|
||||
@@ -0,0 +1,64 @@
|
||||
"""Tests for the pinned PixelSeal oracle's pure helpers."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
SCRIPTS = Path(__file__).resolve().parents[1] / "scripts"
|
||||
if str(SCRIPTS) not in sys.path:
|
||||
sys.path.insert(0, str(SCRIPTS))
|
||||
|
||||
import pixelseal_oracle # noqa: E402
|
||||
|
||||
|
||||
class TestMessage:
|
||||
def test_message_is_deterministic_and_256_bits(self) -> None:
|
||||
first = pixelseal_oracle.message_bits()
|
||||
second = pixelseal_oracle.message_bits()
|
||||
|
||||
assert first == second
|
||||
assert len(first) == 256
|
||||
assert set(first) <= {0, 1}
|
||||
|
||||
def test_seed_changes_the_message(self) -> None:
|
||||
assert pixelseal_oracle.message_bits(seed=8) != pixelseal_oracle.message_bits(seed=7)
|
||||
|
||||
|
||||
class TestReading:
|
||||
def test_label_is_hex_of_decoded_bits(self) -> None:
|
||||
reading = pixelseal_oracle.PixelSealReading(1.0, tuple([1] * 8 + [0] * 8))
|
||||
|
||||
assert reading.label == "ff00"
|
||||
|
||||
def test_detection_rule_is_the_documented_adapter_threshold(self) -> None:
|
||||
assert pixelseal_oracle.PixelSealReading(0.899, ()).detected is False
|
||||
assert pixelseal_oracle.PixelSealReading(0.9, ()).detected is True
|
||||
|
||||
|
||||
class TestPins:
|
||||
@pytest.mark.parametrize(
|
||||
"value",
|
||||
[pixelseal_oracle.CHECKPOINT_SHA256, pixelseal_oracle.MODEL_CARD_SHA256],
|
||||
)
|
||||
def test_digests_are_sha256(self, value: str) -> None:
|
||||
assert len(value) == 64
|
||||
assert all(char in "0123456789abcdef" for char in value)
|
||||
|
||||
def test_source_commit_is_pinned(self) -> None:
|
||||
assert len(pixelseal_oracle.SOURCE_COMMIT) == 40
|
||||
|
||||
|
||||
def test_cache_dir_env_override_is_honored(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
||||
original_cache = pixelseal_oracle.CACHE_DIR
|
||||
try:
|
||||
with monkeypatch.context() as environment:
|
||||
environment.setenv("PIXELSEAL_CACHE_DIR", str(tmp_path / "cache"))
|
||||
importlib.reload(pixelseal_oracle)
|
||||
assert tmp_path / "cache" == pixelseal_oracle.CACHE_DIR
|
||||
finally:
|
||||
importlib.reload(pixelseal_oracle)
|
||||
assert original_cache == pixelseal_oracle.CACHE_DIR
|
||||
@@ -393,10 +393,12 @@ def test_jsonl_writer_refuses_overwrite_and_emits_strict_json(tmp_path: Path) ->
|
||||
def test_builtin_adapters_name_their_exact_source_files() -> None:
|
||||
adapters = MODULE.default_adapters()
|
||||
|
||||
assert set(adapters) == {"dwt-dct", "trustmark", "audioseal", "videoseal"}
|
||||
assert set(adapters) == {"dwt-dct", "trustmark", "pixelseal", "audioseal", "perth", "videoseal"}
|
||||
assert adapters["dwt-dct"].source_file.name == "invisible_watermark.py"
|
||||
assert adapters["trustmark"].source_file.name == "trustmark_detector.py"
|
||||
assert adapters["pixelseal"].source_file.name == "pixelseal_oracle.py"
|
||||
assert adapters["audioseal"].source_file.name == "audioseal_oracle.py"
|
||||
assert adapters["perth"].source_file.name == "perth_oracle.py"
|
||||
assert adapters["videoseal"].source_file.name == "videoseal_oracle.py"
|
||||
|
||||
|
||||
@@ -741,6 +743,20 @@ def test_detection_record_omits_temporal_for_non_temporal_adapters() -> None:
|
||||
assert "temporal" not in MODULE._detection_record(outcome, "not_detected", None)
|
||||
|
||||
|
||||
def test_detection_record_carries_message_accuracy_and_presence_score() -> None:
|
||||
outcome = MODULE.DetectorOutcome(
|
||||
status="detected",
|
||||
label="fixed-message",
|
||||
message_bit_accuracy=0.996,
|
||||
score=0.75,
|
||||
)
|
||||
|
||||
record = MODULE._detection_record(outcome, "detected", 2.0)
|
||||
|
||||
assert record["message_bit_accuracy"] == 0.996
|
||||
assert record["score"] == 0.75
|
||||
|
||||
|
||||
def test_run_benchmark_records_videoseal_temporal_evidence(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
if shutil.which("ffmpeg") is None:
|
||||
pytest.skip("video rows decode through the system ffmpeg")
|
||||
|
||||
Reference in new issue
Block a user