diff --git a/services/agents-api/internal/db/queries/sandbox_reset.sql b/services/agents-api/internal/db/queries/sandbox_reset.sql index 01afae0f9..b951a0d3e 100644 --- a/services/agents-api/internal/db/queries/sandbox_reset.sql +++ b/services/agents-api/internal/db/queries/sandbox_reset.sql @@ -22,6 +22,7 @@ UPDATE runtime_deployment SET provider_kind = '', backend_fingerprint = '', mode specification = '{}', idle_seconds = 0, retention_seconds = 0, e2b_template = '', e2b_credential = NULL, e2b_template_build_status = NULL, e2b_template_cpus = NULL, e2b_template_memory_mib = NULL, e2b_template_root_disk_mib = NULL, + e2b_api_url = '', e2b_domain = '', generation = generation + 1, owner_epoch = owner_epoch + 1, admission_paused = false, reset_clear = NULL, reset_requested_at = NULL, reset_deadline_at = NULL, reset_forced_at = NULL, reset_audit = NULL, diff --git a/services/agents-api/internal/db/sqlc/sandbox_reset.sql.go b/services/agents-api/internal/db/sqlc/sandbox_reset.sql.go index fabff44d7..246caee52 100644 --- a/services/agents-api/internal/db/sqlc/sandbox_reset.sql.go +++ b/services/agents-api/internal/db/sqlc/sandbox_reset.sql.go @@ -28,6 +28,7 @@ UPDATE runtime_deployment SET provider_kind = '', backend_fingerprint = '', mode specification = '{}', idle_seconds = 0, retention_seconds = 0, e2b_template = '', e2b_credential = NULL, e2b_template_build_status = NULL, e2b_template_cpus = NULL, e2b_template_memory_mib = NULL, e2b_template_root_disk_mib = NULL, + e2b_api_url = '', e2b_domain = '', generation = generation + 1, owner_epoch = owner_epoch + 1, admission_paused = false, reset_clear = NULL, reset_requested_at = NULL, reset_deadline_at = NULL, reset_forced_at = NULL, reset_audit = NULL, diff --git a/services/agents-api/internal/store/sandbox_deployment_switch_test.go b/services/agents-api/internal/store/sandbox_deployment_switch_test.go index e17bb2e29..b70fed761 100644 --- a/services/agents-api/internal/store/sandbox_deployment_switch_test.go +++ b/services/agents-api/internal/store/sandbox_deployment_switch_test.go @@ -47,6 +47,40 @@ func TestSandboxE2BEndpointPersistenceAndOnlineSwitch(t *testing.T) { t.Fatal("online endpoint switch failed", changed, err) } } + +func TestSandboxResetClearsCustomE2BEndpoint(t *testing.T) { + _, pool := newManagedTestStore(t) + cipher, err := credentialcrypto.New(bytes.Repeat([]byte{7}, 32)) + if err != nil { + t.Fatal(err) + } + s := NewWithCredentialCipher(pool, cipher) + w := executionLease(t, s).Store() + installation := uuid.NewString() + if err := w.ClaimWebSandboxDeployment(t.Context(), installation); err != nil { + t.Fatal(err) + } + input := e2bSelection() + input.E2B.APIURL, input.E2B.Domain = "https://sandbox-test.sandbase.ai", "sandbox-test.sandbase.ai" + configured, err := w.InitializeSandboxDeployment(t.Context(), installation, input) + if err != nil { + t.Fatal(err) + } + ctx := SandboxResetTestContext(t.Context()) + reset, err := w.StartSandboxReset(ctx, installation, SandboxResetRequest{ExpectedGeneration: configured.Generation, Clear: "force"}) + if err != nil { + t.Fatal(err) + } + empty, err := w.CompleteSandboxReset(ctx, installation, configured.Generation, reset.Reset.RequestedAt) + if err != nil || empty.Provider != "" || empty.Reset != nil || empty.Generation != configured.Generation+1 { + t.Fatal("custom endpoint blocked reset completion", empty, err) + } + var apiURL, domain string + if err := pool.QueryRow(t.Context(), "SELECT e2b_api_url, e2b_domain FROM runtime_deployment").Scan(&apiURL, &domain); err != nil || apiURL != "" || domain != "" { + t.Fatal("reset retained custom endpoint", apiURL, domain, err) + } +} + func TestSandboxDirectDeploymentOwnershipAndCleanSwitch(t *testing.T) { _, pool := newManagedTestStore(t) cipher, err := credentialcrypto.New(bytes.Repeat([]byte{4}, 32))