"""Unit tests for the bootstrap module.""" from __future__ import annotations from unittest.mock import MagicMock from prometheus.application.bootstrap import SyntheticBootstrap from prometheus.domain.entities import SyntheticExample from prometheus.domain.ports import SyntheticGeneratorPort class TestSyntheticBootstrap: def test_run_returns_shuffled_examples(self) -> None: mock_gen = MagicMock(spec=SyntheticGeneratorPort) examples = [SyntheticExample(input_text=f"input {i}", id=i) for i in range(10)] mock_gen.generate_inputs.return_value = examples bootstrap = SyntheticBootstrap(generator=mock_gen, seed=42) result = bootstrap.run("task desc", 10) assert len(result) == 10 mock_gen.generate_inputs.assert_called_once_with("task desc", 10) def test_sample_minibatch_returns_correct_size(self) -> None: mock_gen = MagicMock(spec=SyntheticGeneratorPort) pool = [SyntheticExample(input_text=f"input {i}", id=i) for i in range(20)] bootstrap = SyntheticBootstrap(generator=mock_gen, seed=42) batch = bootstrap.sample_minibatch(pool, 5) assert len(batch) == 5 # All items should be from the pool assert all(item in pool for item in batch) def test_sample_minibatch_capped_at_pool_size(self) -> None: mock_gen = MagicMock(spec=SyntheticGeneratorPort) pool = [SyntheticExample(input_text=f"input {i}", id=i) for i in range(3)] bootstrap = SyntheticBootstrap(generator=mock_gen, seed=42) batch = bootstrap.sample_minibatch(pool, 10) assert len(batch) == 3 def test_deterministic_with_same_seed(self) -> None: mock_gen = MagicMock(spec=SyntheticGeneratorPort) pool = [SyntheticExample(input_text=f"input {i}", id=i) for i in range(20)] b1 = SyntheticBootstrap(generator=mock_gen, seed=42) b2 = SyntheticBootstrap(generator=mock_gen, seed=42) assert b1.sample_minibatch(pool, 5) == b2.sample_minibatch(pool, 5)