From 83398c8413275e403528077df8f8c162a6920daa Mon Sep 17 00:00:00 2001 From: gahusb Date: Thu, 11 Jun 2026 02:31:18 +0900 Subject: [PATCH] =?UTF-8?q?fix(insta-lab):=20=EC=84=A0=EB=B3=84=20zero-pre?= =?UTF-8?q?f=20=ED=81=AC=EB=9E=98=EC=8B=9C=20=EA=B0=80=EB=93=9C=20+=20judg?= =?UTF-8?q?e=20max=5Ftokens=20=EC=83=81=ED=96=A5=20+=20404=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- insta-lab/app/selection.py | 2 ++ insta-lab/app/selection_judge.py | 2 +- insta-lab/tests/test_ranked_decision_api.py | 5 +++++ insta-lab/tests/test_selection.py | 8 ++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/insta-lab/app/selection.py b/insta-lab/app/selection.py index 4edca33..80d9c41 100644 --- a/insta-lab/app/selection.py +++ b/insta-lab/app/selection.py @@ -55,6 +55,8 @@ def score_candidates( w = weights or DEFAULT_WEIGHTS now = _parse_iso(now_iso) if now_iso else datetime.now(timezone.utc) max_w = max(prefs.values()) if prefs else 1.0 + if max_w <= 0: + max_w = 1.0 out: List[Dict[str, Any]] = [] for c in candidates: cat = c.get("category", "") diff --git a/insta-lab/app/selection_judge.py b/insta-lab/app/selection_judge.py index b745b96..0de93c7 100644 --- a/insta-lab/app/selection_judge.py +++ b/insta-lab/app/selection_judge.py @@ -43,7 +43,7 @@ def judge_candidates(candidates: List[Dict[str, Any]]) -> Dict[int, float]: try: client = Anthropic(api_key=ANTHROPIC_API_KEY) resp = client.messages.create( - model=ANTHROPIC_MODEL_HAIKU, max_tokens=512, + model=ANTHROPIC_MODEL_HAIKU, max_tokens=1024, messages=[{"role": "user", "content": PROMPT.format(items=items)}], ) return parse_judge_response(resp.content[0].text) diff --git a/insta-lab/tests/test_ranked_decision_api.py b/insta-lab/tests/test_ranked_decision_api.py index 9ca95d8..ad1aa34 100644 --- a/insta-lab/tests/test_ranked_decision_api.py +++ b/insta-lab/tests/test_ranked_decision_api.py @@ -40,3 +40,8 @@ def test_decision_invalid_400(client): sid = db.add_card_slate({"keyword": "x", "category": "economy"}) r = client.post(f"/api/insta/slates/{sid}/decision", json={"decision": "maybe"}) assert r.status_code == 400 + + +def test_decision_unknown_slate_404(client): + r = client.post("/api/insta/slates/99999/decision", json={"decision": "approved"}) + assert r.status_code == 404 diff --git a/insta-lab/tests/test_selection.py b/insta-lab/tests/test_selection.py index 818e80f..3d762f2 100644 --- a/insta-lab/tests/test_selection.py +++ b/insta-lab/tests/test_selection.py @@ -45,3 +45,11 @@ def test_claude_included_when_provided(): cands = [_cand(1, "A", "economy", 0.5, NOW)] out = score_candidates(cands, [], {"economy": 1.0}, {1: 1.0}, threshold=0.0, now_iso=NOW) assert out[0]["breakdown"]["claude"] == 1.0 + + +def test_all_zero_prefs_no_crash(): + cands = [{"id": 1, "keyword": "A", "category": "economy", "score": 0.8, + "suggested_at": "2026-06-11T00:00:00Z"}] + prefs = {"economy": 0.0, "psychology": 0.0} + out = score_candidates(cands, [], prefs, None, threshold=0.0, now_iso="2026-06-11T00:00:00Z") + assert out[0]["breakdown"]["account_fit"] == 0.0 # 0가중 → fit 0, 크래시 없음