← 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/decision-fields.test.ts
125 lines · 3.8 KB · TypeScriptimport assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import {
composeDecisionSummary,
formatReportDecisionFields,
hasDecisionShape,
normalizeDecisionOptions,
} from './decision-fields.ts'
describe('normalizeDecisionOptions', () => {
it('accepts an array or newline list and caps at 4 unique choices', () => {
assert.deepEqual(
normalizeDecisionOptions([
'Keep',
'Keep',
'Ship',
'Defer',
'Ignore',
'Page',
]),
['Keep', 'Ship', 'Defer', 'Ignore'],
)
assert.deepEqual(
normalizeDecisionOptions('1. Keep grace window\n2. Lower the probe\n'),
['Keep grace window', 'Lower the probe'],
)
})
it('renders structured difficulty/change as an impact tag', () => {
assert.deepEqual(
normalizeDecisionOptions([
{ label: 'Keep as-is', difficulty: 'Easy', change: 'low' },
{ text: 'Rewrite it', difficulty: 'Hard' },
]),
[
'Keep as-is · 🟢 Easy · low change',
'Rewrite it · 🔴 Hard · radical',
],
)
})
})
describe('composeDecisionSummary', () => {
it('passes through a legacy summary when no structured fields exist', () => {
assert.equal(
composeDecisionSummary({ summary: 'one short paragraph' }),
'one short paragraph',
)
})
it('composes glanceable stored text from first-class fields', () => {
const text = composeDecisionSummary({
title: 'Idle D1 false alarm?',
context: 'audit_db flapped while app stayed up.',
recommendation: 'Close as idle-D1 false alarm.',
options: ['Close as false alarm', 'Page on-call'],
summary: 'Close as idle-D1 false alarm.',
})
assert.match(text, /Idle D1 false alarm\?/)
assert.match(text, /Context: audit_db/)
assert.match(text, /Recommendation: Close as idle-D1/)
assert.match(text, /1\. Close as false alarm/)
assert.equal(
text.includes(
'Close as idle-D1 false alarm.\n\nClose as idle-D1 false alarm.',
),
false,
)
})
})
describe('formatReportDecisionFields', () => {
it('omits summary when first-class fields are present', () => {
const fields = formatReportDecisionFields({
title: 'Waitlist replies',
context: 'A user replied to waitlist mail.',
recommendation: 'Route them to Pam.',
options: ['Route to Pam', 'Add to admin queue'],
summary: 'long dump that must not replace context',
})
assert.equal(fields.summary, undefined)
assert.deepEqual(fields.options, ['Route to Pam', 'Add to admin queue'])
})
it('keeps summary for legacy callers', () => {
assert.equal(
formatReportDecisionFields({ summary: 'one short paragraph' }).summary,
'one short paragraph',
)
assert.equal(hasDecisionShape({ summary: 'x' }), false)
assert.equal(hasDecisionShape({ title: 'Decide this' }), true)
})
})
describe('right fix', () => {
it('includes Right fix and why only when it differs', () => {
const same = composeDecisionSummary({
title: 'Timeouts',
recommendation: 'Raise the timeout.',
rightFix: 'Raise the timeout.',
options: ['Raise it', 'Leave it'],
})
assert.match(same, /Right fix: Raise the timeout/)
assert.equal(same.includes("Why the recommendation isn't the right fix"), false)
const different = composeDecisionSummary({
title: 'Waitlist',
recommendation: 'Keep the Gmail filter as-is.',
rightFix: 'Parse waitlist replies in-product.',
whyNotRightFix: 'The parser is the real fix; the filter is the cheap now.',
options: ['Keep filter', 'Build parser'],
})
assert.match(different, /Right fix: Parse waitlist/)
assert.match(different, /Why the recommendation isn't the right fix: The parser/)
const fields = formatReportDecisionFields({
recommendation: 'Keep the filter.',
rightFix: 'Parse in-product.',
whyNotRightFix: 'Platform change.',
})
assert.equal(fields.rightFix, 'Parse in-product.')
assert.equal(fields.whyNotRightFix, 'Platform change.')
})
})