← Public packages
@kody/kody-factory
Forkable multi-project software factory: signals, priority queue, project UI, sweep job. Agent runners and Sentry reach it by events.
Files
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { setOwnerLogin } from './human.ts'
import type { NormalizedCheck, PrSnapshot } from './snapshot.ts'
import { computeShip } from './status.ts'
const HEAD = 'abc123def456789012345678901234567890abcd'
const NOW = Date.parse('2026-11-19T12:00:00Z')
// cursor[bot]'s real reply on a PR it will not review (kody-hq/kody#5380).
const CANNOT_RUN_BODY =
"<h3>Bugbot couldn't run \u2014 not your pull request</h3>\n\nBugbot on an individual plan only reviews pull requests you author, and someone else authored this one.\n\nTo review pull requests from other contributors, connect this repository's Cursor GitHub install to a team with Bugbot."
function check(name: string, state: NormalizedCheck['state'], app: string | null = 'github-actions'): NormalizedCheck {
return {
name,
source: 'check_run',
state,
status: state === 'pending' ? 'IN_PROGRESS' : 'COMPLETED',
conclusion: state === 'pending' ? null : state === 'success' ? 'SUCCESS' : 'FAILURE',
url: null,
app,
description: state === 'success' && name === 'Devin Review' ? 'Completed analysis in 1m 4s' : null,
startedAt: '2026-11-19T11:00:00Z',
completedAt: state === 'pending' ? null : '2026-11-19T11:05:00Z',
}
}
const devinPassed = check('Devin Review', 'success', 'devin-ai-integration')
const cannotRunComment = {
id: 1,
author: 'cursor[bot]',
body: CANNOT_RUN_BODY,
createdAt: '2026-11-19T11:10:00Z',
url: 'https://github.com/test/repo/pull/42#issuecomment-1',
authorAssociation: 'NONE',
}
function snapshot(overrides: Partial<PrSnapshot> = {}): PrSnapshot {
return {
locator: { owner: 'test', repo: 'repo', prNumber: 42, prUrl: 'https://github.com/test/repo/pull/42', key: 'test/repo#42' },
title: 'Test PR',
state: 'OPEN',
isDraft: false,
merged: false,
mergedAt: null,
mergeCommitSha: null,
mergeable: 'MERGEABLE',
mergeStateStatus: 'CLEAN',
reviewDecision: null,
author: 'devin-ai-integration[bot]',
baseRef: 'main',
headRef: 'feature',
headSha: HEAD,
headCommittedDate: '2026-11-19T10:00:00Z',
createdAt: '2026-11-19T10:00:00Z',
readyForReviewAt: null,
additions: 10,
deletions: 2,
checks: [check('Validate', 'success'), devinPassed],
duplicateChecksHidden: 0,
headRuns: [],
threads: [],
threadsTruncated: false,
reviews: [],
issueComments: [cannotRunComment],
deployRuns: null,
fetchedAt: '2026-11-19T12:00:00Z',
...overrides,
}
}
function aiReview(snap: PrSnapshot) {
setOwnerLogin('kentcdodds')
const result = computeShip(snap, [], [], { risk: 'medium', mergeAuthority: false, now: NOW, report: {}, expand: 'all' })
const step = [...result.done, ...result.remaining].find((s) => s.id === 'ai-review')
if (!step) throw new Error('ai-review step missing')
return step
}
test('Kent-authored PR still requires Bugbot even with the cannot-run message', () => {
const step = aiReview(snapshot({ author: 'kentcdodds' }))
assert.equal(step.status, 'todo')
assert.match(step.summary, /Bugbot not triggered/)
})
test('non-Kent PR with the cannot-run message and a passing Devin Review passes, and says so', () => {
const step = aiReview(snapshot())
assert.equal(step.status, 'done')
assert.match(step.summary, /Bugbot requirement skipped/)
assert.match(step.summary, /Devin Review stood in and passed/)
})
test('non-Kent PR with the cannot-run message but no Devin Review stays blocked', () => {
const step = aiReview(snapshot({ checks: [check('Validate', 'success')] }))
assert.equal(step.status, 'needs_attention')
assert.match(step.summary, /nothing stands in for Bugbot/)
})
test('non-Kent PR with the cannot-run message waits while Devin Review is still running', () => {
const step = aiReview(snapshot({ checks: [check('Validate', 'success'), check('Devin Review', 'pending', 'devin-ai-integration')] }))
assert.equal(step.status, 'waiting')
assert.match(step.summary, /devin \(standing in for Bugbot\)/)
})
test('non-Kent PR with an unresolved Devin finding stays blocked', () => {
const step = aiReview(
snapshot({
threads: [
{
id: 'PRRT_1',
isResolved: false,
isOutdated: false,
path: 'src/a.ts',
line: 3,
comments: [
{
id: 11,
author: 'devin-ai-integration[bot]',
body: '\u{1F534} **Crash on empty input**\n\nThis throws when the list is empty.',
createdAt: '2026-11-19T11:06:00Z',
url: null,
replyToId: null,
},
],
},
],
}),
)
assert.notEqual(step.status, 'done')
})
test('non-Kent PR where Bugbot did run still requires Bugbot', () => {
const running = aiReview(snapshot({ checks: [check('Validate', 'success'), devinPassed, check('Cursor Bugbot', 'pending', 'cursor')] }))
assert.equal(running.status, 'waiting')
assert.match(running.summary, /waiting on bugbot/)
const earlierReview = aiReview(
snapshot({
reviews: [
{ id: 5, author: 'cursor[bot]', state: 'COMMENTED', body: 'Bugbot reviewed.', submittedAt: '2026-11-19T09:00:00Z', commitSha: 'old', url: null },
],
}),
)
assert.equal(earlierReview.status, 'todo')
assert.match(earlierReview.summary, /Bugbot not triggered/)
})
test('no owner login configured means no stand-in', () => {
setOwnerLogin('')
const result = computeShip(snapshot(), [], [], { risk: 'medium', mergeAuthority: false, now: NOW, report: {}, expand: 'all' })
const step = [...result.done, ...result.remaining].find((s) => s.id === 'ai-review')
assert.equal(step?.status, 'todo')
})