from worker_watcher.config import AppConfig, CollectorConfig, WatcherConfig
from worker_watcher.watcher import Watcher


def test_failed_collector_does_not_stop_next_collector(tmp_path) -> None:
    config = AppConfig(WatcherConfig(database_path=tmp_path / "isolation.sqlite"),
                       (CollectorConfig("broken", "not-a-real-collector"), CollectorConfig("generic", "generic_worker")))
    watcher = Watcher(config, tmp_path)
    try:
        result = watcher.run_once()
        assert result.collectors_total == 2
        assert result.collectors_failed == 1
        assert result.observations_created == 0
        assert watcher.repository.collector_rows(2)[0]["success"] in (0, 1)
        assert watcher.connection.execute("SELECT event_type FROM watcher_events").fetchone()[0] == "collector_failed"
    finally:
        watcher.close()
