Skip to content

codegen/go: allow imports without a session - #14880

Merged
tiborvass merged 1 commit into
mainfrom
codex/import-safe-legacy-codegen
Oct 28, 2026
Merged

tiborvass merged 1 commit into
mainfrom
codex/import-safe-legacy-codegen

Conversation

@tiborvass

@tiborvass tiborvass commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Generated Go bindings read session settings at package load time. A test
that only imports these bindings fails before any test can run. This
forces the test runner to open a session for tests that never use
Dagger.

Read session settings on the first API request. Imports, query
construction, and JSON decoding can then work without a session. Missing
or invalid settings return an error. A later request can try again after
session setup.

The connect layer and the core package share one client. A mutex
protects client setup. Network requests run outside the lock.

Companion PR: dagger/go#83

Validation:

  • GOFLAGS=-race go test ./cmd/codegen/generator/go/... passed.
  • The regression test compiles both generated packages without a
    session.
  • It checks handles created before session setup and configuration
    errors.
  • It also checks concurrent requests, authentication, and JSON decoding.
  • The previous templates fail the regression test at package load time.

Generated Go bindings read session settings at package load time. A test
that only imports these bindings fails before any test can run. This
forces the test runner to open a session for tests that never use
Dagger.

Read the settings on the first API request. Share one client between
normal queries and handles decoded from JSON. Return an error for
missing or invalid settings, and allow a later request to try again.
Keep the client after the first successful configuration check.

The regression test compiles both generated packages without a session.
It checks handles created before session setup, configuration errors,
concurrent requests, and authentication. The test fails with the
original package initialization panic on the previous templates.

Validation: GOFLAGS=-race go test ./cmd/codegen/generator/go/...

Companion change: dagger/go#83

Signed-off-by: Tibor Vass <[email protected]>
@tiborvass
tiborvass force-pushed the codex/import-safe-legacy-codegen branch from 42e0e98 to 077d57f Compare October 27, 2026 14:21
tiborvass added a commit to dagger/go that referenced this pull request Oct 27, 2026
The test runner opens a Dagger session for every test command. Generated
bindings require this at package load time, even when the tests never
call Dagger. The same wrapper also starts sessions for tests that do not
import those bindings.

Generate the gobuild bindings with the deferred session setup from
dagger/dagger#14880. Run otelgotest without the session wrapper. Keep
access to the mounted CLI so tests can start a session when they need
one. Update the nesting test to open its own session and check workspace
access.

The engine used for generation must include dagger/dagger#14880. The
released engine still writes the previous initializers, so the
generated-file check fails until that dependency is available.

Validation: gobuild tests passed without session settings. The
single-module, skips-non-modules, tests-collection, and binary checks
passed. Scanner tests also passed without session settings and with an
invalid CLI path.

Depends on: dagger/dagger#14880

Signed-off-by: Tibor Vass <[email protected]>
@tiborvass tiborvass changed the title fix(codegen): defer Go module session lookup until requests codegen/go: allow imports without a session Oct 27, 2026
@tiborvass
tiborvass merged commit b5f175d into main Oct 28, 2026
92 checks passed
@tiborvass
tiborvass deleted the codex/import-safe-legacy-codegen branch October 28, 2026 18:02
tiborvass added a commit to dagger/go that referenced this pull request Nov 2, 2026
The test runner opens a Dagger session for every test command. Generated
bindings require this at package load time, even when the tests never
call Dagger. The same wrapper also starts sessions for tests that do not
import those bindings.

Generate the gobuild bindings with the deferred session setup from
dagger/dagger#14880. Run otelgotest without the session wrapper. Keep
access to the mounted CLI so tests can start a session when they need
one. Update the nesting test to open its own session and check workspace
access.

The engine used for generation must include dagger/dagger#14880. The
released engine still writes the previous initializers, so the
generated-file check fails until that dependency is available.

Validation: gobuild tests passed without session settings. The
single-module, skips-non-modules, tests-collection, and binary checks
passed. Scanner tests also passed without session settings and with an
invalid CLI path.

Depends on: dagger/dagger#14880

Signed-off-by: Tibor Vass <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants