Skip to content

Commit c31546e

Browse files
committed
fix: improve resource trackers and fix tests
- Standardize file naming by renaming ShellTracker.ts to shellTracker.ts - Fix tests to use toolContext.shellTracker instead of local instances - Update test assertions to work with the new tracker structure - Fix test for piped commands to be more reliable
1 parent fb89dd8 commit c31546e

14 files changed

+41
-48
lines changed

packages/agent/src/core/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { JsonSchema7Type } from 'zod-to-json-schema';
33

44
import { BrowserTracker } from '../tools/browser/browserTracker.js';
55
import { AgentTracker } from '../tools/interaction/agentTracker.js';
6-
import { ShellTracker } from '../tools/system/ShellTracker.js';
6+
import { ShellTracker } from '../tools/system/shellTracker.js';
77
import { Logger } from '../utils/logger.js';
88

99
import { TokenTracker } from './tokens.js';

packages/agent/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export * from './tools/system/sequenceComplete.js';
1010
export * from './tools/system/shellMessage.js';
1111
export * from './tools/system/shellExecute.js';
1212
export * from './tools/system/listShells.js';
13-
export * from './tools/system/ShellTracker.js';
13+
export * from './tools/system/shellTracker.js';
1414

1515
// Tools - Browser
1616
export * from './tools/browser/BrowserManager.js';

packages/agent/src/tools/getTools.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { MockLogger } from '../utils/mockLogger.js';
77
import { BrowserTracker } from './browser/browserTracker.js';
88
import { getTools } from './getTools.js';
99
import { AgentTracker } from './interaction/agentTracker.js';
10-
import { ShellTracker } from './system/ShellTracker.js';
10+
import { ShellTracker } from './system/shellTracker.js';
1111

