|
1 | 1 | """ |
2 | | -Regression test: ensure MCP-Gym auto-creates a session on first tool call |
3 | | -without requiring a prior initial state fetch, and returns JSON. |
| 2 | +Regression tests for the airline MCP server. |
| 3 | +
|
| 4 | +The tests in this module ensure we can exercise key behaviours from the |
| 5 | +AirlineDomainMcp server. They also act as regression coverage for performance |
| 6 | +fixes that impact readiness probes. |
4 | 7 | """ |
5 | 8 |
|
| 9 | +import importlib.util |
| 10 | +from pathlib import Path |
6 | 11 | import time |
7 | 12 | from multiprocessing import Process |
8 | 13 |
|
|
13 | 18 | from eval_protocol.types import MCPSession |
14 | 19 |
|
15 | 20 |
|
| 21 | +def _load_airline_environment_module(): |
| 22 | + module_name = "airline_environment_for_test" |
| 23 | + module_path = ( |
| 24 | + Path(__file__).resolve().parents[2] |
| 25 | + / "eval_protocol" |
| 26 | + / "mcp_servers" |
| 27 | + / "tau2" |
| 28 | + / "airplane_environment" |
| 29 | + / "airline_environment.py" |
| 30 | + ) |
| 31 | + spec = importlib.util.spec_from_file_location(module_name, module_path) |
| 32 | + assert spec and spec.loader is not None |
| 33 | + module = importlib.util.module_from_spec(spec) |
| 34 | + spec.loader.exec_module(module) |
| 35 | + return module |
| 36 | + |
| 37 | + |
| 38 | +def test_airline_environment_reset_uses_cached_db(monkeypatch): |
| 39 | + """AirlineEnvironment should only hit disk the first time it's reset.""" |
| 40 | + |
| 41 | + airline_module = _load_airline_environment_module() |
| 42 | + |
| 43 | + from vendor.tau2.environment import db as db_module |
| 44 | + |
| 45 | + load_file_calls = 0 |
| 46 | + original_load_file = db_module.load_file |
| 47 | + |
| 48 | + def counting_load_file(path: str, *args, **kwargs): |
| 49 | + nonlocal load_file_calls |
| 50 | + load_file_calls += 1 |
| 51 | + return original_load_file(path, *args, **kwargs) |
| 52 | + |
| 53 | + monkeypatch.setattr(db_module, "load_file", counting_load_file) |
| 54 | + |
| 55 | + env = airline_module.AirlineEnvironment() |
| 56 | + |
| 57 | + env.reset() |
| 58 | + assert load_file_calls == 1 |
| 59 | + assert env.db.users, "Expected seeded users in the airline database" |
| 60 | + |
| 61 | + user_id, user = next(iter(env.db.users.items())) |
| 62 | + original_first_name = user.name.first_name |
| 63 | + env.db.users[user_id].name.first_name = "Changed" |
| 64 | + |
| 65 | + env.reset() |
| 66 | + assert load_file_calls == 1 |
| 67 | + assert env.db.users[user_id].name.first_name == original_first_name |
| 68 | + |
| 69 | + |
16 | 70 | def _run_airline_server(): |
17 | 71 | import os |
18 | 72 |
|
|
0 commit comments