Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
fix: include dotfiles in template file uploads (#1162)
Mish Ushakov222105dc8f1c
diff --git a/.changeset/happy-houses-own.md b/.changeset/happy-houses-own.mdnew file mode 100644index 000000000..330e4708a--- /dev/null+++ b/.changeset/happy-houses-own.md@@ -0,0 +1,6 @@+---+'@e2b/python-sdk': patch+'e2b': patch+---++include .dot files in template file uploaddiff --git a/packages/js-sdk/src/template/utils.ts b/packages/js-sdk/src/template/utils.tsindex 4a03fc5ad..4b9cca2ac 100644--- a/packages/js-sdk/src/template/utils.ts+++ b/packages/js-sdk/src/template/utils.ts@@ -145,6 +145,7 @@ export async function getAllFilesInPath(const globFiles = await glob(src, {ignore: ignorePatterns,withFileTypes: true,+ dot: true,// this is required so that the ignore pattern is relative to the file pathcwd: contextPath,})@@ -164,6 +165,7 @@ export async function getAllFilesInPath(const dirFiles = await glob(dirPattern, {ignore: ignorePatterns,withFileTypes: true,+ dot: true,cwd: contextPath,})dirFiles.forEach((f) => files.set(f.fullpath(), f))diff --git a/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts b/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.tsindex 8d2d68b05..c75962904 100644--- a/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts+++ b/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts@@ -208,6 +208,56 @@ describe('getAllFilesInPath', () => {expect(files).toHaveLength(0)})+ test('should include dotfiles', async () => {+ // Create regular and dotfiles+ await writeFile(join(testDir, 'file.txt'), 'content')+ await writeFile(join(testDir, '.env'), 'SECRET=123')+ await writeFile(join(testDir, '.gitignore'), 'node_modules')++ const files = await getAllFilesInPath('*', testDir, [])++ expect(files).toHaveLength(3)+ expect(files.some((f) => f.fullpath().endsWith('file.txt'))).toBe(true)+ expect(files.some((f) => f.fullpath().endsWith('.env'))).toBe(true)+ expect(files.some((f) => f.fullpath().endsWith('.gitignore'))).toBe(true)+ })++ test('should include dotfiles in subdirectories', async () => {+ await mkdir(join(testDir, 'src'), { recursive: true })+ await writeFile(join(testDir, 'src', 'index.ts'), 'content')+ await writeFile(join(testDir, 'src', '.env.local'), 'SECRET=123')++ const files = await getAllFilesInPath('src', testDir, [])++ expect(files.some((f) => f.fullpath().endsWith('index.ts'))).toBe(true)+ expect(files.some((f) => f.fullpath().endsWith('.env.local'))).toBe(true)+ })++ test('should include dotdirectories and their contents', async () => {+ await mkdir(join(testDir, '.hidden'), { recursive: true })+ await writeFile(join(testDir, '.hidden', 'config.json'), '{}')+ await writeFile(join(testDir, 'visible.txt'), 'content')++ const files = await getAllFilesInPath('*', testDir, [])++ expect(files.some((f) => f.fullpath().endsWith('.hidden'))).toBe(true)+ expect(files.some((f) => f.fullpath().endsWith('config.json'))).toBe(true)+ expect(files.some((f) => f.fullpath().endsWith('visible.txt'))).toBe(true)+ })++ test('should respect ignore patterns for dotfiles', async () => {+ await writeFile(join(testDir, '.env'), 'SECRET=123')+ await writeFile(join(testDir, '.gitignore'), 'node_modules')+ await writeFile(join(testDir, 'file.txt'), 'content')++ const files = await getAllFilesInPath('*', testDir, ['.env'])++ expect(files).toHaveLength(2)+ expect(files.some((f) => f.fullpath().endsWith('.env'))).toBe(false)+ expect(files.some((f) => f.fullpath().endsWith('.gitignore'))).toBe(true)+ expect(files.some((f) => f.fullpath().endsWith('file.txt'))).toBe(true)+ })+test('should handle listing all files in current directory with dot pattern', async () => {// Create a small directory tree inside the test directoryawait writeFile(join(testDir, 'root.txt'), 'root')diff --git a/packages/python-sdk/e2b/template/utils.py b/packages/python-sdk/e2b/template/utils.pyindex 4477eee27..2902dbca8 100644--- a/packages/python-sdk/e2b/template/utils.py+++ b/packages/python-sdk/e2b/template/utils.py@@ -155,7 +155,7 @@ def get_all_files_in_path(abs_context_path = os.path.abspath(context_path)files_glob = glob.glob(src,- flags=glob.GLOBSTAR,+ flags=glob.GLOBSTAR | glob.DOTMATCH,root_dir=abs_context_path,exclude=ignore_patterns,)@@ -170,7 +170,7 @@ def get_all_files_in_path(files.add(file_path)dir_files = glob.glob(normalize_path(file) + "/**/*",- flags=glob.GLOBSTAR,+ flags=glob.GLOBSTAR | glob.DOTMATCH,root_dir=abs_context_path,exclude=ignore_patterns,)diff --git a/packages/python-sdk/tests/shared/template/utils/get_all_files_in_path.py b/packages/python-sdk/tests/shared/template/utils/get_all_files_in_path.pyindex a55815a65..fc1faa8a5 100644--- a/packages/python-sdk/tests/shared/template/utils/get_all_files_in_path.py+++ b/packages/python-sdk/tests/shared/template/utils/get_all_files_in_path.py@@ -223,6 +223,65 @@ class TestGetAllFilesInPath:assert any("helper.ts" in f for f in files)assert not any("test.spec.ts" in f for f in files)+ def test_should_include_dotfiles(self, test_dir):+ """Test that function includes files starting with a dot."""+ with open(os.path.join(test_dir, "file.txt"), "w") as f:+ f.write("content")+ with open(os.path.join(test_dir, ".env"), "w") as f:+ f.write("SECRET=123")+ with open(os.path.join(test_dir, ".gitignore"), "w") as f:+ f.write("node_modules")++ files = get_all_files_in_path("*", test_dir, [])++ assert len(files) == 3+ assert any(".env" in f for f in files)+ assert any(".gitignore" in f for f in files)+ assert any("file.txt" in f for f in files)++ def test_should_include_dotfiles_in_subdirectories(self, test_dir):+ """Test that function includes dotfiles inside subdirectories."""+ os.makedirs(os.path.join(test_dir, "src"), exist_ok=True)+ with open(os.path.join(test_dir, "src", "index.ts"), "w") as f:+ f.write("content")+ with open(os.path.join(test_dir, "src", ".env.local"), "w") as f:+ f.write("SECRET=123")++ files = get_all_files_in_path("src", test_dir, [])++ assert any("index.ts" in f for f in files)+ assert any(".env.local" in f for f in files)++ def test_should_include_dotdirectories_and_their_contents(self, test_dir):+ """Test that function includes dot-prefixed directories and their contents."""+ os.makedirs(os.path.join(test_dir, ".hidden"), exist_ok=True)+ with open(os.path.join(test_dir, ".hidden", "config.json"), "w") as f:+ f.write("{}")+ with open(os.path.join(test_dir, "visible.txt"), "w") as f:+ f.write("content")++ files = get_all_files_in_path("*", test_dir, [])++ assert any(".hidden" in f for f in files)+ assert any("config.json" in f for f in files)+ assert any("visible.txt" in f for f in files)++ def test_should_respect_ignore_patterns_for_dotfiles(self, test_dir):+ """Test that dotfiles can be excluded via ignore patterns."""+ with open(os.path.join(test_dir, ".env"), "w") as f:+ f.write("SECRET=123")+ with open(os.path.join(test_dir, ".gitignore"), "w") as f:+ f.write("node_modules")+ with open(os.path.join(test_dir, "file.txt"), "w") as f:+ f.write("content")++ files = get_all_files_in_path("*", test_dir, [".env"])++ assert len(files) == 2+ assert not any(f.endswith(".env") for f in files)+ assert any(".gitignore" in f for f in files)+ assert any("file.txt" in f for f in files)+def test_should_handle_symlinks(self, test_dir):"""Test that function handles symbolic links."""# Create a file and a symlink to it