import { describe, expect, test } from 'bun:test' import type { CommandRegistry, RegisteredCommand } from '../../runtime/command-registry.js' import { formatCommandHelp, formatGlobalHelp } from '../../runtime/help.js' const globalFlags = [ { name: '--config', type: 'string' as const, description: 'Path to config', placeholder: '', }, ] const command: RegisteredCommand = { name: 'status', description: 'Show migration status', flags: [], pluginFlags: [], pluginName: 'core', } const registry: CommandRegistry = { commands: [command], globalFlags, get: (name) => (name === command.name ? command : undefined), resolveFlags: () => [...globalFlags], } describe('help formatting', () => { test('global help links to full documentation and markdown fetch hint', () => { const help = formatGlobalHelp(registry, '0.0.0-test') expect(help).toContain('Documentation:') expect(help).toContain('Full documentation: https://chkit.obsessiondb.com/') expect(help).toContain( 'Agent-readable markdown: fetch any docs page with Accept: text/markdown', ) }) test('subcommand help lists that subcommand\'s own flags', () => { const ingest: RegisteredCommand = { name: 'ingest', description: 'Plugin: ingest', flags: [], pluginFlags: [], pluginName: 'ingest', subcommands: [ { name: 'run', description: 'Execute streams', flags: [{ name: '--max-duration', type: 'string', description: 'Execution budget', placeholder: '' }], pluginFlags: [], pluginName: 'ingest' }, { name: 'list', description: 'List streams', flags: [], pluginFlags: [], pluginName: 'ingest' }, ], } const help = formatCommandHelp(ingest, globalFlags, 'run') expect(help).toContain('chkit ingest run [options]') expect(help).toContain('--max-duration ') expect(help).not.toContain('List streams') const overview = formatCommandHelp(ingest, globalFlags, 'nope') expect(overview).toContain('chkit ingest [options]') expect(overview).toContain('List streams') expect(overview).not.toContain('--max-duration') }) test('command help links to full documentation and markdown fetch hint', () => { const help = formatCommandHelp(command, globalFlags) expect(help).toContain('Documentation:') expect(help).toContain('Full documentation: https://chkit.obsessiondb.com/') expect(help).toContain( 'Agent-readable markdown: fetch any docs page with Accept: text/markdown', ) }) })