80f4477f72
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
import random
|
|
|
|
import pytest
|
|
|
|
from multi_swarm.genome.hypothesis import HypothesisAgentGenome, ModelTier
|
|
from multi_swarm.genome.mutation import (
|
|
COGNITIVE_STYLES,
|
|
FEATURE_POOL,
|
|
mutate_cognitive_style,
|
|
mutate_feature_access,
|
|
mutate_lookback,
|
|
mutate_temperature,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def base_genome() -> HypothesisAgentGenome:
|
|
return HypothesisAgentGenome(
|
|
system_prompt="x",
|
|
feature_access=["close"],
|
|
temperature=0.9,
|
|
top_p=0.95,
|
|
model_tier=ModelTier.C,
|
|
lookback_window=200,
|
|
cognitive_style="physicist",
|
|
)
|
|
|
|
|
|
def test_mutate_temperature_within_bounds(base_genome: HypothesisAgentGenome) -> None:
|
|
rng = random.Random(0)
|
|
for _ in range(50):
|
|
new = mutate_temperature(base_genome, rng)
|
|
assert 0.6 <= new.temperature <= 1.3
|
|
|
|
|
|
def test_mutate_lookback_within_bounds(base_genome: HypothesisAgentGenome) -> None:
|
|
rng = random.Random(0)
|
|
for _ in range(50):
|
|
new = mutate_lookback(base_genome, rng)
|
|
assert 50 <= new.lookback_window <= 500
|
|
|
|
|
|
def test_mutate_feature_access_changes_set(base_genome: HypothesisAgentGenome) -> None:
|
|
rng = random.Random(0)
|
|
new = mutate_feature_access(base_genome, rng)
|
|
assert set(new.feature_access) != set(base_genome.feature_access) or len(FEATURE_POOL) == 1
|
|
assert all(f in FEATURE_POOL for f in new.feature_access)
|
|
assert len(new.feature_access) >= 1
|
|
|
|
|
|
def test_mutate_cognitive_style_uses_pool(base_genome: HypothesisAgentGenome) -> None:
|
|
rng = random.Random(0)
|
|
new = mutate_cognitive_style(base_genome, rng)
|
|
assert new.cognitive_style in COGNITIVE_STYLES
|
|
|
|
|
|
def test_mutation_preserves_lineage(base_genome: HypothesisAgentGenome) -> None:
|
|
rng = random.Random(0)
|
|
new = mutate_temperature(base_genome, rng)
|
|
assert base_genome.id in new.parent_ids
|
|
assert new.id != base_genome.id
|