import { describe, expect, it } from 'vitest';
import { buildFixRecheckSteps, resolveWorkflowSteps } from '../commands/run.js';
const reviewStep = {
    name: 'review',
    type: 'review',
    reviewer: 'auto',
    max_rounds: 1,
    instructions: 'review instructions',
};
const fixStep = {
    name: 'fix',
    type: 'fix',
    reviewer: 'origin',
    max_rounds: 1,
    instructions: 'fix instructions',
};
const recheckStep = {
    name: 'recheck',
    type: 'recheck',
    reviewer: 'auto',
    max_rounds: 1,
    instructions: 'custom recheck',
};
describe('resolveWorkflowSteps', () => {
    it('synthesizes recheck when --steps asks for it but the workflow has only review+fix', () => {
        const steps = resolveWorkflowSteps([reviewStep, fixStep], ['fix', 'recheck'], 'codex');
        expect(steps.map(step => step.type)).toEqual(['fix', 'recheck']);
        expect(steps[1]).toMatchObject({
            name: 'recheck',
            type: 'recheck',
            reviewer: 'codex',
        });
    });
    it('preserves explicit recheck steps', () => {
        const steps = resolveWorkflowSteps([reviewStep, fixStep, recheckStep], ['fix', 'recheck'], 'claude');
        expect(steps.map(step => step.name)).toEqual(['fix', 'recheck']);
        expect(steps[1]).toMatchObject({
            instructions: 'custom recheck',
            reviewer: 'claude',
        });
    });
    it('pins --reviewer to review and recheck only', () => {
        const steps = resolveWorkflowSteps([reviewStep, fixStep, recheckStep], undefined, 'codex', { reviewer: 'codex' });
        expect(steps.find(step => step.type === 'review')?.reviewer).toBe('codex');
        expect(steps.find(step => step.type === 'recheck')?.reviewer).toBe('codex');
        expect(steps.find(step => step.type === 'fix')?.reviewer).toBe('origin');
    });
    it('pins --fixer to fix only', () => {
        const steps = resolveWorkflowSteps([reviewStep, fixStep, recheckStep], undefined, 'codex', { fixer: 'claude' });
        expect(steps.find(step => step.type === 'review')?.reviewer).toBe('codex');
        expect(steps.find(step => step.type === 'recheck')?.reviewer).toBe('codex');
        expect(steps.find(step => step.type === 'fix')?.reviewer).toBe('claude');
    });
    it('pins --vendor to review, recheck, and fix', () => {
        const steps = resolveWorkflowSteps([reviewStep, fixStep, recheckStep], undefined, 'codex', { vendor: 'claude' });
        expect(steps.find(step => step.type === 'review')?.reviewer).toBe('claude');
        expect(steps.find(step => step.type === 'recheck')?.reviewer).toBe('claude');
        expect(steps.find(step => step.type === 'fix')?.reviewer).toBe('claude');
    });
});
describe('buildFixRecheckSteps', () => {
    it('uses the full workflow for round-mode followups after an initial review-only run', () => {
        const steps = buildFixRecheckSteps([reviewStep], [reviewStep, fixStep], 'codex');
        expect(steps.map(step => step.type)).toEqual(['fix', 'recheck']);
        expect(steps[1]).toMatchObject({
            name: 'recheck',
            type: 'recheck',
            reviewer: 'codex',
        });
    });
    it('prepends fix for round-mode followups after an initial recheck-only run', () => {
        const steps = buildFixRecheckSteps([recheckStep], [reviewStep, fixStep, recheckStep], 'claude');
        expect(steps.map(step => step.type)).toEqual(['fix', 'recheck']);
        expect(steps[1]).toMatchObject({
            name: 'recheck',
            instructions: 'custom recheck',
            reviewer: 'auto',
        });
    });
});
//# sourceMappingURL=run.test.js.map