File size: 4,185 Bytes
6d6b4b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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"