mirror of https://github.com/buster-so/buster.git
moving tools over
This commit is contained in:
parent
ed9ab33b35
commit
6d36edeeb2
|
@ -1,32 +1,23 @@
|
||||||
import { type Sandbox, createSandbox } from '@buster/sandbox';
|
import { createSandbox } from '@buster/sandbox';
|
||||||
import { RuntimeContext } from '@mastra/core/runtime-context';
|
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 { DocsAgentContextKeys } from '../../../context/docs-agent-context';
|
||||||
import { executeBash } from './bash-execute-tool';
|
import { executeBash } from './bash-execute-tool';
|
||||||
|
|
||||||
describe('bash-execute-tool integration test', () => {
|
describe('bash-execute-tool integration test', () => {
|
||||||
const hasApiKey = !!process.env.DAYTONA_API_KEY;
|
const hasApiKey = !!process.env.DAYTONA_API_KEY;
|
||||||
let sandbox: Sandbox;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
async function createTestSandbox() {
|
||||||
if (!hasApiKey) return;
|
return await createSandbox({
|
||||||
|
|
||||||
// Create a sandbox for the tests
|
|
||||||
sandbox = await createSandbox({
|
|
||||||
language: 'typescript',
|
language: 'typescript',
|
||||||
});
|
});
|
||||||
}, 60000); // 60 second timeout for sandbox creation
|
}
|
||||||
|
|
||||||
afterAll(async () => {
|
it.concurrent.skipIf(!hasApiKey)('should execute bash commands in sandbox environment', async () => {
|
||||||
// Clean up the sandbox
|
const sandbox = await createTestSandbox();
|
||||||
if (sandbox) {
|
try {
|
||||||
await sandbox.delete();
|
const runtimeContext = new RuntimeContext();
|
||||||
}
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
});
|
|
||||||
|
|
||||||
it.skipIf(!hasApiKey)('should execute bash commands in sandbox environment', async () => {
|
|
||||||
const runtimeContext = new RuntimeContext();
|
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
|
||||||
|
|
||||||
const result = await executeBash.execute({
|
const result = await executeBash.execute({
|
||||||
context: {
|
context: {
|
||||||
|
@ -64,11 +55,16 @@ describe('bash-execute-tool integration test', () => {
|
||||||
exitCode: 0,
|
exitCode: 0,
|
||||||
});
|
});
|
||||||
expect(result.results[2]?.stdout).toBeTruthy();
|
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 runtimeContext = new RuntimeContext();
|
const sandbox = await createTestSandbox();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
try {
|
||||||
|
const runtimeContext = new RuntimeContext();
|
||||||
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
|
|
||||||
const result = await executeBash.execute({
|
const result = await executeBash.execute({
|
||||||
context: {
|
context: {
|
||||||
|
@ -95,19 +91,25 @@ describe('bash-execute-tool integration test', () => {
|
||||||
success: false,
|
success: false,
|
||||||
exitCode: 1,
|
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 runtimeContext = new RuntimeContext();
|
const sandbox = await createTestSandbox();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
try {
|
||||||
|
const runtimeContext = new RuntimeContext();
|
||||||
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
|
|
||||||
|
const testFile = `test-bash-${Date.now()}.txt`;
|
||||||
const result = await executeBash.execute({
|
const result = await executeBash.execute({
|
||||||
context: {
|
context: {
|
||||||
commands: [
|
commands: [
|
||||||
{ command: 'echo "test content" > test.txt', description: 'Create file' },
|
{ command: `echo "test content" > ${testFile}`, description: 'Create file' },
|
||||||
{ command: 'cat test.txt', description: 'Read file' },
|
{ command: `cat ${testFile}`, description: 'Read file' },
|
||||||
{ command: 'rm test.txt', description: 'Remove file' },
|
{ command: `rm ${testFile}`, description: 'Remove file' },
|
||||||
{ command: 'cat test.txt', description: 'Try to read removed file' },
|
{ command: `cat ${testFile}`, description: 'Try to read removed file' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
runtimeContext,
|
runtimeContext,
|
||||||
|
@ -129,11 +131,16 @@ describe('bash-execute-tool integration test', () => {
|
||||||
|
|
||||||
// Try to read removed file should fail
|
// Try to read removed file should fail
|
||||||
expect(result.results[3]?.success).toBe(false);
|
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 runtimeContext = new RuntimeContext();
|
const sandbox = await createTestSandbox();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
try {
|
||||||
|
const runtimeContext = new RuntimeContext();
|
||||||
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
|
|
||||||
const result = await executeBash.execute({
|
const result = await executeBash.execute({
|
||||||
context: {
|
context: {
|
||||||
|
@ -147,5 +154,8 @@ describe('bash-execute-tool integration test', () => {
|
||||||
expect(result.results).toHaveLength(1);
|
expect(result.results).toHaveLength(1);
|
||||||
expect(result.results[0]?.success).toBe(false);
|
expect(result.results[0]?.success).toBe(false);
|
||||||
expect(result.results[0]?.error).toContain('timed out');
|
expect(result.results[0]?.error).toContain('timed out');
|
||||||
});
|
} finally {
|
||||||
|
await sandbox.delete();
|
||||||
|
}
|
||||||
|
}, 65000); // Increase timeout for this test since it creates a sandbox
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,32 +1,23 @@
|
||||||
import { type Sandbox, createSandbox } from '@buster/sandbox';
|
import { createSandbox } from '@buster/sandbox';
|
||||||
import { RuntimeContext } from '@mastra/core/runtime-context';
|
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 { DocsAgentContextKeys } from '../../../context/docs-agent-context';
|
||||||
import { createFiles } from './create-file-tool';
|
import { createFiles } from './create-file-tool';
|
||||||
|
|
||||||
describe('create-file-tool integration test', () => {
|
describe('create-file-tool integration test', () => {
|
||||||
const hasApiKey = !!process.env.DAYTONA_API_KEY;
|
const hasApiKey = !!process.env.DAYTONA_API_KEY;
|
||||||
let sandbox: Sandbox;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
async function createTestSandbox() {
|
||||||
if (!hasApiKey) return;
|
return await createSandbox({
|
||||||
|
|
||||||
// Create a sandbox for the tests
|
|
||||||
sandbox = await createSandbox({
|
|
||||||
language: 'typescript',
|
language: 'typescript',
|
||||||
});
|
});
|
||||||
}, 60000); // 60 second timeout for sandbox creation
|
}
|
||||||
|
|
||||||
afterAll(async () => {
|
it.concurrent.skipIf(!hasApiKey)('should create files in sandbox environment', async () => {
|
||||||
// Clean up the sandbox
|
const sandbox = await createTestSandbox();
|
||||||
if (sandbox) {
|
try {
|
||||||
await sandbox.delete();
|
const runtimeContext = new RuntimeContext();
|
||||||
}
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
});
|
|
||||||
|
|
||||||
it.skipIf(!hasApiKey)('should create files in sandbox environment', async () => {
|
|
||||||
const runtimeContext = new RuntimeContext();
|
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
|
||||||
|
|
||||||
const result = await createFiles.execute({
|
const result = await createFiles.execute({
|
||||||
context: {
|
context: {
|
||||||
|
@ -74,11 +65,16 @@ describe('create-file-tool integration test', () => {
|
||||||
expect(fileContents['test1.txt']).toBe('Hello from test1');
|
expect(fileContents['test1.txt']).toBe('Hello from test1');
|
||||||
expect(fileContents['test2.txt']).toBe('Hello from test2');
|
expect(fileContents['test2.txt']).toBe('Hello from test2');
|
||||||
expect(fileContents['subdir/test3.txt']).toBe('Hello from subdirectory');
|
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 runtimeContext = new RuntimeContext();
|
const sandbox = await createTestSandbox();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
try {
|
||||||
|
const runtimeContext = new RuntimeContext();
|
||||||
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
|
|
||||||
const result = await createFiles.execute({
|
const result = await createFiles.execute({
|
||||||
context: {
|
context: {
|
||||||
|
@ -108,11 +104,16 @@ describe('create-file-tool integration test', () => {
|
||||||
const verification = JSON.parse(verifyResult.result);
|
const verification = JSON.parse(verifyResult.result);
|
||||||
expect(verification.success).toBe(true);
|
expect(verification.success).toBe(true);
|
||||||
expect(verification.content).toBe('Absolute path content');
|
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 runtimeContext = new RuntimeContext();
|
const sandbox = await createTestSandbox();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
try {
|
||||||
|
const runtimeContext = new RuntimeContext();
|
||||||
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
|
|
||||||
// First create a file
|
// First create a file
|
||||||
await createFiles.execute({
|
await createFiles.execute({
|
||||||
|
@ -145,11 +146,16 @@ describe('create-file-tool integration test', () => {
|
||||||
|
|
||||||
const verifyResult = await sandbox.process.codeRun(verifyCode);
|
const verifyResult = await sandbox.process.codeRun(verifyCode);
|
||||||
expect(JSON.parse(verifyResult.result)).toBe('New content');
|
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 runtimeContext = new RuntimeContext();
|
const sandbox = await createTestSandbox();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
try {
|
||||||
|
const runtimeContext = new RuntimeContext();
|
||||||
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
|
|
||||||
const specialContent = 'Line 1\nLine 2\tTabbed\n"Quoted"\n\'Single quoted\'';
|
const specialContent = 'Line 1\nLine 2\tTabbed\n"Quoted"\n\'Single quoted\'';
|
||||||
|
|
||||||
|
@ -174,11 +180,16 @@ describe('create-file-tool integration test', () => {
|
||||||
|
|
||||||
const verifyResult = await sandbox.process.codeRun(verifyCode);
|
const verifyResult = await sandbox.process.codeRun(verifyCode);
|
||||||
expect(JSON.parse(verifyResult.result)).toBe(specialContent);
|
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 runtimeContext = new RuntimeContext();
|
const sandbox = await createTestSandbox();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
try {
|
||||||
|
const runtimeContext = new RuntimeContext();
|
||||||
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
|
|
||||||
// Try to create a file in a restricted directory
|
// Try to create a file in a restricted directory
|
||||||
const result = await createFiles.execute({
|
const result = await createFiles.execute({
|
||||||
|
|
Loading…
Reference in New Issue