Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
updated js-sdk tests to check empty path behavior
0div7767d8f2ee46
diff --git a/packages/js-sdk/tests/sandbox/files/write.test.ts b/packages/js-sdk/tests/sandbox/files/write.test.tsindex 2aa82d1e0..51a7b968b 100644--- a/packages/js-sdk/tests/sandbox/files/write.test.ts+++ b/packages/js-sdk/tests/sandbox/files/write.test.ts@@ -1,15 +1,26 @@import path from 'path'import { assert, onTestFinished } from 'vitest'-import { EntryInfo } from '../../../src/index.js'-import { WriteData } from '../../../src/sandbox/filesystem/index.js'+import { WriteEntry } from '../../../src/sandbox/filesystem/index.js'import { sandboxTest } from '../../setup.js'sandboxTest('write file', async ({ sandbox }) => {const filename = 'test_write.txt'const content = 'This is a test file.'- const info = (await sandbox.files.write(filename, content)) as EntryInfo+ // Attempt to write with undefined path and content+ await sandbox.files+ // @ts-ignore+ .write(undefined, content)+ .then((e) => {+ assert.isUndefined(e)+ })+ .catch((err) => {+ assert.instanceOf(err, Error)+ assert.include(err.message, 'Cannot read properties of undefined')+ })++ const info = await sandbox.files.write(filename, content)assert.isFalse(Array.isArray(info))assert.equal(info.name, filename)assert.equal(info.type, 'file')@@ -27,6 +38,18 @@ sandboxTest('write multiple files', async ({ sandbox }) => {assert.isTrue(Array.isArray(emptyInfo))assert.equal(emptyInfo.length, 0)+ // Attempt to write with undefined path and file array+ await sandbox.files+ // @ts-ignore+ .write(undefined, [{ path: 'one_test_file.txt', data: 'This is a test file.' }])+ .then((e) => {+ assert.isUndefined(e)+ })+ .catch((err) => {+ assert.instanceOf(err, Error)+ assert.include(err.message, 'Cannot read properties of undefined')+ })+// Attempt to write with path and file arrayawait sandbox.files// @ts-ignore@@ -47,7 +70,7 @@ sandboxTest('write multiple files', async ({ sandbox }) => {assert.equal(info[0].path, `/home/user/one_test_file.txt`)// Attempt to write with multiple files in array- let files: Array<{ data: WriteData; path: string }> = []+ let files: WriteEntry[] = []for (let i = 0; i < 10; i++) {let path = ''@@ -68,12 +91,12 @@ sandboxTest('write multiple files', async ({ sandbox }) => {const infos = await sandbox.files.write(files)assert.isTrue(Array.isArray(infos))- assert.equal((infos as EntryInfo[]).length, files.length)+ assert.equal(infos.length, files.length)// Attempt to write with multiple files in arrayfor (let i = 0; i < files.length; i++) {const file = files[i]- const info = infos[i] as EntryInfo+ const info = infos[i]assert.equal(info.name, path.basename(file.path))assert.equal(info.path, file.path)@@ -90,7 +113,7 @@ sandboxTest('write file', async ({ sandbox }) => {const filename = 'test_write.txt'const content = 'This is a test file.'- const info = (await sandbox.files.write(filename, content)) as EntryInfo+ const info = await sandbox.files.write(filename, content)assert.isFalse(Array.isArray(info))assert.equal(info.name, filename)assert.equal(info.type, 'file')diff --git a/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.pyindex 22bba6249..0a97b542b 100644--- a/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py@@ -53,9 +53,9 @@ def test_write_multiple_files(sandbox):# Attempt to write with multiple files in arrayfiles = []for i in range(10):- filename = f"test_write_{i}.txt"+ path = f"test_write_{i}.txt"content = f"This is a test file {i}."- files.append({"path": filename, "data": content})+ files.append({"path": path, "data": content})infos = sandbox.files.write(files)assert isinstance(infos, list)@@ -63,7 +63,7 @@ def test_write_multiple_files(sandbox):for i, info in enumerate(infos):assert isinstance(info, EntryInfo)assert info.path == f"/home/user/test_write_{i}.txt"- exists = sandbox.files.exists(filename)+ exists = sandbox.files.exists(path)assert existsread_content = sandbox.files.read(info.path)