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홈런 — 이 경기 활약 상위");