import { describe, expect, it } from 'vitest';
import { SSH_DEFAULTS, mergeSshConfig } from './config.js';

describe('ssh/config', () => {
  it('defaults to disabled with safe values', () => {
    expect(SSH_DEFAULTS.enabled).toBe(false);
    expect(SSH_DEFAULTS.allowPrivateAddresses).toBe(false);
    expect(SSH_DEFAULTS.adminBypassesGrants).toBe(true);
    expect(SSH_DEFAULTS.callTimeoutSeconds).toBeGreaterThan(0);
    expect(SSH_DEFAULTS.maxOutputBytes).toBeGreaterThan(0);
    expect(SSH_DEFAULTS.abuseFailureThreshold).toBeGreaterThan(0);
  });

  it('merges partial overrides on top of defaults', () => {
    const merged = mergeSshConfig({ enabled: true, callTimeoutSeconds: 60 });
    expect(merged.enabled).toBe(true);
    expect(merged.callTimeoutSeconds).toBe(60);
    expect(merged.allowPrivateAddresses).toBe(SSH_DEFAULTS.allowPrivateAddresses);
    expect(merged.maxOutputBytes).toBe(SSH_DEFAULTS.maxOutputBytes);
  });

  it('returns defaults when partial is undefined', () => {
    expect(mergeSshConfig(undefined)).toEqual(SSH_DEFAULTS);
  });

  it('returns defaults when partial is empty', () => {
    expect(mergeSshConfig({})).toEqual(SSH_DEFAULTS);
  });

  it('does not mutate SSH_DEFAULTS when merging', () => {
    const before = { ...SSH_DEFAULTS };
    mergeSshConfig({ enabled: true });
    expect(SSH_DEFAULTS).toEqual(before);
  });
});
