From 498edb57abc9c047e2bd1ea828cc591618745bc4 Mon Sep 17 00:00:00 2001
From: Allen Hutchison <adh@google.com>
Date: Wed, 30 Jul 2025 15:09:32 -0700
Subject: fix(testing): make ModelStatsDisplay snapshot test deterministic
 (#5236)

Co-authored-by: Jacob Richman <jacob314@gmail.com>
---
 packages/cli/src/ui/components/ModelStatsDisplay.test.tsx | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

(limited to 'packages/cli/src/ui/components/ModelStatsDisplay.test.tsx')

diff --git a/packages/cli/src/ui/components/ModelStatsDisplay.test.tsx b/packages/cli/src/ui/components/ModelStatsDisplay.test.tsx
index 57382d91..6adf2652 100644
--- a/packages/cli/src/ui/components/ModelStatsDisplay.test.tsx
+++ b/packages/cli/src/ui/components/ModelStatsDisplay.test.tsx
@@ -5,7 +5,7 @@
  */
 
 import { render } from 'ink-testing-library';
-import { describe, it, expect, vi } from 'vitest';
+import { describe, it, expect, vi, beforeAll, afterAll } from 'vitest';
 import { ModelStatsDisplay } from './ModelStatsDisplay.js';
 import * as SessionContext from '../contexts/SessionContext.js';
 import { SessionMetrics } from '../contexts/SessionContext.js';
@@ -38,6 +38,19 @@ const renderWithMockedStats = (metrics: SessionMetrics) => {
 };
 
 describe('<ModelStatsDisplay />', () => {
+  beforeAll(() => {
+    vi.spyOn(Number.prototype, 'toLocaleString').mockImplementation(function (
+      this: number,
+    ) {
+      // Use a stable 'en-US' format for test consistency.
+      return new Intl.NumberFormat('en-US').format(this);
+    });
+  });
+
+  afterAll(() => {
+    vi.restoreAllMocks();
+  });
+
   it('should render "no API calls" message when there are no active models', () => {
     const { lastFrame } = renderWithMockedStats({
       models: {},
-- 
cgit v1.2.3

