Skip to content

codegen: name module declarations through the engine - #120

Merged
TomChv merged 3 commits into
mainfrom
format-identifiers
Nov 25, 2026
Merged

TomChv merged 3 commits into
mainfrom
format-identifiers

Conversation

@vito

@vito vito commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What

Current status: rebased onto main 724f572 (v1.1.0, already paired with engine v1.0.0-beta.28 by #141) and squashed to three commits; head 564b723. The engine-e2e pin stays main's v1.0.0-beta.28 tag commit, and the library bindings and bundle are regenerated on the released beta.28 engine. Since the bundle target (beta.28) is past the naming cut, generated entrypoints now select post-cut names end to end, and the e2e naming check exercises that.

The generated entrypoints call a module through its own interfaces, send and receive its enums there, and pick which object of an [entrypoint] module carries the constructor. They do all of this by the names the engine gives the module's own declarations. This PR stops predicting those names: it reads the served source's naming context through ModuleSource.naming and asks Query.naming(version:).module(name:, originalName:) for the names, shipped in Dagger v1.0.0-beta.26 (dagger/dagger#14996).

The engine answers by the rules of the version it names the module by: strcase before the identifier-casing cut (v1.0.0-beta.26), and its identifier naming rules from the cut on. So nothing here mirrors a rule or compares versions locally, and no legacy prediction path is left.

TypeScript's own identifiers made from schema names are styled by the engine too, through Query.naming(version:).formatIdentifiers (see Identifiers styled by the engine below): enum member keys, enum converter functions, Opts types and the client import aliases. Nothing in codegen styles a name locally.

Mechanism

  • typescript-sdk.dang reads naming.version, naming.name and naming.originalName from the same final-staged module source the engine loads (ws.moduleSource(scope)). It passes these plain strings as --naming-version, --module-name and --module-original-name to codegen entrypoint (__dagger.entrypoint.ts, entrypoint/__dagger.dispatch.ts) and codegen dang-entrypoint (entrypoint/main.dang), running as nested clients of the session. No source ID or ID file travels into the codegen exec.

  • The generators reconstruct that module naming, as Go does, and send one query for every name their typedef declares. The version is the source's resolved naming version, not the running engine, SDK floor or generated core version; both names are required to preserve aliasing and namespace behavior:

    naming(version: $version) {
      module(name: $name, originalName: $originalName) {
        typeNames(names: $types)              # the module's interfaces, namespaced
        fieldNames(names: $fields)            # their functions and arguments
        enumMemberNames(names: $members)      # the module's enum members
        mainObject(candidates: $objects)      # the objects, in registration order
      }
    }
    • A name looked up that wasn't in that query is asked for directly; in practice none is.
    • A failed answer fails generation. That includes a name the engine can't parse: there's no pre-filter.
  • The constructor goes only on the object mainObject names. A module with objects when the engine takes none of them for the main one fails generation, and the error lists the objects. No fallback is left.

  • The typedef is parsed in one place, codegen, so there's no names file, no Dang-side typedef parsing and no request/lookup cross-check. That also means this PR has no Dang release dependency (no JSON.decode into Map).

No other name the entrypoints use is the engine's to give, which matters for the other SDKs:

  • No constructor field. The self client and every dependency client are generated from the engine's real schema.
  • No enum names outside own interfaces. The engine converts the owning module's enums to and from its runtime by the member's original name (core/enum.go, ConvertToSDKInput/ConvertFromSDKResult with Local), and patches enum defaults from original names (Module.Patch). So the dispatcher's enum coercion and the typedef defaults use declared names, which are right on both sides of the cut.
  • No dispatch names. The engine dispatches by original names (parentName/receiverType, fnName, argument keys).

What changes for users

The names were wrong on every engine before, and broke the module wherever they differed from the engine's. Output only changes where they were wrong (generated identifiers aside: see Identifiers styled by the engine).

  • Function and argument names of a call through an own interface were sent as declared. getURL selected getURL, which the engine names getUrl. The e2e caught it: Cannot query field "getURL" on type "NamingAppHttpFetcher". Did you mean "getUrl"?.
  • Interfaces were namespaced as the scanner's PascalCase of the module's name followed by the interface's:
    • an acronym run was kept: FooHTTPClient became FooFooHTTPClient, which strcase names FooHttpclient;
    • a prefix the engine drops was repeated: PondHttpClient in module pond became PondPondHttpClient.
  • The main object of an [entrypoint] module was matched pascalized against the scanner's name. K8sTools in k8s-tools, which is how this SDK's own templates name the class, got no constructor. Now only the engine's mainObject decides. The other way round, K8STools in a k8s-tools that strcase names (K8sTools) used to get the constructor from that match, and it now fails generation. Under the new rules the engine takes it.
  • Enums through own interfaces. An argument was sent as the TS value, quoted ("arm64"), where the field takes the member's name. A result came back as the name, not the value. Arguments, results and lists of them, nullable ones included, now convert through the query builder's enum metadata.
  • From the cut on, a module declaring v1.0.0-beta.26 or later is called by the engine's new names: NamingAppHTTPFetcher, e2eTest, ARM64.

The SDK module declares engineVersion = "v1.0.0-beta.26" in dagger-module.toml and dagger.json. That is the floor, the first release serving ModuleSource.naming, and nothing checks it in code. Engines compare base versions only, so beta.12–25 engines aren't refused: they break wherever the SDK selects something they lack. Declaring it has two consequences:

  • The SDK's Dang code selects that view's core names (introspectionSchemaJson, clientSchemaIntrospectionJson, htmlRepoUrl).
  • User-visible rename: the engine names the SDK module by its identifier naming rules. Its types become TypescriptSDK, TypescriptSDKClientTarget, TypescriptSDKModConfig, TypescriptSDKRuntime and TypescriptSDKTemplate, where strcase gave TypescriptSdk…. The constructor stays typescriptSdk, because field names write acronyms like words (Capitalized). Only the types are renamed. No caller in this repo names those types; they all go through the constructor.

The README, docs/module-sources.md and the bundleEngineVersion docs say so. Loading an unpinned generated module still needs only beta.18. A module the engine names by the new rules needs an engine at the cut to load, because an older engine would name it by strcase.

Identifiers styled by the engine

The TypeScript identifiers the bindings derive from schema names follow two rules: TypeScript's convention, which is PascalCase for enum members and types, and the engine's styling, so no local casing helper is involved. The bindings generators (codegen module, client, library) take them from naming(version: <the schema's __schemaVersion>) { formatIdentifiers(names:, casing: PASCAL, acronyms: UPPERCASE) }, as the Go SDK styles its names:

  • enum member keys (NetworkProtocol.TCP);
  • enum converter functions, <Enum>ValueToName / <Enum>NameToValue, at their declarations, imports and call sites alike;
  • options types, <Parent><Field>Opts (the field part);
  • the __dag<Dep> / __mod<Dep> import aliases, in place of strcase.ToCamel.

Details:

  • Acronym style UPPERCASE, to match the type names the same bindings already expose, which keep acronyms in capitals (HTTPClient, LLMMessageRole).
  • It's one up-front query over the nested session for every enum, enum member, field with optional arguments and module file name in the rendered schema (the core's too, unless the library's core ships as it is). A name looked up that wasn't is styled directly, and a failed answer fails generation.
  • toPascalCase and its LLM special case are deleted.

User-visible renames: the library's core bindings and bundle are regenerated on the released v1.0.0-beta.28 engine (packager:library-bindings, then packager:library-bundle). Where the engine's styling differs from toPascalCase (method names still mirror the schema's fields, e.g. withSdk, clientSchemaIntrospectionJson):

before after
NetworkProtocol Tcp, Udp TCP, UDP
ImageMediaTypes Oci OCI
RegistryProtocol Http, Https HTTP, HTTPS
Artifact.uri options ArtifactUriOpts ArtifactURIOpts
dag.http options ClientHttpOpts ClientHTTPOpts
dag.sshfsVolume options ClientSshfsVolumeOpts ClientSSHFSVolumeOpts
Workspace.withSdk options WorkspaceWithSdkOpts WorkspaceWithSDKOpts
Workspace.withoutSdk options WorkspaceWithoutSdkOpts WorkspaceWithoutSDKOpts
ModuleSource.clientSchemaIntrospectionJson options ModuleSourceClientSchemaIntrospectionJsonOpts ModuleSourceClientSchemaIntrospectionJSONOpts
SDK module types TypescriptSdk, TypescriptSdkClientTarget, TypescriptSdkModConfig, TypescriptSdkRuntime, TypescriptSdkTemplate TypescriptSDK… (constructor stays typescriptSdk)

Under remoteCoreLib a scope takes @dagger.io/core from npm, which dagger/dagger publishes with its own (still toPascalCase) styling, so these names differ between the vendored and the published core until that catches up; the README says so.

Every other core key, converter and Opts type is unchanged (TypeDefKind.StringKind, FunctionCachePolicy.PerSession, LLMMessageRole.User, LLMContentBlockKindValueToName, ContainerWithExecOpts, …). All-caps words outside the engine's acronym dictionary stay words: DOCKER → Docker, VALUE → Value. Module and dependency bindings get the same styling, e.g. a member http_only → HTTPOnly, a field asJson's options FileAsJSONOpts (where toPascalCase gave FileAsJsonOpts).

No aliases keep the old names: code written against NetworkProtocol.Tcp or ClientHttpOpts (including pre-1.0 source the compat shim otherwise keeps compiling) needs the new one.

Commit history

Squashed on the rebase onto 724f572 (the 24-commit development history is in the PR's timeline):

commit what
4c2d99c codegen: name module declarations through engine helpers/codegen: Naming.module lookups (types, fields, enum members, mainObject), enum conversion through own interfaces, formatIdentifiers styling, the nested-session client, fake engine and tests
05ddd5f sdk: pass module naming to codegen, floor beta.26 typescript-sdk.dang, manifests, e2e naming check + fixture, packager nesting, docs
564b723 library: regenerate with engine-styled identifiers generated library/src/core/client.gen.ts + library/bundle/* on released beta.28; VENDOR.md

Integration with what main gained since b75eb1a (remoteCoreLib, globalClient/split clients, split runtime imports, bundle pruning, the beta.28 pairing): flag sets and configs merged, generateModuleDispatcher/generateDangEntrypoint keep main's --remote-core-lib/--split-runtime-imports arguments, the now-unused pascalize helper is removed, and when the core ships as it is (--core-file) the core enums' names join the one up-front formatIdentifiers query (their converters are imported by module clients). The remote-entrypoint fixture keeps main's real, tagged github.com/dagger/[email protected].

If the cut moves

Nothing in the code compares versions: the engine decides which rules name a module, and the SDK only declares its floor (engineVersion = "v1.0.0-beta.26" in dagger-module.toml and dagger.json; there is no module-root dang.toml). The cut shipped in beta.26, so this section is reference only.

If the API itself moves (a field or argument is renamed), the queries are in templates/module_naming.go (namingQuery, LoadModuleNames, lookup) and templates/identifiers.go (formatIdentifiersQuery), and the fake engine is generator/namingtest (its Styles table holds the engine's expected answers for the test schemas' names).

Tests

At head 564b723, against the released registry.dagger.io/engine:v1.0.0-beta.28 (run as a service, driven by that image's CLI, with .dagger/modules/engine-e2e/workspace.toml as the workspace config, as the playground uses):

  • helpers/codegen: go test -count=1 ./... and go vet ./... pass.
  • dagger generate --auto-apply (all generators) writes nothing beyond the committed library regeneration.
  • 38 checks pass:
    • e2e:naming:calls-check (new and owned-older-config fixture both select NamingAppHTTPFetcher / e2eTest / getUrl; the module's self-call check passes);
    • packager:library-bindings/stale, library-bundle/stale, library-tests, layering-check;
    • runtimes:* (all 18, interface-returns and interface-field-entrypoint included; their inner failures are the deliberate ones they assert);
    • e2e:generate:{generate-self-call, generate-dependency-bindings, generate-module-type-checks, generate-compat-shim-type-checks, generate-deno-module-type-checks, global-client, entrypoint-installs-dependencies, generate-idempotent}-check, e2e:client:{generate-client-compiles, module-scope-client-bindings}-check, e2e:version:{dang-config, entrypoint-regenerate-no-diff, core-from-bundle}-check, e2e:sdk:helper-tests-check, e2e:manifest:remote-entrypoint-replaced-check.
  • Manual SDK smoke on the same engine: dagger sdk list lists typescript; dagger module init typescript --legacy-runtime and call base-image-address work; an [entrypoint] init writes entrypoint/dang.toml at beta.28 and its functions load; the SDK module's type is TypescriptSDK.

Not run: the engine-e2e playground checks (dev-sdk-check, dev-sdk-settings-check, checks-check), which build the beta.28 engine from source; and the rest of e2e:*.

The naming check's pinned case uses v1.0.0-beta.26 for the owned older dang.toml: it is the oldest pin generation can load through to heal (see VersionChecks.dangConfigCheck; older ones fail on keyByContent). The check no longer reads ModuleSource.naming itself, which the e2e module's pre-cut view of the API lacks; the post-cut names in the dispatcher stand in for it.

Unit tests (fake engine, helpers/codegen/generator/namingtest) cover: one up-front query plus a direct one on a miss (naming and styling); an unknown source and a name the engine can't give or style both fail; pre/post-cut naming versions distinct from the core version; renamed module identity plus original name; interface type/field names, enum conversions (lists, nullable lists), the main object from the engine's answer and the failure when it takes none; both entrypoint CLI modes against an HTTP fake.

A pre-existing own-interface enum-alias issue (duplicate TypeScript object keys for equal enum values) was reported by an earlier review and is unchanged here.

Loading the SDK module on a pre-beta.26 engine fails: its Dang code selects post-cut core names. That is the declared floor.

Engine-side, not naming: the enum conversion through own interfaces is unit-tested only. A self-call whose schema holds an own interface with an own-enum argument fails at schema load, interface "NamingAppHttpFetcher" function "getUrl" cannot accept arg "arch" of external type from dependency module "naming-app" (core/interface.go), so the e2e fixture's interface carries no enum.

Follow-ups / open questions

  • The TS entrypoint templates spell a few core keys literally (TypeDefKind.StringKind, FunctionCachePolicy.Never), which the engine styles the same today.
  • The generators preserve the name and originalName of the served source used at generation. A workspace or toolchain that later loads the module under a different name namespaces its interfaces under that other name; the generated entrypoint does not anticipate a future alias. That's documented on ModuleSource.naming in core: add ModuleSource.naming for SDK codegen dagger#14996.
  • library/src/module/introspector/introspection_json.ts (not wired) still has strcase ports. Whoever wires it should ask the engine instead.
  • Dependency clients still use each dependency's own client schema. Switching them to ModuleSource.clientSchemaIntrospectionJson(clientVersion: <consumer>) (core: add clientVersion to client schemas dagger#14959) would serve core at the consumer's view; only the core part of a dependency client would change.
  • The engine refusal above (an own-enum argument on an own interface, in a self-call).

vito added 3 commits November 23, 2026 18:48
The generated entrypoints call a module through its own interfaces, send
and receive its enums there, and pick the object of an [entrypoint] module
that carries the constructor. They now take those names from the engine
(Query.naming(version:).module(name:, originalName:)) instead of predicting
them, given the served source's naming version, name and original name as
--naming-version, --module-name and --module-original-name. The constructor
goes only on the object mainObject names.

TypeScript identifiers derived from schema names (enum member keys, enum
converters, Opts types, dependency import aliases) are styled through
Naming.formatIdentifiers with PascalCase and uppercase acronyms, in one
up-front query plus direct calls on misses. toPascalCase and pascalize are
removed.

Names the engine cannot give or style fail generation; there is no fallback
and no pre-filter.

Signed-off-by: Alex Suraci <[email protected]>
typescript-sdk.dang reads naming.version, name and originalName from the
final module source the engine loads and passes them as plain strings to the
entrypoint generators, which run as nested clients. The SDK module declares
engineVersion v1.0.0-beta.26, the first release serving ModuleSource.naming,
and selects that view's core names (introspectionSchemaJson,
clientSchemaIntrospectionJson, htmlRepoUrl). Nothing checks the floor in code.

Being named by the engine's identifier rules renames the module's types
(TypescriptSdk* -> TypescriptSDK*); the constructor stays typescriptSdk.

Adds the e2e:naming calls check: a fixture generated at the bundle target
(beta.28, past the cut), new and with an owned older dang.toml, selects
NamingAppHTTPFetcher/e2eTest/getUrl and passes its self-call.

Signed-off-by: Alex Suraci <[email protected]>
Regenerated on the released v1.0.0-beta.28 engine (packager:library-bindings
then packager:library-bundle). Enum member keys and Opts types now take the
engine's PascalCase styling with uppercase acronyms: NetworkProtocol.TCP/UDP,
ImageMediaTypes.OCI, RegistryProtocol.HTTP/HTTPS, ArtifactURIOpts,
ClientHTTPOpts, ClientSSHFSVolumeOpts, WorkspaceWithSDKOpts,
WorkspaceWithoutSDKOpts, ModuleSourceClientSchemaIntrospectionJSONOpts.
VENDOR.md records the divergence from upstream's bindings.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the format-identifiers branch from 379b3e4 to 564b723 Compare November 23, 2026 18:49
@vito
vito marked this pull request as ready for review November 23, 2026 19:00
@TomChv
TomChv merged commit dfa785d into main Nov 25, 2026
6 checks passed
TomChv added a commit that referenced this pull request Nov 25, 2026
`e2e/sdk/helper-tests-check` is red on main: `go test ./...` in
helpers/codegen fails TestGenerateDangEntrypointCachePolicy (3 subtests)
and TestGenerateEntrypointDispatchLoadsModuleCode.

Neither is a regression in #120's code, and neither PR could have caught
it. #120 made every generator that renders a module's own declarations
ask the engine for their names, and added `Naming` to each test that
builds a generator config. Its branch predates both of these tests:

- dang_entrypoint_cache_policy_test.go arrived with #143.
- TestGenerateEntrypointDispatchLoadsModuleCode arrived with #144.

Both merged after #120's CI ran, git merged all three cleanly, and the
combination was never tested. Without a naming context the dang
entrypoint finds no main object among typedef_smoke.json's objects, and
the dispatcher cannot name the fixture's own interface.

Both now use `smokeNaming()`, as every other test on that fixture does.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv added a commit that referenced this pull request Nov 25, 2026
sdk-helpers v1.0.13 (dagger/sdk-helpers#14) adopts the beta.26 identifier
naming conventions in its source and declares v1.0.0-beta.26 as its floor.
That is not a schema change: a beta.26+ caller was already served
SDKHelpers*, loadToml and loadJson, which this SDK has selected since it
took the same floor in #120. The one real rename, withLegacyPHPRuntime ->
withLegacyPhpRuntime, has no caller here.

So this is a pin bump only. Both lockfiles gain the tag's resolution;
engine-e2e's workspace.lock is the playground's, refreshed by its own
generator.

dagger generate reports no changes to apply, and the module loads against
the new pin.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv added a commit that referenced this pull request Nov 25, 2026
sdk-helpers v1.0.13 (dagger/sdk-helpers#14) adopts the beta.26 identifier
naming conventions in its source and declares v1.0.0-beta.26 as its floor.
That is not a schema change: a beta.26+ caller was already served
SDKHelpers*, loadToml and loadJson, which this SDK has selected since it
took the same floor in #120. The one real rename, withLegacyPHPRuntime ->
withLegacyPhpRuntime, has no caller here.

So this is a pin bump only. Both lockfiles gain the tag's resolution;
engine-e2e's workspace.lock is the playground's, refreshed by its own
generator.

dagger generate reports no changes to apply, and the module loads against
the new pin.

Signed-off-by: Tom Chauveau <[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