Commit 23883d3
committed
fix(codegen): mask stale generated outputs from the loader instead of unlinking them
Root cause of the check-generate CI failures on this PR, found by running
`go generate ./...` locally: base and master pass, every commit of this
branch failed deterministically (the "different type each run" in CI was
map-iteration order picking which missing type to report first — the
failure itself was 100% reproducible).
The old upfront `syscall.Unlink` of the exec + model outputs was not
redundant — it was LOAD-BEARING for every config that autobinds the
package its models are generated into (all codegen/testserver fixtures,
the federation examples):
1. old: unlink first → stale models file GONE at schema-load time →
autobind finds nothing → modelgen generates all types → OK.
2. this branch (before this commit): stale models file VISIBLE at
load → autobind binds the previously-generated types as if they
were user-written models → modelgen SKIPS them → the freshly
written models file loses them → the exec build reload fails with
"unable to find type: <pkg>.<Type>".
But the unlink is also exactly what #2345/#3505 are about: delete-then-
interrupted leaves the user with no generated file at all. Both
properties need to hold, so replace the destructive unlink with a
NON-destructive loader mask:
- internal/code.Packages gains an Overlay (packages.Config.Overlay)
threaded into every Load, plus MaskFile/UnmaskFile.
- api.generate masks each existing output (exec + model) with a
package-clause-only stub read from the file's own package clause
(empty bytes would be a parse error and break loading the rest of
the package). Missing/unparseable files are left alone — nothing
stale to bind, matching the old unlink's no-op there.
- config.Config owns the overlay map (MaskGeneratedFile) because
LoadSchema RECREATES c.Packages mid-generation — an overlay set
only on the first instance would silently vanish. The map is shared
by reference with every instance the Config creates.
- templates.write unmasks each file once its new contents are on disk
(including the unchanged-content short-circuit path): from that
moment disk is truth, and the exec build's reload right after
modelgen must see the just-generated types, not the stub.
Disk state is now only ever changed by the atomic rename — kill
generation at any instant and the previous outputs are intact — while
the loader sees the same "outputs don't exist yet" world the old unlink
provided.
Verified:
- `go generate ./...` (the exact check-generate CI command): failed
with 22 "unable to find type" errors before, exits 0 with this
commit, run twice back-to-back with a clean tree both times
(regenerated output identical to committed).
- The deterministic single-package repro (codegen/testserver/
followschema: `rm -f resolver.go && go run testdata/gqlgen.go
-config gqlgen.yml -stub stub.go` on a clean tree) fails without
this commit and passes with it; models-gen.go regenerates at full
436 lines instead of being emptied to a bare package clause.
- api, codegen/templates, internal/code, codegen/config suites green;
gofmt/vet/golines/gci clean.
No standalone regression test is added: a minimal self-autobind fixture
does NOT reproduce (the trigger needs the testserver fixtures' richer
interface/implementor topology), and the check-generate CI step already
runs the full corpus — it is the deterministic gate that caught this.1 parent 614e973 commit 23883d3
4 files changed
Lines changed: 131 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
6 | 9 | | |
7 | 10 | | |
| |||
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
29 | 58 | | |
30 | 59 | | |
31 | 60 | | |
| |||
54 | 83 | | |
55 | 84 | | |
56 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
57 | 104 | | |
58 | 105 | | |
59 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
81 | 88 | | |
82 | 89 | | |
83 | 90 | | |
| |||
337 | 344 | | |
338 | 345 | | |
339 | 346 | | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
340 | 363 | | |
341 | 364 | | |
342 | 365 | | |
343 | 366 | | |
344 | 367 | | |
345 | 368 | | |
| 369 | + | |
346 | 370 | | |
347 | 371 | | |
348 | 372 | | |
| |||
1168 | 1192 | | |
1169 | 1193 | | |
1170 | 1194 | | |
| 1195 | + | |
1171 | 1196 | | |
1172 | 1197 | | |
1173 | 1198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
737 | 737 | | |
738 | 738 | | |
739 | 739 | | |
| 740 | + | |
| 741 | + | |
740 | 742 | | |
741 | 743 | | |
742 | 744 | | |
| |||
806 | 808 | | |
807 | 809 | | |
808 | 810 | | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
809 | 816 | | |
810 | 817 | | |
811 | 818 | | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
812 | 827 | | |
813 | 828 | | |
814 | 829 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
61 | 74 | | |
62 | 75 | | |
63 | 76 | | |
| |||
69 | 82 | | |
70 | 83 | | |
71 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
72 | 114 | | |
73 | 115 | | |
74 | 116 | | |
| |||
132 | 174 | | |
133 | 175 | | |
134 | 176 | | |
| 177 | + | |
135 | 178 | | |
136 | 179 | | |
137 | 180 | | |
| |||
208 | 251 | | |
209 | 252 | | |
210 | 253 | | |
| 254 | + | |
211 | 255 | | |
212 | 256 | | |
213 | 257 | | |
| |||
0 commit comments