Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/app/teams/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,9 @@ def parse_bid_award(reply: str, candidate_ids: set[str]) -> dict[str, Any] | Non
score = float(item.get("score"))
except (TypeError, ValueError):
continue
# 与 parse_bid_scores 一致:裁决分数同样落在 0-10,避免污染血条与看板
scores[str(agent_id)] = {
"score": score,
"score": min(10.0, max(0.0, score)),
"rationale": str(item.get("rationale") or "").strip(),
}
return {
Expand Down
17 changes: 17 additions & 0 deletions backend/tests/test_teams_bidding.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,23 @@ def test_parse_bid_award_requires_candidate_winner() -> None:
assert parse_bid_award("没有块", candidates) is None


def test_parse_bid_award_clamps_scores_to_zero_ten() -> None:
candidates = {"agent_a", "agent_b"}
reply = (
"```json\n"
'{"bid_award": {"winner_agent_id": "agent_a", '
'"scores": {"agent_a": {"score": 12.0, "rationale": "超出"}, '
'"agent_b": {"score": -3.0, "rationale": "负分"}}, '
'"comment": "甲更匹配"}}\n```'
)
award = parse_bid_award(reply, candidates)
assert award is not None
assert award["winner_agent_id"] == "agent_a"
# 与 parse_bid_scores 一致,裁决分数也截断到 0-10,避免污染血条(HP)与看板
assert award["scores"]["agent_a"] == {"score": 10.0, "rationale": "超出"}
assert award["scores"]["agent_b"] == {"score": 0.0, "rationale": "负分"}


def test_parse_bid_scores() -> None:
candidates = {"agent_a", "agent_b"}
scores = parse_bid_scores(_score_reply(("agent_a", 9.0), ("agent_b", 8.0)), candidates)
Expand Down