From 723b8d33c26ed7a7233ced61d91875a07f8693d4 Mon Sep 17 00:00:00 2001 From: Adam Weidman <65992621+adamfweidman@users.noreply.github.com> Date: Tue, 21 Oct 2025 01:40:54 +0200 Subject: [PATCH] chore: update tests with removed exclude from cli tsconfig (#11540) --- .../cli/src/ui/utils/computeStats.test.ts | 12 ++--- packages/cli/src/ui/utils/computeStats.ts | 7 ++- packages/cli/src/utils/cleanup.test.ts | 45 +++++++++---------- .../cli/src/utils/handleAutoUpdate.test.ts | 10 ++++- packages/cli/tsconfig.json | 10 +---- 5 files changed, 41 insertions(+), 43 deletions(-) diff --git a/packages/cli/src/ui/utils/computeStats.test.ts b/packages/cli/src/ui/utils/computeStats.test.ts index db8d4cc9b7..54cd196137 100644 --- a/packages/cli/src/ui/utils/computeStats.test.ts +++ b/packages/cli/src/ui/utils/computeStats.test.ts @@ -121,7 +121,7 @@ describe('computeSessionStats', () => { totalSuccess: 0, totalFail: 0, totalDurationMs: 0, - totalDecisions: { accept: 0, reject: 0, modify: 0 }, + totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 }, byName: {}, }, files: { @@ -169,7 +169,7 @@ describe('computeSessionStats', () => { totalSuccess: 1, totalFail: 0, totalDurationMs: 250, - totalDecisions: { accept: 0, reject: 0, modify: 0 }, + totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 }, byName: {}, }, files: { @@ -207,7 +207,7 @@ describe('computeSessionStats', () => { totalSuccess: 0, totalFail: 0, totalDurationMs: 0, - totalDecisions: { accept: 0, reject: 0, modify: 0 }, + totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 }, byName: {}, }, files: { @@ -229,7 +229,7 @@ describe('computeSessionStats', () => { totalSuccess: 8, totalFail: 2, totalDurationMs: 1000, - totalDecisions: { accept: 6, reject: 2, modify: 2 }, + totalDecisions: { accept: 6, reject: 2, modify: 2, auto_accept: 0 }, byName: {}, }, files: { @@ -252,7 +252,7 @@ describe('computeSessionStats', () => { totalSuccess: 0, totalFail: 0, totalDurationMs: 0, - totalDecisions: { accept: 0, reject: 0, modify: 0 }, + totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 }, byName: {}, }, files: { @@ -278,7 +278,7 @@ describe('computeSessionStats', () => { totalSuccess: 0, totalFail: 0, totalDurationMs: 0, - totalDecisions: { accept: 0, reject: 0, modify: 0 }, + totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 }, byName: {}, }, files: { diff --git a/packages/cli/src/ui/utils/computeStats.ts b/packages/cli/src/ui/utils/computeStats.ts index cc0d870e74..f9d51794b2 100644 --- a/packages/cli/src/ui/utils/computeStats.ts +++ b/packages/cli/src/ui/utils/computeStats.ts @@ -60,12 +60,15 @@ export const computeSessionStats = ( const totalDecisions = tools.totalDecisions.accept + tools.totalDecisions.reject + - tools.totalDecisions.modify; + tools.totalDecisions.modify + + tools.totalDecisions.auto_accept; const successRate = tools.totalCalls > 0 ? (tools.totalSuccess / tools.totalCalls) * 100 : 0; const agreementRate = totalDecisions > 0 - ? (tools.totalDecisions.accept / totalDecisions) * 100 + ? ((tools.totalDecisions.accept + tools.totalDecisions.auto_accept) / + totalDecisions) * + 100 : 0; return { diff --git a/packages/cli/src/utils/cleanup.test.ts b/packages/cli/src/utils/cleanup.test.ts index 0b254bac67..87ce5e1dbe 100644 --- a/packages/cli/src/utils/cleanup.test.ts +++ b/packages/cli/src/utils/cleanup.test.ts @@ -4,36 +4,34 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { vi } from 'vitest'; -import { registerCleanup, runExitCleanup } from './cleanup'; +import { vi, describe, it, expect, beforeEach } from 'vitest'; +import type { registerCleanup, runExitCleanup } from './cleanup.js'; describe('cleanup', () => { - const originalCleanupFunctions = global['cleanupFunctions']; + let register: typeof registerCleanup; + let runExit: typeof runExitCleanup; - beforeEach(() => { - // Isolate cleanup functions for each test - global['cleanupFunctions'] = []; - }); - - afterAll(() => { - // Restore original cleanup functions - global['cleanupFunctions'] = originalCleanupFunctions; + beforeEach(async () => { + vi.resetModules(); + const cleanupModule = await import('./cleanup.js'); + register = cleanupModule.registerCleanup; + runExit = cleanupModule.runExitCleanup; }); it('should run a registered synchronous function', async () => { const cleanupFn = vi.fn(); - registerCleanup(cleanupFn); + register(cleanupFn); - await runExitCleanup(); + await runExit(); expect(cleanupFn).toHaveBeenCalledTimes(1); }); it('should run a registered asynchronous function', async () => { const cleanupFn = vi.fn().mockResolvedValue(undefined); - registerCleanup(cleanupFn); + register(cleanupFn); - await runExitCleanup(); + await runExit(); expect(cleanupFn).toHaveBeenCalledTimes(1); }); @@ -42,25 +40,24 @@ describe('cleanup', () => { const syncFn = vi.fn(); const asyncFn = vi.fn().mockResolvedValue(undefined); - registerCleanup(syncFn); - registerCleanup(asyncFn); + register(syncFn); + register(asyncFn); - await runExitCleanup(); + await runExit(); expect(syncFn).toHaveBeenCalledTimes(1); expect(asyncFn).toHaveBeenCalledTimes(1); }); it('should continue running cleanup functions even if one throws an error', async () => { - const errorFn = vi.fn(() => { - throw new Error('Test Error'); + const errorFn = vi.fn().mockImplementation(() => { + throw new Error('test error'); }); const successFn = vi.fn(); + register(errorFn); + register(successFn); - registerCleanup(errorFn); - registerCleanup(successFn); - - await runExitCleanup(); + await expect(runExit()).resolves.not.toThrow(); expect(errorFn).toHaveBeenCalledTimes(1); expect(successFn).toHaveBeenCalledTimes(1); diff --git a/packages/cli/src/utils/handleAutoUpdate.test.ts b/packages/cli/src/utils/handleAutoUpdate.test.ts index bab3d685cb..a27da9a7db 100644 --- a/packages/cli/src/utils/handleAutoUpdate.test.ts +++ b/packages/cli/src/utils/handleAutoUpdate.test.ts @@ -26,7 +26,7 @@ vi.mock('./updateEventEmitter.js', async () => { return { ...actual, updateEventEmitter: { - ...actual.updateEventEmitter, + ...(actual['updateEventEmitter'] as EventEmitter), emit: vi.fn(), }, }; @@ -247,7 +247,13 @@ describe('handleAutoUpdate', () => { }); it('should use the "@nightly" tag for nightly updates', async () => { - mockUpdateInfo.update.latest = '2.0.0-nightly'; + mockUpdateInfo = { + ...mockUpdateInfo, + update: { + ...mockUpdateInfo.update, + latest: '2.0.0-nightly', + }, + }; mockGetInstallationInfo.mockReturnValue({ updateCommand: 'npm i -g @google/gemini-cli@latest', updateMessage: 'This is an additional message.', diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index 2224f2f52c..e361d7ffe0 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -13,14 +13,6 @@ "src/**/*.json", "./package.json" ], - "exclude": [ - "node_modules", - "dist", - // TODO(5691): Fix type errors and remove excludes. - "src/utils/cleanup.test.ts", - "src/utils/handleAutoUpdate.test.ts", - "src/utils/startupWarnings.test.ts", - "src/ui/utils/computeStats.test.ts" - ], + "exclude": ["node_modules", "dist"], "references": [{ "path": "../core" }] }