test descriptions
This commit is contained in:
@@ -21,27 +21,32 @@ MODEL = "stub-model"
|
||||
|
||||
|
||||
def test_newcomer_gets_elevated_audit_rate():
|
||||
"Newcomer gets elevated audit rate\n\nTags: general"
|
||||
|
||||
sampler = AdaptiveAuditSampler()
|
||||
rate = sampler.wallet_base_rate(completed_job_count=0, reputation=1.0)
|
||||
assert 0.20 <= rate <= 0.30
|
||||
|
||||
|
||||
def test_veteran_in_good_standing_floors_near_target():
|
||||
"Veteran in good standing floors near target\n\nTags: general"
|
||||
|
||||
sampler = AdaptiveAuditSampler()
|
||||
rate = sampler.wallet_base_rate(completed_job_count=1000, reputation=1.0)
|
||||
assert rate == pytest.approx(0.02)
|
||||
|
||||
|
||||
def test_veteran_rate_never_drops_below_floor():
|
||||
"Veteran rate never drops below floor\n\nTags: general"
|
||||
|
||||
sampler = AdaptiveAuditSampler(AuditRateConfig(veteran_floor=0.02))
|
||||
rate = sampler.wallet_base_rate(completed_job_count=10_000, reputation=1.0)
|
||||
assert rate >= 0.02
|
||||
|
||||
|
||||
def test_low_reputation_wallet_sampled_more_than_high_reputation_wallet():
|
||||
"""Red (test-first item 1): a uniform sampler ignores reputation. A
|
||||
low-reputation wallet must get a higher rate than a high-reputation one
|
||||
with the same tenure."""
|
||||
"Red (test-first item 1): a uniform sampler ignores reputation.\n\nTags: security, wallet"
|
||||
|
||||
sampler = AdaptiveAuditSampler()
|
||||
low_rep_rate = sampler.sample_rate_for(completed_job_count=200, reputation=0.1)
|
||||
high_rep_rate = sampler.sample_rate_for(completed_job_count=200, reputation=1.0)
|
||||
@@ -49,6 +54,8 @@ def test_low_reputation_wallet_sampled_more_than_high_reputation_wallet():
|
||||
|
||||
|
||||
def test_low_reputation_escalates_even_for_a_tenured_wallet():
|
||||
"Low reputation escalates even for a tenured wallet\n\nTags: security, wallet"
|
||||
|
||||
sampler = AdaptiveAuditSampler()
|
||||
rate = sampler.wallet_base_rate(completed_job_count=1000, reputation=0.0)
|
||||
assert rate == pytest.approx(sampler.config.newcomer_rate)
|
||||
@@ -58,9 +65,8 @@ def test_low_reputation_escalates_even_for_a_tenured_wallet():
|
||||
|
||||
|
||||
def test_fleet_wide_audit_rate_tracks_configured_target_within_one_point():
|
||||
"""Test-first item 2: over >=1000 requests with a fixed seed and a mixed
|
||||
wallet population, the measured fleet audit rate lands within +-1.0
|
||||
percentage point of the configured 5% target."""
|
||||
"Test-first item 2: over >=1000 requests with a fixed seed and a mixed\n\nTags: general"
|
||||
|
||||
sampler = AdaptiveAuditSampler(random_seed=1234)
|
||||
rng = random.Random(99)
|
||||
|
||||
@@ -82,6 +88,8 @@ def test_fleet_wide_audit_rate_tracks_configured_target_within_one_point():
|
||||
|
||||
|
||||
def test_fleet_wide_audit_rate_respects_custom_target():
|
||||
"Fleet wide audit rate respects custom target\n\nTags: general"
|
||||
|
||||
sampler = AdaptiveAuditSampler(AuditRateConfig(target_rate=0.10), random_seed=42)
|
||||
audited = sum(
|
||||
1
|
||||
@@ -93,6 +101,8 @@ def test_fleet_wide_audit_rate_respects_custom_target():
|
||||
|
||||
|
||||
def test_sampling_is_deterministic_for_a_fixed_seed():
|
||||
"Sampling is deterministic for a fixed seed\n\nTags: general"
|
||||
|
||||
sampler_a = AdaptiveAuditSampler(random_seed=7)
|
||||
sampler_b = AdaptiveAuditSampler(random_seed=7)
|
||||
decisions_a = [sampler_a.should_audit(completed_job_count=0, reputation=1.0) for _ in range(200)]
|
||||
@@ -104,6 +114,8 @@ def test_sampling_is_deterministic_for_a_fixed_seed():
|
||||
|
||||
|
||||
def test_tripwire_flag_bumps_audit_rate_for_that_wallet():
|
||||
"Tripwire flag bumps audit rate for that wallet\n\nTags: security, wallet"
|
||||
|
||||
sampler = AdaptiveAuditSampler()
|
||||
normal_rate = sampler.sample_rate_for(completed_job_count=800, reputation=1.0, tripwire=False)
|
||||
flagged_rate = sampler.sample_rate_for(completed_job_count=800, reputation=1.0, tripwire=True)
|
||||
@@ -111,11 +123,8 @@ def test_tripwire_flag_bumps_audit_rate_for_that_wallet():
|
||||
|
||||
|
||||
def test_tripwire_does_not_change_other_wallets_rate():
|
||||
"""A tripwire hit must never leak the multiplier into the shared
|
||||
budget-balance history -- only the wallet's un-boosted base rate is
|
||||
recorded, so a flagged decision affects the running budget scale exactly
|
||||
like a plain decision for the same wallet would, and never inflates or
|
||||
depresses everyone else's rate on top of that."""
|
||||
"A tripwire hit must never leak the multiplier into the shared\n\nTags: security, wallet"
|
||||
|
||||
flagged = AdaptiveAuditSampler(random_seed=5)
|
||||
flagged.should_audit(completed_job_count=800, reputation=1.0, tripwire=True)
|
||||
|
||||
@@ -128,15 +137,21 @@ def test_tripwire_does_not_change_other_wallets_rate():
|
||||
|
||||
|
||||
def test_detect_output_tripwire_flags_repetition_loop():
|
||||
"Detect output tripwire flags repetition loop\n\nTags: general"
|
||||
|
||||
degenerate = " ".join(["loop"] * 20)
|
||||
assert detect_output_tripwire(degenerate) is True
|
||||
|
||||
|
||||
def test_detect_output_tripwire_flags_empty_output():
|
||||
"Detect output tripwire flags empty output\n\nTags: general"
|
||||
|
||||
assert detect_output_tripwire("") is True
|
||||
|
||||
|
||||
def test_detect_output_tripwire_passes_normal_prose():
|
||||
"Detect output tripwire passes normal prose\n\nTags: general"
|
||||
|
||||
normal = "The quick brown fox jumps over the lazy dog near the riverbank."
|
||||
assert detect_output_tripwire(normal) is False
|
||||
|
||||
@@ -163,8 +178,8 @@ def _record_event(contracts, session_id: str, wallet: str) -> None:
|
||||
|
||||
|
||||
def test_validator_uses_audit_sampler_when_configured(reference_node):
|
||||
"""A flagged low-reputation wallet gets audited far more often than a
|
||||
veteran in good standing when routed through the same validator."""
|
||||
"A flagged low-reputation wallet gets audited far more often than a\n\nTags: general"
|
||||
|
||||
contracts = LocalSolanaContracts()
|
||||
contracts.registry.record_completed_jobs("wallet-veteran", 800)
|
||||
for _ in range(9):
|
||||
|
||||
Reference in New Issue
Block a user