From de35ef21ce448a04c064aafce0665a3be57b11f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9C=A4=EC=A0=95=EB=AF=BC?= Date: Fri, 3 Jul 2026 16:42:33 +0900 Subject: [PATCH] Align final score order with team name order in tool output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 종료 스코어를 "원정:홈" 위치 표기에서 팀명 순서(우리팀:상대)로 정렬 — 순서 불일치로 모델이 홈 승리(8:3)를 "3:8 패배"로 오독하고 패배 서사까지 지어내던 문제 수정 - formatLineupResult 종료 스코어에 승패 명기 추가(기존엔 승패 표기 없음) - 원정 관점 회귀 테스트 추가. 프로브 실측: 동일 질문 5회 중 오독 2회 → 0회 --- src/services/chatToolService.ts | 14 ++++++++++---- tests/services/chatToolService.test.ts | 11 +++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/services/chatToolService.ts b/src/services/chatToolService.ts index 7c83235..54ebb83 100644 --- a/src/services/chatToolService.ts +++ b/src/services/chatToolService.ts @@ -141,9 +141,14 @@ export function formatLineupResult( const myPitcher = isHome ? game.homeStartingPitcher : game.awayStartingPitcher; const oppPitcher = isHome ? game.awayStartingPitcher : game.homeStartingPitcher; // 종료 경기의 최종 스코어는 결정된 사실 — 주입 허용(진행 중 스코어와 구분). + // 점수는 팀명 순서(우리팀:상대)와 일치시키고 승패를 명기한다 — "원정:홈" 위치 표기는 + // 앞의 "우리팀 vs 상대" 재배열과 어긋나 모델이 홈 승리를 패배로 오독했다. + const myScore = isHome ? game.homeScore : game.awayScore; + const oppScore = isHome ? game.awayScore : game.homeScore; const finalScore = - game.status === "completed" && game.awayScore != null && game.homeScore != null ? - ` — 종료 ${game.awayScore}:${game.homeScore}` : + game.status === "completed" && myScore != null && oppScore != null ? + ` — 종료 ${myScore}:${oppScore} (${teamLabel(team)} ${ + myScore > oppScore ? "승" : myScore < oppScore ? "패" : "무"})` : ""; const head = `${dateLabel} ${teamLabel(team)} vs ${teamLabel(oppCode)} (${game.time} ${game.stadium})${finalScore}. ` + @@ -313,10 +318,11 @@ export function formatGameStandouts( ): string { const isHome = game.homeTeamCode === team; const oppCode = (isHome ? game.awayTeamCode : game.homeTeamCode) as TeamCode; - const score = - game.awayScore != null && game.homeScore != null ? `${game.awayScore}:${game.homeScore}` : "?"; const my = isHome ? game.homeScore : game.awayScore; const opp = isHome ? game.awayScore : game.homeScore; + // 점수는 팀명 순서(우리팀:상대)와 일치시킨다 — "원정:홈" 위치 표기는 앞의 팀명 + // 재배열과 어긋나 모델이 홈 승리(8:3)를 "3:8 패배"로 오독하고 서사까지 지어냈다. + const score = my != null && opp != null ? `${my}:${opp}` : "?"; const result = my != null && opp != null ? (my > opp ? "승" : my < opp ? "패" : "무") : ""; const head = `${dateLabel} ${teamLabel(team)} vs ${teamLabel(oppCode)} — 종료 ${score} (${teamLabel(team)} ${result})`; diff --git a/tests/services/chatToolService.test.ts b/tests/services/chatToolService.test.ts index c3bbb42..e479dd3 100644 --- a/tests/services/chatToolService.test.ts +++ b/tests/services/chatToolService.test.ts @@ -149,7 +149,8 @@ describe("chatToolService", () => { "2026-05-01", ); expect(out).toContain("2026-05-01"); - expect(out).toContain("종료 3:5"); + // 점수는 팀명 순서(우리팀:상대) — 한화(홈) 5, LG(원정) 3. 승패 명기로 오독 방지. + expect(out).toContain("종료 5:3 (한화 이글스 승)"); expect(out).toContain("[확정 선발 라인업]"); }); @@ -359,11 +360,17 @@ describe("chatToolService", () => { it("종료 스코어와 WPA 상위 타자·투수를 기록과 함께 전한다", () => { const out = formatGameStandouts(TeamCode.HH, completed, hitters, pitchers, "2026-05-01"); - expect(out).toContain("종료 3:8"); + // 점수는 팀명 순서(우리팀:상대) — 한화(홈) 8, LG(원정) 3. away:home 표기는 오독 유발. + expect(out).toContain("종료 8:3 (한화 이글스 승)"); expect(out).toContain("양의지: 4타수 3안타 2타점 1홈런"); expect(out).toContain("곽빈: 6이닝 1실점 7K"); }); + it("원정 팀 관점에서는 점수·승패가 뒤집힌다", () => { + const out = formatGameStandouts(TeamCode.LG, completed, hitters, pitchers, "2026-05-01"); + expect(out).toContain("종료 3:8 (LG 트윈스 패)"); + }); + it("player 인자가 활약 상위에 있으면 그 사실을 표시한다", () => { const out = formatGameStandouts(TeamCode.HH, completed, hitters, pitchers, "2026-05-01", "양의지"); expect(out).toContain("양의지: 4타수 3안타 2타점 1홈런 — 이 경기 활약 상위");