also looking at this
feat(touch): post the checkboxes the finishing-touch flow waits on
#1424
7 files
+149
-5
| @@ -2,8 +2,10 @@ import { describe, expect, it } from 'bun:test' | ||
| 2 | 2 | import { |
| 3 | 3 | FINISHING_TOUCHES, |
| 4 | 4 | getFinishingTouch, |
| 5 | hasTouchOffer, | |
| 5 | 6 | parseTouchSelections, |
| 6 | 7 | renderTouchOffer, |
| 8 | withTouchOffer, | |
| 7 | 9 | } from '../src/agent/tasks' |
| 8 | 10 | import { |
| 9 | 11 | constrainLabels, |
| @@ -167,3 +169,57 @@ describe('finishing touches', () => { | ||
| 167 | 169 | expect(parseTouchSelections(renderTouchOffer())).toEqual([]) |
| 168 | 170 | }) |
| 169 | 171 | }) |
| 172 | ||
| 173 | /** | |
| 174 | * `renderTouchOffer` had no production caller. `buddy touch` read ticked boxes | |
| 175 | * out of `pullRequest.body`, and nothing ever wrote any there — so the flow the | |
| 176 | * feature page is built around ("tick the checkbox Buddy posts") could not | |
| 177 | * start. `--offer` is what posts them. | |
| 178 | */ | |
| 179 | describe('offering finishing touches', () => { | |
| 180 | it('success case - appends the offer to a body', () => { | |
| 181 | const body = withTouchOffer('The original description.') | |
| 182 | ||
| 183 | expect(body).toContain('The original description.') | |
| 184 | expect(body).toContain('buddy:touch=unit-tests') | |
| 185 | }) | |
| 186 | ||
| 187 | it('success case - the offer it writes is the one the parser reads', () => { | |
| 188 | // The two halves have to agree on the marker, or a tick is invisible. | |
| 189 | const ticked = withTouchOffer('desc').replace('- [ ] <!-- buddy:touch=unit-tests', '- [x] <!-- buddy:touch=unit-tests') | |
| 190 | ||
| 191 | expect(parseTouchSelections(ticked)).toEqual(['unit-tests']) | |
| 192 | }) | |
| 193 | ||
| 194 | it('failure case - a body that already has the offer is left alone', () => { | |
| 195 | // The job posts on `opened` and on `ready_for_review`, so a draft marked | |
| 196 | // ready would otherwise get a second set of boxes that tick independently | |
| 197 | // of the first. | |
| 198 | const once = withTouchOffer('desc') | |
| 199 | ||
| 200 | expect(withTouchOffer(once)).toBe(once) | |
| 201 | expect(once.match(/buddy:touches/g)).toHaveLength(1) | |
| 202 | }) | |
| 203 | ||
| 204 | it('success case - recognises a body that carries the offer', () => { | |
| 205 | expect(hasTouchOffer(withTouchOffer('desc'))).toBe(true) | |
| 206 | expect(hasTouchOffer('desc')).toBe(false) | |
| 207 | expect(hasTouchOffer(null)).toBe(false) | |
| 208 | }) | |
| 209 | ||
| 210 | it('edge case - an empty body still gets an offer', () => { | |
| 211 | expect(hasTouchOffer(withTouchOffer(null))).toBe(true) | |
| 212 | }) | |
| 213 | ||
| 214 | it('edge case - offering nothing changes nothing', () => { | |
| 215 | // `renderTouchOffer([])` is empty, and an empty offer must not append a | |
| 216 | // marker that `parseTouchSelections` would then find no boxes under. | |
| 217 | expect(withTouchOffer('desc', [])).toBe('desc') | |
| 218 | }) | |
| 219 | ||
| 220 | it('success case - ticks already in the body survive being offered again', () => { | |
| 221 | const ticked = withTouchOffer('desc').replace('- [ ] <!-- buddy:touch=docstrings', '- [x] <!-- buddy:touch=docstrings') | |
| 222 | ||
| 223 | expect(parseTouchSelections(withTouchOffer(ticked))).toEqual(['docstrings']) | |
| 224 | }) | |
| 225 | }) | |