1212
// Mock context
1313
export const getMockToolContext = (): ToolContext => ({

packages/agent/src/tools/interaction/agentTools.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { TokenTracker } from '../../core/tokens.js';
44
import { ToolContext } from '../../core/types.js';
55
import { MockLogger } from '../../utils/mockLogger.js';
66
import { BrowserTracker } from '../browser/browserTracker.js';
7-
import { ShellTracker } from '../system/ShellTracker.js';
7+
import { ShellTracker } from '../system/shellTracker.js';
88

99
import { agentMessageTool } from './agentMessage.js';
1010
import { agentStartTool, agentStates } from './agentStart.js';

packages/agent/src/tools/interaction/subAgent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { TokenTracker } from '../../core/tokens.js';
44
import { ToolContext } from '../../core/types.js';
55
import { MockLogger } from '../../utils/mockLogger.js';
66
import { BrowserTracker } from '../browser/browserTracker.js';
7-
import { ShellTracker } from '../system/ShellTracker.js';
7+
import { ShellTracker } from '../system/shellTracker.js';
88

99
import { AgentTracker } from './agentTracker.js';
1010
import { subAgentTool } from './subAgent.js';

packages/agent/src/tools/interaction/subAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { toolAgent } from '../../core/toolAgent/toolAgentCore.js';
99
import { Tool, ToolContext } from '../../core/types.js';
1010
import { BrowserTracker } from '../browser/browserTracker.js';
1111
import { getTools } from '../getTools.js';
12-
import { ShellTracker } from '../system/ShellTracker.js';
12+
import { ShellTracker } from '../system/shellTracker.js';
1313

1414
import { AgentTracker } from './agentTracker.js';
1515

packages/agent/src/tools/system/listShells.test.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ToolContext } from '../../core/types.js';
44
import { getMockToolContext } from '../getTools.test.js';
55

66
import { listShellsTool } from './listShells.js';
7-
import { ShellStatus, ShellTracker } from './ShellTracker.js';
7+
import { ShellStatus } from './shellTracker.js';
88

99
const toolContext: ToolContext = getMockToolContext();
1010

@@ -15,8 +15,7 @@ vi.spyOn(Date, 'now').mockImplementation(() => mockNow);
1515
describe('listShellsTool', () => {
1616
beforeEach(() => {
1717
// Clear shells before each test
18-
const shellTracker = new ShellTracker('test');
19-
shellTracker['shells'] = new Map();
18+
toolContext.shellTracker['shells'] = new Map();
2019

2120
// Set up some test shells with different statuses
2221
const shell1 = {
@@ -52,9 +51,9 @@ describe('listShellsTool', () => {
5251
};
5352

5453
// Add the shells to the tracker
55-
shellTracker['shells'].set('shell-1', shell1);
56-
shellTracker['shells'].set('shell-2', shell2);
57-
shellTracker['shells'].set('shell-3', shell3);
54+
toolContext.shellTracker['shells'].set('shell-1', shell1);
55+
toolContext.shellTracker['shells'].set('shell-2', shell2);
56+
toolContext.shellTracker['shells'].set('shell-3', shell3);
5857
});
5958

6059
it('should list all shells by default', async () => {
@@ -82,7 +81,6 @@ describe('listShellsTool', () => {
8281

8382
expect(result.shells.length).toBe(1);
8483
expect(result.count).toBe(1);
85-
expect(result.shells.length).toBe(1);
8684
expect(result.shells[0]!.id).toBe('shell-1');
8785
expect(result.shells[0]!.status).toBe(ShellStatus.RUNNING);
8886
});
@@ -106,11 +104,10 @@ describe('listShellsTool', () => {
106104
toolContext,
107105
);
108106

109-
expect(result.shells.length).toBe(1);
110107
expect(result.shells.length).toBe(1);
111108
expect(result.shells[0]!.id).toBe('shell-3');
112109
expect(result.shells[0]!.status).toBe(ShellStatus.ERROR);
113110
expect(result.shells[0]!.metadata).toBeDefined();
114111
expect(result.shells[0]!.metadata?.error).toBe('Command not found');
115112
});
116-
});
113+
});

packages/agent/src/tools/system/listShells.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
33

44
import { Tool } from '../../core/types.js';
55

6-
import { ShellStatus } from './ShellTracker.js';
6+
import { ShellStatus } from './shellTracker.js';
77

88
const parameterSchema = z.object({
99
status: z

packages/agent/src/tools/system/shellMessage.test.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { getMockToolContext } from '../getTools.test.js';
66

77
import { shellMessageTool, NodeSignals } from './shellMessage.js';
88
import { shellStartTool } from './shellStart.js';
9-
import { ShellTracker } from './ShellTracker.js';
109

1110
const toolContext: ToolContext = getMockToolContext();
1211

@@ -22,17 +21,16 @@ const getInstanceId = (
2221

2322
describe('shellMessageTool', () => {
2423
let testInstanceId = '';
25-
const shellTracker = new ShellTracker('test');
2624

2725
beforeEach(() => {
28-
shellTracker.processStates.clear();
26+
toolContext.shellTracker.processStates.clear();
2927
});
3028

3129
afterEach(() => {
32-
for (const processState of shellTracker.processStates.values()) {
30+
for (const processState of toolContext.shellTracker.processStates.values()) {
3331
processState.process.kill();
3432
}
35-
shellTracker.processStates.clear();
33+
toolContext.shellTracker.processStates.clear();
3634
});
3735

3836
it('should interact with a running process', async () => {
@@ -64,7 +62,7 @@ describe('shellMessageTool', () => {
6462
expect(result.completed).toBe(false);
6563

6664
// Verify the instance ID is valid
67-
expect(shellTracker.processStates.has(testInstanceId)).toBe(true);
65+
expect(toolContext.shellTracker.processStates.has(testInstanceId)).toBe(true);
6866
});
6967

7068
it('should handle nonexistent process', async () => {
@@ -106,7 +104,7 @@ describe('shellMessageTool', () => {
106104

107105
expect(result.completed).toBe(true);
108106
// Process should still be in processStates even after completion
109-
expect(shellTracker.processStates.has(instanceId)).toBe(true);
107+
expect(toolContext.shellTracker.processStates.has(instanceId)).toBe(true);
110108
});
111109

112110
it('should handle SIGTERM signal correctly', async () => {
@@ -209,7 +207,7 @@ describe('shellMessageTool', () => {
209207

210208
expect(checkResult.signaled).toBe(true);
211209
expect(checkResult.completed).toBe(true);
212-
expect(shellTracker.processStates.has(instanceId)).toBe(true);
210+
expect(toolContext.shellTracker.processStates.has(instanceId)).toBe(true);
213211
});
214212

215213
it('should respect showStdIn and showStdout parameters', async () => {
@@ -226,7 +224,7 @@ describe('shellMessageTool', () => {
226224
const instanceId = getInstanceId(startResult);
227225

228226
// Verify process state has default visibility settings
229-
const processState = shellTracker.processStates.get(instanceId);
227+
const processState = toolContext.shellTracker.processStates.get(instanceId);
230228
expect(processState?.showStdIn).toBe(false);
231229
expect(processState?.showStdout).toBe(false);
232230

@@ -243,7 +241,7 @@ describe('shellMessageTool', () => {
243241
);
244242

245243
// Verify process state still exists
246-
expect(shellTracker.processStates.has(instanceId)).toBe(true);
244+
expect(toolContext.shellTracker.processStates.has(instanceId)).toBe(true);
247245
});
248246

249247
it('should inherit visibility settings from process state', async () => {
@@ -262,7 +260,7 @@ describe('shellMessageTool', () => {
262260
const instanceId = getInstanceId(startResult);
263261

264262
// Verify process state has the specified visibility settings
265-
const processState = shellTracker.processStates.get(instanceId);
263+
const processState = toolContext.shellTracker.processStates.get(instanceId);
266264
expect(processState?.showStdIn).toBe(true);
267265
expect(processState?.showStdout).toBe(true);
268266

@@ -277,6 +275,6 @@ describe('shellMessageTool', () => {
277275
);
278276

279277
// Verify process state still exists
280-
expect(shellTracker.processStates.has(instanceId)).toBe(true);
278+
expect(toolContext.shellTracker.processStates.has(instanceId)).toBe(true);
281279
});
282-
});
280+
});

packages/agent/src/tools/system/shellMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
44
import { Tool } from '../../core/types.js';
55
import { sleep } from '../../utils/sleep.js';
66

7-
import { ShellStatus } from './ShellTracker.js';
7+
import { ShellStatus } from './shellTracker.js';
88

99
// Define NodeJS signals as an enum
1010
export enum NodeSignals {

0 commit comments

Comments
 (0)