Phase 3: industry & trade tools (character + corp)
Add read-only industry tools (industry jobs, blueprints, mining ledger; corp jobs + blueprints) and trade tools (contracts, own market orders; corp contracts + orders). New charutil helper runs a fetcher over one or all characters, with a corp variant that resolves each character's corp id. account._run now reuses it. 27 tools total, 70 tests, coverage 91%. Closes #18 and #19; covers most of #20. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
7 files changed
+391
-24
No files matched your search
@@ -0,0 +1,92 @@
|
||||
"""Industry tools (character + corp), auth & ESI mocked."""
|
||||
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from conftest import route
|
||||
from familiar import auth, industry
|
||||
from familiar.server import mcp
|
||||
|
||||
CHARS = [
|
||||
{"character_id": 99, "character_name": "Alpha", "scopes": []},
|
||||
{"character_id": 100, "character_name": "Beta", "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)
|
||||
|
||||
def resolve(identifier):
|
||||
for c in CHARS:
|
||||
if (
|
||||
str(c["character_id"]) == str(identifier)
|
||||
or (c["character_name"] or "").lower() == str(identifier).lower()
|
||||
):
|
||||
return c["character_id"]
|
||||
raise auth.NotAuthenticated("no such character")
|
||||
|
||||
monkeypatch.setattr(auth, "resolve_character", resolve)
|
||||
return CHARS
|
||||
|
||||
|
||||
def test_industry_jobs_all_characters(mock_esi, fake_auth):
|
||||
jobs = [{"job_id": 1, "activity_id": 1, "status": "active"}]
|
||||
mock_esi(lambda r: route(r, {"/industry/jobs/": jobs}))
|
||||
res = asyncio.run(industry.get_industry_jobs())
|
||||
assert len(res["characters"]) == 2
|
||||
assert res["characters"][0]["count"] == 1
|
||||
|
||||
|
||||
def test_blueprints_single_character(mock_esi, fake_auth):
|
||||
bps = [{"item_id": 1}, {"item_id": 2}]
|
||||
mock_esi(lambda r: route(r, {"/blueprints/": bps}))
|
||||
res = asyncio.run(industry.get_blueprints(character="Alpha"))
|
||||
assert len(res["characters"]) == 1
|
||||
assert res["characters"][0]["count"] == 2
|
||||
|
||||
|
||||
def test_mining_ledger(mock_esi, fake_auth):
|
||||
ledger = [{"date": "2026-06-01", "type_id": 34, "quantity": 1000}]
|
||||
mock_esi(lambda r: route(r, {"/mining/": ledger}))
|
||||
res = asyncio.run(industry.get_mining_ledger(character=99))
|
||||
assert res["characters"][0]["sample"][0]["type_id"] == 34
|
||||
|
||||
|
||||
def test_corp_industry_jobs_resolves_corp(mock_esi, fake_auth):
|
||||
fixtures = {
|
||||
"/corporations/": [{"job_id": 7}],
|
||||
"/characters/": {"corporation_id": 2000},
|
||||
}
|
||||
mock_esi(lambda r: route(r, fixtures))
|
||||
res = asyncio.run(industry.get_corp_industry_jobs(character=99))
|
||||
entry = res["characters"][0]
|
||||
assert entry["corporation_id"] == 2000
|
||||
assert entry["count"] == 1
|
||||
|
||||
|
||||
def test_corp_blueprints(mock_esi, fake_auth):
|
||||
fixtures = {
|
||||
"/corporations/": [{"item_id": 5}, {"item_id": 6}],
|
||||
"/characters/": {"corporation_id": 2000},
|
||||
}
|
||||
mock_esi(lambda r: route(r, fixtures))
|
||||
res = asyncio.run(industry.get_corp_blueprints(character="Beta"))
|
||||
assert res["characters"][0]["count"] == 2
|
||||
|
||||
|
||||
def test_not_logged_in_raises(monkeypatch):
|
||||
monkeypatch.setattr(auth, "list_characters", lambda: [])
|
||||
with pytest.raises(auth.NotAuthenticated):
|
||||
asyncio.run(industry.get_industry_jobs())
|
||||
|
||||
|
||||
def test_industry_tools_registered():
|
||||
tools = {t.name for t in asyncio.run(mcp.list_tools())}
|
||||
assert {"get_industry_jobs", "get_blueprints", "get_corp_industry_jobs"} <= tools
|
||||
Reference in new issue
Block a user