fix(tests): align stale tests with current API + bypass identity-map cache

- test_recipes: split update test into in-place vs copy-on-write paths
  (PUT now updates in-place when current version has no measurements).
  Added _seed_measurement() helper to force copy-on-write where needed.
- test_tasks::reorder: expunge_all() between POST and GET so the shared
  test session re-fetches RecipeVersion.tasks instead of returning the
  cached collection. Prod uses one session per request, so identity-map
  staleness only affects tests.
- test_measure::save_measurement_proxy: payload aligned to current API
  (version_id is required; pass_fail/deviation are computed server-side).

All 179 tests green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-18 17:07:32 +02:00
parent 6a8931e108
commit fb96bad000
3 changed files with 85 additions and 25 deletions
+6 -2
View File
@@ -189,7 +189,7 @@ class TestReorderTasks:
"""Maker can reorder tasks by providing task IDs in desired order."""
recipe = await create_test_recipe(db_session, maker_user.id)
# Add a second task via copy-on-write
# Add a second task (no measurements → appended to current version)
add_resp = await client.post(
f"/api/recipes/{recipe.id}/tasks",
headers=auth_headers(maker_user),
@@ -197,7 +197,11 @@ class TestReorderTasks:
)
assert add_resp.status_code == 201
# Get tasks from new version
# Force SQLA to re-fetch RecipeVersion.tasks: the shared test session
# caches the collection from create_test_recipe, so the GET below would
# otherwise return a stale list. In prod each request gets its own session.
db_session.expunge_all()
tasks_resp = await client.get(
f"/api/recipes/{recipe.id}/tasks",
headers=auth_headers(maker_user),