from __future__ import annotations import pytest from scripts import run_leo_agent_challenger_loop as runner def test_remote_script_embeds_stateless_challenger_read_only_guard_and_bounded_context() -> None: script = runner.build_remote_script("abc123", challenger_max_tokens=512) assert "stateless_openrouter_agent" in script assert "gatewayrunner_temp_profile_no_model_tools" in script assert "blocked by isolated challenger-loop read-only guard" in script context_source = runner._patched_db_context_source() assert '"--limit",\n "4",' in context_source assert '"--context-limit",\n "6",' in context_source assert "CHALLENGER_MAX_TOKENS = 512" in script assert "posted_to_telegram" in script assert "db_fingerprint_unchanged" in script def test_remote_script_rejects_unbounded_tokens_and_unsafe_report_prefix() -> None: with pytest.raises(ValueError, match="between 128 and 2048"): runner.build_remote_script("abc123", challenger_max_tokens=4096) with pytest.raises(ValueError, match="report_prefix"): runner.build_remote_script("abc123", report_prefix="bad/path")