Skip to content

feat(core): add CurrentModule.asSDK for SDK-owned module discovery - #13522

Merged
grouville merged 7 commits into
dagger:design/cli-1.0from
eunomie:fix-generate-empty-changeset
Jun 20, 2026
Merged

grouville merged 7 commits into
dagger:design/cli-1.0from
eunomie:fix-generate-empty-changeset

Conversation

@eunomie

@eunomie eunomie commented Jun 19, 2026

Copy link
Copy Markdown
Member

Problem

On design/cli-1.0, after dagger sdk install go + dagger module init go my-module --template=legacy, deleting .dagger/modules/my-module/internal and running dagger generate (a.k.a. go-sdk:generate-all) returns an empty changeset and does not restore internal/.

Root cause

dagger generate discovers and dispatches to an SDK module's generator (e.g. go-sdk:generate-all), which must know which workspace modules it manages. On cli-1.0 that source of truth is the engine's workspace config ([[modules.<name>.as-sdk.modules]]), but SDK modules had no way to read it — so they fall back to scanning the filesystem for legacy dagger.json modules and silently find nothing for dagger-module.toml workspace modules, producing an empty changeset.

This is the engine half of the fix described in future/current-module-as-sdk.md.

This PR

Adds CurrentModule.asSDK, exposing the currently executing module's as-sdk role data resolved from workspace config:

extend type CurrentModule { asSDK: CurrentModuleAsSDK! }

type CurrentModuleAsSDK {
  name: String!
  modules: [CurrentModuleAsSDKModule!]!   # { path }
  clients: [CurrentModuleAsSDKClient!]!   # { path, module, pin }
}

SDK generators can now discover their managed modules via dag.CurrentModule().AsSDK() instead of scanning the workspace themselves.

Notes:

  • Unversioned, matching the other workspace-introspection primitives SDK modules already rely on (currentWorkspace, Workspace.directory/file/findUp), so SDK modules pinned to older engine versions can consume it.
  • The current module is matched to its workspace install entry by name (the convention generators() already uses for skip patterns), falling back to the sole installed SDK entry and erroring on ambiguity / when the current module is not installed as an SDK.
  • Kept minimal per the design (modules/clients expose only the persisted fields the SDKs need); the design's derived source/moduleSource fields are deferred until a consumer needs them.
  • docs/docs-graphql/schema.graphqls and the API reference stubs were regenerated via dagger generate docs:references.

Follow-up (separate PRs)

This is the engine discovery primitive. The full user-visible fix also needs the SDK modules to use it:

  • dagger/go-sdk, dagger/typescript-sdk, dagger/python-sdk: generateAll discovers via currentModule.asSDK.modules instead of scanning dagger.json.
  • dagger/sdk-sdk: the shared polyfill codegen helper needs to recognize dagger-module.toml (it currently hardcodes dagger.json).

eunomie added 2 commits June 19, 2026 17:39
dagger generate dispatches to an SDK module's generator (e.g.
go-sdk:generate-all), which must know which workspace modules and clients
it manages. On design/cli-1.0 that source of truth is the engine's
workspace config ([[modules.<name>.as-sdk.modules]] / .clients), but SDK
modules had no way to read it, so they fell back to scanning the
filesystem for legacy dagger.json modules and silently found nothing for
dagger-module.toml workspace modules (empty changeset).

Add CurrentModule.asSDK, exposing the currently executing module's
as-sdk role data (name, managed modules, generated clients) resolved from
workspace config, per future/current-module-as-sdk.md. SDK generators can
now discover their modules via dag.CurrentModule().AsSDK() instead of
scanning the workspace themselves.

The field is unversioned, matching the other workspace-introspection
primitives SDK modules rely on (currentWorkspace, Workspace.directory/
file/findUp), so SDK modules pinned to older engine versions can consume
it. The current module is matched to its workspace install entry by name
(the same convention generators() uses for skip patterns), falling back
to the sole installed SDK entry and erroring on ambiguity or when the
current module is not installed as an SDK.

