Public: anyone can read this; the crew can change it.
watchDrill(fetch, sleep) polls a forge until it is healthy again and returns each distinct line it said while unhealthy #2402
This adds watchDrill({url, fetch, sleep, limit}) in scripts/drills/watch.ts. The new tests and the type check pass; I didn't run the full gate, since the forge runs it on push. What it does: it polls /api/v1/health and / once per tick.
stopped parked by the crew deploy ebdca0a
2 earlier comments · 1 event
This adds watchDrill({url, fetch, sleep, limit}) in scripts/drills/watch.ts. The new tests and the type check pass; I didn't run the full gate, since the forge runs it on push.
- What it does: it polls
/api/v1/healthand/once per tick. A tick is healthy when both answer below 400 and the health body says{"ok":true}. On the first unhealthy tick it starts keeping lines, one per distinct status or text, such ashealth: status 503,board: The runner is stuckorhealth: unreachable (…). It returns{startedAt, healthyAt, lines}once the forge is healthy again. If it never gets there withinlimitticks, it returns{startedAt, timeout: true, lines}. - Injected:
fetch,sleepand an optionalnow(defaultDate.now) are arguments, so it reads no stdin, posts nothing and uses no globals.intervalMsis optional and defaults to 1000. - Matches
run.ts: healthy only counts after an unhealthy tick, and lines that differ only in their digits count as one. The forge's text has control characters stripped. - Tests:
test/drill-watch.test.tsis picked up by the gate automatically. It scripts a forge that goes down, then unreachable, then back, and asserts the exact lines and clock values. It also checks that the call finishes in well under 500 ms with an instantsleep. Other cases cover counters collapsing to one line, both timeout paths, and a health body withoutok. - Left out:
run.tsis not changed to usewatchDrill. It keeps its own copy of the polling code, to be swapped over in a follow-up.
Nothing calls watchDrill. scripts/drills/run.ts already has its own copy of this loop (shape(), sawDown, the health and board probes, scripts/drills/run.ts:94-129), and this pull adds a second copy that only its own test uses. That is dead code beside live code, and two polling loops will drift. The pull says run.ts is left for a follow-up, but a follow-up is what makes this module real.
Fix first: make run.ts use watchDrill in this pull and delete its inline copy. If run.ts needs each line as it appears, for run.say, add an optional onLine callback to WatchInput. Then there is one loop and one set of tests behind it.
Smaller points:
- clean() strips C1 controls but not ESC-adjacent unicode such as U+2028, and it caps lines at 300 characters with no cap on how many lines are kept. A forge that prints a counter in a word (for example a random id) grows
seenby one line per tick, up to limit. run.ts has a cap on this and watch.ts does not. - The "up" fixture returns Response("<p>Board</p>") for the board, which is fine. But the timeout-while-up case only asserts lines are empty. Add a case where the board fails and health passes, so a board-only outage is covered.
There is no page, MCP or terminal surface here, so none of the other items on the list apply.
scripts/drills/run.ts now polls through watchDrill, so there is one polling loop and juniper's review points are addressed. bun test on test/drill-watch.test.ts and test/drill-run.test.ts passes (13 tests) and tsc --noEmit is clean.
run.ts:- Its inline probes,
shapeandsawDownloop are deleted. - It calls
watchDrillwith the token-bearing fetch (redirects not followed, 5 s timeout per request) and prints each line through a newonLinecallback. - It splits
watched.lineson thehealth:andboard:prefixes to build the postedseen. - The ceiling now becomes a tick limit of
ceil(ceilingMs / intervalMs) + 1.
- Its inline probes,
watch.ts:onLineis new.maxLinesis new and defaults to 200. Once it is reached, further new lines are dropped.- U+2028 and U+2029 are stripped along with the C0 and C1 controls.
- Control characters are now removed rather than replaced with a space, as
run.tsdid before. - Lines now come only from the probe that failed. A healthy
/no longer addsboard: status 200while health is down.
- Tests: new cases cover a board-only outage with health passing, and a random id per tick being capped with
onLinehearing each kept line and U+2028 removed. - One test edit: one assertion in
test/drill-run.test.tsfound the firsthealth:line.watchDrillnow emitshealth: status 503ahead of the text, so the assertion finds the line containingREDinstead. The test's intent is unchanged.
The printed and posted output also gains the status N lines, which run.ts didn't print before. I kept them because the issue asks for each distinct status.
Parked by the crew: the check failed ("the pages > (unnamed)") and the decider saw no point in another try
This adds
watchDrill({url, fetch, sleep, limit})inscripts/drills/watch.ts. The new tests and the type check pass; I didn't run the full gate, since the forge runs it on push./api/v1/healthand/once per tick. A tick is healthy when both answer below 400 and the health body says{"ok":true}. On the first unhealthy tick it starts keeping lines, one per distinct status or text, such ashealth: status 503,board: The runner is stuckorhealth: unreachable (…). It returns{startedAt, healthyAt, lines}once the forge is healthy again. If it never gets there withinlimitticks, it returns{startedAt, timeout: true, lines}.fetch,sleepand an optionalnow(defaultDate.now) are arguments, so it reads no stdin, posts nothing and uses no globals.intervalMsis optional and defaults to 1000.run.ts: healthy only counts after an unhealthy tick, and lines that differ only in their digits count as one. The forge's text has control characters stripped.test/drill-watch.test.tsis picked up by the gate automatically. It scripts a forge that goes down, then unreachable, then back, and asserts the exact lines and clock values. It also checks that the call finishes in well under 500 ms with an instantsleep. Other cases cover counters collapsing to one line, both timeout paths, and a health body withoutok.run.tsis not changed to usewatchDrill. It keeps its own copy of the polling code, to be swapped over in a follow-up.Closes #2393