Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { describe, it, expect } from 'vitest'
import { beforeEach, describe, expect, it, type Mock, vi } from 'vitest'

import { buildCliOptions } from './index'
vi.mock('./config-writer.js', () => ({
writeConfig: vi.fn(),
}))

import { writeConfig } from './config-writer.js'
import { buildCliOptions, setupProgram } from './index'

describe('buildCliOptions', () => {
it('builds options for run command with no flags', () => {
Expand Down Expand Up @@ -196,3 +201,55 @@ describe('buildCliOptions', () => {
expect(result.keepConfig).toBe(true)
})
})


describe('setupProgram CLI parity', () => {
const baseConfigArgs = [
'config',
'--server-name',
'glean_default',
'--server-url',
'https://example.com/mcp/default',
'--binary-url-prefix',
'https://example.com/binaries',
]

beforeEach(() => {
;(writeConfig as Mock).mockReset()
})

async function parse(args: string[]): Promise<void> {
const program = setupProgram()
program.exitOverride()
program.configureOutput({
writeErr: () => undefined,
writeOut: () => undefined,
})
await program.parseAsync(['node', 'glean-mdm', ...args])
}

it('uses the last auto-update flag when --auto-update follows --no-auto-update', async () => {
await parse([...baseConfigArgs, '--no-auto-update', '--auto-update'])

expect(writeConfig).toHaveBeenCalledWith(expect.objectContaining({ autoUpdate: true }))
})

it('uses the last auto-update flag when --no-auto-update follows --auto-update', async () => {
await parse([...baseConfigArgs, '--auto-update', '--no-auto-update'])

expect(writeConfig).toHaveBeenCalledWith(expect.objectContaining({ autoUpdate: false }))
})

it('does not expose an extra completion command', () => {
const commandNames = setupProgram().commands.map((command) => command.name())

expect(commandNames).not.toContain('completion')
})

it("keeps Commander's version shorthand as -V and does not claim -v", () => {
const versionOption = setupProgram().options.find((option) => option.long === '--version')

expect(versionOption?.short).toBe('-V')
expect(setupProgram().helpInformation()).not.toContain('-v, --version')
})
})
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async function executeConfig(options: CliOptions): Promise<void> {
}
}

function setupProgram(): Command {
export function setupProgram(): Command {
const program = new Command()

program
Expand Down