Skip to content

fix: clean legacy generated-code ignores during setup - #13720

Merged
grouville merged 4 commits into
dagger:mainfrom
grouville:fix/setup-legacy-gitignore
Jul 29, 2026
Merged

grouville merged 4 commits into
dagger:mainfrom
grouville:fix/setup-legacy-gitignore

Conversation

@grouville

@grouville grouville commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

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 generate writes 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 .gitignore entries 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 /.env stay in place.

The implementation asks the module's configured SDK for VCSGeneratedPaths and VCSIgnoredPaths, 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:

dagger call engine-dev test --pkg=./core/integration --run='^TestWorkspaceMigration/TestWorkspaceMigrateGeneratedCodeGitignore$'

Also verified with:

go test ./core/schema ./core/workspace
dagger call engine-dev test --pkg=./core/integration --run='^TestWorkspaceMigration$'

All 38 workspace-migration integration tests pass.

Fixes #13717

@grouville
grouville force-pushed the fix/setup-legacy-gitignore branch from 61bafab to 87d8de5 Compare July 23, 2026 02:12
@grouville
grouville requested review from TomChv and kpenfound July 23, 2026 02:14
@grouville
grouville force-pushed the fix/setup-legacy-gitignore branch from 87d8de5 to 95b9cf5 Compare July 23, 2026 02:16
}

sourceSchema := &moduleSourceSchema{}
generatedCode, err := sourceSchema.runSDKCodegen(ctx, source)

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.

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 :)

@grouville grouville Jul 27, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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 {

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.

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?

@grouville grouville Jul 27, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

Comment thread core/schema/workspace_migrate.go Outdated
return dir, err
}
for _, cleanup := range cleanups {
stat, err := dir.Self().Stat(ctx, dir, srv, cleanup.Path, true)

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.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in d97b8af.

@grouville
grouville force-pushed the fix/setup-legacy-gitignore branch from 95b9cf5 to d97b8af Compare July 27, 2026 22:06
@grouville

Copy link
Copy Markdown
Member Author

Rebased on main and addressed the review in two follow-up commits (b2e799c, d97b8af). Full TestWorkspaceMigration suite green (40 tests).

@grouville
grouville requested a review from TomChv July 27, 2026 22:07
@grouville
grouville force-pushed the fix/setup-legacy-gitignore branch 2 times, most recently from 7e22805 to 2334d46 Compare July 28, 2026 16:08
@grouville
grouville force-pushed the fix/setup-legacy-gitignore branch from 2334d46 to fe9fa4e Compare July 28, 2026 21:21
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]>
@grouville
grouville force-pushed the fix/setup-legacy-gitignore branch from fe9fa4e to 9920b1e Compare July 28, 2026 21:23
@grouville

Copy link
Copy Markdown
Member Author

golang:test-all is a flake, it's ok to omit. The test suite was green before the current redness, since the rebase.

@grouville
grouville merged commit b17b3e8 into dagger:main Jul 29, 2026
87 checks passed
TomChv added a commit to dagger/typescript-sdk that referenced this pull request Oct 9, 2026
…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]>
TomChv added a commit to dagger/typescript-sdk that referenced this pull request Oct 9, 2026
…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]>
TomChv added a commit to dagger/typescript-sdk that referenced this pull request Oct 9, 2026
…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]>
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.

Legacy .gitignore rules break trusted runtimes after module migration

2 participants