Сквозной тест совместимости с jira-agent v14 по HTTP (I-3)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Andrey Epifancev 2026-10-24 03:56:13 +04:00
parent 4600634a61
commit 90d1af57f1

View File

@ -285,3 +285,48 @@ def test_agent_cannot_touch_foreign_command(hub_server_two_modules):
assert e.value.status == 404
assert jira.get(f"/agent/commands/{jc['id']}")["id"] == jc["id"]
assert stub.post(f"/agent/commands/{sc['id']}/result", {"status": "done", "result": {}})["status"] == "done"
def test_v14_agent_over_http_on_v6_base(tmp_path):
"""I-3: база v6 → HTTP-сервер → прежний токен T-agent в форме запросов jira-agent v14, без прямых вызовов обработчиков."""
import json
import threading
from pathlib import Path
from jira_hub.core.client import HubClient
make_v6_db(tmp_path / "hub.sqlite")
old = tmp_path / "release" # прежняя раскладка v14: release/agent.py
old.mkdir()
(old / "agent.py").write_text("AGENT_VERSION = 14\n", encoding="utf-8")
release.publish(old, old / "agent.py")
h = api.Hub(tmp_path / "hub.sqlite", backups_dir=tmp_path / "backups", release_root=old)
h.claim_wait = 0
srv = api.make_server(h, "127.0.0.1", 0)
th = threading.Thread(target=srv.serve_forever, daemon=True)
th.start()
try:
a = HubClient(f"http://127.0.0.1:{srv.server_port}", "T-agent")
out = a.post("/agent/claim", {"agent_version": 14, "settings_version": 1, "last_jira_call_at": "2026-10-24T10:00:00+00:00",
"update_state": None, "launcher_version": 2})
assert out["command"] is None and out["agent_release"]["version"] == 14
conn = h.conn()
try:
row = conn.execute("SELECT last_call_at, agent_version FROM agent_status WHERE agent = 'jira'").fetchone()
assert row["last_call_at"] == "2026-10-24T10:00:00+00:00" and row["agent_version"] == "14"
finally:
conn.close()
expected = json.loads((Path(__file__).parent / "fixtures" / "settings_v6.json").read_text(encoding="utf-8"))["agent_keys"]
got = a.get("/agent/settings")
assert set(got) == set(expected) - {"board_id"}
assert a.get("/agent/release")["version"] == 14
assert a.post("/agent/state", {"issues": [{"key": "A-1", "summary": "Т", "labels": []}], "links": [],
"neighbor_keys": []}) == {"issues": 1, "links": 0}
assert a.get("/agent/known-keys")["keys"] == ["A-1"]
item = {"history_id": "5001", "seq": 0, "key": "A-1", "created": "2026-10-22T09:00:00.000+0300", "author": "П",
"field_id": "status", "field_name": "status", "from": "3", "from_string": "a", "to": "4", "to_string": "b"}
assert a.post("/agent/history", {"command_id": None, "changes": [item]}) == {"accepted": 1, "duplicates": 0}
finally:
srv.shutdown()
srv.server_close()
th.join(5)