Skip to content

test(api): pin the spec autoPause default to sandboxtypes.AutoPauseDefault - #3767

Open
AdaAibaby wants to merge 1 commit into
e2b-dev:mainfrom
AdaAibaby:fix/autopause-default-spec-contract
Open

AdaAibaby wants to merge 1 commit into
e2b-dev:mainfrom
AdaAibaby:fix/autopause-default-spec-contract

Conversation

@AdaAibaby

Copy link
Copy Markdown
Contributor

Problem

Fixes #3765.

The sandbox default timeout action (autoPause when omitted) is declared in two places in this repo with no test keeping them in sync:

  1. OpenAPI spec — spec/openapi.yml, both NewSandbox and NewSandboxV2 declare autoPause: { type: boolean, default: false }. Documentation only: the generated Go type is *bool + omitempty (api.gen.go), so the spec default is never applied at decode time.
  2. Go constant — sandboxtypes.AutoPauseDefault = false, which sandbox_create.go actually applies via DerefOrDefault(body.AutoPause, sandbox.AutoPauseDefault) when the request omits autoPause.

The SDKs read and document the spec value as the default (e2b-dev/E2B #2057 — both SDKs hardcode currently kill against it). A drift between the spec and the constant would silently make the published contract lie about what an omitted autoPause does, with no signal.

Change

Add a contract test (mirroring the existing TestSpecSecuritySchemeHeaderNames / TestTemplateBuildMinimumFreeDiskContract pattern in spec_test.go) asserting the spec's autoPause default on NewSandbox and NewSandboxV2 equals sandboxtypes.AutoPauseDefault. Fails CI on drift, making the spec the single documented source of the default.

Test-only; no behavior change. External test package (api_test) because sandboxtypes imports the api package (an in-package test would be an import cycle).

This is the infra-side half of the drift concern in e2b-dev/E2B #2057; the SDK-side half (single-sourcing the SDK's local assumption) is handled in e2b-dev/E2B#2058.

Test

go test ./internal/api/ -run TestSpecAutoPauseDefaultMatchesConstant passes (both subtests); go vet and golangci-lint clean on the file.

…fault

The default timeout action (autoPause when omitted) is declared twice with no
guard: in spec/openapi.yml (NewSandbox/NewSandboxV2 autoPause: default: false,
documentation only — the generated field is *bool omitempty) and in the Go
constant sandboxtypes.AutoPauseDefault that sandbox_create actually applies.
The SDKs read and document the spec value as the default (e2b-dev/E2B e2b-dev#2057),
so a drift between the two silently makes the published contract lie about what
an omitted autoPause does.

Add a contract test asserting the spec's autoPause default on both create
schemas equals sandboxtypes.AutoPauseDefault, mirroring the existing
spec_test.go contract tests. External test package (api_test) because
sandboxtypes imports the api package.

Fixes e2b-dev#3765

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

api: autoPause default is declared in the spec and in a Go constant with no test keeping them in sync

2 participants