The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
/**
* Steps inside a task (design docs/plans/2026-11-02-task-steps-design.md). Ken, 2026-11-02: one pull request showed as three
* tasks (#1835, its review #1918 and its test #1919). A step is a linked group (`reviewOf`) with a name the instructions give;
* readers show it inside its task. No step name means anything to the server.
*/
import { describe, expect, it } from 'vitest'
import type { Command } from './commands.js'
import { agent, type Actor } from './model.js'
import { extracted } from './parts/write.js'
import { owner, stepsFixture } from './steps.test-support.js'
import { stepEndedRows, stepSleeps } from './steps.js'
import { reportedAs } from './projectUpdates.js'
import { idleNotices } from './tidy.js'
import { QUIET_RUNNING_MS, sweepForLead, sweepLiveness } from './liveness.js'
const HOLD = { kind: 'person', personId: 'owner', defaultAt: '2026-11-06T02:00:00.000Z' } as const
describe('opening a step', () => {
it('opens on a task of its project, numbered, its opener in the task', () => {
const f = stepsFixture()
const name = 'Thiết kế "v2" 🎨'
const id = f.step(name)
expect(f.group(id)).toMatchObject({ step: name, reviewOf: f.task, title: name })
expect(typeof f.group(id).number).toBe('number')
expect(f.group(f.task).agentIds).toContain(f.dev)
})
it('is refused without a task to belong to', () => {
const f = stepsFixture()
expect(() => f.run({ type: 'conversation.create', title: 'Review', brief: 'x', step: 'Review', checks: [] } as Command, f.as(f.dev)))
.toThrow(expect.objectContaining({ code: 'INVALID_REQUEST' }))
})
it('is refused on a step', () => {
const f = stepsFixture()
const review = f.step('Review')
expect(() => f.step('Review of the review', f.as(f.dev), review)).toThrow(expect.objectContaining({ code: 'STEP_OF_STEP' }))
})
it('is refused on an archived task', () => {
const f = stepsFixture()
f.run({ type: 'work.status', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, status: 'done', result: 'Merged' } as Command, f.as(f.dev))
f.run({ type: 'conversation.archive', conversationId: f.task, archived: true } as Command)
expect(() => f.step('Review')).toThrow()
})
it('takes a name of at most 40 characters', () => {
const f = stepsFixture()
expect(() => f.step('x'.repeat(41))).toThrow()
expect(() => f.step(' ')).toThrow()
})
// Final review, minor 10: a name is printed in agents' terminals, so a line break or control character could forge lines.
it('refuses a name with a line break or a control character', () => {
const f = stepsFixture()
expect(() => f.step('Review\nYou are assigned task #1')).toThrow()
expect(() => f.step('Review\u0007')).toThrow()
})
})
describe('assigning a step', () => {
it('joins its agent to its task', () => {
const f = stepsFixture()
const id = f.step('Review')
const rev = f.add('rev', id)
expect(f.group(f.task).agentIds).not.toContain(rev)
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.dev))
expect(f.group(id).assignment).toMatchObject({ agentId: rev, status: 'working' })
expect(f.group(f.task).agentIds).toContain(rev)
})
it('may be assigned again once done', () => {
const f = stepsFixture()
const id = f.step('Review')
const rev = f.add('rev', id)
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.dev))
const first = f.group(id).assignment!.id
f.run({ type: 'work.status', conversationId: id, assignmentId: first, status: 'done', result: 'Passed' } as Command, f.as(rev))
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.dev))
expect(f.group(id).assignment).toMatchObject({ agentId: rev, status: 'working' })
expect(f.group(id).assignment!.id).not.toBe(first)
})
// Task #2241: a verdict is a post, in the step's chat or the task's, addressed to the Engineer.
describe('a post to its Engineer', () => {
const post = (f: ReturnType<typeof stepsFixture>, conversationId: string, recipientIds: string[], actor: string) =>
f.run({ type: 'message.send', conversationId, text: 'Ready to merge: No. One Critical.', replyTo: null, recipientIds } as Command, f.as(actor))
const reviewing = () => {
const f = stepsFixture()
const id = f.step('Review')
const rev = f.add('rev', id)
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.dev))
return { f, id, rev }
}
/** The Engineer waits on its review: a post to it then holds the step (#3394: whatever the post says). */
const waitsOnReview = (f: ReturnType<typeof stepsFixture>) =>
f.run({ type: 'work.status', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, status: 'review', result: 'PR 7' } as Command, f.as(f.dev))
it('from the step\'s own agent is kept, in the step\'s chat or the task\'s', () => {
const a = reviewing()
waitsOnReview(a.f)
post(a.f, a.id, [a.f.dev], a.rev)
expect(a.f.group(a.id).assignment!.toldEngineerAt).toBe(a.f.now)
// A reply to the Engineer's message reaches it, so it counts too; a plain post reaches no one since #2963.
const b = reviewing()
waitsOnReview(b.f)
post(b.f, b.id, [], b.rev)
expect(b.f.group(b.id).assignment!.toldEngineerAt).toBeUndefined()
const asked = b.f.run({ type: 'message.send', conversationId: b.id, text: 'Ready for review.', replyTo: null, recipientIds: [b.rev] } as Command, b.f.as(b.f.dev)).messages[0]!
b.f.run({ type: 'message.send', conversationId: b.id, text: 'Ready to merge: No.', replyTo: asked.id, recipientIds: [] } as Command, b.f.as(b.rev),
{ reply: { id: asked.id, conversationId: b.id, author: asked.author, createdAt: 0 } })
expect(b.f.group(b.id).assignment!.toldEngineerAt).toBe(b.f.now)
// Named from the task's own chat, once the Reviewer is in it.
const c = reviewing()
waitsOnReview(c.f)
c.f.run({ type: 'conversation.agent', conversationId: c.f.task, agentId: c.rev, present: true, lead: false })
post(c.f, c.f.task, [c.f.dev], c.rev)
expect(c.f.group(c.id).assignment!.toldEngineerAt).toBe(c.f.now)
})
it('is what counts: not a post to someone else, nor the Engineer\'s own post to the step', () => {
const f = reviewing()
const other = f.f.add('other', f.id)
post(f.f, f.id, [other], f.rev)
expect(f.f.group(f.id).assignment!.toldEngineerAt).toBeUndefined()
post(f.f, f.id, [f.rev], f.f.dev)
expect(f.f.group(f.id).assignment!.toldEngineerAt).toBeUndefined()
})
// An existing rule (integration/superTabLiveness.test.ts): a Reviewer's note to a working Engineer keeps no hung Reviewer.
// Dee, #3394: its words are not read for a verdict either; a failed check, recorded at the head it read, is the verdict.
it('holds nothing when it\'s a note to an Engineer already working, whatever it says; a failed check does', () => {
const f = reviewing()
const note = (text: string) => f.f.run({ type: 'message.send', conversationId: f.id, text, replyTo: null, recipientIds: [f.f.dev] } as Command, f.f.as(f.rev))
note('Still reading the parser changes.')
note('Ready to merge: Yes, once CI is green.')
note('**Ready to merge: With fixes.** One Important finding.')
note('Ready to merge: No.')
expect(f.f.group(f.id).assignment).not.toHaveProperty('toldEngineerAt')
expect(f.f.group(f.id).assignment).not.toHaveProperty('changesRequestedAt')
f.f.run({ type: 'conversation.agent', conversationId: f.f.task, agentId: f.rev, present: true, lead: false })
f.f.run({ type: 'work.check', conversationId: f.f.task, assignmentId: f.f.group(f.f.task).assignment!.id, checkId: f.f.group(f.f.task).checks[0]!.id,
passed: false, evidence: 'One Important finding' } as Command, f.f.as(f.rev))
expect(f.f.group(f.id).assignment!.changesRequestedAt).toBe(f.f.now)
})
it('counts whatever it says when the Engineer was waiting on this review, as a Tester\'s verdict has no set form', () => {
const f = reviewing()
f.f.run({ type: 'work.status', conversationId: f.f.task, assignmentId: f.f.group(f.f.task).assignment!.id, status: 'review', result: 'PR 7' } as Command, f.f.as(f.f.dev))
f.f.run({ type: 'message.send', conversationId: f.id, text: 'Sign-in fails offline, steps below.', replyTo: null, recipientIds: [f.f.dev] } as Command, f.f.as(f.rev))
expect(f.f.group(f.id).assignment!.toldEngineerAt).toBe(f.f.now)
})
// Review of #2659: Engineers often ask by post, "fixed at abc, please re-check", so a hung Reviewer must not stay held.
it('ends with the Engineer\'s post to it, in the step\'s chat or the task\'s, and its 30 minutes restart', () => {
const a = reviewing()
waitsOnReview(a.f)
post(a.f, a.id, [a.f.dev], a.rev)
a.f.tick(60_000)
post(a.f, a.id, [a.rev], a.f.dev)
expect(a.f.group(a.id).assignment!.toldEngineerAt).toBeUndefined()
expect(a.f.group(a.id).assignment).toMatchObject({ status: 'working', progressAt: a.f.now })
const b = reviewing()
waitsOnReview(b.f)
post(b.f, b.id, [b.f.dev], b.rev)
b.f.run({ type: 'conversation.agent', conversationId: b.f.task, agentId: b.rev, present: true, lead: false })
b.f.tick(60_000)
post(b.f, b.f.task, [b.rev], b.f.dev)
expect(b.f.group(b.id).assignment!.toldEngineerAt).toBeUndefined()
expect(b.f.group(b.id).assignment).toMatchObject({ progressAt: b.f.now })
})
// Diego, 2026-11-03 (#2301): a failed check held the step on its own, so a Reviewer that hung after the Engineer's
// "fixed, please re-check" post stayed working for hours and no stall woke the PM.
it('ends a failed check hold too with the Engineer\'s post to it', () => {
const f = reviewing()
f.f.run({ type: 'work.status', conversationId: f.f.task, assignmentId: f.f.group(f.f.task).assignment!.id, status: 'review', result: 'PR 7' } as Command, f.f.as(f.f.dev))
f.f.run({ type: 'work.check', conversationId: f.f.task, assignmentId: f.f.group(f.f.task).assignment!.id, checkId: f.f.group(f.f.task).checks[0]!.id,
passed: false, evidence: 'Drops the session' } as Command, f.f.as(f.rev))
post(f.f, f.id, [f.f.dev], f.rev)
f.f.tick(60_000)
post(f.f, f.id, [f.rev], f.f.dev)
expect(f.f.group(f.id).assignment!.changesRequestedAt).toBeUndefined()
expect(f.f.group(f.id).assignment!.toldEngineerAt).toBeUndefined()
expect(f.f.group(f.id).assignment).toMatchObject({ status: 'working', progressAt: f.f.now })
sweepLiveness(f.f.state, f.f.now + QUIET_RUNNING_MS + 5 * 60_000)
expect(f.f.group(f.id).assignment).toMatchObject({ status: 'lost' })
})
it('gives no time to a Reviewer that isn\'t waiting: the Engineer\'s posts keep no idle Reviewer', () => {
const f = reviewing()
const before = f.f.group(f.id).assignment!.progressAt
f.f.tick(60_000)
post(f.f, f.id, [f.rev], f.f.dev)
expect(f.f.group(f.id).assignment!.progressAt).toBe(before)
})
it('ends with the Engineer\'s next Ready', () => {
const f = reviewing()
post(f.f, f.id, [f.f.dev], f.rev)
f.f.run({ type: 'work.status', conversationId: f.f.task, assignmentId: f.f.group(f.f.task).assignment!.id, status: 'review', result: 'PR 7, fixed' } as Command, f.f.as(f.f.dev))
expect(f.f.group(f.id).assignment!.toldEngineerAt).toBeUndefined()
expect(f.f.group(f.id).assignment).toMatchObject({ status: 'working', progressAt: f.f.now })
})
})
// The fix round Reviewers already wait through (liveness.ts waitingForRevision, Diego 2026-11-01), pinned for steps.
it('stays working across its owner\'s fix round', () => {
const f = stepsFixture()
const id = f.step('Review')
const rev = f.add('rev', id)
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.dev))
const check = f.group(f.task).checks[0]!.id
f.run({ type: 'work.status', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, status: 'review', result: 'PR 7' } as Command, f.as(f.dev))
f.run({ type: 'work.check', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, checkId: check, passed: false, evidence: 'Drops the session' } as Command, f.as(rev))
expect(f.group(id).assignment!.changesRequestedAt).toBeDefined()
f.run({ type: 'work.status', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, status: 'review', result: 'PR 7, fixed' } as Command, f.as(f.dev))
expect(f.group(id).assignment).toMatchObject({ status: 'working' })
expect(f.group(id).assignment!.changesRequestedAt).toBeUndefined()
})
// Ken, 2026-11-04: ~18 of 51 steps moved after 30 quiet minutes in two days were a Reviewer or Tester waiting on the
// Engineer's fix. A Tester's verdict has no set form, and a step agent's failed check on its own step counted as the
// assignee's, so nothing marked the wait.
it('waits for the fix after a failed check on its own step, as after a failed check on the task', () => {
const f = stepsFixture()
const id = f.step('Test', f.as(f.dev), f.task, [{ description: 'Works offline on a Mac', independent: false }])
const tester = f.add('tester', id)
f.run({ type: 'work.assign', conversationId: id, agentId: tester }, f.as(f.dev))
const check = (passed: boolean) => f.run({ type: 'work.check', conversationId: id, assignmentId: f.group(id).assignment!.id,
checkId: f.group(id).checks[0]!.id, passed, evidence: passed ? 'Signs in offline' : 'Sign-in fails offline, steps below' } as Command, f.as(tester))
check(true)
expect(f.group(id).assignment!.changesRequestedAt).toBeUndefined()
check(false)
expect(f.group(id).assignment!.changesRequestedAt).toBe(f.now)
// The Engineer works on the fix (its own status renews only its own task), while the step stays quiet past 30 minutes.
f.tick(QUIET_RUNNING_MS + 5 * 60_000)
f.run({ type: 'work.status', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, status: 'working', result: 'Fixing the offline sign-in' } as Command, f.as(f.dev))
sweepLiveness(f.state, f.now)
expect(f.group(id).assignment).toMatchObject({ status: 'working' })
f.run({ type: 'work.status', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, status: 'review', result: 'PR 7, fixed' } as Command, f.as(f.dev))
expect(f.group(id).assignment!.changesRequestedAt).toBeUndefined()
})
})
describe('a step closes with its task', () => {
const finishStep = (f: ReturnType<typeof stepsFixture>, id: string, agent: string) =>
f.run({ type: 'work.status', conversationId: id, assignmentId: f.group(id).assignment!.id, status: 'done', result: 'Passed' } as Command, f.as(agent))
it('is not marked finished work while open or done, so the archive pass never takes it on its own clock', () => {
const f = stepsFixture()
const id = f.step('Review')
const rev = f.add('rev', id)
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.dev))
finishStep(f, id, rev)
expect(extracted('group', f.group(id), 1).workFinished).toBe(false)
})
it('archiving a task by hand cancels its working step', () => {
const f = stepsFixture()
const working = f.step('Review'), done = f.step('Test')
const rev = f.add('rev', working), tester = f.add('tester', done)
f.run({ type: 'work.assign', conversationId: working, agentId: rev }, f.as(f.dev))
f.run({ type: 'work.assign', conversationId: done, agentId: tester }, f.as(f.dev))
finishStep(f, done, tester)
f.run({ type: 'work.status', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, status: 'done', result: 'Merged' } as Command, f.as(f.dev))
const effects = f.run({ type: 'conversation.archive', conversationId: f.task, archived: true } as Command)
// Final review, finding 2: an archived conversation takes no delivery, so a cancelled step stays open until it sleeps
// with its task, and its agent is told there.
expect(f.group(working)).toMatchObject({ archived: false, assignment: { status: 'cancelled', result: 'Fix login was archived.' } })
expect(f.group(done)).toMatchObject({ archived: true, assignment: { status: 'done' } })
expect(effects.messages.filter(m => m.conversationId === working).map(m => [m.text, m.recipients])).toEqual([['Fix login was archived.', [rev]]])
})
it('cancelling an unassigned task closes its steps', () => {
const f = stepsFixture()
const other = f.run({ type: 'conversation.create', title: 'Docs', brief: 'Write docs.', checks: [{ description: 'Done', independent: false }], priority: 'P2', requesterId: 'owner' }, f.as(f.lead)).result.conversationId as string
const id = f.step('Review', f.as(f.lead), other)
f.run({ type: 'work.cancel', conversationId: other, assignmentId: 'current', reason: 'Not needed' } as Command, f.as(f.lead))
expect(f.group(other).archived).toBe(true)
expect(f.group(id).archived).toBe(true)
})
// Final review, minor 5: a step that slept with a done but unarchived task was not loaded when that task was archived
// later, so it stayed open inside an archived task. It sleeps once its task is archived, when it was closed with it.
it('sleeps only once its task is archived', () => {
expect(stepSleeps(null)).toBe(true)
expect(stepSleeps({ archived: false, dormant: false })).toBe(false)
expect(stepSleeps({ archived: true, dormant: false })).toBe(true)
expect(stepSleeps({ archived: false, dormant: true })).toBe(false)
})
})
// Ken, 2026-11-02: the PM's terminal got a message every few seconds, a builder's or a reviewer's. A step's progress is its
// task owner's to act on; the PM hears what needs a person, what is stuck, and what the owner tells it.
describe('who hears a step', () => {
function reviewing(f = stepsFixture()) {
const id = f.step('Review')
const rev = f.add('rev', id)
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.dev))
const status = (status: string, result: string | null = 'note', on = id, by = rev) =>
f.run({ type: 'work.status', conversationId: on, assignmentId: f.group(on).assignment!.id, status, result, ...(status === 'blocked' || status === 'needs_human' ? { hold: HOLD } : {}) } as Command, f.as(by)).messages
const post = (on: string, by = rev) =>
f.run({ type: 'message.send', conversationId: on, text: 'Two findings.', replyTo: null, recipientIds: [] } as Command, f.as(by)).messages
return { f, id, rev, status, post }
}
const to = (messages: Array<{ conversationId: string; recipients: string[]; text: string }>, id: string) =>
messages.filter(m => m.conversationId === id).map(m => m.recipients)
it('a step\'s review and done reach the task\'s owner, not the coordinator', () => {
const { f, id, status } = reviewing()
expect(to(status('review', 'Findings posted'), id)).toEqual([[f.dev]])
expect(to(status('done', 'Passed'), id)).toEqual([[f.dev]])
})
// Ken, 2026-11-02 (screenshot): a Builder set its task done before its Tester's verdict, and the verdict reached the PM.
// The task's assignee owns it while that agent is in the Swarm, its work done or not.
it('a step\'s done reaches the owner after the owner\'s own work is done', () => {
const { f, id, status } = reviewing()
status('done', 'Merged', f.task, f.dev)
expect(to(status('done', 'Passed'), id)).toEqual([[f.dev]])
})
it('an unnamed post in the task reaches no one after the owner\'s own work is done', () => {
const { f, post, status } = reviewing()
status('done', 'Merged', f.task, f.dev)
expect(to(post(f.task), f.task)).toEqual([[]])
})
it('with the owner gone from the Swarm, a step\'s done reaches the coordinator', () => {
const { f, id, status } = reviewing()
status('done', 'Merged', f.task, f.dev)
f.run({ type: 'agent.remove', agentId: f.dev } as Command)
expect(to(status('done', 'Passed'), id)).toEqual([[f.lead]])
})
it('a step\'s blocked reaches the coordinator and the owner', () => {
const { f, id, status } = reviewing()
expect(to(status('blocked', 'No Mac'), id).map(r => [...r].sort())).toEqual([[f.lead, f.dev].sort()])
})
it('a step\'s review row reads Ready', () => {
const { id, status } = reviewing()
expect(status('review', 'Findings posted').filter(m => m.conversationId === id).map(m => m.text)).toEqual(['Ready\n\nFindings posted'])
})
// #2963: a step agent names its Engineer; its unnamed post in the task reaches the task's assignee, the Engineer.
it('a step agent\'s unnamed post reaches no one in its step, and the owner in its task', () => {
const { f, id, post } = reviewing()
expect(to(post(id), id)).toEqual([[]])
expect(to(post(f.task), f.task)).toEqual([[f.dev]])
})
// Diego, 2026-11-02: "Fixed in abc123, please re-check" from the Engineer woke the PM and the Reviewer never heard it.
it('the owner\'s unnamed post in its active step reaches the step\'s agent only', () => {
const { f, id, rev, post } = reviewing()
expect(to(post(id, f.dev), id)).toEqual([[rev]])
})
it('the owner\'s post in its step naming the coordinator still reaches the coordinator', () => {
const { f, id } = reviewing()
const named = f.run({ type: 'message.send', conversationId: id, text: 'Need a ruling.', replyTo: null, recipientIds: [f.lead] } as Command, f.as(f.dev)).messages
expect(to(named, id)).toEqual([[f.lead]])
})
it('the owner\'s unnamed reply to the PM in its step reaches the PM and the step\'s agent', () => {
const { f, id, rev } = reviewing()
const asked = f.run({ type: 'message.send', conversationId: id, text: 'Status?', replyTo: null, recipientIds: [f.dev] } as Command, f.as(f.lead)).messages[0]!
const answer = f.run({ type: 'message.send', conversationId: id, text: 'Almost.', replyTo: asked.id, recipientIds: [] } as Command, f.as(f.dev),
{ reply: { id: asked.id, conversationId: id, author: asked.author, createdAt: 0 } }).messages
expect(to(answer, id)).toEqual([[f.lead, rev]])
})
it('an agent with no open step in the task reaches the task\'s assignee, never the coordinator', () => {
const { f, post } = reviewing()
const other = f.add('other', f.task)
expect(to(post(f.task, other), f.task)).toEqual([[f.dev]])
})
})
describe('the PM\'s reports', () => {
it('name a step by its own number and its task', () => {
const f = stepsFixture()
const id = f.step('Review')
expect(reportedAs(f.state, f.group(id))).toBe(`#${f.group(id).number} (step Review of #${f.group(f.task).number})`)
expect(reportedAs(f.state, f.group(f.task))).toBe(`#${f.group(f.task).number}`)
})
})
// Ken, 2026-11-02 (a Reviewer's and a builder's every hand-over reached the PM): an agent's Ready on its own task wakes
// nobody by itself. It names whom it hands to; the PM hears Done, Stuck and Needs a human.
describe('an agent\'s own Ready', () => {
it('reaches nobody by itself', () => {
const f = stepsFixture()
const messages = f.run({ type: 'work.status', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, status: 'review', result: 'PR 7' } as Command, f.as(f.dev)).messages
expect(messages.filter(m => m.conversationId === f.task).map(m => m.recipients)).toEqual([[]])
})
it('Done still reaches the coordinator', () => {
const f = stepsFixture()
const messages = f.run({ type: 'work.status', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, status: 'done', result: 'Merged' } as Command, f.as(f.dev)).messages
expect(messages.filter(m => m.conversationId === f.task && m.text.startsWith('Done')).map(m => m.recipients)).toEqual([[f.lead]])
})
})
// Final review, finding 1: a step the PM opened has no owner in it, so a Ready or Done told to the owner was never
// delivered (store.ts deliveryAllowed reads membership). The owner joins the step when it is told.
describe('a step the PM opened', () => {
it('its Done reaches the owner, who joins the step', () => {
const f = stepsFixture()
const id = f.step('Review', f.as(f.lead))
const rev = f.add('rev', id)
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.lead))
expect(f.group(id).agentIds).not.toContain(f.dev)
const messages = f.run({ type: 'work.status', conversationId: id, assignmentId: f.group(id).assignment!.id, status: 'done', result: 'Passed' } as Command, f.as(rev)).messages
// Its Done, then the row that says the owner joined to hear it (#2207).
expect(messages.filter(m => m.conversationId === id).map(m => m.recipients)).toEqual([[f.dev], []])
expect(f.group(id).agentIds).toContain(f.dev)
})
})
describe('cancelling an assigned task', () => {
it('cancels its open steps and tells their agents, leaving finished ones', () => {
const f = stepsFixture()
const working = f.step('Review'), done = f.step('Test')
const rev = f.add('rev', working), tester = f.add('tester', done)
f.run({ type: 'work.assign', conversationId: working, agentId: rev }, f.as(f.dev))
f.run({ type: 'work.assign', conversationId: done, agentId: tester }, f.as(f.dev))
f.run({ type: 'work.status', conversationId: done, assignmentId: f.group(done).assignment!.id, status: 'done', result: 'Passed' } as Command, f.as(tester))
const effects = f.run({ type: 'work.cancel', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, reason: 'Not needed' } as Command, f.as(f.lead))
expect(f.group(working).assignment).toMatchObject({ status: 'cancelled', result: 'Fix login was cancelled.' })
expect(f.group(done).assignment).toMatchObject({ status: 'done' })
expect(effects.messages.filter(m => m.conversationId === working).map(m => [m.text, m.recipients])).toEqual([['Fix login was cancelled.', [rev]]])
})
})
// Ken, 2026-11-02 (screenshot): the PM opened "Test: PR #2514" the old way, with no step name, a minute after saving the
// workflow that says steps, and the Tester's posts reached the PM. Every linked task is a step, named or not: what reaches
// the PM no longer rests on an agent remembering the workflow.
describe('a linked task opened without a step name', () => {
function linked() {
const f = stepsFixture()
const id = f.run({ type: 'conversation.create', title: 'Test: PR #2514', brief: 'Test it.', reviewOf: f.task, checks: [] } as Command, f.as(f.lead)).result.conversationId as string
const tester = f.add('tester', id)
f.run({ type: 'work.assign', conversationId: id, agentId: tester }, f.as(f.lead))
return { f, id, tester }
}
it('tells the task\'s owner its Ready and Done, and its unnamed posts', () => {
const { f, id, tester } = linked()
const done = f.run({ type: 'work.status', conversationId: id, assignmentId: f.group(id).assignment!.id, status: 'done', result: 'Passed' } as Command, f.as(tester)).messages
expect(done.filter(m => m.conversationId === id).map(m => m.recipients)).toEqual([[f.dev], []])
expect(f.group(f.task).agentIds).toContain(tester)
})
it('an unnamed post from its agent reaches no one, and one naming the owner reaches it (#2963)', () => {
const { f, id, tester } = linked()
const posted = f.run({ type: 'message.send', conversationId: id, text: 'Starting on the simulator.', replyTo: null, recipientIds: [] } as Command, f.as(tester)).messages
expect(posted.map(m => m.recipients)).toEqual([[]])
const named = f.run({ type: 'message.send', conversationId: id, text: 'Ready to merge: No.', replyTo: null, recipientIds: [f.dev] } as Command, f.as(tester)).messages
expect(named.map(m => m.recipients)[0]).toEqual([f.dev])
})
it('closes with its task, not on its own clock', () => {
const { f, id, tester } = linked()
f.run({ type: 'work.status', conversationId: id, assignmentId: f.group(id).assignment!.id, status: 'done', result: 'Passed' } as Command, f.as(tester))
expect(extracted('group', f.group(id), 1).workFinished).toBe(false)
})
it('is named in reports by its title', () => {
const { f, id } = linked()
expect(reportedAs(f.state, f.group(id))).toBe(`#${f.group(id).number} (step Test: PR #2514 of #${f.group(f.task).number})`)
})
})
// Ken, 2026-11-02: in 20 minutes the PM got 23 messages; about half were agents' posts it had nothing to do with.
describe('the PM is not told what a step\'s agent says to its task', () => {
it('a step agent that lost its step reaches the owner by name, in the step', () => {
const f = stepsFixture()
const id = f.step('Review')
const rev = f.add('rev', id)
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.dev))
f.run({ type: 'work.status', conversationId: id, assignmentId: f.group(id).assignment!.id, status: 'done', result: 'Passed' } as Command, f.as(rev))
const unnamed = f.run({ type: 'message.send', conversationId: id, text: 'Re-read the new head: still passes.', replyTo: null, recipientIds: [] } as Command, f.as(rev)).messages
expect(unnamed.map(m => m.recipients)).toEqual([[]])
const posted = f.run({ type: 'message.send', conversationId: id, text: 'Re-read the new head: still passes.', replyTo: null, recipientIds: [f.dev] } as Command, f.as(rev)).messages
expect(posted.map(m => m.recipients)[0]).toEqual([f.dev])
})
it('an agent whose step is done still reaches the owner, in the task', () => {
const f = stepsFixture()
const id = f.step('Review')
const rev = f.add('rev', id)
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.dev))
f.run({ type: 'work.status', conversationId: id, assignmentId: f.group(id).assignment!.id, status: 'done', result: 'Passed' } as Command, f.as(rev))
const posted = f.run({ type: 'message.send', conversationId: f.task, text: 'Both re-checks pass.', replyTo: null, recipientIds: [] } as Command, f.as(rev)).messages
expect(posted.map(m => m.recipients)).toEqual([[f.dev]])
})
it('the PM is not told a step-only agent is idle while the task it checked is open', () => {
const f = stepsFixture()
const id = f.step('Review')
const rev = f.add('rev', id)
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.dev))
const project = f.state.projects![0]!.id
const idle = () => idleNotices(f.state, project, f.now + 60 * 60_000, new Set()).map(n => n.source?.agentId)
expect(idle()).not.toContain(rev)
// Its step done, the Engineer may still ask it for the next round (workflow 3).
f.run({ type: 'work.status', conversationId: id, assignmentId: f.group(id).assignment!.id, status: 'done', result: 'Passed' } as Command, f.as(rev))
expect(idle()).not.toContain(rev)
})
// Diego, 2026-11-02: a step-only Reviewer or Tester was never reported idle while its finished task stayed unarchived,
// holding a machine slot and quota unseen.
it('the PM is told a step-only agent is idle once every task it checked has ended, archived or not', () => {
const f = stepsFixture()
const id = f.step('Review')
const rev = f.add('rev', id)
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.dev))
f.run({ type: 'work.status', conversationId: id, assignmentId: f.group(id).assignment!.id, status: 'done', result: 'Passed' } as Command, f.as(rev))
f.run({ type: 'work.status', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, status: 'done', result: 'Merged' } as Command, f.as(f.dev))
expect(f.group(f.task).archived).toBeFalsy()
const project = f.state.projects![0]!.id
const notices = idleNotices(f.state, project, f.now + 60 * 60_000, new Set()).map(n => n.source?.agentId)
expect(notices).toContain(f.dev)
expect(notices).toContain(rev)
})
it('a step-only agent with a step of another task still open is not reported idle', () => {
const f = stepsFixture()
const id = f.step('Review')
const rev = f.add('rev', id)
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.dev))
f.run({ type: 'work.status', conversationId: id, assignmentId: f.group(id).assignment!.id, status: 'done', result: 'Passed' } as Command, f.as(rev))
const other = f.run({ type: 'conversation.create', title: 'Fix logout', brief: 'Sign out works.', checks: [{ description: 'Done', independent: false }], priority: 'P2', requesterId: 'owner' }, f.as(f.lead)).result.conversationId as string
const dev2 = f.add('dev2', other)
f.run({ type: 'work.assign', conversationId: other, agentId: dev2 }, f.as(f.lead))
const second = f.step('Review', f.as(dev2), other)
f.run({ type: 'conversation.agent', conversationId: second, agentId: rev, present: true, lead: false } as Command, f.as(dev2))
f.run({ type: 'work.assign', conversationId: second, agentId: rev }, f.as(dev2))
f.run({ type: 'work.status', conversationId: second, assignmentId: f.group(second).assignment!.id, status: 'done', result: 'Passed' } as Command, f.as(rev))
f.run({ type: 'work.status', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, status: 'done', result: 'Merged' } as Command, f.as(f.dev))
const project = f.state.projects![0]!.id
expect(idleNotices(f.state, project, f.now + 60 * 60_000, new Set()).map(n => n.source?.agentId)).not.toContain(rev)
})
})
// The archive pass writes these with no command behind it, so they must never stop it: a delivery to an agent that has left throws.
describe("the row a step's ended work leaves", () => {
const state = { people: [{ id: 'owner', generation: 'g' }, { id: 'rejoined', generation: 'new' }], agents: [
{ id: 'kept', name: 'Reviewer', contributorId: 'owner', membershipGeneration: 'g' },
// agent() throws for both of these, as writeMessages calls it for each recipient (review 2 of #2596).
{ id: 'orphaned', name: 'Reviewer', contributorId: 'left', membershipGeneration: 'g' },
{ id: 'stale', name: 'Reviewer', contributorId: 'rejoined', membershipGeneration: 'old' },
] } as never
const step = (agentId: string) => ({ id: `step-${agentId}`, assignment: { agentId } }) as never
const lead = { kind: 'agent', id: 'lead', name: 'Lead', membershipGeneration: 'g' } as const
it("goes to the step's agent, in that step, as the author given", () => {
expect(stepEndedRows(state, [step('kept')], 'Fix was archived.', lead, s => `row-${s.id}`)).toEqual([expect.objectContaining({
id: 'row-step-kept', conversationId: 'step-kept', author: lead, text: 'Fix was archived.', recipients: ['kept'], source: { kind: 'system' } })])
})
it('goes to nobody when its agent has left the Swarm', () => {
expect(stepEndedRows(state, [step('gone')], 'Fix was archived.', lead, s => s.id)[0]!.recipients).toEqual([])
})
it('goes to nobody, and never throws at its delivery, when its agent\'s contributor is gone or has another generation', () => {
for (const id of ['orphaned', 'stale']) {
const [row] = stepEndedRows(state, [step(id)], 'Fix was archived.', lead, s => s.id)
expect(row!.recipients).toEqual([])
expect(() => { for (const recipient of row!.recipients) agent(state, recipient) }).not.toThrow()
expect(stepEndedRows(state, [step(id)], 'Fix was archived.', null, s => s.id)).toEqual([])
}
expect(() => agent(state, 'orphaned')).toThrow()
})
it('is written as the agent told when there is no Lead, and not at all when there is nobody to write it', () => {
expect(stepEndedRows(state, [step('kept')], 'Fix was archived.', null, s => s.id)[0]!.author).toMatchObject({ kind: 'agent', id: 'kept' })
expect(stepEndedRows(state, [step('gone')], 'Fix was archived.', null, s => s.id)).toEqual([])
})
})
// Diego, 2026-11-03 (#2311): Review and Test record the same checks in parallel, and a Reviewer's pass used to erase the
// Tester's failure and its crash log, so the check read passed on a pull request whose test failed.
describe('checks with several checkers', () => {
const checkers = () => {
const f = stepsFixture()
const tester = f.add('tester', f.task), reviewer = f.add('reviewer', f.task)
const check = (actor: string, passed: boolean, evidence: string) => f.run({ type: 'work.check', conversationId: f.task,
assignmentId: f.group(f.task).assignment!.id, checkId: f.group(f.task).checks[0]!.id, passed, evidence } as Command, f.as(actor))
return { f, tester, reviewer, check, read: () => f.group(f.task).checks[0]! }
}
it('Tester fails, Reviewer passes: the check reads failed and keeps the Tester\'s evidence', () => {
const { f, tester, reviewer, check, read } = checkers()
check(tester, false, 'Crashes offline\nlog')
f.tick(1000)
check(reviewer, true, 'Diff reads right')
expect(read()).toMatchObject({ passedBy: null, evidence: 'Crashes offline\nlog' })
expect(read().verdicts).toEqual([
{ by: `agent:${tester}`, passed: false, evidence: 'Crashes offline\nlog', at: f.now - 1000, name: expect.any(String) },
{ by: `agent:${reviewer}`, passed: true, evidence: 'Diff reads right', at: f.now, name: expect.any(String) },
])
})
it('the same Tester passing it then passes the check', () => {
const { tester, reviewer, check, read } = checkers()
check(tester, false, 'Crashes offline')
check(reviewer, true, 'Diff reads right')
check(tester, true, 'Signs in offline now')
expect(read()).toMatchObject({ passedBy: `agent:${tester}`, evidence: 'Signs in offline now' })
expect(read().verdicts!.map(v => [v.by, v.passed])).toEqual([[`agent:${reviewer}`, true], [`agent:${tester}`, true]])
})
it('the assignee passing a check the Reviewer failed leaves it failed', () => {
const { f, reviewer, check, read } = checkers()
check(reviewer, false, 'Drops the session')
check(f.dev, true, 'Fixed it')
expect(read()).toMatchObject({ passedBy: null, evidence: 'Drops the session' })
})
it('two failures: failed until both pass, the latest failure\'s evidence shown', () => {
const { tester, reviewer, check, read } = checkers()
check(tester, false, 'Crashes offline')
check(reviewer, false, 'Leaks the token')
expect(read()).toMatchObject({ passedBy: null, evidence: 'Leaks the token' })
check(reviewer, true, 'Token kept')
expect(read()).toMatchObject({ passedBy: null, evidence: 'Crashes offline' })
check(tester, true, 'Works offline')
expect(read()).toMatchObject({ passedBy: `agent:${tester}`, evidence: 'Works offline' })
})
it('a pass kept from before verdicts counts as its checker\'s verdict', () => {
const { tester, reviewer, check, read } = checkers()
// As a check recorded before verdicts were kept: its pass and evidence only.
Object.assign(read(), { passedBy: `agent:${reviewer}`, evidence: 'Diff reads right' })
check(tester, false, 'Crashes offline')
expect(read()).toMatchObject({ passedBy: null, evidence: 'Crashes offline' })
check(reviewer, true, 'Still right')
expect(read().verdicts!.map(v => [v.by, v.passed, v.evidence])).toEqual([
[`agent:${tester}`, false, 'Crashes offline'], [`agent:${reviewer}`, true, 'Still right']])
})
// Diego, 2026-11-04 (#2656): a check failed by a checker who then left the Swarm could never pass again in that attempt.
// A later pass by the task's PM or an owner clears departed checkers' failures; nobody else's does.
describe('a failure by a checker who left the Swarm', () => {
const departed = () => {
const c = checkers()
c.check(c.reviewer, false, 'Drops the session')
c.f.run({ type: 'agent.remove', agentId: c.reviewer } as Command)
const second = c.f.add('reviewer-2', c.f.task)
c.check(second, true, 'Session kept')
return { ...c, second }
}
it('stays failed after another checker passes it', () => {
const { f, check, read } = departed()
expect(read()).toMatchObject({ passedBy: null, evidence: 'Drops the session' })
check(f.dev, true, 'Fixed it')
expect(read()).toMatchObject({ passedBy: null, evidence: 'Drops the session' })
})
it('is cleared by the owner\'s pass, which then names the check\'s passer and evidence', () => {
const { f, second, read } = departed()
f.run({ type: 'work.check', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id,
checkId: read().id, passed: true, evidence: 'Reviewer left; Reviewer 2 passed it' } as Command)
expect(read()).toMatchObject({ passedBy: 'person:owner', evidence: 'Reviewer left; Reviewer 2 passed it' })
expect(read().verdicts!.map(v => [v.by, v.passed])).toEqual([[`agent:${second}`, true], ['person:owner', true]])
})
it('is cleared by the task\'s PM\'s pass', () => {
const { f, check, read } = departed()
check(f.lead, true, 'Reviewer left; passed on the second review')
expect(read()).toMatchObject({ passedBy: `agent:${f.lead}`, evidence: 'Reviewer left; passed on the second review' })
})
// Review of #2916 (Alder2878): removing a PM clears its lead on every task it led, so "the task's PM" is the project's
// coordinator now, not the task's lead.
it('is cleared by a new PM\'s pass after the PM who opened the task was replaced', () => {
const { f, check, read } = departed()
// As a PM switch lands (commands.ts, leadFor.switchId): the new agent leads the project chat, then the old one goes.
const pm = f.add('pm-2')
f.group('lead').leadId = pm
f.run({ type: 'agent.remove', agentId: f.lead } as Command)
expect(f.group(f.task).leadId).toBeNull()
f.run({ type: 'conversation.agent', conversationId: f.task, agentId: pm, present: true, lead: false } as Command)
check(pm, true, 'Reviewer left; passed on the second review')
expect(read()).toMatchObject({ passedBy: `agent:${pm}`, evidence: 'Reviewer left; passed on the second review' })
})
// Security reviews 1 and 2 of #2916 (Heron2639, Grebe2639): a cleared failure must stay on the record, and only an owner
// among people clears.
const ownerCheck = (f: ReturnType<typeof departed>['f'], actor: Actor, evidence: string) => f.run({ type: 'work.check',
conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, checkId: f.group(f.task).checks[0]!.id,
passed: true, evidence } as Command, actor)
it('leaves a line in the task naming the departed checker, its evidence and who cleared it', () => {
const c = checkers()
const name = c.f.state.agents.find(a => a.id === c.reviewer)!
c.check(c.reviewer, false, 'Drops the session\nfull log')
c.f.run({ type: 'agent.remove', agentId: c.reviewer } as Command)
const effects = ownerCheck(c.f, owner, 'Reviewer left; passed on the second review')
expect(effects.messages).toContainEqual(expect.objectContaining({ conversationId: c.f.task, recipients: [],
text: `[email protected] cleared ${name.displayName ?? name.name}'s failure of “Signs in offline”, as they left the Swarm: Drops the session` }))
})
it('stays failed after a collaborator\'s pass: only an owner among people clears it', () => {
const { f, read } = departed()
f.state.people.push({ id: 'peer', email: '[email protected]', role: 'collaborator', generation: 'first' })
const effects = ownerCheck(f, { kind: 'person', userId: 'peer', email: '[email protected]' }, 'Looks fine')
expect(read()).toMatchObject({ passedBy: null, evidence: 'Drops the session' })
expect(effects.messages.filter(m => m.text.includes('cleared'))).toEqual([])
})
it('is cleared by the project\'s owner who doesn\'t own the Swarm', () => {
const { f, read } = departed()
f.state.people.push({ id: 'peer', email: '[email protected]', role: 'collaborator', generation: 'first' })
f.state.projects = [{ id: 'lead', name: 'Pilot', ownerId: 'peer', leadConversationId: 'lead', visibility: 'public', members: [], updateMinutes: 5 }]
ownerCheck(f, { kind: 'person', userId: 'peer', email: '[email protected]' }, 'Reviewer left; I own this project')
expect(read()).toMatchObject({ passedBy: 'person:peer', evidence: 'Reviewer left; I own this project' })
})
it('leaves a live checker\'s failure standing, whoever passes', () => {
const { f, tester, check, read } = departed()
check(tester, false, 'Crashes offline')
check(f.lead, true, 'Looks fine')
f.run({ type: 'work.check', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id,
checkId: read().id, passed: true, evidence: 'Looks fine' } as Command)
expect(read()).toMatchObject({ passedBy: null, evidence: 'Crashes offline' })
expect(read().verdicts!.map(v => v.by)).toEqual(expect.arrayContaining([`agent:${tester}`]))
})
})
it('a new attempt starts with no verdicts', () => {
const { f, tester, check, read } = checkers()
check(tester, false, 'Crashes offline')
f.run({ type: 'work.cancel', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, reason: 'Again.' } as Command, f.as(f.lead))
f.run({ type: 'work.assign', conversationId: f.task, agentId: f.dev }, f.as(f.lead))
expect(read()).toMatchObject({ passedBy: null, evidence: null })
expect(read()).not.toHaveProperty('verdicts')
})
})
// Diego, 2026-11-03 (#2323): liveness read waiting only from a task's own status. An Engineer that stayed working while its
// Review and Test steps ran lost its task 35 minutes in, and a step in Ready, itself the review, woke the PM as a review
// nobody had opened.
describe('an Engineer waiting on its own steps', () => {
const MIN = 60_000
const reviewing = () => {
const f = stepsFixture()
const id = f.step('Review')
const rev = f.add('rev', id)
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.dev))
const stepStatus = (status: string) =>
f.run({ type: 'work.status', conversationId: id, assignmentId: f.group(id).assignment!.id, status, result: `Review ${status}` } as Command, f.as(rev))
// The Reviewer keeps reporting while it reviews; the Engineer's screen stays still.
const reviewFor = (minutes: number) => { for (let m = 0; m < minutes; m += 4) { f.tick(4 * MIN); stepStatus('working') } }
return { f, id, rev, stepStatus, reviewFor, task: () => f.group(f.task).assignment! }
}
it('keeps its task while a step is working, and is lost 30 minutes after the last step ends', () => {
const { f, stepStatus, reviewFor, task } = reviewing()
reviewFor(36)
sweepLiveness(f.state, f.now)
expect(task()).toMatchObject({ status: 'working' })
stepStatus('done')
f.tick(QUIET_RUNNING_MS - MIN)
sweepLiveness(f.state, f.now)
expect(task()).toMatchObject({ status: 'working' })
f.tick(2 * MIN)
sweepLiveness(f.state, f.now)
expect(task()).toMatchObject({ status: 'lost' })
})
it('gets its 30 minutes from a step\'s Ready, its turn to act on the verdict', () => {
const { f, stepStatus, reviewFor, task } = reviewing()
reviewFor(36)
stepStatus('review')
f.tick(QUIET_RUNNING_MS - MIN)
sweepLiveness(f.state, f.now)
expect(task()).toMatchObject({ status: 'working' })
f.tick(2 * MIN)
sweepLiveness(f.state, f.now)
expect(task()).toMatchObject({ status: 'lost' })
})
// Review of #2744 (Wren2): a Reviewer stays working through the fix round its verdict asked for, waiting on the Engineer's
// new revision; counting that step held the two on each other, so a hung Engineer was never found.
// A verdict asking for changes is a failed check (#3394: a post's words are not read).
it('gets its 30 minutes from a verdict asking for changes, while its Reviewer waits on it', () => {
const { f, rev, reviewFor, task } = reviewing()
reviewFor(8)
f.run({ type: 'work.check', conversationId: f.task, assignmentId: task().id, checkId: f.group(f.task).checks[0]!.id, passed: false,
evidence: 'One Important at x.ts:1' } as Command, f.as(rev))
f.tick(QUIET_RUNNING_MS - MIN)
sweepLiveness(f.state, f.now)
expect(task()).toMatchObject({ status: 'working' })
f.tick(2 * MIN)
sweepLiveness(f.state, f.now)
expect(task()).toMatchObject({ status: 'lost' })
})
// Diego, 2026-11-04 (#2578): a step lost inside the PM's poll left its task recorded as waiting on it, so the same poll woke
// the PM with a false stall and the Engineer lost its task 30 seconds later instead of after its 30 minutes.
it('gets its 30 minutes when its Reviewer goes quiet and the step is lost in the PM\'s poll, with no stall woken', () => {
const { f, id, reviewFor, task } = reviewing()
reviewFor(36)
f.tick(QUIET_RUNNING_MS + 5 * MIN)
const rows = sweepForLead(f.state, f.now)
expect(f.group(id).assignment).toMatchObject({ status: 'lost' })
expect(rows.filter(r => r.source?.kind === 'work-stalled')).toEqual([])
expect(task()).toMatchObject({ status: 'working' })
f.tick(30_000)
expect(sweepForLead(f.state, f.now).filter(r => r.source?.kind === 'work-stalled')).toEqual([])
expect(task()).toMatchObject({ status: 'working' })
f.tick(QUIET_RUNNING_MS - 30_000 - MIN)
sweepForLead(f.state, f.now)
expect(task()).toMatchObject({ status: 'working' })
f.tick(2 * MIN)
sweepForLead(f.state, f.now)
expect(task()).toMatchObject({ status: 'lost' })
})
it('a step in Ready waits on its task owner and never wakes the PM as a stalled review', () => {
const { f, id, stepStatus } = reviewing()
stepStatus('review')
f.tick(31 * MIN)
const rows = sweepForLead(f.state, f.now)
expect(rows.filter(r => r.source?.kind === 'work-stalled')).toEqual([])
expect(f.group(id).liveness).toMatchObject({ state: 'waiting', why: 'review' })
})
})
// Dee, #3394: a verdict records the pull request head it read, and counts only at that head or one with the same patch.
describe('a verdict at a pull request head', () => {
const PR = 'https://github.com/acme/app/pull/7'
const A = 'aaaaaaa1111111111111111111111111111111aa', B = 'bbbbbbb2222222222222222222222222222222bb'
const watched = () => {
const f = stepsFixture()
const reviewer = f.add('reviewer', f.task)
// What the task's PR watch read last (store.ts pullRequestSeen).
Object.assign(f.group(f.task), { pullRequestUrls: [PR], pullRequestHeads: { [PR]: { head: A, patch: 'p1', at: 1 } } })
const check = (group: string, passed: boolean, head?: string) => f.run({ type: 'work.check', conversationId: group,
assignmentId: f.group(group).assignment!.id, checkId: f.group(group).checks[0]!.id, passed, evidence: 'Read it', ...head ? { head } : {} } as Command,
f.as(reviewer))
return { f, reviewer, check }
}
it('records the head the checker read, with its patch, and counts at it', () => {
const { f, check } = watched()
check(f.task, true, A.toUpperCase())
expect(f.group(f.task).checks[0]!.verdicts!.at(-1)).toMatchObject({ pullRequest: PR, head: A, patch: 'p1' })
expect(f.group(f.task).checks[0]!.passedBy).not.toBeNull()
})
it('on a step, records its task\'s pull request', () => {
const { f, reviewer, check } = watched()
const step = f.step('Review', f.as(f.dev), f.task, [{ description: 'Diff reads right', independent: true }])
f.run({ type: 'conversation.agent', conversationId: step, agentId: reviewer, present: true, lead: false })
f.run({ type: 'work.assign', conversationId: step, agentId: reviewer }, f.as(f.dev))
check(step, true, A)
expect(f.group(step).checks[0]!.verdicts!.at(-1)).toMatchObject({ pullRequest: PR, head: A, patch: 'p1' })
})
it('records the head the checker names; an older one does not count', () => {
const { f, check } = watched()
check(f.task, true, B)
const read = f.group(f.task).checks[0]!
expect(read.verdicts!.at(-1)).toMatchObject({ pullRequest: PR, head: B, stale: A })
expect(read.verdicts!.at(-1)).not.toHaveProperty('patch')
expect(read).toMatchObject({ passedBy: null, evidence: null })
})
// Security review of #3218 (Warden2), Important 3: the head the watch read last may be a push nobody reviewed. An agent's
// verdict naming no head is recorded and said not to count; nothing is refused.
it('an agent\'s verdict naming no head is not given the watched head, does not count, and says what to send', () => {
const { f, check } = watched()
const effects = check(f.task, true)
const read = f.group(f.task).checks[0]!
expect(read.verdicts!.at(-1)).toMatchObject({ pullRequest: PR, stale: A })
expect(read.verdicts!.at(-1)).not.toHaveProperty('head')
expect(read.passedBy).toBeNull()
expect(effects.result).toMatchObject({ counts: false })
expect(String(effects.result.next)).toContain('head')
})
it('a person\'s verdict naming no head is given the head the watch read last, as the screen showed it', () => {
const { f } = watched()
f.run({ type: 'work.check', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, checkId: f.group(f.task).checks[0]!.id,
passed: true, evidence: 'Looked at it' } as Command)
expect(f.group(f.task).checks[0]!.verdicts!.at(-1)).toMatchObject({ pullRequest: PR, head: A, patch: 'p1' })
expect(f.group(f.task).checks[0]!.passedBy).toBe('person:owner')
})
// Security review of #3218 (Warden2), Important 2: a short head could match a commit ground to share its characters.
it('takes a head only as a whole commit id', () => {
const { f, check } = watched()
for (const head of ['abc', A.slice(0, 7), A.slice(0, 39), 'not-a-sha!', 'g'.repeat(40), 'a'.repeat(41)]) expect(() => check(f.task, true, head)).toThrow()
})
})
// Review of #3218 (Ledger), Important 4: a failure for a head the pull request has moved past asks for no changes.
describe('a failure at an old head', () => {
it('does not hold its Reviewer\'s step waiting for a revision', () => {
const f = stepsFixture()
const PR = 'https://github.com/acme/app/pull/7'
const A = 'aaaaaaa1111111111111111111111111111111aa', B = 'bbbbbbb2222222222222222222222222222222bb'
const id = f.step('Review')
const rev = f.add('rev', id)
f.run({ type: 'work.assign', conversationId: id, agentId: rev }, f.as(f.dev))
f.run({ type: 'conversation.agent', conversationId: f.task, agentId: rev, present: true, lead: false })
Object.assign(f.group(f.task), { pullRequestUrls: [PR], pullRequestHeads: { [PR]: { head: B, patch: 'p2', at: 1 } } })
const fail = (head: string) => f.run({ type: 'work.check', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id,
checkId: f.group(f.task).checks[0]!.id, passed: false, evidence: 'Drops the session', head } as Command, f.as(rev))
fail(A)
expect(f.group(id).assignment).not.toHaveProperty('changesRequestedAt')
fail(B)
expect(f.group(id).assignment!.changesRequestedAt).toBe(f.now)
})
})
// Review of #3218 (Ledger, round 3), Important 1: a task from before steps were listed keeps listing none until its PR watch
// looks its dormant steps up, so a step opened meanwhile never hides the ones before it.
describe('a step on a task from before step lists', () => {
it('leaves its task unlisted; a listed task lists it', () => {
const f = stepsFixture()
expect(f.group(f.task).stepIds).toEqual([])
const first = f.step('Review')
expect(f.group(f.task).stepIds).toEqual([first])
delete f.group(f.task).stepIds
f.step('Test')
expect(f.group(f.task)).not.toHaveProperty('stepIds')
})
})
// Review of #3218 (Ledger, round 4), Important 1: with #3399, a failure by someone other than the Engineer brings a handed task
// back to it. A failure for a head the pull request moved past is no verdict on what is in review: it reopens nothing.
describe('a failure at an old head on a handed task', () => {
it('leaves it handed and tells nobody; a failure at its head brings it back', () => {
const f = stepsFixture()
const PR = 'https://github.com/acme/app/pull/7'
const A = 'aaaaaaa1111111111111111111111111111111aa', B = 'bbbbbbb2222222222222222222222222222222bb'
const rev = f.add('rev', f.task)
Object.assign(f.group(f.task), { pullRequestUrls: [PR], pullRequestHeads: { [PR]: { head: B, patch: 'p2', at: 1 } } })
f.run({ type: 'work.status', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, status: 'review', result: `${B} ${PR}` } as Command, f.as(f.dev))
const fail = (head: string) => f.run({ type: 'work.check', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id,
checkId: f.group(f.task).checks[0]!.id, passed: false, evidence: 'Drops the session', head } as Command, f.as(rev))
const stale = fail(A)
expect(f.group(f.task).assignment).toMatchObject({ status: 'review' })
expect(f.group(f.task).assignment).not.toHaveProperty('reopened')
expect(stale.messages.filter(m => m.recipients.includes(f.dev))).toEqual([])
fail(B)
expect(f.group(f.task).assignment).toMatchObject({ status: 'working', reopened: expect.objectContaining({ why: expect.any(String) }) })
})
})
// Security review of #3218 (Warden2, round 5) and review round 7 (Ledger): a checker names the base branch it read against, as it
// names the head: any branch name GitHub takes, never one with a space or a control character.
describe('a verdict naming its base', () => {
const PR = 'https://github.com/acme/app/pull/7', A = 'aaaaaaa1111111111111111111111111111111aa'
const watched = (base: string) => {
const f = stepsFixture()
const rev = f.add('rev', f.task)
Object.assign(f.group(f.task), { pullRequestUrls: [PR], pullRequestHeads: { [PR]: { head: A, patch: 'p', at: 1, base } } })
const check = (fields: Record<string, string>) => f.run({ type: 'work.check', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id,
checkId: f.group(f.task).checks[0]!.id, passed: true, evidence: 'Read it', ...fields } as Command, f.as(rev))
return { f, check }
}
it('is recorded with it, for any branch name', () => {
for (const base of ['release/1.2', 'release+hotfix', 'feature/修正', 'user@{x}']) {
const { f, check } = watched(base)
check({ head: A, base })
expect(f.group(f.task).checks[0]!.verdicts!.at(-1)).toMatchObject({ head: A, base, patch: 'p' })
expect(f.group(f.task).checks[0]!.passedBy).not.toBeNull()
}
})
it('is refused only as no branch name at all', () => {
const { check } = watched('main')
for (const base of ['', 'a b', 'x\ny', 'tab\there', 'z'.repeat(256)]) expect(() => check({ head: A, base })).toThrow()
})
it('naming none, does not count, and the result asks for the base', () => {
const { f, check } = watched('main')
const effects = check({ head: A })
expect(f.group(f.task).checks[0]!.passedBy).toBeNull()
expect(effects.result).toMatchObject({ counts: false })
expect(String(effects.result.next)).toContain('base')
})
it('from a person naming neither, gets the head and base the watch read last', () => {
const { f } = watched('main')
f.run({ type: 'work.check', conversationId: f.task, assignmentId: f.group(f.task).assignment!.id, checkId: f.group(f.task).checks[0]!.id,
passed: true, evidence: 'Looked at it' } as Command)
expect(f.group(f.task).checks[0]!.verdicts!.at(-1)).toMatchObject({ head: A, base: 'main', patch: 'p' })
expect(f.group(f.task).checks[0]!.passedBy).toBe('person:owner')
})
})