-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_nav_eta.py
More file actions
60 lines (46 loc) · 2.17 KB
/
Copy pathtest_nav_eta.py
File metadata and controls
60 lines (46 loc) · 2.17 KB
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
"""st_navigate / st_ship hand the agent the ETA in SECONDS + an explicit wait() call
(#1702) — so it yields once instead of diffing an ISO arrival, under-waiting, and
polling in a loop (which stacked wake-ups)."""
from __future__ import annotations
import asyncio
import importlib
from datetime import datetime, timedelta, timezone
from pathlib import Path
import pytest
testkit = pytest.importorskip("graph.plugins.testkit")
ROOT = Path(__file__).resolve().parent
@pytest.fixture(scope="module")
def tools():
pkg = testkit.load_plugin(ROOT, "spacetraders")
return importlib.import_module(f"{pkg.__name__}.tools")
def _arrival_in(seconds: int) -> str:
return (datetime.now(timezone.utc) + timedelta(seconds=seconds)).isoformat()
def test_navigate_returns_eta_seconds_and_the_exact_wait_call(tools, monkeypatch):
async def fake_call(method, path, **kw):
if path.endswith("/navigate"):
return {
"nav": {
"waypointSymbol": "X1-DF55-B2",
"flightMode": "CRUISE",
"route": {"arrival": _arrival_in(203)},
},
"fuel": {"current": 80, "capacity": 100},
}
return {} # orbit / patch
monkeypatch.setattr(tools, "call", fake_call)
out = asyncio.run(tools.st_navigate.ainvoke({"ship": "PT-1", "waypoint": "X1-DF55-B2"}))
assert "arriving in 203s" in out
assert "wait(203," in out # the exact call, not an ISO timestamp to diff
assert "ONCE" in out and "poll" in out.lower()
def test_ship_in_transit_nudges_a_single_wait(tools, monkeypatch):
async def fake_call(method, path, **kw):
return {
"symbol": "PT-1",
"nav": {"status": "IN_TRANSIT", "waypointSymbol": "X1-DF55-B2", "route": {"arrival": _arrival_in(150)}},
"fuel": {"current": 50, "capacity": 100},
"cargo": {"units": 0, "capacity": 40, "inventory": []},
"cooldown": {"remainingSeconds": 0},
}
monkeypatch.setattr(tools, "call", fake_call)
out = asyncio.run(tools.st_ship.ainvoke({"ship": "PT-1"}))
assert "arriving in 150s" in out and "wait(150," in out and "don't re-check" in out