From bd73ca0b6dde1c2c9d3f0af54a620add69f8d598 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Tue, 14 Apr 2026 14:57:16 -0700 Subject: [PATCH] fix(tests): correct build endpoint test fixture - Use monkeypatch.setattr to patch cloud_session._LOCAL_KIWI_DB instead of wrong KIWI_DB_PATH env var (module-level singleton computed at import time; env var had no effect) - Assert id > 0 (real persisted DB id) instead of -1 (old pre-persistence sentinel value) --- tests/api/test_recipe_build_endpoints.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/api/test_recipe_build_endpoints.py b/tests/api/test_recipe_build_endpoints.py index f40ed4c..8d21a89 100644 --- a/tests/api/test_recipe_build_endpoints.py +++ b/tests/api/test_recipe_build_endpoints.py @@ -4,14 +4,14 @@ from fastapi.testclient import TestClient @pytest.fixture -def client(tmp_path): +def client(tmp_path, monkeypatch): """FastAPI test client with a seeded in-memory DB.""" import os - os.environ["KIWI_DB_PATH"] = str(tmp_path / "test.db") + db_path = tmp_path / "test.db" os.environ["CLOUD_MODE"] = "false" - from app.main import app + # Seed DB before app imports so migrations run and data is present from app.db.store import Store - store = Store(tmp_path / "test.db") + store = Store(db_path) store.conn.execute( "INSERT INTO products (name, barcode) VALUES (?,?)", ("chicken breast", None) ) @@ -25,6 +25,11 @@ def client(tmp_path): "INSERT INTO inventory_items (product_id, location, status) VALUES (2,'pantry','available')" ) store.conn.commit() + store.close() + # Patch the module-level DB path used by local-mode session resolution + import app.cloud_session as _cs + monkeypatch.setattr(_cs, "_LOCAL_KIWI_DB", db_path) + from app.main import app return TestClient(app) @@ -65,7 +70,7 @@ def test_post_build_returns_recipe(client): }) assert resp.status_code == 200 data = resp.json() - assert data["id"] == -1 + assert data["id"] > 0 # persisted to DB with real integer ID assert len(data["directions"]) > 0