Skip to content

fix: drop the pre-1.0 /sdk and /__dagger.entrypoint.ts ignores on generate - #76

Merged
TomChv merged 1 commit into
mainfrom
fix/legacy-gitignore
Oct 9, 2026
Merged

TomChv merged 1 commit into
mainfrom
fix/legacy-gitignore

Conversation

@TomChv

@TomChv TomChv commented Oct 8, 2026

Copy link
Copy Markdown
Member

Problem

#25 [TypeScript SDK] Converting dagger.json leaves /sdk in .gitignore — case G14.
The module can't load; a scope without a name is renamed <dir>-dev.

From the G14 write-up: "dg -y generate converts dagger.json -> dagger-module.toml and removes dagger.json, but (1) leaves /sdk in .gitignore, so the module can't load: module "legacy-typescript" has runtime codegen disabled but committed generated file "sdk/client.gen.ts" is missing (file is on disk); (2) when the scope has no name, the module is renamed from legacy-typescript to G14-dev (dir default), which breaks the module. [...] workspace migrate does drop /sdk (G3/G4), the SDK's own conversion doesn't."

(SDK Main-Engine Test Run, 2026-10-07 — issue #25, case G14.)

This PR fixes half (1). Half (2) is out of scope — see Not covered.

Root cause

A module written by a pre-1.0 engine carries a .gitignore naming the files its
runtime used to regenerate on every call. The v0.21 TypeScript SDK declared
sdk/** generated and sdk, **/node_modules/**, **/.pnpm-store/** ignorable
([email protected] sdk/typescript/runtime/main.go:147-154), the engine added
.env (core/codegen.go:134), and then appended one root-anchored line per
entry (core/schema/modulesource.go, the writeGitignore block at :2479). So
a v0.21 module's .gitignore reads exactly — see
.dagger/modules/e2e/fixtures/generate-legacy-deps/app/.gitignore:

/sdk
/**/node_modules/**
/**/.pnpm-store/**
/.env
/__dagger.entrypoint.ts

Under 1.0 those generated files are committed: the trusted runtime does no
codegen. Module source loading applies .gitignore before the runtime sees the
tree (core/schema/modulesource.go:1269, Gitignore: src.Workspace.Self() != nil || …), so /sdk hides sdk/client.gen.ts and the module cannot load even
though the file is on disk — the loop described in dagger/dagger#13717.

dagger/dagger#13720 taught dagger setup to remove exactly the ignore lines that
name generated paths (core/schema/workspace_migrate.go:245 learns them,
:825 removeWorkspaceMigrationGitignoreEntries applies them). It learns them
by running the legacy SDK's Codegen, which an SDK-module provider like this one
does not implement, so it bails at :294 (ErrSDKCodegenNotImplemented) and
returns nothing for a TypeScript module. And this SDK's own conversion
(typescript-sdk.dang, withModuleManifest's hasJSON branch) never touched
.gitignore at all. Hence: workspace migrate drops /sdk, the SDK's own
conversion did not.

Fix

withoutLegacyIgnores (typescript-sdk.dang:454), applied from generateScope
at :249:

  • operates on <module source dir>/.gitignore (moduleFiles' sourcePath, the
    directory the generated files land in), only if the file exists — never creates
    one;
  • removes only the exact lines /sdk (/sdk/ accepted) and
    /__dagger.entrypoint.ts. Every other line survives byte for byte — the
    node_modules, .pnpm-store and .env rules, comments, blank lines — and a
    removed line takes only its own terminator (\r included);
  • writes the file only when a line was actually removed. A rewrite with identical
    bytes still lands in the changeset layer and is reported as a whole-file
    addition on the next run (see writeChanged's docstring at :1654);
    Asserts.untouched is what proves it did not;
  • leaves a file the removal empties in place, empty, rather than deleting it:
    v0.21 always wrote more than these two lines, so an emptied file is one the
    user trimmed by hand, and removing it is a bigger surprise than taking two
    lines out.

Two deliberate choices beyond the brief:

It runs for both layouts, not only [runtime]. The lines are stale under
either, an entrypoint module has no sdk/ for /sdk to hide anyway, and a
module moved back onto a [runtime] would be unloadable again with no migration
left to repair it.

It runs on every generation, not only in the hasJSON migration branch, and
before the first module load of the run
rather than on the way out. A manifest
that dagger setup or an earlier version of this SDK migrated has already lost
the dagger.json that marks a module as migrating, so its next generate is the
only chance to repair it. Early, because a workspace-backed module source applies
the module's .gitignore too: left in place, /sdk hides the staged sdk/ from
the self client's load inside the same run, and the module silently generates
without its own client (visible in the repro below — before the fix the module
got no sdk/legacydep.gen.ts).

README.md gains one sentence in the migration paragraph.

Verification

Engine: dagger --x-release=55e112468d5b08e3a8746e7e74a4dc38898cf07a
(v1.0.0-beta.17 · 55e11246), DAGGER_LEAVE_OLD_ENGINE=1, on the legacy
[runtime] layout the matrix row was observed on (Gen.scope defaults to
legacyRuntime: true; the manual repro pins the scope setting explicitly). The
default was not changed.

New checks, before the fix

Same checks, SDK without the fix:

✘ dag://?check=generate/generate-cleans-legacy-ignore-check 42.4s ERROR
  ! expected modified path: .dagger/modules/e2e/fixtures/generate-legacy-deps/app/.gitignore
✔ dag://?check=generate/generate-leaves-other-ignores-check 35.5s OK
✔ dag://?check=generate/generate-legacy-ignore-settles-check 48.0s OK
== CHECKS ==  ✘ 1 failed  ✔ 2 passed

The other two are green before the fix by construction: nothing wrote
.gitignore at all, so "already clean is not rewritten" and "a module without
one gets none" were trivially true. They are the regression guards for the
fix's write only when a line went and never create clauses, and they would
fail on a version of this fix that rewrote the file unconditionally.

New checks, after the fix

✔ dag://?check=generate/generate-cleans-legacy-ignore-check 10m2s OK
✔ dag://?check=generate/generate-dependency-check 5m59s OK
✔ dag://?check=generate/generate-idempotent-check 5m13s OK
✔ dag://?check=generate/generate-leaves-other-ignores-check 5m58s OK
✔ dag://?check=generate/generate-legacy-ignore-settles-check 10m49s OK
✔ dag://?check=generate/generate-migrates-legacy-config-check 5m58s OK
== CHECKS ==  ✔ 6 passed

Run: dagger check -m .dagger/modules/e2e generate/generate-cleans-legacy-ignore-check generate/generate-legacy-ignore-settles-check generate/generate-leaves-other-ignores-check generate/generate-migrates-legacy-config-check generate/generate-idempotent-check generate/generate-dependency-check in a scratch copy of this branch using
.dagger/modules/engine-e2e/workspace.toml as its dagger.toml.

The rest of the suite (68 checks, including runtimes:*) is being run on this
branch by the coordinator, against the baseline it recorded on unmodified main:
67/68 green, the one red being packager/library-bindings/stale, which is
expected on an engine newer than the committed library bindings and untouched
here.

Manual repro

A workspace with this SDK vendored, dagger module install, and
fixtures/generate-legacy-deps/dep copied in as a scope
(is-module = true, name = "legacydep", settings.legacyRuntime = true) whose
.gitignore is exactly what v0.21 wrote. Then dagger generate -y, commit,
dagger -m legacy call value.

Before — the two lines survive, git tracks nothing generated, the call fails:

$ cat legacy/.gitignore            # after generate
/sdk
/**/node_modules/**
/**/.pnpm-store/**
/.env
/__dagger.entrypoint.ts

$ git ls-files legacy
legacy/.gitattributes
legacy/.gitignore
legacy/dagger-module.toml
legacy/package.json
legacy/src/index.ts
legacy/tsconfig.json

$ dagger -m legacy call value
! query module objects: loading modules: loading extra module "legacy": failed to get
  module runtime: failed to call sdk moduleRuntime: module "legacydep" has runtime
  codegen disabled but committed generated file "sdk/client.gen.ts" is missing; run
  `dagger generate` and commit every generated file: the whole sdk/ directory and
  __dagger.entrypoint.ts
exit status 1

After — the two lines are gone, the other three are untouched, the generated
tree is committable, and the call runs:

$ cat legacy/.gitignore            # after generate
/**/node_modules/**
/**/.pnpm-store/**
/.env

$ git ls-files legacy
legacy/.gitattributes
legacy/.gitignore
legacy/__dagger.entrypoint.ts
legacy/dagger-module.toml
legacy/package.json
legacy/sdk/client.gen.ts
legacy/sdk/core.d.ts
legacy/sdk/core.js
legacy/sdk/index.ts
legacy/sdk/legacydep.gen.ts
legacy/sdk/loader.gen.ts
legacy/sdk/telemetry.ts
legacy/src/index.ts
legacy/tsconfig.json

$ dagger -m legacy functions
Name    Description
value   -

$ dagger -m legacy call value
dep

legacy/sdk/legacydep.gen.ts appearing only in the second run is the
self-client half of the same bug: before the fix the module's own .gitignore
hid the staged sdk/ from the self client's load during generation.

Not covered / follow-ups

  • Half (2) of the row — the scope-name default — is out of scope. A scope
    recorded without a name is renamed after its directory, so
    legacy-typescript becomes <dir>-dev. That is the engine's inference
    (core/schema/workspace_sdk_module.go resolveSDKModuleName →
    workspace.InferSDKModuleName), not something this SDK can decide; the
    coordinator reports it separately.
  • The engine's own cleanup still does nothing for an SDK-module provider
    (workspace_migrate.go:294 bails on ErrSDKCodegenNotImplemented), so a
    dagger setup of a TypeScript module leaves the lines for the first
    dagger generate to remove. Repairing it engine-side — e.g. letting a
    provider declare its stale ignore lines — would also cover SDKs that have no
    equivalent of this step.

@grouville
grouville self-requested a review October 9, 2026 06:49
@TomChv
TomChv force-pushed the fix/legacy-gitignore branch from 0a01b02 to 5b3aa6a Compare October 9, 2026 11:41
…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
TomChv force-pushed the fix/legacy-gitignore branch from 5b3aa6a to 0108a91 Compare October 9, 2026 14:17
@TomChv
TomChv merged commit 1330539 into main Oct 9, 2026
5 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.

2 participants