mirror of https://github.com/buster-so/buster.git
moving tools over
This commit is contained in:
parent
ed9ab33b35
commit
6d36edeeb2
|
@ -1,30 +1,21 @@
|
||||||
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 () => {
|
|
||||||
// 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();
|
const runtimeContext = new RuntimeContext();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
|
|
||||||
|
@ -64,9 +55,14 @@ 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 sandbox = await createTestSandbox();
|
||||||
|
try {
|
||||||
const runtimeContext = new RuntimeContext();
|
const runtimeContext = new RuntimeContext();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
|
|
||||||
|
@ -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 sandbox = await createTestSandbox();
|
||||||
|
try {
|
||||||
const runtimeContext = new RuntimeContext();
|
const runtimeContext = new RuntimeContext();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
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,9 +131,14 @@ 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 sandbox = await createTestSandbox();
|
||||||
|
try {
|
||||||
const runtimeContext = new RuntimeContext();
|
const runtimeContext = new RuntimeContext();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
|
|
||||||
|
@ -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,30 +1,21 @@
|
||||||
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 () => {
|
|
||||||
// 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();
|
const runtimeContext = new RuntimeContext();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
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['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 sandbox = await createTestSandbox();
|
||||||
|
try {
|
||||||
const runtimeContext = new RuntimeContext();
|
const runtimeContext = new RuntimeContext();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
|
|
||||||
|
@ -108,9 +104,14 @@ 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 sandbox = await createTestSandbox();
|
||||||
|
try {
|
||||||
const runtimeContext = new RuntimeContext();
|
const runtimeContext = new RuntimeContext();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
|
|
||||||
|
@ -145,9 +146,14 @@ 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 sandbox = await createTestSandbox();
|
||||||
|
try {
|
||||||
const runtimeContext = new RuntimeContext();
|
const runtimeContext = new RuntimeContext();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
|
|
||||||
|
@ -174,9 +180,14 @@ 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 sandbox = await createTestSandbox();
|
||||||
|
try {
|
||||||
const runtimeContext = new RuntimeContext();
|
const runtimeContext = new RuntimeContext();
|
||||||
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
runtimeContext.set(DocsAgentContextKeys.Sandbox, sandbox);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue