fix: tighten CLI contract validation (#3874)

This commit is contained in:
Jinjing
2026-05-30 12:55:47 -07:00
committed by GitHub
parent 8484830b9e
commit ffbc4c3cfb
13 changed files with 394 additions and 27 deletions
+33 -1
View File
@@ -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'
)
})
})