test(cleanup): fix temporary directory leaks in test suites (#26217)

This commit is contained in:
Adib234
2026-05-04 15:08:02 -04:00
committed by GitHub
parent a7beb890d0
commit 75a8de83fc
4 changed files with 50 additions and 11 deletions
+17 -5
View File
@@ -45,6 +45,7 @@ import type { ResourceRegistry } from '../resources/resource-registry.js';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { cleanupTmpDir } from '@google/gemini-cli-test-utils';
import { coreEvents } from '../utils/events.js';
import type { EnvironmentSanitizationConfig } from '../services/environmentSanitization.js';
@@ -105,9 +106,11 @@ describe('mcp-client', () => {
workspaceContext = new WorkspaceContext(testWorkspace);
});
afterEach(() => {
vi.restoreAllMocks();
afterEach(async () => {
vi.useRealTimers();
await cleanupTmpDir(testWorkspace);
workspaceContext = null as unknown as WorkspaceContext;
vi.restoreAllMocks();
});
describe('McpClient', () => {
@@ -2410,7 +2413,10 @@ describe('connectToMcpServer with OAuth', () => {
vi.mocked(MCPOAuthProvider).mockReturnValue(mockAuthProvider);
});
afterEach(() => {
afterEach(async () => {
vi.useRealTimers();
await cleanupTmpDir(testWorkspace);
workspaceContext = null as unknown as WorkspaceContext;
vi.clearAllMocks();
});
@@ -2617,7 +2623,10 @@ describe('connectToMcpServer - HTTP→SSE fallback', () => {
vi.spyOn(console, 'error').mockImplementation(() => {});
});
afterEach(() => {
afterEach(async () => {
vi.useRealTimers();
await cleanupTmpDir(testWorkspace);
workspaceContext = null as unknown as WorkspaceContext;
vi.clearAllMocks();
});
@@ -2780,7 +2789,10 @@ describe('connectToMcpServer - OAuth with transport fallback', () => {
});
});
afterEach(() => {
afterEach(async () => {
vi.useRealTimers();
await cleanupTmpDir(testWorkspace);
workspaceContext = null as unknown as WorkspaceContext;
vi.clearAllMocks();
vi.unstubAllGlobals();
});