Repository navigation
fix: prune a scope's legacy client packages by ownership, not wholesale - #110
Merged
Merged
Conversation
`dagger generate` deleted a user's directory. Any direct child of a TypeScript scope that holds a file named after it — types/types.gen.ts, api/api.gen.ts, graphql/graphql.gen.ts, the layout an openapi or graphql codegen writes — was removed whole, every file of the user's in it, exit 0 and nothing printed. prunedClientPackages migrates the layout that wrote each client as a package at the scope root, and it recognized one by that marker alone and took the directory with withoutDirectory. It was the last wholesale removal over a path whose contents are not all this SDK's: #99 made every sibling prune ownership-based — prunedOwnedFiles, prunedFiles, prunedEmbeddedSdk, withoutLegacyWorkspaceCore — and this one was outside that scope. Its own docstring and the README already claimed the rule it did not follow. Route it through prunedFiles with the set ownedFiles claims, the same rule the siblings use: the generated files go, and the directory follows only once nothing is left in it. Ownership is read from a synthetic parent because ownedFiles knows a package's manifest as <name>/package.json, the depth the layout gave it — so an all-generated package still goes whole, manifest included, rather than lingering as a husk. Both call sites are covered by a check that fails without the fix: a module scope on the entrypoint path, and a client-only scope. Each asserts the resulting tree, and each asserts the other half too, so the intent survives. Signed-off-by: Tom Chauveau <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
dagger generatesilently deletes a user's directory.Any direct child directory
X/of a TypeScript scope that contains a file namedX.gen.tsis removed whole, the user's files included.types/types.gen.ts,api/api.gen.tsandgraphql/graphql.gen.tsare the mainstream openapi/graphql codegen layouts, so a project reaches this by accident, with no warning and nothing printed.Reproduced on the published v1.0.3 against engine v1.0.0-beta.18 (the release v1.0.3 declares as its floor):
Control, same tree with
types.gen.tsremoved and nothing else changed:dagger generate -yexits 0, reportsno changes to apply, andm/types/keepme.tsis still there. One filename apart — this is the SDK, not the engine.--no-applyrenders the loss asm/types/ -2and never names the user's file.It contradicts this SDK's own documented rule.
prunedClientPackages' docstring says "leaving the user's own files untouched", andREADME.mdsays "Only what the SDK generates is removed … A file of your own … stays, and so does the directory holding it".Root cause
typescript-sdk.dang:2515,prunedClientPackages— the migration that removes the client packages an earlier layout wrote directly at a scope root:It recognizes a stale package by that one marker and then takes the directory whole. It was the last surviving wholesale
withoutDirectoryover a path whose contents are not all SDK-owned: #99 made every sibling prune ownership-based —prunedOwnedFiles,prunedFiles,prunedEmbeddedSdk,withoutLegacyWorkspaceCore— and this one sat outside that work's scope.It is reached on every run that generates a scope: unconditionally from the module path (
moduleFiles,typescript-sdk.dang:1842, the entrypoint layout that is the default since #73) and from both branches of the client-only path (clientScope,:2411and:2418).Fix
Route the removal through the ownership rule the siblings use:
prunedFileswith the setownedFilesclaims. The package's generated files go, and the directory follows only once nothing is left in it — so a file of the user's beside atypes.gen.tskeeps the directory open, and a stale package that holds nothing but generated files still disappears whole.Ownership is read from a synthetic parent (
directory.withDirectory(name, …)) becauseownedFilesknows a package's manifest as<name>/package.json— the depth the layout actually gave it. Read at the package's own root, apackage.jsonwould look like a file of the user's and the migrated package would linger as a husk, which is the half of the intent that has to survive the fix.Behaviour for an all-generated legacy package (
<name>/<name>.gen.ts+<name>/package.json, whatclientPackageJSONwrote) is unchanged: the directory goes.Verification
Engine
v1.0.0-beta.18throughout, via the e2e harness (.dagger/modules/e2e) on a scratch copy of the branch.Two new checks, both asserting the resulting tree rather than just the changeset, and both covering the two halves — the user's directory survives, an all-generated package still goes whole:
generate:generate-keeps-user-files-in-scope-package-check— a module scope on the entrypoint path (moduleFilescall site).client:generate-client-keeps-user-files-in-scope-package-check— a client-only scope (clientScopecall site).Red without the fix. With
typescript-sdk.dangreverted tomainand the checks kept, both fail:With the fix,
client:*plus the generate checks that exercise the same path:covering
client:remove-clients-check,client:remove-clients-keeps-user-files-check,client:generate-client-respects-existing-check(the one asserting the legacy.dagger/clientsmigration),client:generate-client-on-synthetic-workspace-check,generate:generate-check,generate:generate-idempotent-checkandgenerate:generate-every-scope-check.The repro above was also re-run on the published v1.0.3 to confirm the user-visible symptom and its control, as quoted in Problem.
Not covered
withoutLegacyScopeClients(typescript-sdk.dang:2430) is left wholesale, deliberately. It removes<scope>/.dagger/clients, a directory this SDK wrote in full: that layout's package was "self-contained: its ownpackage.jsonandtsconfig.json, generated" (design/module-max.md), so unliketypes/types.gen.tsnothing a third-party codegen writes can land there by accident, and the path is inside the engine's own dot-directory. Making it ownership-based would also need a new rule inownedFiles— that flat layout'spackage.jsonandtsconfig.jsonsit beside the*.gen.tsfiles rather than one level down, so no existing rule claims them — which would widen the blast radius to every other prune for a case with no accidental collision. Residual exposure: a file a user dropped into<scope>/.dagger/clientsgoes with the migration.client:generate-client-respects-existing-checkasserts that directory is removed whole.modulesargument ofprunedClientPackagesis[]at all three call sites; left as is.