Skip to content

test(taskctl): improve pipeline.test.ts to cover processAdversarialVerdicts state machine #220

@randomm

Description

@randomm

Context

Phase 3b (PR on feature/taskctl-pipeline) implemented the developer→adversarial→commit inner loop in packages/opencode/src/tasks/pulse.ts. The tests in packages/opencode/test/tasks/pipeline.test.ts currently only verify that adversarial verdict data is correctly stored in the task store — they do not test the actual state machine logic.

What's missing

The following pulse.ts functions have no meaningful test coverage:

  • processAdversarialVerdicts() — APPROVED path should result in task status closed + PM notification fired; ISSUES_FOUND should increment pipeline.attempt and respawn developer; 3rd failure should set status failed and escalate
  • commitTask() — happy path closes task; failure path calls escalateCommitFailure
  • respawnDeveloper() — new session created in same worktree, attempt counter incremented, adversarial feedback passed in prompt
  • escalateToPM() — task status set to failed, BackgroundTaskEvent published
  • spawnAdversarial() — spawned when pipeline.stage === 'reviewing', double-spawn prevention via adversarial-running stage

Why it's hard

These functions call Session.createNext(), SessionPrompt.prompt(), and Worktree.create/remove — real infrastructure that's difficult to test without a running server. The tests were scoped to Store-level data assertions as a pragmatic choice.

Suggested approach

Mock or stub Session and Worktree at the module boundary. Options:

  1. Extract the state-transition logic into pure functions that take/return plain objects (easier to test)
  2. Use Bun's module mock capabilities to stub Session.createNext and SessionPrompt.prompt
  3. Create a lightweight integration test harness that sets up a minimal in-process session

Acceptance criteria

  • processAdversarialVerdicts: APPROVED → task closed test
  • processAdversarialVerdicts: ISSUES_FOUND → attempt incremented, developer respawned test
  • processAdversarialVerdicts: 3rd failure → task failed + escalation test
  • Double-processing prevention: verdict cleared before action (regression test)
  • bun test passes, bun run typecheck passes

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions