import json import os from pathlib import Path import yaml from bioeval_core import bedrock_client, claude_proxy from bioeval_core.container_tools import sidecar_tool from bioeval_core.container_tools.submit_answer import create_submission from bioeval_core.task_registry import TASK_NAMES ROOT = Path(__file__).resolve().parents[1] TASKS = TASK_NAMES def test_proxy_config_routes_only_declared_bedrock_model(monkeypatch): monkeypatch.setenv("BIOEVAL_RESEARCH_MODEL", "us.anthropic.test-model") monkeypatch.setenv("BEDROCK_AWS_REGION", "us-test-1") config = claude_proxy.build_config() assert config["model_list"] == [ { "model_name": "us.anthropic.test-model", "litellm_params": { "model": "bedrock/us.anthropic.test-model", "aws_region_name": "us-test-1", "custom_llm_provider": "bedrock", }, } ] assert "credential" not in json.dumps(config).lower() assert config["litellm_settings"]["telemetry"] is False def test_bedrock_client_promotes_isolated_host_token(monkeypatch): monkeypatch.delenv("AWS_BEARER_TOKEN_BEDROCK", raising=False) monkeypatch.setenv("BIOEVAL_BEDROCK_BEARER_TOKEN", "ABSK-isolated") bedrock_client.ensure_bedrock_bearer_token() assert os.environ["AWS_BEARER_TOKEN_BEDROCK"] == "ABSK-isolated" def test_sidecar_tool_rejects_request_outside_workspace(tmp_path, monkeypatch): workspace = tmp_path / "app" workspace.mkdir() request = tmp_path / "outside.json" request.write_text("{}") monkeypatch.setenv("BIOEVAL_WORKSPACE", str(workspace)) try: sidecar_tool._request_path(str(request)) except ValueError as exc: assert "inside /app" in str(exc) else: raise AssertionError("outside request path was accepted") def test_compose_keeps_main_isolated_from_proxy_credentials(): for task_name in TASKS: compose = yaml.safe_load( ( ROOT / "tasks" / task_name / "environment/docker-compose.yaml" ).read_text() ) main = compose["services"]["main"] proxy = compose["services"]["claude-proxy"] assert main["networks"] == ["bioeval-internal"] assert "environment" not in main assert set(proxy["networks"]) == {"bioeval-internal", "bioeval-egress"} assert "AWS_BEARER_TOKEN_BEDROCK" in proxy["environment"] assert "/private/" not in json.dumps(proxy) assert "volumes" not in proxy def test_launcher_replaces_all_claude_auth_with_internal_proxy_key(): launcher = (ROOT / "run_agents.sh").read_text() assert 'unset AWS_BEARER_TOKEN_BEDROCK' in launcher assert 'unset CLAUDE_CODE_OAUTH_TOKEN' in launcher assert 'export ANTHROPIC_BASE_URL="http://claude-proxy:4000"' in launcher assert 'export ANTHROPIC_API_KEY="bioeval-internal-proxy"' in launcher assert "-a claude-code" in launcher def test_claude_code_installer_is_artifact_and_digest_pinned(): digest = "e69e7f72d784c243bcc377a578ad9ff8e65ae14da672fbbf9f2ba7bf47eca7ec" artifact = ( "https://github.com/anthropics/claude-code/releases/download/" "v2.1.220/claude-linux-x64.tar.gz" ) for task_name in TASKS: dockerfile = ( ROOT / "tasks" / task_name / "environment/Dockerfile" ).read_text() assert artifact in dockerfile assert digest in dockerfile assert "sha256sum -c -" in dockerfile assert "bootstrap.sh" not in dockerfile def test_answer_file_submission_keeps_manifest_contract(tmp_path): workspace = tmp_path / "app" workspace.mkdir() artifact = workspace / "metrics.csv" artifact.write_text("metric,estimate\nvalue,1\n") manifest = workspace / "analysis_manifest.json" manifest.write_text(json.dumps({"artifacts": [{"path": "metrics.csv"}]})) result = create_submission( answer="supported conclusion", analysis_manifest=str(manifest), workspace_root=workspace, submit_dir=workspace / "submission", ) assert result is not None assert result["artifacts"][0]["path"] == "metrics.csv"