Repository navigation
fix: clean legacy generated-code ignores during setup - #13720
Conversation
61bafab to
87d8de5
Compare
87d8de5 to
95b9cf5
Compare
| } | ||
|
|
||
| sourceSchema := &moduleSourceSchema{} | ||
| generatedCode, err := sourceSchema.runSDKCodegen(ctx, source) |
There was a problem hiding this comment.
The long term plan is to move the codegen outside the dagger engine so that runSDKCodegen might disapear or just proxy a function in the sdk module's.
I think that's fine to rely on that for now but we should keep that in mind for later :)
There was a problem hiding this comment.
Agreed, when codegen moves out of the engine, this becomes a call to the SDK module's generator. Easy to adapt then.
| cleanups := make([]workspaceMigrationGitignoreCleanup, 0, len(compatWorkspaces)) | ||
| warnings := make([]string, 0) | ||
| for _, compatWorkspace := range compatWorkspaces { | ||
| if compatWorkspace == nil || compatWorkspace.Config == nil || compatWorkspace.Config.SDK == nil { |
There was a problem hiding this comment.
The cleanup is generated for every legacy config with an SDK, independent of whether that module is actually migrated. The conversion path skips discovered modules that keep their own workspace semantics (HasOwnWorkspaceSemantics), but this loop does not — so a discovered local toolchain/blueprint module that also has an SDK is left as legacy (still runtime-codegen, files not committed) yet has its .gitignore generated-ignores stripped anyway. On its own that cleanup gets dropped by empty(), but alongside another migrated module it would be applied, reintroducing the ignore/regenerate loop in reverse. Could we gate this on the same "is this module being migrated?" predicate?
There was a problem hiding this comment.
Checked whether this can actually happen: it can't today. the dep walk skips such modules at discovery (workspace_migrate.go:517, the "must be migrated separately" warning), so they never reach this loop. Gated it anyway on the same predicate as the conversion filter (workspaceMigrationLeavesModuleLegacy) so the loop doesn't depend on that, and added a test pinning the behavior: b2e799c
| return dir, err | ||
| } | ||
| for _, cleanup := range cleanups { | ||
| stat, err := dir.Self().Stat(ctx, dir, srv, cleanup.Path, true) |
There was a problem hiding this comment.
nit: Stat/DirectoryReadFile get the raw cleanup.Path here while withNewFile below normalizes with path.Clean(filepath.ToSlash(...)). Same result on the Linux engine, but the sibling helpers normalize before every dagql call — worth matching for consistency.
95b9cf5 to
d97b8af
Compare
7e22805 to
2334d46
Compare
2334d46 to
fe9fa4e
Compare
Legacy codegen writes generated SDK paths to the module's `.gitignore`. After `dagger setup` migrates that module to the trusted runtime model, those same files must be part of the module source, but the old rules still hide them. Reproduce the transition through the public flow: let the Go SDK generate its files and ignore entries, run setup, and call the migrated module. Keep a user rule and the unrelated `/.env` entry in the fixture so the expected cleanup is explicitly limited to generated code. Signed-off-by: Guillaume de Rouville <[email protected]>
`dagger setup` changes generated SDK files from disposable runtime output into module source that must be committed. Leaving the old Dagger-written ignore rules behind means those files exist on disk but are filtered out when the migrated module loads. Ask each legacy SDK for its generated and ignored paths, then remove the paths present in both lists. This keeps setup shared across SDKs instead of baking language-specific paths into the migration. Only remove exact lines written by Dagger. User rules and SDK ignores that do not describe generated code, such as `/.env`, stay in place. A missing `.gitignore` or an SDK without codegen remains a no-op, and an SDK that cannot be inspected adds a migration warning instead of blocking the config changes. Signed-off-by: Guillaume de Rouville <[email protected]>
A nested workspace dependency (own toolchains/blueprint) is not migrated and keeps runtime codegen, so its generated-code ignore rules must stay. The dependency walk already skips such modules at discovery; gate the cleanup on the same predicate as the in-place conversion filter so this loop does not depend on that, and pin the behavior with a test. Signed-off-by: Guillaume de Rouville <[email protected]>
Stat and read used the raw path while withNewFile normalized it; normalize once and use it for every call. Signed-off-by: Guillaume de Rouville <[email protected]>
fe9fa4e to
9920b1e
Compare
|
|
…erate A module written by a v0.21 engine carries a .gitignore naming sdk/ and __dagger.entrypoint.ts, because its runtime regenerated both on every call. A 1.0 module commits them, the trusted runtime does no codegen, and source loading honours .gitignore before the runtime sees the tree, so the two lines hide the very files the module requires: `committed generated file "sdk/client.gen.ts" is missing`, with the file on disk. dagger/dagger#13720 taught `dagger setup` to remove exactly those lines, but it learns them by running the legacy SDK's codegen, which an SDK-module provider like this one does not implement, so for a module this SDK converts the engine removes nothing — and this SDK's own dagger.json conversion never touched the file either (SDK Main-Engine Test Run, 2026-10-07 — issue #25, case G14). generateScope now takes the `/sdk` (or `/sdk/`) and `/__dagger.entrypoint.ts` lines out of the module's .gitignore with the same semantics as #13720: only those exact root-anchored lines, every other line kept byte for byte, a removed line taking only its own terminator, the file written only when a line went, never created, and left in place when emptied. It runs on every generation under either loading path, because a manifest written by an earlier SDK version or by `dagger setup` has already lost the dagger.json that marks a migration, and before the first module load of the run, because a workspace-backed module source applies the .gitignore too and would hide the staged sdk/ from the self client's load. Three e2e checks cover it on the legacy-deps fixture pair: the lines go and the rest survives verbatim, a second generation leaves the file untouched (asserted on the changeset layer), and a module with no .gitignore or one naming no generated file is not written. Signed-off-by: Tom Chauveau <[email protected]>
…erate A module written by a v0.21 engine carries a .gitignore naming sdk/ and __dagger.entrypoint.ts, because its runtime regenerated both on every call. A 1.0 module commits them, the trusted runtime does no codegen, and source loading honours .gitignore before the runtime sees the tree, so the two lines hide the very files the module requires: `committed generated file "sdk/client.gen.ts" is missing`, with the file on disk. dagger/dagger#13720 taught `dagger setup` to remove exactly those lines, but it learns them by running the legacy SDK's codegen, which an SDK-module provider like this one does not implement, so for a module this SDK converts the engine removes nothing — and this SDK's own dagger.json conversion never touched the file either (SDK Main-Engine Test Run, 2026-10-07 — issue #25, case G14). generateScope now takes the `/sdk` (or `/sdk/`) and `/__dagger.entrypoint.ts` lines out of the module's .gitignore with the same semantics as #13720: only those exact root-anchored lines, every other line kept byte for byte, a removed line taking only its own terminator, the file written only when a line went, never created, and left in place when emptied. It runs on every generation under either loading path, because a manifest written by an earlier SDK version or by `dagger setup` has already lost the dagger.json that marks a migration, and before the first module load of the run, because a workspace-backed module source applies the .gitignore too and would hide the staged sdk/ from the self client's load. Three e2e checks cover it on the legacy-deps fixture pair: the lines go and the rest survives verbatim, a second generation leaves the file untouched (asserted on the changeset layer), and a module with no .gitignore or one naming no generated file is not written. Signed-off-by: Tom Chauveau <[email protected]>
…erate (#76) A module written by a v0.21 engine carries a .gitignore naming sdk/ and __dagger.entrypoint.ts, because its runtime regenerated both on every call. A 1.0 module commits them, the trusted runtime does no codegen, and source loading honours .gitignore before the runtime sees the tree, so the two lines hide the very files the module requires: `committed generated file "sdk/client.gen.ts" is missing`, with the file on disk. dagger/dagger#13720 taught `dagger setup` to remove exactly those lines, but it learns them by running the legacy SDK's codegen, which an SDK-module provider like this one does not implement, so for a module this SDK converts the engine removes nothing — and this SDK's own dagger.json conversion never touched the file either (SDK Main-Engine Test Run, 2026-10-07 — issue #25, case G14). generateScope now takes the `/sdk` (or `/sdk/`) and `/__dagger.entrypoint.ts` lines out of the module's .gitignore with the same semantics as #13720: only those exact root-anchored lines, every other line kept byte for byte, a removed line taking only its own terminator, the file written only when a line went, never created, and left in place when emptied. It runs on every generation under either loading path, because a manifest written by an earlier SDK version or by `dagger setup` has already lost the dagger.json that marks a migration, and before the first module load of the run, because a workspace-backed module source applies the .gitignore too and would hide the staged sdk/ from the self client's load. Three e2e checks cover it on the legacy-deps fixture pair: the lines go and the rest survives verbatim, a second generation leaves the file untouched (asserted on the changeset layer), and a module with no .gitignore or one naming no generated file is not written. Signed-off-by: Tom Chauveau <[email protected]>
What was broken
Legacy SDK codegen ignores generated files because they used to be recreated at runtime. After
dagger setup, trusted runtimes expect those files to be committed instead.That leaves migrated modules in a loop:
dagger generatewrites the files, source loading filters them out, and the runtime asks the user to generate them again.What this does
During migration, setup removes the legacy
.gitignoreentries that describe generated code. It only removes exact, root-anchored lines in the format Dagger wrote, so user rules and non-generated SDK ignores such as/.envstay in place.The implementation asks the module's configured SDK for
VCSGeneratedPathsandVCSIgnoredPaths, then removes the overlap. The legacy config only identifies the SDK; it does not contain these paths. Using the SDK keeps the migration correct for the configured SDK version and for custom SDKs, without teaching core about Go, Python, or TypeScript filenames.This can load and run SDK codegen once during setup. That is a deliberate one-time migration cost: the work runs in Dagger's DAG and benefits from caching. If the SDK cannot be inspected, setup records a migration warning and continues with the config migration.
Testing
The first commit reproduces the full transition: legacy Go codegen writes its generated files and ignore rules, setup migrates the module, and the trusted module must still load.
Run the focused test with:
Also verified with:
All 38 workspace-migration integration tests pass.
Fixes #13717