UNPKG

@measey/mycoder-agent

Version:

Agent module for mycoder - an AI-powered software development assistant

72 lines 2.8 kB
import { describe, expect, it, vi } from 'vitest'; import { shellExecuteTool } from './shellExecute'; // Mock child_process.exec vi.mock('child_process', () => ({ exec: vi.fn(), })); // Mock util.promisify to return our mocked exec function vi.mock('util', () => ({ promisify: vi.fn((fn) => fn), })); describe('shellExecuteTool', () => { // Original test - skipped it.skip('should execute a shell command', async () => { // This is a dummy test that will be skipped expect(true).toBe(true); }); // New test for newline conversion it('should properly convert literal newlines in stdinContent', async () => { // Setup const { exec } = await import('child_process'); const stdinWithLiteralNewlines = 'Line 1\\nLine 2\\nLine 3'; const expectedProcessedContent = 'Line 1\nLine 2\nLine 3'; // Create a minimal mock context const mockContext = { logger: { debug: vi.fn(), error: vi.fn(), log: vi.fn(), warn: vi.fn(), info: vi.fn(), }, workingDirectory: '/test', headless: false, userSession: false, tokenTracker: { trackTokens: vi.fn() }, githubMode: false, provider: 'anthropic', maxTokens: 4000, temperature: 0, agentTracker: { registerAgent: vi.fn() }, shellTracker: { registerShell: vi.fn(), processStates: new Map() }, browserTracker: { registerSession: vi.fn() }, }; // Create a real Buffer but spy on the toString method const realBuffer = Buffer.from('test'); const bufferSpy = vi .spyOn(Buffer, 'from') .mockImplementationOnce((content) => { // Store the actual content for verification if (typeof content === 'string') { // This is where we verify the content has been transformed expect(content).toEqual(expectedProcessedContent); } return realBuffer; }); // Mock exec to resolve with empty stdout/stderr exec.mockImplementationOnce((cmd, opts, callback) => { callback(null, { stdout: '', stderr: '' }); }); // Execute the tool with literal newlines in stdinContent await shellExecuteTool.execute({ command: 'cat', description: 'Testing literal newline conversion', stdinContent: stdinWithLiteralNewlines, }, mockContext); // Verify the Buffer.from was called expect(bufferSpy).toHaveBeenCalled(); // Reset mocks bufferSpy.mockRestore(); }); }); //# sourceMappingURL=shellExecute.test.js.map