Fleet: get_fleet (read, handles not-in-fleet); guarded invite_to_fleet and update_fleet. UI: guarded set_waypoint and open_window (market/info/contract). All writes go through write-safety. Closes #27, #28. 128 tests, coverage 89%. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
4 files changed
+248
No files matched your search
@@ -0,0 +1,85 @@
|
||||
"""Fleet (read + write) and UI command tools."""
|
||||
|
||||
import asyncio
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from conftest import route
|
||||
from familiar import auth, fleet, ui
|
||||
from familiar.server import mcp
|
||||
|
||||
CHARS = [{"character_id": 99, "character_name": "Alpha", "scopes": []}]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_auth(monkeypatch):
|
||||
monkeypatch.setattr(auth, "list_characters", lambda: list(CHARS))
|
||||
|
||||
async def get_auth(cid, **kw):
|
||||
return f"token-{cid}", cid
|
||||
|
||||
monkeypatch.setattr(auth, "get_auth", get_auth)
|
||||
monkeypatch.setattr(auth, "resolve_character", lambda i: 99)
|
||||
return CHARS
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def writes_on(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("FAMILIAR_DATA_DIR", str(tmp_path))
|
||||
monkeypatch.setenv("FAMILIAR_ENABLE_WRITES", "true")
|
||||
|
||||
|
||||
def test_get_fleet_when_in_fleet(mock_esi, fake_auth):
|
||||
fixtures = {
|
||||
"/characters/99/fleet/": {"fleet_id": 123, "role": "fleet_commander"},
|
||||
"/members/": [{"character_id": 1}, {"character_id": 2}],
|
||||
}
|
||||
mock_esi(lambda r: route(r, fixtures))
|
||||
res = asyncio.run(fleet.get_fleet())
|
||||
entry = res["characters"][0]
|
||||
assert entry["in_fleet"] is True
|
||||
assert entry["member_count"] == 2
|
||||
|
||||
|
||||
def test_get_fleet_not_in_fleet(mock_esi, fake_auth):
|
||||
mock_esi(lambda r: httpx.Response(404, json={"error": "not in fleet"}))
|
||||
res = asyncio.run(fleet.get_fleet())
|
||||
assert res["characters"][0]["in_fleet"] is False
|
||||
|
||||
|
||||
def test_invite_dry_run(mock_esi, fake_auth):
|
||||
posted = []
|
||||
mock_esi(lambda r: (posted.append(r), httpx.Response(204, content=b""))[1])
|
||||
res = asyncio.run(fleet.invite_to_fleet(99, 123, 5))
|
||||
assert res["dry_run"] is True
|
||||
assert not posted
|
||||
|
||||
|
||||
def test_update_fleet_executes(mock_esi, fake_auth, writes_on):
|
||||
mock_esi(lambda r: httpx.Response(204, content=b""))
|
||||
res = asyncio.run(fleet.update_fleet(99, 123, motd="form up", confirm=True))
|
||||
assert res["executed"] is True
|
||||
|
||||
|
||||
def test_set_waypoint_executes(mock_esi, fake_auth, writes_on):
|
||||
mock_esi(lambda r: httpx.Response(204, content=b""))
|
||||
res = asyncio.run(ui.set_waypoint(99, 30000142, confirm=True))
|
||||
assert res["executed"] is True
|
||||
assert res["action"] == "set_waypoint"
|
||||
|
||||
|
||||
def test_open_window_validates_kind(mock_esi, fake_auth, writes_on):
|
||||
mock_esi(lambda r: httpx.Response(204, content=b""))
|
||||
with pytest.raises(ValueError):
|
||||
asyncio.run(ui.open_window(99, "banana", 1, confirm=True))
|
||||
|
||||
|
||||
def test_open_window_dry_run(mock_esi, fake_auth):
|
||||
res = asyncio.run(ui.open_window(99, "market", 34))
|
||||
assert res["dry_run"] is True
|
||||
|
||||
|
||||
def test_fleet_ui_tools_registered():
|
||||
tools = {t.name for t in asyncio.run(mcp.list_tools())}
|
||||
assert {"get_fleet", "invite_to_fleet", "update_fleet", "set_waypoint", "open_window"} <= tools
|
||||
Reference in new issue
Block a user