fix: tighten CLI contract validation (#3874)
This commit is contained in:
+33
-1
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { parseArgs } from './args'
|
||||
import { parseArgs, validateCommandAndFlags } from './args'
|
||||
|
||||
describe('parseArgs', () => {
|
||||
it('keeps an empty string as a flag value', () => {
|
||||
@@ -38,3 +38,35 @@ describe('parseArgs', () => {
|
||||
expect(parsed.flags.get('url')).toBe('https://example.com')
|
||||
})
|
||||
})
|
||||
|
||||
describe('validateCommandAndFlags', () => {
|
||||
const specs = [
|
||||
{
|
||||
path: ['demo'],
|
||||
summary: 'Demo command',
|
||||
usage: 'orca demo',
|
||||
allowedFlags: []
|
||||
}
|
||||
]
|
||||
|
||||
it('allows global runtime selector flags even when the command spec omits them', () => {
|
||||
const parsed = parseArgs([
|
||||
'demo',
|
||||
'--pairing-code',
|
||||
'remote-runtime',
|
||||
'--environment',
|
||||
'server',
|
||||
'--json'
|
||||
])
|
||||
|
||||
expect(() => validateCommandAndFlags(specs, parsed)).not.toThrow()
|
||||
})
|
||||
|
||||
it('still rejects unknown command-specific flags', () => {
|
||||
const parsed = parseArgs(['demo', '--bogus'])
|
||||
|
||||
expect(() => validateCommandAndFlags(specs, parsed)).toThrow(
|
||||
'Unknown flag --bogus for command: demo'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user