ReviewOS

also looking at this

stacks/uplink

fix: answer a text that arrived while the Mac was asleep

#54
Merged glennmichael123 wants to merge fix/stale-text-gets-an-answer into main
2 files +115 -2
tests/unit/uplink/uplink.test.tsmodified+59-0
Changes to tests/unit/uplink/uplink.test.ts
@@ -243,4 +243,63 @@ describe('Uplink', () => {
243243 expect(h.sender.texts()[0]).toContain('claude setup-token')
244244 expect(h.store.runs.get(1)?.status).toBe('failed')
245245 })
246
247 /**
248 * #16. The cutoff is right: a Mac waking up must not replay a day of texts.
249 * Saying nothing was not, because over a satellite link the send itself may
250 * have taken minutes and silence is the worst available answer.
251 */
252 it('tells you a text arrived while the Mac was asleep, and does not run it', async () => {
253 const h = await harness()
254 h.fake.add({ chat: ME, text: 'deploy the thing', fromMe: true, at: Date.now() - 2 * 3_600_000 })
255 await h.uplink.tick()
256
257 expect(h.sender.texts()).toHaveLength(1)
258 expect(h.sender.texts()[0]).toContain('while this Mac was asleep')
259 expect(h.sender.texts()[0]).toContain('Send it again')
260 // Never run automatically: that is what the cutoff is for.
261 expect(h.engine.runs).toHaveLength(0)
262 expect(h.store.runs.size).toBe(0)
263 })
264
265 it('answers a backlog once, not once per text', async () => {
266 const h = await harness()
267 const asleep = Date.now() - 2 * 3_600_000
268 for (let i = 0; i < 8; i++)
269 h.fake.add({ chat: ME, text: `task ${i}`, fromMe: true, at: asleep + i * 1000 })
270 await h.uplink.tick()
271
272 expect(h.sender.texts()).toHaveLength(1)
273 expect(h.sender.texts()[0]).toContain('8 texts')
274 expect(h.engine.runs).toHaveLength(0)
275 })
276
277 it('says nothing about a control word that was skipped', async () => {
278 const h = await harness()
279 // Answered live or not at all: reporting an unanswered midnight "status"
280 // is noise, not information.
281 h.fake.add({ chat: ME, text: 'status', fromMe: true, at: Date.now() - 2 * 3_600_000 })
282 h.fake.add({ chat: ME, text: 'stop', fromMe: true, at: Date.now() - 2 * 3_600_000 })
283 await h.uplink.tick()
284 expect(h.sender.texts()).toEqual([])
285 })
286
287 it('says nothing about a text from last week', async () => {
288 const h = await harness()
289 h.fake.add({ chat: ME, text: 'a task', fromMe: true, at: Date.now() - 7 * 24 * 3_600_000 })
290 await h.uplink.tick()
291 expect(h.sender.texts()).toEqual([])
292 })
293
294 it('runs the fresh text in the same wake and explains only the old one', async () => {
295 const h = await harness()
296 h.fake.add({ chat: ME, text: 'old task', fromMe: true, at: Date.now() - 2 * 3_600_000 })
297 h.fake.add({ chat: ME, text: 'new task', fromMe: true })
298 await h.uplink.tick()
299
300 expect(h.engine.runs).toHaveLength(1)
301 expect(h.engine.runs[0].request.prompt).toContain('new task')
302 expect(h.sender.texts().filter(t => t.includes('while this Mac was asleep'))).toHaveLength(1)
303 })
246304})
305