Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
test: write test fixtures to temp dirs instead of the repo tree (#1689)
cursor[bot]e09b318f8cc8
diff --git a/packages/cli/tests/commands/template/create.test.ts b/packages/cli/tests/commands/template/create.test.tsindex 903070f36..926720e54 100644--- a/packages/cli/tests/commands/template/create.test.ts+++ b/packages/cli/tests/commands/template/create.test.ts@@ -1,5 +1,6 @@import { spawnSync } from 'node:child_process'import * as fs from 'node:fs/promises'+import * as os from 'node:os'import * as path from 'node:path'import { afterAll, beforeAll, describe, expect, test } from 'vitest'@@ -18,7 +19,7 @@ describe('template create cli backend integration', () => {'E2B_API_KEY must be set to run template create backend tests')}- testDir = await fs.mkdtemp('e2b-create-test-')+ testDir = await fs.mkdtemp(path.join(os.tmpdir(), 'e2b-create-test-'))await fs.writeFile(path.join(testDir, 'e2b.Dockerfile'),'FROM ubuntu:latest\n'diff --git a/packages/cli/tests/commands/template/delete.test.ts b/packages/cli/tests/commands/template/delete.test.tsindex 1dda94aee..d7896cb96 100644--- a/packages/cli/tests/commands/template/delete.test.ts+++ b/packages/cli/tests/commands/template/delete.test.ts@@ -1,4 +1,5 @@import * as fs from 'fs/promises'+import * as os from 'os'import * as path from 'path'import { execSync } from 'child_process'import { afterEach, beforeEach, describe, expect, test } from 'vitest'@@ -7,7 +8,9 @@ describe('Template Delete --config', () => {let testDir: stringbeforeEach(async () => {- testDir = await fs.mkdtemp('e2b-delete-config-test-')+ testDir = await fs.mkdtemp(+ path.join(os.tmpdir(), 'e2b-delete-config-test-')+ )const defaultConfig = `template_id = "default-template-id"dockerfile = "e2b.Dockerfile"`diff --git a/packages/cli/tests/commands/template/init.test.ts b/packages/cli/tests/commands/template/init.test.tsindex a46d9ce46..c3256f48a 100644--- a/packages/cli/tests/commands/template/init.test.ts+++ b/packages/cli/tests/commands/template/init.test.ts@@ -1,6 +1,7 @@import { execSync } from 'child_process'import { existsSync } from 'fs'import * as fs from 'fs/promises'+import * as os from 'os'import * as path from 'path'import { afterEach, beforeEach, describe, expect, test } from 'vitest'import { Language } from '../../../src/commands/template/generators'@@ -11,7 +12,7 @@ describe('Template Init', () => {beforeEach(async () => {// Use Node.js built-in temp directory handling- testDir = await fs.mkdtemp('e2b-init-test-')+ testDir = await fs.mkdtemp(path.join(os.tmpdir(), 'e2b-init-test-'))})afterEach(async () => {diff --git a/packages/cli/tests/commands/template/migrate.test.ts b/packages/cli/tests/commands/template/migrate.test.tsindex ee6cbb3e5..70e29f04c 100644--- a/packages/cli/tests/commands/template/migrate.test.ts+++ b/packages/cli/tests/commands/template/migrate.test.ts@@ -1,5 +1,6 @@import { afterEach, beforeEach, describe, expect, test } from 'vitest'import * as fs from 'fs/promises'+import * as os from 'os'import * as path from 'path'import { execSync } from 'child_process'import { Language } from '../../../src/commands/template/generators'@@ -39,7 +40,7 @@ describe('Template Migration', () => {beforeEach(async () => {// Use Node.js built-in temp directory handling- testDir = await fs.mkdtemp('e2b-migrate-test-')+ testDir = await fs.mkdtemp(path.join(os.tmpdir(), 'e2b-migrate-test-'))})afterEach(async () => {diff --git a/packages/cli/tests/commands/template/publish.test.ts b/packages/cli/tests/commands/template/publish.test.tsindex d90e700f6..ef7b7df96 100644--- a/packages/cli/tests/commands/template/publish.test.ts+++ b/packages/cli/tests/commands/template/publish.test.ts@@ -1,4 +1,5 @@import * as fs from 'fs/promises'+import * as os from 'os'import * as path from 'path'import { execSync } from 'child_process'import { afterEach, beforeEach, describe, expect, test } from 'vitest'@@ -7,7 +8,9 @@ describe('Template Publish --config', () => {let testDir: stringbeforeEach(async () => {- testDir = await fs.mkdtemp('e2b-publish-config-test-')+ testDir = await fs.mkdtemp(+ path.join(os.tmpdir(), 'e2b-publish-config-test-')+ )const defaultConfig = `template_id = "default-template-id"dockerfile = "e2b.Dockerfile"`diff --git a/packages/js-sdk/tests/template/build.test.ts b/packages/js-sdk/tests/template/build.test.tsindex 241e8f172..3e06263ce 100644--- a/packages/js-sdk/tests/template/build.test.ts+++ b/packages/js-sdk/tests/template/build.test.ts@@ -1,12 +1,18 @@import fs from 'node:fs'+import os from 'node:os'import path from 'node:path'import { afterAll, beforeAll } from 'vitest'import { defaultBuildLogger, Template, waitForTimeout } from '../../src'import { buildTemplateTest } from '../setup'-const folderPath = path.join(__dirname, 'folder')+// The file context lives in a temp directory so a test run never writes into+// the repository tree. It is created in beforeAll rather than at module load so+// that a skipped or filtered run does not orphan a temp directory.+let contextPath: stringbeforeAll(async () => {+ contextPath = fs.mkdtempSync(path.join(os.tmpdir(), 'js-build-test-'))+ const folderPath = path.join(contextPath, 'folder')fs.mkdirSync(folderPath, { recursive: true })fs.writeFileSync(path.join(folderPath, 'test.txt'), 'This is a test file.')@@ -24,11 +30,13 @@ beforeAll(async () => {})afterAll(() => {- fs.rmSync(folderPath, { recursive: true })+ if (contextPath) {+ fs.rmSync(contextPath, { recursive: true, force: true })+ }})buildTemplateTest('build template', async ({ buildTemplate }) => {- const template = Template()+ const template = Template({ fileContextPath: contextPath })// using base image to avoid re-building ubuntu:22.04 image.fromBaseImage().copy('folder/*', 'folder', { forceUpload: true })@@ -48,7 +56,7 @@ buildTemplateTest()buildTemplateTest('build template with symlinks', async ({ buildTemplate }) => {- const template = Template()+ const template = Template({ fileContextPath: contextPath }).fromImage('ubuntu:22.04').skipCache().copy('folder/*', 'folder', { forceUpload: true })@@ -60,7 +68,7 @@ buildTemplateTest('build template with symlinks', async ({ buildTemplate }) => {buildTemplateTest('build template with resolveSymlinks',async ({ buildTemplate }) => {- const template = Template()+ const template = Template({ fileContextPath: contextPath }).fromImage('ubuntu:22.04').skipCache().copy('folder/symlink.txt', 'folder/symlink.txt', {diff --git a/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts b/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.tsindex fefc0e9a2..30d888fde 100644--- a/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts+++ b/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts@@ -1,14 +1,15 @@import { expect, test, describe, beforeAll, afterAll, beforeEach } from 'vitest'-import { writeFile, mkdir, rm } from 'fs/promises'+import { writeFile, mkdir, mkdtemp, rm } from 'fs/promises'+import { tmpdir } from 'os'import { join, basename } from 'path'import { getAllFilesInPath } from '../../../src/template/utils'describe('getAllFilesInPath', () => {- const testDir = join(__dirname, 'folder')+ // A temp directory, so a test run never writes into the repository tree.+ let testDir: stringbeforeAll(async () => {- await rm(testDir, { recursive: true, force: true })- await mkdir(testDir, { recursive: true })+ testDir = await mkdtemp(join(tmpdir(), 'getAllFilesInPath-test-'))})afterAll(async () => {diff --git a/packages/js-sdk/tests/template/utils/spoolTarArchive.test.ts b/packages/js-sdk/tests/template/utils/spoolTarArchive.test.tsindex 397f5b3ee..9ad88e7e2 100644--- a/packages/js-sdk/tests/template/utils/spoolTarArchive.test.ts+++ b/packages/js-sdk/tests/template/utils/spoolTarArchive.test.ts@@ -1,5 +1,13 @@import { expect, test, describe, beforeAll, afterAll, beforeEach } from 'vitest'-import { writeFile, mkdir, rm, symlink, readFile, access } from 'fs/promises'+import {+ writeFile,+ mkdir,+ mkdtemp,+ rm,+ symlink,+ readFile,+ access,+} from 'fs/promises'import { join, dirname } from 'path'import { tmpdir } from 'os'import { spoolTarArchive } from '../../../src/template/utils'@@ -7,11 +15,11 @@ import * as tar from 'tar'import { ReadEntry } from 'tar'describe('spoolTarArchive', () => {- const testDir = join(__dirname, 'tar-test-folder')+ // A temp directory, so a test run never writes into the repository tree.+ let testDir: stringbeforeAll(async () => {- await rm(testDir, { recursive: true, force: true })- await mkdir(testDir, { recursive: true })+ testDir = await mkdtemp(join(tmpdir(), 'spoolTarArchive-test-'))})afterAll(async () => {