Files
deepseek-harness/scripts/gen-cli-help.spec.ts
T
Tianyi Cui 75935af1d0 feat(cli): generate the CLI help reference and add dsh plugin help
`scripts/gen-cli-help.ts` runs the source `dsh` launcher with temporary
Harness and Agents homes and captures the launcher, `dsh plugin`, and every
shipped profile's text help (profile names come from `PROFILE_TEMPLATES`).
It recursively discovers subcommands from each page's `Commands:` section,
shows identical alias help once with every invocation, and writes
`docs/cli-help.md`, its Chinese page, and their pairing record. The record
resolves links between the two pages as written, so a first run already
matches `verify-translation-pairing`. `verify-cli-help` checks all three
files and runs as the `cli-help` doc-sync leaf, which the static CI lane
also runs on an unbuilt tree.

`dsh plugin` now owns `-h`/`--help` and reads its own options only before
the forwarded pnpm arguments: `dsh plugin --help` prints its help instead of
failing on the missing `--profile`, while everything after the pnpm command
(including `-h`, `--help`, and `--profile`) reaches pnpm verbatim. A
`--profile` placed after the pnpm command is no longer accepted; the
v0.2.1-alpha.1 upgrade guide covers the migration.

Refs #4114
2026-10-05 17:45:17 +08:00

35 lines
1.7 KiB
TypeScript

/** Command discovery and complete output preservation for the CLI reference. */
import { describe, expect, it } from 'vitest'
import { collectCliHelp, parseCliHelp } from './gen-cli-help.ts'
describe('CLI help discovery', () => {
it('reads command rows while retaining wrapped descriptions and examples', () => {
const help = 'Usage: dsh\r\n\r\nCommands:\r\n web [options] Serve the browser\r\n with a wrapped description\r\n plugin Manage plugins\r\n\r\nExamples:\r\n dsh web\r\n'
const result = parseCliHelp(help)
expect(result.commands).toEqual(['web', 'plugin'])
expect(result.output).toBe(help.replaceAll('\r\n', '\n'))
})
it('includes plugin, both profile forms, and their nested commands when launcher help has no command list', async () => {
const visited: string[] = []
const pages = await collectCliHelp(async (args) => {
visited.push(args.join(' '))
if (args.length === 0) return 'Usage: dsh [--profile] <name>\n'
if (args[0] === 'plugin') return 'Usage: dsh plugin --profile <name> <args...>\n'
const selected = args[0] === '--profile' ? args.slice(1) : args
if (selected[1] === 'nested') return 'Usage: nested\n'
return `Usage: ${selected[0]} [command]\n\nCommands:\n nested Run the nested command\n`
}, ['web'])
expect(visited).toEqual(['', 'plugin', 'web', 'web nested', '--profile web'])
expect(pages.map(page => page.invocations)).toEqual([
['dsh'], ['dsh plugin'], ['dsh web', 'dsh --profile web'],
['dsh web nested', 'dsh --profile web nested'],
])
})
it.each(['', ' \r\n\n'])('rejects blank help %j', (help) => {
expect(() => parseCliHelp(help)).toThrow('CLI help returned empty output')
})
})