File size: 1,587 Bytes
e918a5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Copyright (c) Meta Platforms, Inc. and affiliates.

import json

from pathway_analysis_env.server.case_loader import (
    CASE_SECRET_KEYS,
    load_case_file,
    strip_case_secrets,
)
from pathway_analysis_env.server.pathway_environment import DATA_DIR, PathwayEnvironment
from pathway_analysis_env.models import PathwayAction


def test_strip_case_secrets():
    raw = {
        "case_id": "x",
        "true_pathway": "MAPK signaling",
        "expected_keywords": ["mapk"],
        "counts": {"G1": [1, 2]},
    }
    pub = strip_case_secrets(raw)
    for k in CASE_SECRET_KEYS:
        assert k not in pub
    assert "counts" in pub


def test_reset_agent_safe_case_has_no_secrets_in_memory():
    env = PathwayEnvironment(case_file="toy_case_001.json")
    env.reset(eval_mode=True, orchestrator_mode=False)
    dumped = json.dumps(env._case)
    assert "true_pathway" not in dumped


def test_episode_observation_no_correct_without_orchestrator():
    env = PathwayEnvironment(case_file="toy_case_legacy.json")
    env.reset()
    env.step(PathwayAction(action_type="run_differential_expression"))
    env.step(PathwayAction(action_type="run_pathway_enrichment"))
    fin = env.step(
        PathwayAction(action_type="submit_answer", hypothesis="MAPK signaling")
    )
    assert fin.metadata.get("correct") is None
    assert env.episode_outcome.get("correct") is True


def test_load_case_file_roundtrip():
    case, secrets = load_case_file(DATA_DIR, "toy_case_001.json", agent_safe=False)
    assert secrets["true_pathway"] == "MAPK signaling"
    assert case["case_id"]