Public Access
feat: orchestrator runner — run_step / run_week per-family loop
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -423,3 +423,45 @@ def test_step_finalize_no_approved_sends_empty_message(db, weekly_run_deadline_p
|
||||
step_finalize(weekly_run_deadline_passed, db)
|
||||
assert weekly_run_deadline_passed.finalized_at is not None
|
||||
assert "No meals were approved" in sent[0]["html"]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# runner tests
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_run_step_upserts_weekly_run(db, family, monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
"app.services.orchestrator.steps.ScraperService.run_scrape",
|
||||
lambda self, **kw: {"status": "success", "items_scraped": 0},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"app.services.orchestrator.runner.SessionLocal",
|
||||
lambda: db,
|
||||
)
|
||||
from app.services.orchestrator.runner import run_step
|
||||
run_step("scrape", WEEK)
|
||||
from app.models import WeeklyRun
|
||||
run = db.query(WeeklyRun).filter(WeeklyRun.family_id == family.id).first()
|
||||
assert run is not None
|
||||
assert run.scraped_at is not None
|
||||
|
||||
|
||||
def test_run_step_invalid_raises(monkeypatch):
|
||||
from app.services.orchestrator.runner import run_step
|
||||
with pytest.raises(ValueError, match="Unknown step"):
|
||||
run_step("bogus", WEEK)
|
||||
|
||||
|
||||
def test_run_week_calls_all_steps(monkeypatch):
|
||||
called = []
|
||||
|
||||
def fake_run_step(step, week):
|
||||
called.append(step)
|
||||
|
||||
monkeypatch.setattr(
|
||||
"app.services.orchestrator.runner.run_step",
|
||||
fake_run_step,
|
||||
)
|
||||
from app.services.orchestrator.runner import run_week
|
||||
run_week(WEEK)
|
||||
assert called == ["scrape", "generate", "email", "deadline", "finalize"]
|
||||
|
||||
Reference in New Issue
Block a user