Repository navigation
fix: make dagger module init work from a subdirectory workspace - #13890
Conversation
1fbeedb to
9901d2c
Compare
d38bb22 to
a3e1762
Compare
a3e1762 to
05312c7
Compare
b318e1b to
99b2dc0
Compare
|
I found two issues worth addressing:
|
Init writes files the caller does not own: the workspace dagger.toml, the
new module's dagger-module.toml, and whatever the SDK scaffolds. It then
exports them itself, at the workspace root -- Workspace.export writes to
ExportHostPath. Everything about that flow is measured from the root.
Two things were measured from the caller's cwd instead.
The SDK stages its files relative to Workspace.cwd, because a changeset
returned from an ordinary function call is applied wherever the client is
standing. Handed the caller's workspace, it strips the cwd prefix and
scatters its files away from the config the engine wrote. Give it a
root-anchored workspace, so the cwd it stages against matches where its
changeset lands.
Reading the diff had the same problem from the other side: Workspace.changes
re-roots to the caller's cwd, and init's root-owned edits -- the workspace
dagger.toml above all -- have no cwd-relative spelling from a subdirectory,
so the preview failed with
changes fall outside the current directory "sub": ..., dagger.toml
That belongs to whoever pairs changes() with export(), not to init: the CLI
asks for the root-measured view, exactly as `dagger setup` already does for
migration. The workspace init returns is the caller's, moved only by the
changeset -- withInitModule is not a chdir.
Neither the polyfill nor any SDK changes, and the cwd-relative rule stays as
it is for changesets that really are applied at the caller's cwd.
Signed-off-by: Yves Brissaud <[email protected]>
The default module path was joined against the workspace root, while [modules.<name>].source is resolved against the directory holding the dagger.toml. With a config in a subdirectory the two point at different places, so the install entry init writes would name a module outside the project the config belongs to. Anchor the default at the config directory and convert the recorded source back to config-directory-relative, the same conversion `dagger install` performs when it records a local ref. At the workspace root -- where every existing workspace has its config -- both are what they were. --path keeps its documented workspace-root-relative meaning; the CLI help and the Go SDK page now say so outright, because `--path ci` from a subdirectory means <workspace root>/ci and reads like ./ci. Signed-off-by: Yves Brissaud <[email protected]>
The init fixture SDK wrote its scaffold at whatever workspace-root-relative
path the engine handed it, so it could not observe the cwd the engine shows
an SDK. Give it the polyfill's rebasing -- resolve the path against
Workspace.cwd, refuse anything outside it -- and it reproduces the real
failure: the SDK's file lands cwd-stripped while the engine's config stays
put, leaving a split, non-loadable module.
Two suites, for the two ways a caller ends up below the workspace root:
- a dagger.toml in a subdirectory of the repo, the monorepo layout, with
--path cases inside and outside the caller's cwd
- a dagger.toml at the root with the caller in a subdirectory, which is
the same mismatch with none of the monorepo setup
The fixture SDK module moves off .dagger/ to a dot-free path: a client's
module ref is classified as local by a leading "." or "/" and otherwise by
the absence of a dot, so a nested "common/.dagger/init-fixture" would be
taken for a remote ref.
Signed-off-by: Yves Brissaud <[email protected]>
99b2dc0 to
3df428f
Compare
|
Thanks @tiborvass — both fixed in 1. The returned workspace no longer moves the cwd. You were right that this needed separating rather than papering over. The root-measured view moved to the caller instead: the CLI does Added a regression test asserting the workspace before and after init share a cwd, so the leak cannot come back quietly. 2. Arg docs updated. Full One thing I did not change, in case you have a view: |
`module init --path` and `api client init <path>` were workspace-root-relative, while every other path a user types at the workspace -- Workspace.directory, Workspace.file, a local ref given to `dagger install` -- is relative to where they are standing, with a leading "/" meaning the workspace root. From a subdirectory that made `--path ci` mean <root>/ci rather than ./ci, silently, and left no spelling at all for "the workspace root". Route both through resolveWorkspacePath, the resolver `dagger install` already uses. `ci` now means ./ci, `/ci` means <root>/ci, and `../ci` climbs; everything downstream still sees a workspace-root-relative path. Escaping the root is still rejected, as is a client path resolving to the root itself. The argument docs say so too, so the published API reference matches; the generated schema and SDK clients carry those strings and are regenerated here. This is a behaviour change for anyone passing these paths from a subdirectory; at the workspace root, where cwd and root coincide, nothing moves. Signed-off-by: Yves Brissaud <[email protected]>
3df428f to
75d96de
Compare
dagger/dagger#13890 landed in 1.0.0-beta.10 and fixes the three checks this group added red: init changesets are now applied at the workspace root with the SDK shown a matching cwd, and the default module path is anchored at the directory holding the dagger.toml being edited. It also changed `module init --path` deliberately. The path now resolves against the caller's cwd, with a leading slash meaning the workspace root, like every other workspace path a user types. explicit-path-keeps-module-whole passed a workspace-root-relative path naming the config directory, which under the new resolver means a directory of that name *below* the config directory, so it asserted the old spelling. Pass a relative path instead and assert it lands under the caller's cwd. Add rooted-path-anchors-module-at-root for the other half of the resolver. With the default path now anchored beside its dagger.toml and a relative --path resolved against the caller, a leading slash is the only remaining way to hand the SDK a module path the caller's cwd does not contain — the shape a cwd-scoped SDK cannot stage at all. beta.9 rejected it outright as absolute. Five of the six now fail on beta.9 and all six pass on beta.10. Signed-off-by: Tom Chauveau <[email protected]>
Fixes #13889.
dagger module initmisplaces or rejects files whenever you run it fromanywhere other than the workspace root. Three fixes here, all in the same
corner of init; they're separate commits and can be read independently.
1. Init is anchored at the workspace root
Init writes files the caller doesn't own — the workspace
dagger.toml, the newmodule's
dagger-module.toml, and whatever the SDK scaffolds — then exportsthem itself at the workspace root (
Workspace.exportwrites toExportHostPath). Two things were measured from the caller's cwd instead.The SDK stages its files relative to
Workspace.cwd, because a changesetreturned from an ordinary function call is applied wherever the client stands.
Handed the caller's workspace, it strips the cwd prefix, so the module comes out
split — engine config in one directory, sources in another:
Workspace.changesre-roots to the caller's cwd for the same reason, so theworkspace init hands back can't describe its own edits from a subdirectory — the
workspace
dagger.tomlsits above the caller and has no cwd-relative spelling:Both are now anchored at the root: the SDK gets a workspace whose cwd matches
where its changeset lands, and the workspace init returns measures its changes
from the same place it exports them. Nothing changes for changesets that really
are applied at the caller's cwd —
dagger generateincluded — and neither thepolyfill nor any SDK is touched.
Note this is not specific to a
dagger.tomlin a subdirectory. A config at therepo root with the caller one directory down hits it identically; a subdirectory
config just guarantees it, since the workspace root is the git root.
2. The default module path follows its
dagger.toml.dagger/modules/<name>was joined against the workspace root, but[modules.<name>].sourceis resolved against the config directory. With aconfig in a subdirectory those disagree, and init would record an entry pointing
outside its own project. The default is now
<config dir>/.dagger/modules/<name>,with the recorded source made config-dir-relative — the same conversion
dagger installalready does for a local ref. Nothing changes for a workspacewhose config is at the root.
3. Init paths are resolved against the caller
module init --pathandapi client init <path>were workspace-root-relative,while every other path you type at the workspace —
Workspace.directory,Workspace.file, a local ref given todagger install— is relative to whereyou are standing, with a leading
/meaning the workspace root. From asubdirectory that made
--path cimean<root>/cirather than./ci,silently, and left no spelling for the root at all.
Both now go through
resolveWorkspacePath, the resolverdagger installalready uses:
Everything downstream still sees a workspace-root-relative path. Escaping the
root is still rejected, as is a client path resolving to the root itself.
This is a behaviour change for anyone passing these paths from a subdirectory.
At the workspace root, where cwd and root coincide, nothing moves.
Tests
TestInitFromSubdirectoryWorkspaceandTestInitFromSubdirectoryCwdcover thetwo ways a caller ends up below the workspace root — a subdirectory config, and
a root config with the caller in a subdirectory — for module init, client init,
and
--pathresolved relatively, rooted with a leading/, climbing with.., and rejected when it escapes the workspace.The fixture SDK now mirrors the polyfill's cwd rebasing, so it reproduces the
real failure rather than a synthetic one.