Skip to content

Declare the Dagger version in the dagger import - #206

Merged
vito merged 4 commits into
mainfrom
dagger-view
Oct 28, 2026
Merged

vito merged 4 commits into
mainfrom
dagger-view

Conversation

@vito

@vito vito commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Based on main (#185 has merged). A Dagger import's dagger key now takes the Dagger API version its source is written against, the same way dang = "..." takes the Dang version:

[imports.Dagger]
dagger = "v0.19.0"

Why

Since #185, dang sets up Dagger only when dang.toml declares a Dagger import. A nearby dagger.json or dagger.toml no longer turns it on just because a dang.toml exists. That makes the declaration worth something: it can say which core API the module targets, so a newer engine keeps serving the API the code was written for.

The dagger key

  • Format: the same rules as dang (Declare the Dang version per project, add dang migrate #185's shared parseVersion): an optional leading v, X.Y or X.Y.Z, and an optional prerelease or build suffix, which is dropped (Keep the prerelease of the declared Dagger version #208 keeps the prerelease, which Dagger's prerelease-granular API views need). A module's engineVersion, e.g. v1.0.0-beta.19, can be copied in as is.
  • What reaches Dagger: always vX.Y.Z, since Dagger guesses at versions without the v or the patch (vX.Y.Z[-prerelease] with Keep the prerelease of the declared Dagger version #208). "0.19" becomes v0.19.0.
  • No range check in Dang. The engine refuses versions below its minimum, and Dang checks for an engine older than the version (below).
  • dagger = true still works and means what it did: no version is sent, the API follows the dagger CLI that starts the session, and a Dagger module's schema follows its engineVersion. The docs lead with the version form. true is also the form to use with endpoint.
  • Refused: a version with endpoint, since an endpoint's version was set by whoever started it, and "0.0".
  • Public API change: ImportSource.Dagger is now a DaggerSource{Enabled, Version}, and ImportConfig gains DaggerVersion. Embedders (the Dagger SDK) can read the version with DaggerSource.VersionString() / DaggerVersionString(Version), which return vX.Y.Z, or "" for dagger = true. Don't use Version.String(), which uses Dang's format.
  • Encoding: DaggerSource reads and writes false, true or "vX.Y.Z" in both TOML and JSON (a service's JSON output is read into ImportSource), and "dagger": null means no Dagger import.

How Dagger picks the API version

From reading dagger/dagger main at the time (the same at v0.19.0). Since then: dagger#14881 (merged) lets a module's clients declare their own version, which is what a standalone dang session's --version already does; dagger#14810 (in review) makes v1.0.0 prerelease views granular from v1.0.0-beta.22 and caps a module's declared view at the engine's; dagger#14902 (in review) makes the dang.toml governing an entrypoint module's sources that module's engine version.

  • The API follows the client's version. The engine serves the core API at engine.APIViewVersion(clientVersion) (engine/server/session.go:1542). Prerelease and build suffixes are dropped (engine/version.go:165).
  • dagger session --version <v> sets the client version (internal/cmd/dagger/session.go:53, engine/client/client.go:1889-1906). Requests can't override it, because the session proxy rewrites X-Dagger-Client-Metadata (client.go:1710). The Go SDK's WithVersionOverride uses the same flag.
  • Without --version, the CLI's own version is used. The API served follows the dagger CLI that starts the session, not the engine's latest.
  • Versions that are too old are refused. The engine rejects anything below MinimumClientVersion (v0.19.0), and dagger session fails on startup.
  • Versions that are too new are not refused. An older engine serves its own latest API and echoes the requested version in __schemaVersion.
  • Module-aware introspection uses the module's engineVersion, not the session's (core/schema/modulesource.go:1128-1141). ModuleSource.withEngineVersion overrides it.

What Dang does with a version

  • Session: --version vX.Y.Z is added to the session command, the default dagger session or a custom service.
  • Engine check: when the session starts, Dang queries { version __schemaVersion }. If the engine is older than the declared version, it stops with "…the Dagger engine is vX; upgrade Dagger". This catches the case where the engine would otherwise quietly serve an older API.
  • Type-checking: in a Dagger module directory, the module schema comes from moduleSource(ref).withEngineVersion("vX.Y.Z").introspectionSchemaJSON.

Open questions (resolved)

  1. An explicit version that differs from a Dagger module's engineVersion: resolved on the Dagger side. Dagger will make dang.toml's dagger the version of every Dang module, winning over engineVersion (which is being retired): dagger#14902 does it for entrypoint modules, and a follow-up does it for all Dang modules. Type-checking and the runtime then agree by construction, so Dang needs no warning.
  2. --version is a hidden flag that Dagger calls test-only: resolved. The Go SDK now passes session --version by default (dagger#14879, merged), so Dagger relies on the flag outside tests. It has been stable from v0.19 to main.

Tests

pkg/dang/dagger_version_test.go, with no real engine involved:

  • dagger key parsing: true, false, version forms, null, wrong types, and the refused combinations;
  • TOML and JSON round-trips of ImportSource for each form;
  • the session command, with the default and a custom service;
  • the engine check against a fake client: newer, older, prerelease and unparseable engines, and a session that ignored the version;
  • the module-schema query with and without a version, including through ResolveDaggerImport;
  • an end-to-end run from a dang.toml through a fake dagger script and HTTP server. It asserts the session was started as session --version v0.19.0, that the check runs before introspection, that an older engine fails, and that dagger = true starts a plain session with no check.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Deploying dang with  Cloudflare Pages  Cloudflare Pages

Latest commit: f5c896e
Status: ✅  Deploy successful!
Preview URL: https://027c3ed6.dang-3kk.pages.dev
Branch Preview URL: https://dagger-view.dang-3kk.pages.dev

View logs

@vito
vito added this pull request to stack #207 October 21, 2026 18:02
@vito vito changed the title Declare a Dagger import's API view Declare the Dagger version in the dagger import Oct 21, 2026
Base automatically changed from editions to main October 27, 2026 18:07
vito added 4 commits October 27, 2026 14:07
A Dagger import's `dagger` key takes the Dagger API version its source is
written against, written like the `dang` key:

    [imports.Dagger]
    dagger = "v0.19.0"

The engine picks a client's core API view from its client version, which
`dagger session --version` sets, so the version is appended to the session
command (the default one or a custom `service`). A Dagger module's schema is
introspected with ModuleSource.withEngineVersion, since
introspectionSchemaJSON otherwise uses the module's own engineVersion. Both
get vX.Y.Z: Dagger guesses at versions without the "v" or the patch, and
the parser already drops prerelease suffixes as engine.APIViewVersion does.

An engine older than the version would silently serve its own API and echo
the requested view in __schemaVersion, so a new session is checked against
the engine's version first. A version can't be combined with `endpoint`,
whose view Dang doesn't control.

`dagger = true` keeps its meaning: no version is passed, so the API follows
the dagger CLI that starts the session, and a module's schema follows its
engineVersion. ImportSource.Dagger and ImportConfig.DaggerVersion let
embedders read the version.

Signed-off-by: Alex Suraci <[email protected]>
Show `dagger = "vX.Y.Z"` in the dang.toml reference and the dang-language
skill, in place of `dagger = true`.

Signed-off-by: Alex Suraci <[email protected]>
Version.String writes Dang versions: it drops a zero patch and prints the
zero Version as the current Dang version, so an embedder formatting
ImportConfig.DaggerVersion for `dagger = true` got "2.1". Export
DaggerVersionString and DaggerSource.VersionString, which give "vX.Y.Z" or
"" for no version, use them internally, and point the doc comments at them.

DaggerSource now marshals to JSON and TOML as false, true or "vX.Y.Z", and
a JSON null decodes as no Dagger import, so a marshaled ImportSource
decodes back.

Signed-off-by: Alex Suraci <[email protected]>
Say what the older form means, and that it's the one to use with endpoint.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito merged commit 984d740 into main Oct 28, 2026
8 of 9 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.

1 participant