File size: 1,499 Bytes
3476d6b | 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 | import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from models import ActionType, OpsguardAction
from server.opsguard_environment import OpsguardEnvironment
def test_query_history_returns_episode_memory():
env = OpsguardEnvironment()
env.reset(scenario_id="E1_typosquat_wave", seed=0)
seen_authors = set()
for _ in range(15):
obs = env.step(OpsguardAction(action_type=ActionType.LABEL, label="bug"))
if obs.current_issue:
seen_authors.add(obs.current_issue.author_login)
if obs.done:
break
obs = env.step(OpsguardAction(action_type=ActionType.QUERY_HISTORY, query=list(seen_authors)[0]))
assert obs.memory_hits, "expected memory hits from prior steps"
assert any(h.get("source") == "episode_memory" for h in obs.memory_hits)
def test_memory_persists_across_long_horizon():
env = OpsguardEnvironment()
env.reset(scenario_id="E2_social_eng_buildup", seed=0)
for _ in range(80):
obs = env.step(OpsguardAction(action_type=ActionType.LABEL, label="bug"))
if obs.done:
break
assert env._episode is not None
assert env._episode.memory.stats()["episodic"] >= 30
if __name__ == "__main__":
test_query_history_returns_episode_memory()
print("PASS test_query_history_returns_episode_memory")
test_memory_persists_across_long_horizon()
print("PASS test_memory_persists_across_long_horizon")
print("ALL GREEN")
|