← Public packages
@kentcdodds/kody-issue-triage
Loop-safe triage for Kody run errors and fleet package-runtime error-rate elevations. Wakes Cole (Grok Bot) to decide; Cursor agents only when Cole escalates.
src/loop-guard.test.ts
106 lines · 2.7 KB · TypeScriptimport assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import {
emptyLoopGuardSnapshot,
formatLoopGuardForPrompt,
runMatchesRecord,
} from './loop-guard.ts'
describe('runMatchesRecord', () => {
const record = {
fingerprint: 'export:sonos-house:cannot-read-properties-of-undefined',
owner: 'sonos-house',
kody_id: 'sonos-house',
error_family: 'cannot-read-properties-of-undefined',
}
it('matches the same fingerprint and same-owner coarse family', () => {
assert.equal(
runMatchesRecord(
{
surface: 'export',
kody_id: 'sonos-house',
error_message: "Cannot read properties of undefined (reading 'sonos_list_groups')",
},
record,
),
true,
)
assert.equal(
runMatchesRecord(
{
surface: 'workflow',
kody_id: 'sonos-house',
error_message: "Cannot read properties of undefined (reading 'sonos_list_players')",
},
record,
),
true,
)
assert.equal(
runMatchesRecord(
{
surface: 'job',
kody_id: 'shade-automation',
name: 'daily',
error_message: 'Execution timed out after 90s',
},
record,
),
false,
)
})
it('matches truncated shade wrapper runs to the coarse TypeError row', () => {
const shade = {
fingerprint: 'workflow:shade-automation:cannot-read-properties-of-undefined',
owner: 'shade-automation',
kody_id: 'shade-automation',
error_family: 'cannot-read-properties-of-undefined',
sample_message:
'Shade workflow event failed: {"key":"kitchen-door-day-open","failed":[{"error":"Cannot read properties of undefined (reading \'bond_shade_set_position\')"}]}',
}
assert.equal(
runMatchesRecord(
{
surface: 'workflow',
kody_id: 'shade-automation',
error_message:
'Shade workflow event failed: {"key":"hot-east-office-reopen","failed":[{"label":"laundryEast"',
},
shade,
),
true,
)
})
})
describe('formatLoopGuardForPrompt', () => {
it('sanitizes run text and includes caps', () => {
const markdown = formatLoopGuardForPrompt({
...emptyLoopGuardSnapshot(),
gatheredAt: '2026-08-19T06:00:00.000Z',
capRemaining: 1,
spawnedThisHour: 2,
alreadyEscalatedToKody: true,
matchingOpenRunCount: 1,
openRunsScanned: 12,
matchingOpenRuns: [
{
id: 'run-1',
surface: 'export',
name: './status `rm -rf`',
kodyId: 'sonos-house',
startedAt: null,
activityUrl: 'https://kody.codes/account/activity/run-1',
errorMessage: 'boom ```inject```',
},
],
})
assert.match(markdown, /capRemaining: 1/)
assert.match(markdown, /alreadyEscalatedToKody: yes/)
assert.match(markdown, /run-1/)
assert.equal(markdown.includes('`rm -rf`'), false)
assert.equal(markdown.includes('```inject```'), false)
})
})