mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
test(agent_session_endpoints): bulk-update tests for nested route + items key
Mass rewrite of POST /v2/sessions -> POST /v2/agents/{agent_id}/sessions
(agent_id removed from JSON body) and .json()["data"] -> .json()["items"]
across all test files in tests/test_litellm/proxy/agent_session_endpoints/.
This commit is contained in:
parent
16dfa061a5
commit
c71535dfe7
15 changed files with 62 additions and 62 deletions
|
|
@ -16,9 +16,9 @@ def _create_agent(client) -> str:
|
|||
|
||||
def _create_session(client, agent_id: str) -> str:
|
||||
res = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{agent_id}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": agent_id, "repos": []},
|
||||
json={"repos": []},
|
||||
)
|
||||
assert res.status_code == 200, res.text
|
||||
return res.json()["id"]
|
||||
|
|
@ -53,5 +53,5 @@ def test_sessions_under_agent_listed_by_filter(client, noop_provider):
|
|||
headers={"Authorization": "Bearer k"},
|
||||
)
|
||||
assert res.status_code == 200
|
||||
listed_ids = {s["id"] for s in res.json()["data"]}
|
||||
listed_ids = {s["id"] for s in res.json()["items"]}
|
||||
assert listed_ids == set(sids)
|
||||
|
|
|
|||
|
|
@ -22,14 +22,14 @@ def test_delete_agent_terminates_sessions_and_calls_provider(
|
|||
aid = agent["id"]
|
||||
|
||||
sess_a = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{aid}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": aid, "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
sess_b = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{aid}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": aid, "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
|
||||
# Create a run on session A so cascade exercises run-cancel path too.
|
||||
|
|
@ -74,18 +74,18 @@ def test_delete_agent_skips_session_already_in_terminal_status(
|
|||
|
||||
# An "active" session that should still get terminated by the cascade.
|
||||
sess_active = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{aid}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": aid, "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
# A session whose status was already flipped to ``error`` (terminal)
|
||||
# but with ``terminated_at`` deliberately left None — the legacy
|
||||
# filter would have re-terminated this row, but the status-based
|
||||
# filter should skip it.
|
||||
sess_already_terminal = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{aid}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": aid, "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
terminal_row = next(
|
||||
r
|
||||
|
|
@ -122,9 +122,9 @@ def test_delete_session_terminates_active_runs(
|
|||
json={"name": "t", "model": "gpt-4"},
|
||||
).json()
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{agent["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": agent["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
sid = sess["id"]
|
||||
run = client.post(
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ async def test_sweeper_terminates_expired_sessions(
|
|||
json={"name": "t", "model": "gpt-4"},
|
||||
).json()
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{a["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": a["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
sid = sess["id"]
|
||||
|
||||
|
|
@ -61,9 +61,9 @@ async def test_sweeper_marks_dead_daemon_sessions_error(
|
|||
json={"name": "t", "model": "gpt-4"},
|
||||
).json()
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{a["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": a["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
sid = sess["id"]
|
||||
|
||||
|
|
@ -95,9 +95,9 @@ async def test_sweeper_marks_stuck_runs_error(
|
|||
json={"name": "t", "model": "gpt-4"},
|
||||
).json()
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{a["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": a["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
sid = sess["id"]
|
||||
client.post(
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ def _bootstrap_ready(client, noop_provider):
|
|||
json={"name": "t", "model": "gpt-4"},
|
||||
).json()
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{agent["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": agent["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
daemon_token = sess["daemon_token"]
|
||||
sid = sess["id"]
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ def test_event_append_real_collision_returns_409(
|
|||
json={"name": "t", "model": "gpt-4"},
|
||||
).json()
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{a["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": a["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
sid = sess["id"]
|
||||
|
||||
|
|
@ -109,9 +109,9 @@ def test_event_append_unrelated_error_does_not_become_409(
|
|||
json={"name": "t", "model": "gpt-4"},
|
||||
).json()
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{a["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": a["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
sid = sess["id"]
|
||||
daemon_token = sess["daemon_token"]
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ def _bootstrap_session(client):
|
|||
json={"name": "concurrent", "model": "gpt-4"},
|
||||
).json()
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{agent["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": agent["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
return sess["id"]
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ def _bootstrap_ready(client, noop_provider):
|
|||
json={"name": "t", "model": "gpt-4"},
|
||||
).json()
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{agent["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": agent["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
daemon_token = sess["daemon_token"]
|
||||
sid = sess["id"]
|
||||
|
|
|
|||
|
|
@ -19,14 +19,14 @@ def test_session_idempotency(client, noop_provider, fake_prisma_client):
|
|||
|
||||
headers = {"Authorization": "Bearer k", "Idempotency-Key": "uuid-A"}
|
||||
a = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{agent_id}/sessions",
|
||||
headers=headers,
|
||||
json={"agent_id": agent_id, "repos": []},
|
||||
json={"repos": []},
|
||||
)
|
||||
b = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{agent_id}/sessions",
|
||||
headers=headers,
|
||||
json={"agent_id": agent_id, "repos": []},
|
||||
json={"repos": []},
|
||||
)
|
||||
assert a.status_code == 200 and b.status_code == 200
|
||||
assert a.json()["id"] == b.json()["id"]
|
||||
|
|
@ -37,9 +37,9 @@ def test_session_idempotency(client, noop_provider, fake_prisma_client):
|
|||
def test_run_idempotency(client, noop_provider, fake_prisma_client):
|
||||
agent_id = _create_agent(client)
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{agent_id}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": agent_id, "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
sid = sess["id"]
|
||||
daemon_token = sess["daemon_token"]
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ def test_cross_tenant_isolation(client, other_tenant_client, noop_provider):
|
|||
).json()
|
||||
aid = agent["id"]
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{aid}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": aid, "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
sid = sess["id"]
|
||||
run = client.post(
|
||||
|
|
@ -52,13 +52,13 @@ def test_cross_tenant_isolation(client, other_tenant_client, noop_provider):
|
|||
assert (
|
||||
other_tenant_client.get(
|
||||
"/v2/agents", headers={"Authorization": "Bearer other"}
|
||||
).json()["data"]
|
||||
).json()["items"]
|
||||
== []
|
||||
)
|
||||
assert (
|
||||
other_tenant_client.get(
|
||||
"/v2/sessions", headers={"Authorization": "Bearer other"}
|
||||
).json()["data"]
|
||||
).json()["items"]
|
||||
== []
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ def _bootstrap(client, noop_provider):
|
|||
json={"name": "t", "model": "gpt-4"},
|
||||
).json()
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{agent["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": agent["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
return agent, sess
|
||||
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ def _bootstrap(client):
|
|||
json={"name": "osc", "model": "gpt-4"},
|
||||
).json()
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{agent["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": agent["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
return sess["id"]
|
||||
|
||||
|
|
|
|||
|
|
@ -71,9 +71,9 @@ def test_session_starts_provisioning(client, noop_provider):
|
|||
agent_id = res.json()["id"]
|
||||
|
||||
res = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{agent_id}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": agent_id, "repos": []},
|
||||
json={"repos": []},
|
||||
)
|
||||
assert res.status_code == 200
|
||||
body = res.json()
|
||||
|
|
@ -90,9 +90,9 @@ def test_daemon_register_flips_to_ready(client, noop_provider, fake_prisma_clien
|
|||
agent_id = res.json()["id"]
|
||||
|
||||
res = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{agent_id}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": agent_id, "repos": []},
|
||||
json={"repos": []},
|
||||
)
|
||||
body = res.json()
|
||||
sid = body["id"]
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ def _bootstrap_ready(client, noop_provider):
|
|||
json={"name": "t", "model": "gpt-4"},
|
||||
).json()
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{agent["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": agent["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
daemon_token = sess["daemon_token"]
|
||||
sid = sess["id"]
|
||||
|
|
|
|||
|
|
@ -45,14 +45,14 @@ def test_token_for_session_a_rejected_by_session_b(client, noop_provider):
|
|||
json={"name": "x", "model": "gpt-4"},
|
||||
).json()
|
||||
sess_a = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{a["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": a["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
sess_b = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{a["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": a["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
|
||||
# Use sess_a's daemon token to register sess_b.
|
||||
|
|
@ -71,9 +71,9 @@ def test_expired_jwt_rejected(client, noop_provider):
|
|||
json={"name": "t", "model": "gpt-4"},
|
||||
).json()
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{a["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": a["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
|
||||
# Mint a token that expired 1 minute ago.
|
||||
|
|
@ -100,9 +100,9 @@ def test_terminated_session_rejects_its_token(
|
|||
json={"name": "t", "model": "gpt-4"},
|
||||
).json()
|
||||
sess = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{a["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": a["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
sid = sess["id"]
|
||||
daemon_token = sess["daemon_token"]
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ def _create_tenant_a_resources(client):
|
|||
json={"name": "tenant-a-agent", "model": "gpt-4"},
|
||||
).json()
|
||||
session = client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{agent["id"]}/sessions",
|
||||
headers={"Authorization": "Bearer k"},
|
||||
json={"agent_id": agent["id"], "repos": []},
|
||||
json={"repos": []},
|
||||
).json()
|
||||
run = client.post(
|
||||
f"/v2/sessions/{session['id']}/runs",
|
||||
|
|
@ -74,9 +74,9 @@ def test_view_only_admin_cannot_create_session(view_only_admin_client, noop_prov
|
|||
# Even minting a session with a non-existent agent must short-circuit
|
||||
# to 403 BEFORE any DB activity — the role check is the first guard.
|
||||
res = view_only_admin_client.post(
|
||||
"/v2/sessions",
|
||||
f"/v2/agents/{"agt_doesnotexist"}/sessions",
|
||||
headers={"Authorization": "Bearer view-only"},
|
||||
json={"agent_id": "agt_doesnotexist", "repos": []},
|
||||
json={"repos": []},
|
||||
)
|
||||
assert res.status_code == 403
|
||||
|
||||
|
|
@ -159,4 +159,4 @@ def test_view_only_admin_can_still_read_other_tenant_resources(
|
|||
"/v2/agents", headers={"Authorization": "Bearer view-only"}
|
||||
)
|
||||
assert res.status_code == 200
|
||||
assert any(a["id"] == agent_id for a in res.json()["data"])
|
||||
assert any(a["id"] == agent_id for a in res.json()["items"])
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue