Fix status/active mirror drift in upsert_sources (pre Promote-candidate)
Per Codex: upsert_sources() wrote `active` but not `status`, so a candidate promoted inactive (the pipeline default) became active=0 + status='active' — the exact mirror drift Phase 1 set out to avoid (scheduler won't poll, admin UI shows "active"). Now derive status from an explicit value or from active, mirror active off status, and write both columns together (insert + conflict update). Test: promote_candidate(active=False) → status='paused', active=0. Also fix stale source_health docstring (now includes retired). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -36,9 +36,10 @@ def test_promote_creates_inactive_source_and_marks_promoted(conn):
|
||||
cand = save_candidate(conn, "http://x/feed", name="Lovely Feed")
|
||||
source_id = promote_candidate(conn, cand["id"]) # inactive by default
|
||||
|
||||
src = conn.execute("SELECT name, active FROM sources WHERE id = ?", (source_id,)).fetchone()
|
||||
src = conn.execute("SELECT name, active, status FROM sources WHERE id = ?", (source_id,)).fetchone()
|
||||
assert src["name"] == "Lovely Feed"
|
||||
assert src["active"] == 0 # active-on-approval: not polled until activated
|
||||
assert src["status"] == "paused" # status mirrors active — no drift (active=0 ⇒ paused)
|
||||
|
||||
status = conn.execute("SELECT status FROM source_candidates WHERE id = ?", (cand["id"],)).fetchone()["status"]
|
||||
assert status == "promoted"
|
||||
@@ -47,7 +48,8 @@ def test_promote_creates_inactive_source_and_marks_promoted(conn):
|
||||
def test_promote_active_flag(conn):
|
||||
cand = save_candidate(conn, "http://y/feed", name="Y")
|
||||
sid = promote_candidate(conn, cand["id"], active=True)
|
||||
assert conn.execute("SELECT active FROM sources WHERE id = ?", (sid,)).fetchone()["active"] == 1
|
||||
src = conn.execute("SELECT active, status FROM sources WHERE id = ?", (sid,)).fetchone()
|
||||
assert src["active"] == 1 and src["status"] == "active" # both set together
|
||||
|
||||
|
||||
def test_promote_unknown_raises(conn):
|
||||
|
||||
Reference in New Issue
Block a user