Repository navigation
Commit ee66ae8
authored
chore: make yarn setup work unattended, for CI and coding agents (#21989)
* chore: make yarn setup work unattended, for CI and coding agents
A fresh sandbox clones the repo with no node_modules, so the first tests
or linters cannot run until yarn install finishes. `yarn setup` could
not be that command unattended: it installs a global yarn, writes to
yarn's machine-global link registry, and rewrites the lockfile rather
than verifying it.
It now picks a path instead. A contributor at a terminal gets exactly
what they got before, short-circuit included, so `prelint` is unchanged.
Anything else installs against a frozen lockfile and links the checkout
in as node_modules/webpack directly, which config cases and examples
need to resolve bare "webpack".
What it reads is a TTY plus an unset CI, never a list of vendor
variables: such a list is wrong the day another agent ships, and wrong
silently, since the one it forgot would run the interactive path.
WEBPACK_SETUP=interactive|automated forces either.
* fix: take the safe setup path on any defined CI, and say what is missing
`!process.env.CI` is true for `CI=""`, so a terminal with an explicitly
empty CI ran the contributor path — the one that installs a global yarn
and writes to yarn's link registry. Any defined value now selects
automation, since that is the side a wrong guess is cheap on.
That path installs nothing globally, so without yarn it died on exit
code 127 from the shell. It now says what is missing and which override
installs it, and the yarn check it needs is shared with the contributor
path rather than duplicated.
The docs claimed every coding agent takes the automated path. One that
allocates a PTY does not, and reads as a contributor; both files now
state the predicate and name the override.
Reported by CodeRabbit on #21989.
* test(setup): cover which path setup picks
The mode selection is the whole of this change and nothing exercised it,
so a regression in it would surface as a contributor's machine getting a
global yarn install rather than as a red suite.
`setup.js` exports the predicate and runs itself only as the entry
point, the way `check-comment-length.js` already does, and the case
covers both forced modes, an unknown forced value, each stream being a
terminal alone, and CI unset, empty and set. Reverting the empty-CI fix
fails it.
The paths that spawn a process are left to the manual check: what they
do depends on what is on PATH, which a unit test would have to fake
rather than observe.
Reported by CodeRabbit on #21989.
* test(setup): cover the paths, not just the choice between them
Covering only the predicate made the patch metric worse than covering
nothing: until a test required setup.js the file was absent from the
report, so its lines were not coverable, and pulling it in left 19% of
them hit. Codecov read that as 23.80% of the diff.
The cases now drive the dispatcher with a stubbed child process, which
is where the contract this change exists for can be asserted: the
automated path runs yarn against a frozen lockfile and never npm
install -g, the contributor path links through the registry, an
existing link skips both, and a missing yarn stops before installing.
That takes setup.js from 19% to 92% of lines.
Note that nothing under test/ is transformed, so jest.mock is not
hoisted and is registered above the requires rather than below them.
* fix(setup): return the exit code instead of setting it
The bun job runs the unit suites too, and there setup() assigning
process.exitCode did not read back, so six cases failed on a runtime
the Node ones pass. Asserting on global process state was the mistake:
setup() now returns the code and only the entry point assigns it, which
is both testable and honest about what the function does.
The effects it reaches for are read from one object rather than from
the imports, because bun's jest cannot mock a built-in module at all —
jest.mock on child_process throws "Attempted to assign to readonly
property" before a single case runs, and jest.spyOn on fs silently
records nothing.
Reproduced by applying test/patches the way the bun job does: the
pushed commit fails 6 of 13 there and passes 13 of 13 with this.1 parent 72e3e43 commit ee66ae8
4 files changed
Lines changed: 326 additions & 40 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
96 | | - | |
| 97 | + | |
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
11 | 17 | | |
12 | 18 | | |
13 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
6 | 16 | | |
7 | 17 | | |
8 | 18 | | |
9 | 19 | | |
10 | 20 | | |
11 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
12 | 24 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
31 | 48 | | |
32 | 49 | | |
33 | 50 | | |
| 51 | + | |
| 52 | + | |
34 | 53 | | |
35 | 54 | | |
36 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
37 | 58 | | |
38 | 59 | | |
39 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
40 | 86 | | |
41 | 87 | | |
42 | 88 | | |
| |||
45 | 91 | | |
46 | 92 | | |
47 | 93 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
57 | 98 | | |
58 | 99 | | |
59 | 100 | | |
60 | 101 | | |
61 | 102 | | |
62 | 103 | | |
63 | 104 | | |
64 | | - | |
| 105 | + | |
65 | 106 | | |
66 | | - | |
| 107 | + | |
67 | 108 | | |
68 | 109 | | |
69 | | - | |
70 | 110 | | |
71 | 111 | | |
72 | | - | |
| 112 | + | |
73 | 113 | | |
74 | | - | |
| 114 | + | |
75 | 115 | | |
76 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
77 | 123 | | |
78 | 124 | | |
79 | 125 | | |
| |||
92 | 138 | | |
93 | 139 | | |
94 | 140 | | |
95 | | - | |
| 141 | + | |
96 | 142 | | |
97 | 143 | | |
98 | 144 | | |
| |||
120 | 166 | | |
121 | 167 | | |
122 | 168 | | |
123 | | - | |
| 169 | + | |
124 | 170 | | |
125 | 171 | | |
126 | 172 | | |
| |||
138 | 184 | | |
139 | 185 | | |
140 | 186 | | |
141 | | - | |
| 187 | + | |
| 188 | + | |
142 | 189 | | |
143 | 190 | | |
144 | 191 | | |
145 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
0 commit comments