moving tools over

This commit is contained in:
dal 2025-07-29 07:39:09 -06:00
parent ed9ab33b35
commit 6d36edeeb2
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
2 changed files with 89 additions and 68 deletions

View File

@ -1,30 +1,21 @@
import { type Sandbox, createSandbox } from '@buster/sandbox';
import { createSandbox } from '@buster/sandbox';
import { RuntimeContext } from '@mastra/core/runtime-context';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { describe, expect, it } from 'vitest';
import { DocsAgentContextKeys } from '../../../context/docs-agent-context';
import { executeBash } from './bash-execute-tool';
describe('bash-execute-tool integration test', () => {
const hasApiKey = !!process.env.DAYTONA_API_KEY;
let sandbox: Sandbox;
beforeAll(async () => {
if (!hasApiKey) return;
// Create a sandbox for the tests
sandbox = await createSandbox({
async function createTestSandbox() {
return await createSandbox({
language: 'typescript',
});
}, 60000); // 60 second timeout for sandbox creation
afterAll(async () => {
// Clean up the sandbox
if (sandbox) {
await sandbox.delete();
}
});
it.skipIf(!hasApiKey)('should execute bash commands in sandbox environment', async () => {
it.concurrent.skipIf(!hasApiKey)('should execute bash commands in sandbox environment', async () => {
const sandbox = await createTestSandbox();
try {
const runtimeContext = new RuntimeContext();
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
@ -64,9 +55,14 @@ describe('bash-execute-tool integration test', () => {
exitCode: 0,
});
expect(result.results[2]?.stdout).toBeTruthy();
} finally {
await sandbox.delete();
}
});
it.skipIf(!hasApiKey)('should handle command failures in sandbox', async () => {
it.concurrent.skipIf(!hasApiKey)('should handle command failures in sandbox', async () => {
const sandbox = await createTestSandbox();
try {
const runtimeContext = new RuntimeContext();
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
@ -95,19 +91,25 @@ describe('bash-execute-tool integration test', () => {
success: false,
exitCode: 1,
});
} finally {
await sandbox.delete();
}
});
it.skipIf(!hasApiKey)('should handle file operations via bash', async () => {
it.concurrent.skipIf(!hasApiKey)('should handle file operations via bash', async () => {
const sandbox = await createTestSandbox();
try {
const runtimeContext = new RuntimeContext();
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
const testFile = `test-bash-${Date.now()}.txt`;
const result = await executeBash.execute({
context: {
commands: [
{ command: 'echo "test content" > test.txt', description: 'Create file' },
{ command: 'cat test.txt', description: 'Read file' },
{ command: 'rm test.txt', description: 'Remove file' },
{ command: 'cat test.txt', description: 'Try to read removed file' },
{ command: `echo "test content" > ${testFile}`, description: 'Create file' },
{ command: `cat ${testFile}`, description: 'Read file' },
{ command: `rm ${testFile}`, description: 'Remove file' },
{ command: `cat ${testFile}`, description: 'Try to read removed file' },
],
},
runtimeContext,
@ -129,9 +131,14 @@ describe('bash-execute-tool integration test', () => {
// Try to read removed file should fail
expect(result.results[3]?.success).toBe(false);
} finally {
await sandbox.delete();
}
});
it.skipIf(!hasApiKey)('should respect command timeout', async () => {
it.concurrent.skipIf(!hasApiKey)('should respect command timeout', async () => {
const sandbox = await createTestSandbox();
try {
const runtimeContext = new RuntimeContext();
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
@ -147,5 +154,8 @@ describe('bash-execute-tool integration test', () => {
expect(result.results).toHaveLength(1);
expect(result.results[0]?.success).toBe(false);
expect(result.results[0]?.error).toContain('timed out');
});
} finally {
await sandbox.delete();
}
}, 65000); // Increase timeout for this test since it creates a sandbox
});

View File

@ -1,30 +1,21 @@
import { type Sandbox, createSandbox } from '@buster/sandbox';
import { createSandbox } from '@buster/sandbox';
import { RuntimeContext } from '@mastra/core/runtime-context';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { describe, expect, it } from 'vitest';
import { DocsAgentContextKeys } from '../../../context/docs-agent-context';
import { createFiles } from './create-file-tool';
describe('create-file-tool integration test', () => {
const hasApiKey = !!process.env.DAYTONA_API_KEY;
let sandbox: Sandbox;
beforeAll(async () => {
if (!hasApiKey) return;
// Create a sandbox for the tests
sandbox = await createSandbox({
async function createTestSandbox() {
return await createSandbox({
language: 'typescript',
});
}, 60000); // 60 second timeout for sandbox creation
afterAll(async () => {
// Clean up the sandbox
if (sandbox) {
await sandbox.delete();
}
});
it.skipIf(!hasApiKey)('should create files in sandbox environment', async () => {
it.concurrent.skipIf(!hasApiKey)('should create files in sandbox environment', async () => {
const sandbox = await createTestSandbox();
try {
const runtimeContext = new RuntimeContext();
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
@ -74,9 +65,14 @@ describe('create-file-tool integration test', () => {
expect(fileContents['test1.txt']).toBe('Hello from test1');
expect(fileContents['test2.txt']).toBe('Hello from test2');
expect(fileContents['subdir/test3.txt']).toBe('Hello from subdirectory');
});
} finally {
await sandbox.delete();
}
}, 65000);
it.skipIf(!hasApiKey)('should handle absolute paths in sandbox', async () => {
it.concurrent.skipIf(!hasApiKey)('should handle absolute paths in sandbox', async () => {
const sandbox = await createTestSandbox();
try {
const runtimeContext = new RuntimeContext();
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
@ -108,9 +104,14 @@ describe('create-file-tool integration test', () => {
const verification = JSON.parse(verifyResult.result);
expect(verification.success).toBe(true);
expect(verification.content).toBe('Absolute path content');
});
} finally {
await sandbox.delete();
}
}, 65000);
it.skipIf(!hasApiKey)('should overwrite existing files', async () => {
it.concurrent.skipIf(!hasApiKey)('should overwrite existing files', async () => {
const sandbox = await createTestSandbox();
try {
const runtimeContext = new RuntimeContext();
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
@ -145,9 +146,14 @@ describe('create-file-tool integration test', () => {
const verifyResult = await sandbox.process.codeRun(verifyCode);
expect(JSON.parse(verifyResult.result)).toBe('New content');
});
} finally {
await sandbox.delete();
}
}, 65000);
it.skipIf(!hasApiKey)('should handle special characters in content', async () => {
it.concurrent.skipIf(!hasApiKey)('should handle special characters in content', async () => {
const sandbox = await createTestSandbox();
try {
const runtimeContext = new RuntimeContext();
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
@ -174,9 +180,14 @@ describe('create-file-tool integration test', () => {
const verifyResult = await sandbox.process.codeRun(verifyCode);
expect(JSON.parse(verifyResult.result)).toBe(specialContent);
});
} finally {
await sandbox.delete();
}
}, 65000);
it.skipIf(!hasApiKey)('should handle permission errors gracefully', async () => {
it.concurrent.skipIf(!hasApiKey)('should handle permission errors gracefully', async () => {
const sandbox = await createTestSandbox();
try {
const runtimeContext = new RuntimeContext();
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);