Skip to content

workspace: add native polyfill replacements - #13854

Merged
grouville merged 7 commits into
dagger:mainfrom
grouville:polyfill-workspace-apis
Aug 14, 2026
Merged

grouville merged 7 commits into
dagger:mainfrom
grouville:polyfill-workspace-apis

Conversation

@grouville

@grouville grouville commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

dagger/polyfill currently provides two pieces of workspace logic that belong in the engine. This PR adds their native replacements without changing how changesets work.

Workspace.findRoots finds projects from marker files such as go.mod or package.json. It searches below the workspace cwd, includes the nearest enclosing project, and prunes excluded trees. glob remains the lower-level API for callers that only need path matching.

SDKs do not need to scan the filesystem for Dagger modules. Those modules are already registered in dagger.toml, so currentModule.asSDK(workspace: ws).modules returns the registered module objects relevant to the workspace cwd.

The PR also preserves a literal engineVersion: "latest" when editing module configuration and adds the missing regression test for loading local dependencies through Workspace.moduleSource.

Review

The main question is the API boundary: findRoots discovers ordinary projects from files, while asSDK.modules reads the Dagger modules already registered for that SDK.

Test

go test ./core ./core/schema
dagger call engine-dev test --run 'TestWorkspaceFindRoots|TestEngineVersionLatestStaysFloating|TestContextualWorkspaceModuleSourceLocalDeps'

#13855 builds on this with workspace generation and explicit changeset comparison.

@grouville
grouville requested review from a team as code owners August 7, 2026 07:45
@grouville grouville changed the title workspace: polyfill removal part 1 — findConfigDirs, floating engineVersion, local-deps test workspace: findConfigDirs + floating engineVersion (polyfill removal, part 1) Aug 7, 2026
@grouville
grouville marked this pull request as draft August 7, 2026 09:47
@grouville
grouville force-pushed the polyfill-workspace-apis branch from 2a3953f to 4ae5a11 Compare August 11, 2026 22:59
@grouville
grouville force-pushed the polyfill-workspace-apis branch 2 times, most recently from 3819203 to 03db422 Compare August 12, 2026 06:22
@grouville
grouville requested a review from vito August 12, 2026 06:23

@eunomie eunomie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.
I haven't manually tried the new API, but the API feels nice. We also discussed the API live.
I love the fix on latest for engineVersion :-) I experienced the issue before and wanted to fix it, but happy it's done 🙏

@grouville
grouville force-pushed the polyfill-workspace-apis branch from 03db422 to 982491c Compare August 13, 2026 01:40
@grouville grouville changed the title workspace: findConfigDirs + floating engineVersion (polyfill removal, part 1) workspace: add native polyfill replacements Aug 13, 2026
@grouville
grouville marked this pull request as draft August 13, 2026 07:32
Projects are commonly identified by marker files such as go.mod or package.json. SDKs need one consistent rule: find marked projects below a starting directory and include the nearest enclosing project when invoked from inside it.

Add that cwd-aware rule as a convenience over glob and findUp. Results are cwd-relative, and exclude patterns prune vendored trees from the downward search.

Integration tests cover root and subdirectory calls, explicit starts, ancestors, exclusions, multiple markers, and invalid marker names.

Signed-off-by: Guillaume de Rouville <[email protected]>
ModuleSource resolves "latest" before using a module. Config edits then wrote that resolved version back, silently turning a floating config into a pin.

Keep the declared value separately for serialization while continuing to use the resolved value for compatibility checks. Tests cover unrelated edits, selecting "latest", and selecting a concrete version.

Signed-off-by: Guillaume de Rouville <[email protected]>
@grouville
grouville force-pushed the polyfill-workspace-apis branch from 6b33a2d to 55f69ab Compare August 14, 2026 02:27
dagger.toml already records the modules managed by each installed SDK, so SDKs should not rediscover them by scanning config files.

Filter CurrentModule.asSDK(workspace).modules using the supplied workspace cwd: return every managed module at or below it, plus the nearest enclosing module when needed. Unit tests cover root, module, nested, unrelated, and duplicate paths.

Signed-off-by: Guillaume de Rouville <[email protected]>
@grouville
grouville force-pushed the polyfill-workspace-apis branch from 279775a to 671495b Compare August 14, 2026 05:12
Loading a workspace-backed module with a local dependency previously failed
when requester context was lost. That engine fix already exists; add the
missing end-to-end regression from issue dagger#13139 so SDK generation cannot
reintroduce it.

Released SDKs still call generateLocalDependencies while loading. Keep that
field visible until the official SDK migrations ship, and record the removal
condition beside the field.

Signed-off-by: Guillaume de Rouville <[email protected]>
Refresh the checked-in clients, GraphQL schema, and reference documentation for
Workspace.findRoots and cwd-scoped CurrentModuleAsSDK.modules.

Signed-off-by: Guillaume de Rouville <[email protected]>
@grouville
grouville force-pushed the polyfill-workspace-apis branch from 671495b to 4ca0b92 Compare August 14, 2026 05:21
The Workspace API additions change the generated reference input. Refresh the checked-in schema so docs:references is clean.

Signed-off-by: Guillaume de Rouville <[email protected]>
@grouville
grouville marked this pull request as ready for review August 14, 2026 07:48
The module loader accepts "latest" as an input and resolves it to the current engine version. Keep that behavior when writing configs so modules remain pinned and reproducible.

Workspace module initialization had started writing the literal value. Write the current concrete version instead, and cover both initialization and later config edits.

Signed-off-by: Guillaume de Rouville <[email protected]>
@grouville

Copy link
Copy Markdown
Member Author
image CI is green, but github cache shows it failing (wrongfully) image

@grouville
grouville merged commit 8afa621 into dagger:main Aug 14, 2026
87 of 88 checks passed
eunomie pushed a commit to grouville/php-sdk that referenced this pull request Aug 21, 2026
The behaviors this module leaned on `dagger/polyfill` for now live in the
engine: dagger/dagger#13854 added the native workspace and module-source
APIs, and #13855 gave `Workspace.changes` an explicit baseline.

Module discovery goes through `currentModule.asSDK(workspace: ws).modules`,
which returns the modules registered to this SDK that are relevant to the
client's cwd. The engine owns both membership and the cwd policy, so the SDK
no longer scans for config files or rebases discovery results by hand — the
`findConfigDirs` walk and its `workspacePath` helper go away with it.

Changesets follow the baseline-diff shape the native APIs were designed for:
stage onto the workspace value already in hand, then diff against it. No
workspace fork is involved, because none is needed. `ModuleSource.generate`
is what produces a module's generated context — it stages the module's local
dependency closure first, applies only that module's own output, and keeps
the caller's workspace as the baseline, so the resulting changeset is rooted
at the client's cwd. `generateAll` folds the per-module changesets together
with `changeset.withChangesets`.

Staging paths anchor at "/" because the native workspace resolves a relative
path from the cwd, where the polyfill's took workspace-root paths.

`Workspace.withNewDirectory` is not a drop-in for the polyfill fork's
`withDirectory`: on a host-backed workspace the edit lands on an empty delta
base and is then diffed against the host tree, so whatever already sat at
that path is reported as removed. The polyfill's merged instead. init has to
layer the template onto the existing contents itself, or `dagger module init`
into a directory a user already has files in deletes them. sdk-sdk's
`contract:does-not-remove-existing-files` only inits into an empty path and
cannot catch that, so `e-2-e:init-layering-check` covers it here.

The engineVersion bump and the dependency removal land together: the version
gate scopes the engine's new changeset rooting to migrated modules.

Signed-off-by: Guillaume de Rouville <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
eunomie pushed a commit to grouville/go that referenced this pull request Aug 21, 2026
The engine now ships Workspace.findRoots (dagger/dagger#13854): the same
cwd-aware project discovery this module got from github.com/dagger/polyfill
as findConfigDirs — same semantics, ported from the polyfill's own design
and test matrix. Swap the call, drop the dependency, and require the engine
release that ships it.

The engineVersion bump and the dependency removal have to land together:
the version gate is what keeps the engine's new changeset behavior scoped
to migrated modules.

Signed-off-by: Guillaume de Rouville <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
eunomie pushed a commit to grouville/php-sdk that referenced this pull request Aug 21, 2026
The behaviors this module leaned on `dagger/polyfill` for now live in the
engine: dagger/dagger#13854 added the native workspace and module-source
APIs, and #13855 gave `Workspace.changes` an explicit baseline.

Module discovery goes through `currentModule.asSDK(workspace: ws).modules`,
which returns the modules registered to this SDK that are relevant to the
client's cwd. The engine owns both membership and the cwd policy, so the SDK
no longer scans for config files or rebases discovery results by hand — the
`findConfigDirs` walk and its `workspacePath` helper go away with it.

Changesets follow the baseline-diff shape the native APIs were designed for:
stage onto the workspace value already in hand, then diff against it. No
workspace fork is involved, because none is needed. `generateAll` folds the
per-module changesets together with `changeset.withChangesets`.

Generation would read as `ModuleSource.generate(ws).changes(ws)`, which is
what #13855 built the pair for. On v1.0.0-beta.10 that pair does not hold its
baseline: once a module's generated files already exist, it reports the whole
generated context as added rather than only what generation changed —
deleting one file and regenerating returned 279 paths instead of 1, including
the engine-owned dagger-module.toml. So generation stages the local dependency
closure itself, takes the module's `generatedContextChangeset`, and re-roots
that at the caller's cwd explicitly, which is the shape the polyfill produced.
`Mod.atCwd` carries the reason and the engine version, so it can go once the
engine holds the baseline.

Staging paths anchor at "/" because the native workspace resolves a relative
path from the cwd, where the polyfill's took workspace-root paths.

`Workspace.withNewDirectory` is not a drop-in for the polyfill fork's
`withDirectory`: on a host-backed workspace the edit lands on an empty delta
base and is then diffed against the host tree, so whatever already sat at
that path is reported as removed. The polyfill's merged instead. init has to
layer the template onto the existing contents itself, or `dagger module init`
into a directory a user already has files in deletes them. sdk-sdk's
`contract:does-not-remove-existing-files` only inits into an empty path and
cannot catch that, so `e-2-e:init-layering-check` covers it here.

The engineVersion bump and the dependency removal land together: the version
gate scopes the engine's new changeset rooting to migrated modules.

Signed-off-by: Guillaume de Rouville <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
TomChv added a commit to dagger/typescript-sdk that referenced this pull request Aug 21, 2026
* Drop the polyfill for native workspace APIs

The TypeScript SDK depended on `dagger/polyfill` for three things: selecting
the modules it manages, forking the workspace to stage edits, and re-rooting
the resulting changeset into the client's cwd. All three are now native in the
engine (dagger/dagger#13854, dagger/dagger#13855), so the dependency goes.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv pushed a commit to grouville/vitest that referenced this pull request Aug 26, 2026
The engine now ships Workspace.findRoots (dagger/dagger#13854): the
same cwd-aware project discovery this module got from
github.com/dagger/polyfill — same semantics, ported from the
polyfill's own design and test matrix. Swap the call, drop the
dependency, and require the engine release that ships it.

The engineVersion bump and the dependency removal have to land
together: the version gate is what keeps the engine's new changeset
behavior scoped to migrated modules.

Signed-off-by: Guillaume de Rouville <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
TomChv pushed a commit to grouville/deno that referenced this pull request Aug 26, 2026
The engine now ships Workspace.findRoots (dagger/dagger#13854): the
same cwd-aware project discovery this module got from
github.com/dagger/polyfill — same semantics, ported from the
polyfill's own design and test matrix. Swap the call, drop the
dependency, and require the engine release that ships it.

The helper was called findConfigDirs while it was in review; it shipped
in v1.0.0-beta.10 as findRoots, taking markers instead of filenames.
The contract is unchanged: cwd-relative paths for the caller's own
project and everything below it, plus the nearest enclosing project as
a ".."-relative path, so inCone still tells the two apart.

The engineVersion bump and the dependency removal have to land
together: the version gate is what keeps the engine's new changeset
behavior scoped to migrated modules. The e2e harness moves to the same
version — it still declared v1.0.0-beta.6, which would have exercised
the module under test through an older schema view than the one it
ships against.

Signed-off-by: Guillaume de Rouville <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
TomChv pushed a commit to dagger/vitest that referenced this pull request Aug 26, 2026
The engine now ships Workspace.findRoots (dagger/dagger#13854): the
same cwd-aware project discovery this module got from
github.com/dagger/polyfill — same semantics, ported from the
polyfill's own design and test matrix. Swap the call, drop the
dependency, and require the engine release that ships it.

The engineVersion bump and the dependency removal have to land
together: the version gate is what keeps the engine's new changeset
behavior scoped to migrated modules.

Signed-off-by: Guillaume de Rouville <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
TomChv added a commit to dagger/deno that referenced this pull request Aug 26, 2026
The engine now ships Workspace.findRoots (dagger/dagger#13854): the
same cwd-aware project discovery this module got from
github.com/dagger/polyfill — same semantics, ported from the
polyfill's own design and test matrix. Swap the call, drop the
dependency, and require the engine release that ships it.

The helper was called findConfigDirs while it was in review; it shipped
in v1.0.0-beta.10 as findRoots, taking markers instead of filenames.
The contract is unchanged: cwd-relative paths for the caller's own
project and everything below it, plus the nearest enclosing project as
a ".."-relative path, so inCone still tells the two apart.

The engineVersion bump and the dependency removal have to land
together: the version gate is what keeps the engine's new changeset
behavior scoped to migrated modules. The e2e harness moves to the same
version — it still declared v1.0.0-beta.6, which would have exercised
the module under test through an older schema view than the one it
ships against.

Resolve discovered project roots from the workspace root

findRoots answers relative to the caller — "." for its own directory, ".."
for an enclosing project — and the module read those back as if they were
workspace-root-relative. From anywhere but the workspace root that names a
directory that does not exist, so every command driving discovery or a
lookup failed:

    $ cd .dagger/modules/e2e/modules
    $ dagger -m ../../.. call project --path hello workspace-root
    workspace directory ".dagger/modules/e2e/modules/.dagger/modules/e2e/modules/hello":
      ... no such file or directory

This predates the migration and reproduces identically on main at
v1.0.0-beta.6; the native call inherits the polyfill's contract, so fix it
where that contract is read. Discovery resolves each hit once, and reads go
through workspace-absolute paths, which is also what lets findWorkspaceRoot
walk above the caller: from inside a member the enclosing workspace root is
an ancestor, and only a walk terminating at "." can reach it. Discovery
alone never sees that root — it is out of range from below — so `projects`
resolves each project's workspace root by walking up rather than from the
roots it happened to discover. Without it a member is mounted as a
standalone project and its cross-member imports do not resolve.

The caller's location still decides one thing: the CLI applies a
generator's changeset from where the caller stands, so the generators key
their directories there instead of at the workspace root. Verified by
applying one from a subdirectory and confirming it landed on the intended
file.

subdir-discovery-check covers all of it from inside a workspace member: the
lookup, the root above the caller surviving being mounted (the cross-member
@ws/util import only resolves from there), the fan-out verbs, and the
changeset keying. It fails without this patch with "stat add/add: no such
file or directory".

Migrate the lockfile to the v2 format


Signed-off-by: Guillaume de Rouville <[email protected]>
Co-authored-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