import { describe, it, expect, vi } from 'vitest';

vi.mock('@octocodeai/octocode-tools-core/config', () => ({
  getConfigSync: vi.fn(() => {
    throw new Error('config unavailable');
  }),
  DEFAULT_OUTPUT_CONFIG: {
    format: 'yaml',
    pagination: { defaultCharLength: 2000 },
  },
}));

import { applyOutputSizeLimit } from '../../../octocode-tools-core/src/utils/pagination/outputSizeLimit.js';

describe('applyOutputSizeLimit — catch branch when getConfigSync throws', () => {
  it('falls back to DEFAULTS when getConfigSync throws', () => {
    const smallContent = 'small content';
    const result = applyOutputSizeLimit(smallContent, {});

    expect(result.wasLimited).toBe(false);
    expect(result.content).toBe(smallContent);
    expect(result.warnings).toHaveLength(0);
  });

  it('still auto-paginates large content after catch', () => {
    const largeContent = 'x'.repeat(50000);
    const result = applyOutputSizeLimit(largeContent, {});

    expect(result.wasLimited).toBe(true);
    expect(result.pagination).toBeDefined();
  });

  it('still applies explicit charLength after catch', () => {
    const content = 'z'.repeat(5000);
    const result = applyOutputSizeLimit(content, { charLength: 1000 });

    expect(result.wasLimited).toBe(true);
    expect(result.content.length).toBe(1000);
  });
});
