/**
 * autoMerge gating — `shouldMergePrOnShip` decides whether a shipped job's PR is
 * auto-merged. Pure (job.autoMerge OR the FLEET_SHIP_MERGES_PR host flag), so we
 * verify the gate without invoking the GitHub CLI.
 */

import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { shouldMergePrOnShip } from './coordinator.js';

describe('shouldMergePrOnShip', () => {
  beforeEach(() => delete process.env.FLEET_SHIP_MERGES_PR);
  afterEach(() => delete process.env.FLEET_SHIP_MERGES_PR);

  it('merges when the job opted in via autoMerge', () => {
    expect(shouldMergePrOnShip({ autoMerge: true })).toBe(true);
  });

  it('merges when the host enables it globally (FLEET_SHIP_MERGES_PR=1)', () => {
    process.env.FLEET_SHIP_MERGES_PR = '1';
    expect(shouldMergePrOnShip({ autoMerge: false })).toBe(true);
    expect(shouldMergePrOnShip({ autoMerge: undefined })).toBe(true);
  });

  it('does NOT merge by default (no opt-in, flag off)', () => {
    expect(shouldMergePrOnShip({ autoMerge: false })).toBe(false);
    expect(shouldMergePrOnShip({ autoMerge: undefined })).toBe(false);
  });
});