Signed-off-by: Yves Brissaud <[email protected]>
Regenerated via 'dagger generate docs:references': adds the schema.graphqls
entries and reference stubs for CurrentModule.asSDK and the CurrentModuleAsSDK
/ CurrentModuleAsSDKModule / CurrentModuleAsSDKClient types, and renumbers
sidebar positions for the inserted types.

Signed-off-by: Yves Brissaud <[email protected]>
@eunomie

eunomie commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

Related PRs for the cli-1.0 generate-all empty-changeset fix (all needed for the end-to-end fix):

The SDK PRs depend on this engine API being available in the engine they run against; verified end-to-end against a dev engine (deleting a Go SDK module's internal/ then dagger generate go-sdk:generate-all restores it).

@eunomie
eunomie force-pushed the fix-generate-empty-changeset branch from 926cb17 to a39591a Compare June 19, 2026 16:38
Signed-off-by: Yves Brissaud <[email protected]>
@eunomie
eunomie force-pushed the fix-generate-empty-changeset branch from a39591a to 8e75caa Compare June 19, 2026 17:43
eunomie and others added 4 commits June 19, 2026 20:29
CurrentModule.asSDK and the CurrentModuleAsSDK* types were unversioned, so
they leaked into the base (oldest module) schema and failed
TestBaseSchemaAllowlist. Gate the field and the object types with
View(AfterVersion("v1.0.0-0")), matching the rest of the cli-1.0 workspace
API, so they (and their auto-generated Binding.as* accessors) stay out of
older module views. SDK modules consume it by declaring engineVersion
>= v1.0.0-0.

Signed-off-by: Yves Brissaud <[email protected]>
CurrentModule.asSDK should only succeed when the currently executing module is
the workspace entry installed as an SDK.

The old resolver had a fallback for workspaces with exactly one SDK install. If
a normal module called CurrentModule.asSDK and its name did not match that SDK,
the resolver still returned the SDK because it was the only SDK in the
workspace.

That was wrong because the current module was not installed as an SDK. It should
receive the documented "not installed as an SDK" error.

Fix this by only resolving `cfg.Modules[curName]` when that exact workspace
entry is marked `AsSDK`. Otherwise return the not-installed error.

Add a regression test where `my-module` runs in a workspace that also has one
installed `go-sdk`. Before this fix, `my-module` resolved as `go-sdk`. Now it
returns the not-installed error.

Validated with the focused resolver unit test and a dev-engine smoke test with
go and python installed as SDKs.

Signed-off-by: Guillaume de Rouville <[email protected]>
CurrentModule.asSDK only succeeds for modules installed as SDKs. That is the
intended CLI flow: `dagger sdk install` writes the workspace as-sdk marker,
while plain `dagger install` leaves a normal module install.

TestGeneratePrivateGitDependency was still installing go-sdk with the generic
module install command. With the stricter asSDK resolver, go-sdk then ran as a
normal module and correctly got the "not installed as an SDK" error.

Update the test setup to use `dagger sdk install go`, matching the SDK-owned
generator path that the test expects to exercise.

Validated with the focused resolver unit test and the failing integration
subtest.

Signed-off-by: Guillaume de Rouville <[email protected]>
CurrentModule.asSDK now requires the current module to be installed with an
as-sdk marker. That is the intended workspace shape for SDK-owned generator
tests.

TestGeneratorGroupChangesSyncWithNestedSDKCodegen writes a dagger.toml fixture
by hand. It installed go-sdk as a normal workspace module, then expected
go-sdk:generate-all to call CurrentModule.asSDK successfully. With the stricter
resolver, that fixture correctly failed as "not installed as an SDK".

Add the go-sdk as-sdk marker to the fixture so it matches the SDK install shape
under test.

Validated with the focused integration subtest.

Signed-off-by: Guillaume de Rouville <[email protected]>
@grouville
grouville merged commit 0b37276 into dagger:design/cli-1.0 Jun 20, 2026
80 checks passed
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