import { describe, it, expect } from 'vitest';
import { evaluateTriggerRule } from '../flow-runner-decisions.js';

describe('evaluateTriggerRule', () => {
  it('all_success requires all deps done', () => {
    expect(evaluateTriggerRule(['a', 'b'], new Set(['a', 'b']), new Set(), new Set())).toBe(true);
    expect(evaluateTriggerRule(['a', 'b'], new Set(['a']), new Set(), new Set())).toBe(false);
  });

  it('one_success fires on first completion', () => {
    expect(evaluateTriggerRule(['a', 'b'], new Set(['a']), new Set(), new Set(), 'one_success')).toBe(true);
    expect(evaluateTriggerRule(['a', 'b'], new Set(), new Set(), new Set(), 'one_success')).toBe(false);
  });

  it('all_done includes skipped deps', () => {
    expect(evaluateTriggerRule(['a', 'b'], new Set(['a']), new Set(['b']), new Set(), 'all_done')).toBe(true);
  });

  it('all_success treats excluded deps as satisfied', () => {
    expect(evaluateTriggerRule(['a', 'b'], new Set(['a']), new Set(), new Set(['b']))).toBe(true);
  });

  it('defaults to all_success', () => {
    expect(evaluateTriggerRule(['a'], new Set(['a']), new Set(), new Set())).toBe(true);
    expect(evaluateTriggerRule(['a'], new Set(), new Set(), new Set())).toBe(false);
  });

  it('returns true for empty deps', () => {
    expect(evaluateTriggerRule([], new Set(), new Set(), new Set())).toBe(true);
  });
});
