Skip to content

Commit 723b8d3

Browse files
authored
chore: update tests with removed exclude from cli tsconfig (#11540)
1 parent 70a99af commit 723b8d3

File tree

5 files changed

+42
-44
lines changed

5 files changed

+42
-44
lines changed

packages/cli/src/ui/utils/computeStats.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe('computeSessionStats', () => {
121121
totalSuccess: 0,
122122
totalFail: 0,
123123
totalDurationMs: 0,
124-
totalDecisions: { accept: 0, reject: 0, modify: 0 },
124+
totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 },
125125
byName: {},
126126
},
127127
files: {
@@ -169,7 +169,7 @@ describe('computeSessionStats', () => {
169169
totalSuccess: 1,
170170
totalFail: 0,
171171
totalDurationMs: 250,
172-
totalDecisions: { accept: 0, reject: 0, modify: 0 },
172+
totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 },
173173
byName: {},
174174
},
175175
files: {
@@ -207,7 +207,7 @@ describe('computeSessionStats', () => {
207207
totalSuccess: 0,
208208
totalFail: 0,
209209
totalDurationMs: 0,
210-
totalDecisions: { accept: 0, reject: 0, modify: 0 },
210+
totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 },
211211
byName: {},
212212
},
213213
files: {
@@ -229,7 +229,7 @@ describe('computeSessionStats', () => {
229229
totalSuccess: 8,
230230
totalFail: 2,
231231
totalDurationMs: 1000,
232-
totalDecisions: { accept: 6, reject: 2, modify: 2 },
232+
totalDecisions: { accept: 6, reject: 2, modify: 2, auto_accept: 0 },
233233
byName: {},
234234
},
235235
files: {
@@ -252,7 +252,7 @@ describe('computeSessionStats', () => {
252252
totalSuccess: 0,
253253
totalFail: 0,
254254
totalDurationMs: 0,
255-
totalDecisions: { accept: 0, reject: 0, modify: 0 },
255+
totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 },
256256
byName: {},
257257
},
258258
files: {
@@ -278,7 +278,7 @@ describe('computeSessionStats', () => {
278278
totalSuccess: 0,
279279
totalFail: 0,
280280
totalDurationMs: 0,
281-
totalDecisions: { accept: 0, reject: 0, modify: 0 },
281+
totalDecisions: { accept: 0, reject: 0, modify: 0, auto_accept: 0 },
282282
byName: {},
283283
},
284284
files: {

packages/cli/src/ui/utils/computeStats.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@ export const computeSessionStats = (
6060
const totalDecisions =
6161
tools.totalDecisions.accept +
6262
tools.totalDecisions.reject +
63-
tools.totalDecisions.modify;
63+
tools.totalDecisions.modify +
64+
tools.totalDecisions.auto_accept;
6465
const successRate =
6566
tools.totalCalls > 0 ? (tools.totalSuccess / tools.totalCalls) * 100 : 0;
6667
const agreementRate =
6768
totalDecisions > 0
68-
? (tools.totalDecisions.accept / totalDecisions) * 100
69+
? ((tools.totalDecisions.accept + tools.totalDecisions.auto_accept) /
70+
totalDecisions) *
71+
100
6972
: 0;
7073

7174
return {

packages/cli/src/utils/cleanup.test.ts

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,34 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import { vi } from 'vitest';
8-
import { registerCleanup, runExitCleanup } from './cleanup';
7+
import { vi, describe, it, expect, beforeEach } from 'vitest';
8+
import type { registerCleanup, runExitCleanup } from './cleanup.js';
99

1010
describe('cleanup', () => {
11-
const originalCleanupFunctions = global['cleanupFunctions'];
12-
13-
beforeEach(() => {
14-
// Isolate cleanup functions for each test
15-
global['cleanupFunctions'] = [];
16-
});
17-
18-
afterAll(() => {
19-
// Restore original cleanup functions
20-
global['cleanupFunctions'] = originalCleanupFunctions;
11+
let register: typeof registerCleanup;
12+
let runExit: typeof runExitCleanup;
13+
14+
beforeEach(async () => {
15+
vi.resetModules();
16+
const cleanupModule = await import('./cleanup.js');
17+
register = cleanupModule.registerCleanup;
18+
runExit = cleanupModule.runExitCleanup;
2119
});
2220

2321
it('should run a registered synchronous function', async () => {
2422
const cleanupFn = vi.fn();
25-
registerCleanup(cleanupFn);
23+
register(cleanupFn);
2624

27-
await runExitCleanup();
25+
await runExit();
2826

2927
expect(cleanupFn).toHaveBeenCalledTimes(1);
3028
});
3129

3230
it('should run a registered asynchronous function', async () => {
3331
const cleanupFn = vi.fn().mockResolvedValue(undefined);
34-
registerCleanup(cleanupFn);
32+
register(cleanupFn);
3533

36-
await runExitCleanup();
34+
await runExit();
3735

3836
expect(cleanupFn).toHaveBeenCalledTimes(1);
3937
});
@@ -42,25 +40,24 @@ describe('cleanup', () => {
4240
const syncFn = vi.fn();
4341
const asyncFn = vi.fn().mockResolvedValue(undefined);
4442

45-
registerCleanup(syncFn);
46-
registerCleanup(asyncFn);
43+
register(syncFn);
44+
register(asyncFn);
4745

48-
await runExitCleanup();
46+
await runExit();
4947

5048
expect(syncFn).toHaveBeenCalledTimes(1);
5149
expect(asyncFn).toHaveBeenCalledTimes(1);
5250
});
5351

5452
it('should continue running cleanup functions even if one throws an error', async () => {
55-
const errorFn = vi.fn(() => {
56-
throw new Error('Test Error');
53+
const errorFn = vi.fn().mockImplementation(() => {
54+
throw new Error('test error');
5755
});
5856
const successFn = vi.fn();
57+
register(errorFn);
58+
register(successFn);
5959

60-
registerCleanup(errorFn);
61-
registerCleanup(successFn);
62-
63-
await runExitCleanup();
60+
await expect(runExit()).resolves.not.toThrow();
6461

6562
expect(errorFn).toHaveBeenCalledTimes(1);
6663
expect(successFn).toHaveBeenCalledTimes(1);

packages/cli/src/utils/handleAutoUpdate.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ vi.mock('./updateEventEmitter.js', async () => {
2626
return {
2727
...actual,
2828
updateEventEmitter: {
29-
...actual.updateEventEmitter,
29+
...(actual['updateEventEmitter'] as EventEmitter),
3030
emit: vi.fn(),
3131
},
3232
};
@@ -247,7 +247,13 @@ describe('handleAutoUpdate', () => {
247247
});
248248

249249
it('should use the "@nightly" tag for nightly updates', async () => {
250-
mockUpdateInfo.update.latest = '2.0.0-nightly';
250+
mockUpdateInfo = {
251+
...mockUpdateInfo,
252+
update: {
253+
...mockUpdateInfo.update,
254+
latest: '2.0.0-nightly',
255+
},
256+
};
251257
mockGetInstallationInfo.mockReturnValue({
252258
updateCommand: 'npm i -g @google/gemini-cli@latest',
253259
updateMessage: 'This is an additional message.',

packages/cli/tsconfig.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@
1313
"src/**/*.json",
1414
"./package.json"
1515
],
16-
"exclude": [
17-
"node_modules",
18-
"dist",
19-
// TODO(5691): Fix type errors and remove excludes.
20-
"src/utils/cleanup.test.ts",
21-
"src/utils/handleAutoUpdate.test.ts",
22-
"src/utils/startupWarnings.test.ts",
23-
"src/ui/utils/computeStats.test.ts"
24-
],
16+
"exclude": ["node_modules", "dist"],
2517
"references": [{ "path": "../core" }]
2618
}

0 commit comments

Comments
 (0)