from pathlib import Path import pytest from lai_automation.config import Settings def settings(**overrides) -> Settings: values = { "database_host": "db", "database_port": 3306, "database_name": "lai", "database_user": "worker", "database_password": "secret", "source_repository": "https://example.test/lai.git", "source_branch": "main", "workspace_root": Path("/tmp/workspaces"), "mode": "dry-run", "allow_direct_main": False, "gitea_url": "https://example.test", "gitea_owner": "owner", "gitea_repository": "lai", "gitea_token": "", "gitea_username": "bot", "agent_command": "aider", "agent_model": "mistral/test", "test_commands": ("php artisan test",), "poll_seconds": 60, "max_changed_files": 12, "max_changed_lines": 800, "stale_claim_minutes": 90, "dry_run": True, } values.update(overrides) return Settings(**values) def test_direct_main_requires_explicit_kill_switch() -> None: config = settings(mode="direct-main", dry_run=False, gitea_token="token") with pytest.raises(ValueError, match="ALLOW_DIRECT_MAIN"): config.validate() def test_pr_requires_gitea_token() -> None: config = settings(mode="pr", dry_run=False) with pytest.raises(ValueError, match="GITEA_TOKEN"): config.validate()