import { describe, it, expect } from 'vitest';
import { formatDirectToolSchemaText } from '@octocodeai/octocode-tools-core';

const LOSS_LANGUAGE: RegExp[] = [
  /may be truncated/i,
  /silently (?:dropped|truncated)/i,
  /first \d+ [^."]*only/i,
];

const TOOL_PAGINATION_KNOBS: Record<string, string[]> = {
  ghSearchCode: ['page'],
  ghGetFileContent: ['startLine', 'endLine'],
  ghViewRepoStructure: ['page'],
  ghSearchRepos: ['page'],
  ghHistoryResearch: ['page'],
  npmSearch: ['page'],
  ghCloneRepo: ['owner', 'repo'],
  localSearchCode: ['page'],
  localViewStructure: ['page'],
  localFindFiles: ['page'],
  localGetFileContent: ['startLine', 'endLine'],
  lspGetSemantics: ['uri', 'lineHint', 'type'],
};

describe('all-tools pagination contract', () => {
  describe.each(Object.entries(TOOL_PAGINATION_KNOBS))(
    '%s',
    (toolName, knobs) => {
      const schemaText = formatDirectToolSchemaText(toolName);

      it(`declares its pagination knob(s): ${knobs.join(', ')}`, () => {
        for (const knob of knobs) {
          expect(schemaText, `missing knob "${knob}"`).toContain(`"${knob}"`);
        }
      });

      it('schema is free of silent-loss language (paginates, never truncates)', () => {
        for (const re of LOSS_LANGUAGE) {
          expect(schemaText, `loss-language matched ${re}`).not.toMatch(re);
        }
      });
    }
  );
});
