Skip to content

Commit 8af8ff9

Browse files
committed
chore: fix broken tests
1 parent fbb5bb0 commit 8af8ff9

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

packages/agent/src/tools/browser/BrowserManager.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ export class BrowserManager {
1414
headless: true,
1515
defaultTimeout: 30000,
1616
};
17-
17+
1818
constructor() {
1919
// Store a reference to the instance globally for cleanup
2020
// This allows the CLI to access the instance for cleanup
2121
(globalThis as any).__BROWSER_MANAGER__ = this;
22-
22+
2323
// Set up cleanup handlers for graceful shutdown
2424
this.setupGlobalCleanup();
2525
}
@@ -92,7 +92,7 @@ export class BrowserManager {
9292
// No need to add individual process handlers for each session
9393
// We'll handle all sessions in the global cleanup
9494
}
95-
95+
9696
/**
9797
* Sets up global cleanup handlers for all browser sessions
9898
*/
@@ -103,23 +103,28 @@ export class BrowserManager {
103103
console.error('Error closing browser sessions:', err);
104104
});
105105
});
106-
106+
107107
// Use exit for synchronous cleanup (as a fallback)
108108
process.on('exit', () => {
109109
// Can only do synchronous operations here
110110
for (const session of this.sessions.values()) {
111111
try {
112112
// Attempt synchronous close - may not fully work
113113
session.browser.close();
114+
// eslint-disable-next-line unused-imports/no-unused-vars
114115
} catch (e) {
115116
// Ignore errors during exit
116117
}
117118
}
118119
});
119-
120+
120121
// Handle SIGINT (Ctrl+C)
121122
process.on('SIGINT', () => {
122-
this.closeAllSessions().catch(() => {})
123+
// eslint-disable-next-line promise/catch-or-return
124+
this.closeAllSessions()
125+
.catch(() => {
126+
return false;
127+
})
123128
.finally(() => {
124129
// Give a moment for cleanup to complete
125130
setTimeout(() => process.exit(0), 500);

packages/cli/src/commands/config.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export interface ConfigOptions extends SharedOptions {
2121
command: 'get' | 'set' | 'list' | 'clear';
2222
key?: string;
2323
value?: string;
24-
all: boolean; // Has default value in builder, so it's always defined
25-
global: boolean; // Has default value in builder, so it's always defined
26-
verbose: boolean; // Has default value in builder, so it's always defined
24+
all: boolean; // Has default value in builder, so it's always defined
25+
global: boolean; // Has default value in builder, so it's always defined
26+
verbose: boolean; // Has default value in builder, so it's always defined
2727
}
2828

2929
export const command: CommandModule<SharedOptions, ConfigOptions> = {
@@ -134,10 +134,9 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
134134
logger.info('Current configuration:');
135135

136136
// Show config file locations
137-
const {
138-
getSettingsDir,
139-
getProjectSettingsDir,
140-
} = require('../settings/settings.js');
137+
const { getSettingsDir, getProjectSettingsDir } = await import(
138+
'../settings/settings.js'
139+
);
141140
const globalConfigPath = path.join(getSettingsDir(), 'config.json');
142141
const projectDir = getProjectSettingsDir();
143142
const projectConfigPath = projectDir

packages/cli/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ await main()
8383
.finally(async () => {
8484
// Report timings if profiling is enabled
8585
await reportTimings();
86-
86+
8787
// Clean up all resources before exit
8888
await cleanupResources();
89-
89+
9090
// Setup a force exit as a failsafe
9191
// This ensures the process will exit even if there are lingering handles
9292
setupForceExit(5000);

packages/cli/src/utils/cleanup.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ import { BrowserManager, processStates } from 'mycoder-agent';
66
*/
77
export async function cleanupResources(): Promise<void> {
88
console.log('Cleaning up resources before exit...');
9-
9+
1010
// 1. Clean up browser sessions
1111
try {
1212
// Get the BrowserManager instance - this is a singleton
13-
const browserManager = (globalThis as any).__BROWSER_MANAGER__ as BrowserManager | undefined;
13+
const browserManager = (globalThis as any).__BROWSER_MANAGER__ as
14+
| BrowserManager
15+
| undefined;
1416
if (browserManager) {
1517
console.log('Closing all browser sessions...');
1618
await browserManager.closeAllSessions();
1719
}
1820
} catch (error) {
1921
console.error('Error closing browser sessions:', error);
2022
}
21-
23+
2224
// 2. Clean up shell processes
2325
try {
2426
if (processStates.size > 0) {
@@ -34,6 +36,7 @@ export async function cleanupResources(): Promise<void> {
3436
if (!state.state.completed) {
3537
state.process.kill('SIGKILL');
3638
}
39+
// eslint-disable-next-line unused-imports/no-unused-vars
3740
} catch (e) {
3841
// Ignore errors on forced kill
3942
}
@@ -47,10 +50,10 @@ export async function cleanupResources(): Promise<void> {
4750
} catch (error) {
4851
console.error('Error terminating shell processes:', error);
4952
}
50-
53+
5154
// 3. Give async operations a moment to complete
5255
await new Promise((resolve) => setTimeout(resolve, 1000));
53-
56+
5457
console.log('Cleanup completed');
5558
}
5659

@@ -63,4 +66,4 @@ export function setupForceExit(timeoutMs = 5000): void {
6366
console.log(`Forcing exit after ${timeoutMs}ms timeout`);
6467
process.exit(0);
6568
}, timeoutMs);
66-
}
69+
}

packages/cli/tests/commands/config.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
updateConfig,
99
getConfigAtLevel,
1010
clearConfigAtLevel,
11+
clearConfigKey,
1112
} from '../../src/settings/config.js';
1213

1314
// Mock dependencies
@@ -17,6 +18,7 @@ vi.mock('../../src/settings/config.js', () => ({
1718
updateConfig: vi.fn(),
1819
getConfigAtLevel: vi.fn(),
1920
clearConfigAtLevel: vi.fn(),
21+
clearConfigKey: vi.fn(),
2022
ConfigLevel: {
2123
DEFAULT: 'default',
2224
GLOBAL: 'global',
@@ -76,6 +78,8 @@ describe('Config Command', () => {
7678
...config,
7779
}));
7880
vi.mocked(getConfigAtLevel).mockReturnValue({});
81+
vi.mocked(clearConfigKey).mockImplementation(() => ({ githubMode: false }));
82+
vi.mocked(clearConfigKey).mockImplementation(() => ({ githubMode: false }));
7983
});
8084

8185
afterEach(() => {

0 commit comments

Comments
 (0)