@@ -42,6 +42,21 @@ type QaRunCliOptions = QaLabSelfCheckCommandOptions &
4242 category ?: QaProfileCommandOptions [ "category" ] ;
4343 } ;
4444
45+ const QA_RUN_PROFILE_ONLY_OPTIONS = [
46+ { optionName : "outputDir" , flag : "--output-dir" } ,
47+ { optionName : "surface" , flag : "--surface" } ,
48+ { optionName : "category" , flag : "--category" } ,
49+ { optionName : "transport" , flag : "--transport" } ,
50+ { optionName : "providerMode" , flag : "--provider-mode" } ,
51+ { optionName : "model" , flag : "--model" } ,
52+ { optionName : "altModel" , flag : "--alt-model" } ,
53+ { optionName : "concurrency" , flag : "--concurrency" } ,
54+ { optionName : "allowFailures" , flag : "--allow-failures" } ,
55+ { optionName : "fast" , flag : "--fast" } ,
56+ ] as const ;
57+
58+ const QA_RUN_SELF_CHECK_ONLY_OPTIONS = [ { optionName : "output" , flag : "--output" } ] as const ;
59+
4560type QaSuiteCliOptions = QaScenarioRunCliOptions & {
4661 runner ?: QaSuiteCommandOptions [ "runner" ] ;
4762 thinking ?: QaSuiteCommandOptions [ "thinking" ] ;
@@ -82,6 +97,43 @@ function parseQaCliPositiveIntegerOption(value: string, flag: string): number {
8297 return parsed ;
8398}
8499
100+ function collectCliSuppliedQaRunFlags (
101+ command : Command ,
102+ options : readonly { optionName : string ; flag : string } [ ] ,
103+ ) : string [ ] {
104+ return options
105+ . filter ( ( option ) => command . getOptionValueSource ( option . optionName ) === "cli" )
106+ . map ( ( option ) => option . flag ) ;
107+ }
108+
109+ function formatFlagList ( flags : readonly string [ ] ) : string {
110+ return flags . length === 1 ? flags [ 0 ] : flags . join ( ", " ) ;
111+ }
112+
113+ function validateQaRunMode ( opts : QaRunCliOptions , command : Command ) {
114+ const hasQaProfile = Boolean ( opts . qaProfile ?. trim ( ) ) ;
115+ if ( command . getOptionValueSource ( "qaProfile" ) === "cli" && ! hasQaProfile ) {
116+ throw new Error ( "--qa-profile must not be empty." ) ;
117+ }
118+
119+ if ( hasQaProfile ) {
120+ const selfCheckFlags = collectCliSuppliedQaRunFlags ( command , QA_RUN_SELF_CHECK_ONLY_OPTIONS ) ;
121+ if ( selfCheckFlags . length > 0 ) {
122+ throw new Error (
123+ `qa run ${ formatFlagList ( selfCheckFlags ) } is only valid for the self-check mode without --qa-profile.` ,
124+ ) ;
125+ }
126+ return ;
127+ }
128+
129+ const profileFlags = collectCliSuppliedQaRunFlags ( command , QA_RUN_PROFILE_ONLY_OPTIONS ) ;
130+ if ( profileFlags . length > 0 ) {
131+ throw new Error (
132+ `qa run ${ formatFlagList ( profileFlags ) } requires --qa-profile; without --qa-profile, qa run only executes the self-check.` ,
133+ ) ;
134+ }
135+ }
136+
85137async function runQaSelfCheck ( opts : QaLabSelfCheckCommandOptions ) {
86138 const runtime = await loadQaLabCliRuntime ( ) ;
87139 await runtime . runQaLabSelfCheckCommand ( opts ) ;
@@ -329,7 +381,8 @@ export function registerQaLabCli(program: Command) {
329381 false ,
330382 )
331383 . option ( "--fast" , "Enable provider fast mode where supported" , false )
332- . action ( async ( opts : QaRunCliOptions ) => {
384+ . action ( async ( opts : QaRunCliOptions , command : Command ) => {
385+ validateQaRunMode ( opts , command ) ;
333386 if ( opts . qaProfile ?. trim ( ) ) {
334387 await runQaProfile ( {
335388 repoRoot : opts . repoRoot ,
0 commit comments