Skip to content

fix: let tests use generated module clients - #75

Merged
TomChv merged 3 commits into
mainfrom
nested-client-session
Oct 26, 2026
Merged

TomChv merged 3 commits into
mainfrom
nested-client-session

Conversation

@TomChv

@TomChv TomChv commented Oct 22, 2026

Copy link
Copy Markdown
Member

Problem

A test run by this module cannot use a generated Dagger module client, and in
Go the failure is total rather than partial:

panic: workspace module source "<project>/.dagger/modules/fixtures" does not contain
  a dagger config file
  .../internal/dagger/clients/fixtures/dag.initClient()

Connect() serves the bound module eagerly and the generated dag package panics
when that fails, so every test that touches dag dies — including one that only
calls dag.Container() and never uses a module function. The equivalent TypeScript
and Python clients return an error and leave the core API usable.

Two causes, in order.

1. The tests join the session running them. A module address then resolves
against this module rather than against the user's workspace — the error says
from module "go". The runner already synthesizes the .git marker a nested
client needs to find its workspace root, so that half was done; the session was
the missing piece.

2. The source mount is Go-only. With its own session the error changes to
workspace module source "…/.dagger/modules/fixtures" does not contain a dagger config file — the directory is there, with its .go files, but
dagger-module.toml is not a Go file and so is not in source(ws, test: true).
The module is visible and unservable.

Fix

  • testExec and runTests run with daggerInDaggerNewSession: true, and set
    _EXPERIMENTAL_DAGGER_CLI_BIN=/dev/.dagger/dagger: with its own session a client
    provisions through a CLI, and the engine already mounts a version-matched one on
    PATH for exactly this case. Newer SDKs find it themselves; older ones only read
    that variable.
  • testEnv also mounts **/dagger-module.toml and **/dagger.json, so a module
    inside the workspace arrives complete.

Only the test execs change; go generate and the build paths keep the shared
session.

Verification

A workspace with a module, a generated client for it, and a go test suite that
calls the core API, a module function, and a module Service bound into a
container the test builds:

before:  every test panics in dag.initClient()
after:   3 passed

Confirmed on an uncached run (source touched to defeat the cache), not a replayed
result.

Known limit

Only what the Go filter selects, plus the module configs, is mounted — a test that
reads the workspace still sees a partial tree. includeExtraFiles widens it.

The runner already synthesizes the .git marker a nested client needs to
find its workspace, but the tests joined the session running them, so a
generated module client resolved its module address against this module
rather than against the user's workspace and failed with 'does not
contain a dagger config file'. In Go that is fatal rather than partial:
Connect() serves the bound module eagerly and the generated dag package
panics when it fails, so even a test that only calls dag.Container()
dies.

Give the test execs a session of their own, and point older clients at
the CLI the engine mounts for exactly this case.

Signed-off-by: Tom Chauveau <[email protected]>
The source mount is filtered to Go files, so a Dagger module inside the
workspace arrives with its .go files but without dagger-module.toml,
and serving it fails with 'does not contain a dagger config file' --
the directory is there, the config is not.

Signed-off-by: Tom Chauveau <[email protected]>
The nesting fixture asserted DAGGER_SESSION_PORT and DAGGER_SESSION_TOKEN,
which is exactly what giving the tests their own session removes. Open one
with the CLI the engine mounts, the way an SDK does, and run the same query
through it. The session lasts as long as its stdin, so the pipe stays open
for the test.

Its workspace assertion moves with the behaviour too: a test now sees the
workspace its container carries, which holds what the runner mounted rather
than every file of the repository, so it looks for a Go module instead of
the repository's LICENSE.

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv
TomChv merged commit e046bac into main Oct 26, 2026
52 checks passed
sipsma added a commit that referenced this pull request Oct 27, 2026
Tests have run in a session of their own since #75, so that a module
address resolves against the user's workspace. But a new session leaves
DAGGER_SESSION_PORT and DAGGER_SESSION_TOKEN unset, and a Dagger Go
module's own package panics on load without them. Every test of a Dagger
Go module failed, gobuild's among them.

Run the tests under the engine-mounted CLI's api with-session instead. It
opens the same kind of new session and hands it to the tests through
those two variables, which every SDK's client connects through.

Signed-off-by: Erik Sipsma <[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