Модуль wiki, агенты модулей, поля проектов (#91) #92
@ -162,13 +162,22 @@ def h_agent_settings(hub, conn, m, q, body):
|
||||
return 200, settings.for_agent(conn, http.agent_of(q))
|
||||
|
||||
|
||||
def _own_command(conn, cmd_id, agent):
|
||||
"""Команда по id, но только своего модуля: чужой тип — тот же 404, что и несуществующая команда (I-1 финального ревью)."""
|
||||
cmd = not_found(queue.get_command(conn, cmd_id), "command")
|
||||
if cmd["type"] not in queue._own_types(agent):
|
||||
raise ApiError(404, "not_found", "command")
|
||||
return cmd
|
||||
|
||||
|
||||
def h_agent_command(hub, conn, m, q, body):
|
||||
"""Команда по id для восстановления из журнала агента: параметры — как при выдаче (с size у команд с файлом)."""
|
||||
cmd = not_found(queue.get_command(conn, int_group(m)), "command")
|
||||
cmd = _own_command(conn, int_group(m), http.agent_of(q))
|
||||
return 200, {**cmd, "params": queue.deliver_params(conn, cmd, hub.files_dir)}
|
||||
|
||||
|
||||
def h_agent_result(hub, conn, m, q, body):
|
||||
_own_command(conn, int_group(m), http.agent_of(q))
|
||||
try:
|
||||
cmd = queue.report_result(conn, int_group(m), body.get("status"), body.get("result"), body.get("error"),
|
||||
body.get("jira_calls", 0), body.get("rate_limited", 0), files_dir=hub.files_dir)
|
||||
|
||||
@ -260,3 +260,28 @@ def test_wiki_agent_token_after_upgrade(tmp_path):
|
||||
assert names == {"jira", "wiki"}
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def test_agent_cannot_touch_foreign_command(hub_server_two_modules):
|
||||
"""I-1: токен модуля не читает и не закрывает команды чужого модуля."""
|
||||
h = hub_server_two_modules
|
||||
jira, stub = h["agents"]["jira"], h["agents"]["stub"]
|
||||
conn = h["hub"].conn()
|
||||
try:
|
||||
queue.create_batch(conn, "w", "t", [{"type": "stub_cmd", "params": {}}])
|
||||
queue.create_batch(conn, "j", "t", [{"type": "ensure_issue",
|
||||
"params": {"temp_key": "new:1", "issue_type": "task", "summary": "Тема"}}])
|
||||
finally:
|
||||
conn.close()
|
||||
jc = jira.post("/agent/claim", {})["command"]
|
||||
sc = stub.post("/agent/claim", {})["command"]
|
||||
assert jc["type"] == "ensure_issue" and sc["type"] == "stub_cmd"
|
||||
for call in (lambda: stub.get(f"/agent/commands/{jc['id']}"),
|
||||
lambda: stub.post(f"/agent/commands/{jc['id']}/result", {"status": "failed"}),
|
||||
lambda: jira.get(f"/agent/commands/{sc['id']}"),
|
||||
lambda: jira.post(f"/agent/commands/{sc['id']}/result", {"status": "failed"})):
|
||||
with pytest.raises(HubError) as e:
|
||||
call()
|
||||
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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user