soulsync/tests/automation
BoulderBadgeDad 6980253a96 Automations: run each as its OWNER profile in the background (part 1 of per-profile sync)
Background automations had no session, so get_current_profile_id() fell back to
admin (1) — wrong for a non-admin's scheduled job. Now the engine declares the
automation's owner around handler execution via a contextvar
(core/profile_context.py), and get_current_profile_id() consults it only when
there's NO web request. So:
- a real logged-in request always wins (foreground unchanged),
- admin + system automations are profile 1 → resolve to admin exactly as before
  (the 8 admin-owned auto-sync pipelines behave identically),
- only non-admin-owned automations gain their correct identity, deep through the
  whole call chain (incl. the per-profile client resolvers) — no threading
  profile_id through dozens of signatures.

Reset in a finally so a pooled thread can't leak the override to the next job.

Tests: contextvar set/reset/nested; get_current_profile_id honours the override
only outside a request (a real session still wins); and end-to-end — the engine
runs a non-admin automation as profile 4, an admin one as 1, an explicit trigger
profile overrides the owner, and the context resets even when the handler raises.
27 + 4 tests pass.

Part 2 (next): point the sync handlers' source-playlist READ at
get_spotify_client_for_profile so a non-admin's auto-sync pulls THEIR playlist.
2026-06-10 15:37:56 -07:00
..
__init__.py Lift /api/automations/* into core/automation/ 2026-04-27 18:05:14 -07:00
test_automation_api.py Add owned_by column for Auto-Sync schedule ownership 2026-05-24 23:40:22 -07:00
test_automation_blocks.py Personalized pipeline: UI multi-select picker for kinds + variants 2026-05-15 19:33:34 -07:00
test_automation_progress.py Lift /api/automations/* into core/automation/ 2026-04-27 18:05:14 -07:00
test_automation_signals.py Lift /api/automations/* into core/automation/ 2026-04-27 18:05:14 -07:00
test_engine_profile_context.py Automations: run each as its OWNER profile in the background (part 1 of per-profile sync) 2026-06-10 15:37:56 -07:00
test_engine_schedule_integration.py Wire automation engine through next_run_at + register monthly_time (PR 2/4) 2026-05-27 12:03:41 -07:00
test_handler_error_storage.py Harden playlist pipeline source refresh 2026-05-24 19:31:00 -07:00
test_handler_registration.py Fix organize-by-playlist downloads: library entries, wishlist, and stale Spotify cache 2026-06-03 10:26:32 +02:00
test_handlers_maintenance.py Fix organize-by-playlist downloads: library entries, wishlist, and stale Spotify cache 2026-06-03 10:26:32 +02:00
test_handlers_personalized_pipeline.py Fix organize-by-playlist downloads: library entries, wishlist, and stale Spotify cache 2026-06-03 10:26:32 +02:00
test_handlers_playlist.py Sync: automated syncs honor the configured playlist sync mode instead of hardcoding 'replace' (#823) 2026-06-09 08:49:46 -07:00
test_handlers_simple.py Fix organize-by-playlist downloads: library entries, wishlist, and stale Spotify cache 2026-06-03 10:26:32 +02:00
test_playlist_pipeline_folder_mode.py Fix organize-by-playlist downloads: library entries, wishlist, and stale Spotify cache 2026-06-03 10:26:32 +02:00
test_progress_callbacks.py Fix organize-by-playlist downloads: library entries, wishlist, and stale Spotify cache 2026-06-03 10:26:32 +02:00
test_schedule.py Close three review gaps before PR 1 ships 2026-05-27 11:33:05 -07:00