Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Fix e2b tpl publish/delete --config flag (#968)

Jonas Scholz057f9027f0ac
diff --git a/.changeset/hungry-carpets-sit.md b/.changeset/hungry-carpets-sit.md
new file mode 100644
index 000000000..540f5fff6
--- /dev/null
+++ b/.changeset/hungry-carpets-sit.md
@@ -0,0 +1,5 @@
+---
+'@e2b/cli': patch
+---
+
+fixed --config option in e2b tpl publish and e2b tpl delete
diff --git a/packages/cli/src/commands/template/delete.ts b/packages/cli/src/commands/template/delete.ts
index f3651256c..7e2c34e78 100644
--- a/packages/cli/src/commands/template/delete.ts
+++ b/packages/cli/src/commands/template/delete.ts
@@ -109,7 +109,7 @@ export const deleteCommand = new commander.Command('delete')
return
}
} else {
- const configPath = getConfigPath(root)
+ const configPath = getConfigPath(root, opts.config)
const config = fs.existsSync(configPath)
? await loadConfig(configPath)
: undefined
diff --git a/packages/cli/src/commands/template/publish.ts b/packages/cli/src/commands/template/publish.ts
index b6548dc67..b8a853765 100644
--- a/packages/cli/src/commands/template/publish.ts
+++ b/packages/cli/src/commands/template/publish.ts
@@ -106,7 +106,7 @@ async function templateAction(
return
}
} else {
- const configPath = getConfigPath(root)
+ const configPath = getConfigPath(root, opts.config)
const config = fs.existsSync(configPath)
? await loadConfig(configPath)
: undefined
diff --git a/packages/cli/tests/commands/template/delete.test.ts b/packages/cli/tests/commands/template/delete.test.ts
new file mode 100644
index 000000000..1dda94aee
--- /dev/null
+++ b/packages/cli/tests/commands/template/delete.test.ts
@@ -0,0 +1,68 @@
+import * as fs from 'fs/promises'
+import * as path from 'path'
+import { execSync } from 'child_process'
+import { afterEach, beforeEach, describe, expect, test } from 'vitest'
+
+describe('Template Delete --config', () => {
+ let testDir: string
+
+ beforeEach(async () => {
+ testDir = await fs.mkdtemp('e2b-delete-config-test-')
+
+ const defaultConfig = `template_id = "default-template-id"
+dockerfile = "e2b.Dockerfile"`
+ await fs.writeFile(path.join(testDir, 'e2b.toml'), defaultConfig)
+
+ const customConfig = `template_id = "custom-template-id"
+dockerfile = "e2b.Dockerfile"`
+ await fs.writeFile(path.join(testDir, 'custom.toml'), customConfig)
+
+ await fs.writeFile(path.join(testDir, 'e2b.Dockerfile'), 'FROM alpine:3.18')
+ })
+
+ afterEach(async () => {
+ if (testDir) {
+ await fs.rm(testDir, { recursive: true, force: true })
+ }
+ })
+
+ test('uses the config file passed via --config even when e2b.toml exists', async () => {
+ const cliPath = path.join(process.cwd(), 'dist', 'index.js')
+
+ let output = ''
+ try {
+ output = execSync(
+ `node "${cliPath}" template delete --yes --path "${testDir}" --config custom.toml 2>&1`,
+ { encoding: 'utf-8', stdio: 'pipe', timeout: 10_000 }
+ )
+ } catch (err: any) {
+ output = (err?.stdout ?? '') + (err?.stderr ?? '')
+ }
+
+ expect(output).toContain('Sandbox templates to delete')
+ expect(output).toContain('custom-template-id')
+ expect(output).toContain('custom.toml')
+ expect(output).not.toContain('default-template-id')
+ })
+
+ test('uses the default e2b.toml when --config is not provided', async () => {
+ const cliPath = path.join(process.cwd(), 'dist', 'index.js')
+
+ let output = ''
+ try {
+ output = execSync(
+ `node "${cliPath}" template delete --yes --path "${testDir}" 2>&1`,
+ { encoding: 'utf-8', stdio: 'pipe', timeout: 10_000 }
+ )
+ } catch (err: any) {
+ output = (err?.stdout ?? '') + (err?.stderr ?? '')
+ }
+
+ expect(output).toContain('Sandbox templates to delete')
+ expect(output).toContain('default-template-id')
+ expect(output).toContain('e2b.toml')
+ expect(output).not.toContain('custom-template-id')
+ })
+})
+
+
diff --git a/packages/cli/tests/commands/template/publish.test.ts b/packages/cli/tests/commands/template/publish.test.ts
new file mode 100644
index 000000000..d90e700f6
--- /dev/null
+++ b/packages/cli/tests/commands/template/publish.test.ts
@@ -0,0 +1,74 @@
+import * as fs from 'fs/promises'
+import * as path from 'path'
+import { execSync } from 'child_process'
+import { afterEach, beforeEach, describe, expect, test } from 'vitest'
+
+describe('Template Publish --config', () => {
+ let testDir: string
+
+ beforeEach(async () => {
+ testDir = await fs.mkdtemp('e2b-publish-config-test-')
+
+ const defaultConfig = `template_id = "default-template-id"
+dockerfile = "e2b.Dockerfile"`
+ await fs.writeFile(path.join(testDir, 'e2b.toml'), defaultConfig)
+
+ const customConfig = `template_id = "custom-template-id"
+dockerfile = "e2b.Dockerfile"`
+ await fs.writeFile(path.join(testDir, 'custom.toml'), customConfig)
+
+ await fs.writeFile(path.join(testDir, 'e2b.Dockerfile'), 'FROM alpine:3.18')
+ })
+
+ afterEach(async () => {
+ if (testDir) {
+ await fs.rm(testDir, { recursive: true, force: true })
+ }
+ })
+
+ test('uses the config file passed via --config even when e2b.toml exists', async () => {
+ const cliPath = path.join(process.cwd(), 'dist', 'index.js')
+
+ let output = ''
+ try {
+ // This will likely fail on the network call, but we only need stdout up to that point
+ output = execSync(
+ `node "${cliPath}" template publish --yes --path "${testDir}" --config custom.toml 2>&1`,
+ { encoding: 'utf-8', stdio: 'pipe', timeout: 10_000 }
+ )
+ } catch (err: any) {
+ // Capture partial output from the failed process (expected due to no network)
+ output = (err?.stdout ?? '') + (err?.stderr ?? '')
+ }
+
+ // It should log the sandbox template selection with the custom template ID and path
+ expect(output).toContain('Sandbox templates to publish')
+ expect(output).toContain('custom-template-id')
+ expect(output).toContain('custom.toml')
+ // And should not show the default template id when custom is provided
+ expect(output).not.toContain('default-template-id')
+ })
+
+ test('uses the default e2b.toml when --config is not provided', async () => {
+ const cliPath = path.join(process.cwd(), 'dist', 'index.js')
+
+ let output = ''
+ try {
+ output = execSync(
+ `node "${cliPath}" template publish --yes --path "${testDir}" 2>&1`,
+ { encoding: 'utf-8', stdio: 'pipe', timeout: 10_000 }
+ )
+ } catch (err: any) {
+ output = (err?.stdout ?? '') + (err?.stderr ?? '')
+ }
+
+ // Should reference the default config and template id
+ expect(output).toContain('Sandbox templates to publish')
+ expect(output).toContain('default-template-id')
+ expect(output).toContain('e2b.toml')
+ // Should not mention the custom config/template id
+ expect(output).not.toContain('custom-template-id')
+ })
+})
+
+