Files
LatteandClaude Opus 4.8 eeebfaa684
CI / lint (pull_request) Successful in 51s
CI / lint (push) Successful in 53s
CI / test (pull_request) Successful in 1m0s
CI / publish (pull_request) Has been skipped
CI / test (push) Successful in 58s
CI / publish (push) Successful in 51s
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>
2026-06-27 19:28:21 +02:00

79 lines
2.4 KiB
Python

"""Trade tools (contracts + market orders, character + corp), auth & ESI mocked."""
import asyncio
import pytest
from conftest import route
from familiar import auth, trade
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_contracts_all(mock_esi, fake_auth):
contracts = [{"contract_id": 1, "type": "item_exchange"}]
mock_esi(lambda r: route(r, {"/contracts/": contracts}))
res = asyncio.run(trade.get_contracts())
assert len(res["characters"]) == 2
assert res["characters"][0]["count"] == 1
def test_my_orders_single(mock_esi, fake_auth):
orders = [{"order_id": 1, "price": 10.0}, {"order_id": 2, "price": 20.0}]
mock_esi(lambda r: route(r, {"/orders/": orders}))
res = asyncio.run(trade.get_my_orders(character="Alpha"))
assert res["characters"][0]["count"] == 2
def test_corp_contracts_resolves_corp(mock_esi, fake_auth):
fixtures = {
"/corporations/": [{"contract_id": 9}],
"/characters/": {"corporation_id": 2000},
}
mock_esi(lambda r: route(r, fixtures))
res = asyncio.run(trade.get_corp_contracts(character=99))
entry = res["characters"][0]
assert entry["corporation_id"] == 2000
assert entry["count"] == 1
def test_corp_orders(mock_esi, fake_auth):
fixtures = {
"/corporations/": [{"order_id": 3}],
"/characters/": {"corporation_id": 2000},
}
mock_esi(lambda r: route(r, fixtures))
res = asyncio.run(trade.get_corp_orders(character="Beta"))
assert res["characters"][0]["count"] == 1
def test_trade_tools_registered():
tools = {t.name for t in asyncio.run(mcp.list_tools())}
assert {"get_contracts", "get_my_orders", "get_corp_contracts", "get_corp_orders"} <= tools