fix(insta-lab): 선별 zero-pref 크래시 가드 + judge max_tokens 상향 + 404 테스트
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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", "")
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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, 크래시 없음
|
||||
|
||||
Reference in New Issue
Block a user