ReviewOS

also looking at this

stacks/buddy

fix(ci): land the lock-file repair instead of describing it

#1408
Merged glennmichael123 wants to merge fix/persist-the-mechanical-lockfile-repair into main
6 files +193 -15
test/ci-fix.test.tsmodified+62-2
Changes to test/ci-fix.test.ts
@@ -104,7 +104,7 @@ describe('fix attempts', () => {
104104 log: LOCKFILE_LOG,
105105 regenerateLockfile: async () => {
106106 regenerated = true
107 return true
107 return { regenerated: true, pushed: true }
108108 },
109109 })
110110
@@ -130,7 +130,7 @@ describe('fix attempts', () => {
130130 failsOnBase: true,
131131 regenerateLockfile: async () => {
132132 regenerated = true
133 return true
133 return { regenerated: true, pushed: true }
134134 },
135135 })
136136
@@ -161,3 +161,63 @@ describe('fix attempts', () => {
161161 expect(outcome.report).toContain('error TS2322')
162162 })
163163})
164
165describe('the lock-file repair reports what it actually did', () => {
166 const base = { workspace: '/tmp', baseBranch: 'main' }
167
168 it('failure case - a regenerated file that was not pushed is not a fix', async () => {
169 // The report claimed "and pushed the result" long before anything pushed
170 // anything. A file rewritten in a workspace about to be discarded has
171 // repaired nothing, so the run is still red.
172 const outcome = await attemptFix({
173 ...base,
174 log: LOCKFILE_LOG,
175 regenerateLockfile: async () => ({ regenerated: true, pushed: false }),
176 })
177
178 expect(outcome.fixed).toBe(false)
179 expect(outcome.report).toContain('could not push')
180 expect(outcome.report).not.toContain('pushed the result')
181 })
182
183 it('success case - a pushed file is a fix, and says so', async () => {
184 const outcome = await attemptFix({
185 ...base,
186 log: LOCKFILE_LOG,
187 regenerateLockfile: async () => ({ regenerated: true, pushed: true }),
188 })
189
190 expect(outcome.fixed).toBe(true)
191 expect(outcome.report).toContain('pushed the result')
192 })
193
194 it('failure case - a failed install is reported as such', async () => {
195 const outcome = await attemptFix({
196 ...base,
197 log: LOCKFILE_LOG,
198 regenerateLockfile: async () => ({ regenerated: false, pushed: false }),
199 })
200
201 expect(outcome.fixed).toBe(false)
202 expect(outcome.report).toContain('did not succeed')
203 })
204
205 it('success case - a dry run diagnoses without touching the workspace', async () => {
206 // `--dry-run` used to regenerate lock files on disk regardless, because
207 // the callback was passed unconditionally and never consulted the flag.
208 let called = false
209 const outcome = await attemptFix({
210 ...base,
211 log: LOCKFILE_LOG,
212 dryRun: true,
213 regenerateLockfile: async () => {
214 called = true
215 return { regenerated: true, pushed: true }
216 },
217 })
218
219 expect(called).toBe(false)
220 expect(outcome.fixed).toBe(false)
221 expect(outcome.report).toContain('dry run')
222 })
223})