From 33df996f0bff81b2443c4459bf987109432c9b90 Mon Sep 17 00:00:00 2001 From: lhl Date: Fri, 28 Aug 2026 01:59:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(server):=20GET=20/api/sessions=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20project=20=E6=9F=A5=E8=AF=A2=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/genesis/server/app.py | 4 ++-- tests/test_server_api.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/genesis/server/app.py b/src/genesis/server/app.py index c9d7c5f..bb53563 100644 --- a/src/genesis/server/app.py +++ b/src/genesis/server/app.py @@ -154,11 +154,11 @@ def create_app( return {"session_id": rec.session_id, "status": rec.status, "name": rec.name} @app.get("/api/sessions") - def list_sessions(user_id: str = "default"): + def list_sessions(user_id: str = "default", project: str | None = None): return [ {"session_id": r.session_id, "name": r.name, "project": r.project, "status": r.status, "updated_at": r.updated_at} - for r in service.store.list_sessions(user_id) + for r in service.store.list_sessions(user_id, project=project) ] @app.get("/api/sessions/{sid}") diff --git a/tests/test_server_api.py b/tests/test_server_api.py index 32177db..b7883e2 100644 --- a/tests/test_server_api.py +++ b/tests/test_server_api.py @@ -347,3 +347,12 @@ def test_generate_with_project_config_no_template_upload(client): gen = client.post(f"/api/sessions/{sid}/generate", json={}) assert gen.status_code == 200, gen.text assert client.get(f"/api/sessions/{sid}/result/download").status_code == 200 + +def test_api_list_sessions_filter_by_project(client): + r0 = client.post("/api/sessions", json={"user_id": "u1", "project": "stock"}) + r1 = client.post("/api/sessions", json={"user_id": "u1", "project": "other"}) + res = client.get("/api/sessions", params={"user_id": "u1", "project": "stock"}) + assert res.status_code == 200 + ids = {x["session_id"] for x in res.json()} + assert r0.json()["session_id"] in ids + assert r1.json()["session_id"] not in ids