Skip to content

Commit 16e7278

Browse files
lmajanoclaude
andauthored
TESTBOX-456: Simplify BoxLang CLI url scope guard to a param (#205)
Replace the two-condition if-guard (!IS_CLI || isDefined("url")) with a plain `param name="url" default={};` at the top of runRaw()/dryRun(). param is a no-op wherever the scope already exists (every engine, every non-CLI request) and only defaults it in the one case that was ever broken - BoxLang CLI, where the scope isn't registered at all. Verified against real BoxLang v1.17.0+58: dryRun()/runRaw() both complete without throwing in CLI mode (isDefined('url') == false). Co-authored-by: Claude <noreply@anthropic.com>
1 parent 55dbf9a commit 16e7278

1 file changed

Lines changed: 27 additions & 29 deletions

File tree

system/TestBox.cfc

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -408,21 +408,20 @@ component accessors="true" {
408408
// The `url` scope only exists in a real HTTP request - it isn't registered at all when
409409
// TestBox runs via the BoxLang CLI, so even a `structKeyExists( url, ... )` guard throws
410410
// (resolving the bare `url` identifier is what fails, not the key lookup within it).
411-
// `isDefined()` is the safe way to probe for scope existence without that risk, so
412-
// don't just skip on IS_CLI - only skip when the scope truly isn't there.
413-
if ( !variables.IS_CLI || isDefined( "url" ) ) {
414-
if ( structKeyExists( url, "testBundles" ) && !isNull( url.testBundles ) ) {
415-
testBundles.append( listToArray( urlDecode( url.testBundles ) ), true );
416-
}
417-
if ( structKeyExists( url, "testSuites" ) && !isNull( url.testSuites ) ) {
418-
arguments.testSuites.append( listToArray( urlDecode( url.testSuites ) ), true );
419-
}
420-
if ( structKeyExists( url, "testSpecs" ) && !isNull( url.testSpecs ) ) {
421-
arguments.testSpecs.append( listToArray( urlDecode( url.testSpecs ) ), true );
422-
}
423-
if ( structKeyExists( url, "testMethod" ) && !isNull( url.testMethod ) ) {
424-
arguments.testSpecs.append( listToArray( urlDecode( url.testMethod ) ), true );
425-
}
411+
// Param it to an empty struct so it's always safe to touch below - a no-op everywhere
412+
// the scope already exists (every engine, every non-CLI request).
413+
param name="url" default={};
414+
if ( structKeyExists( url, "testBundles" ) && !isNull( url.testBundles ) ) {
415+
testBundles.append( listToArray( urlDecode( url.testBundles ) ), true );
416+
}
417+
if ( structKeyExists( url, "testSuites" ) && !isNull( url.testSuites ) ) {
418+
arguments.testSuites.append( listToArray( urlDecode( url.testSuites ) ), true );
419+
}
420+
if ( structKeyExists( url, "testSpecs" ) && !isNull( url.testSpecs ) ) {
421+
arguments.testSpecs.append( listToArray( urlDecode( url.testSpecs ) ), true );
422+
}
423+
if ( structKeyExists( url, "testMethod" ) && !isNull( url.testMethod ) ) {
424+
arguments.testSpecs.append( listToArray( urlDecode( url.testMethod ) ), true );
426425
}
427426

428427
// Using a directory runner?
@@ -531,20 +530,19 @@ component accessors="true" {
531530
isSimpleValue( arguments.testSpecs ) ? listToArray( arguments.testSpecs ) : arguments.testSpecs
532531
);
533532

534-
// The `url` scope only exists in a real HTTP request - see the identical guard in runRaw().
535-
if ( !variables.IS_CLI || isDefined( "url" ) ) {
536-
if ( structKeyExists( url, "testBundles" ) && !isNull( url.testBundles ) ) {
537-
arguments.testBundles.append( listToArray( urlDecode( url.testBundles ) ), true );
538-
}
539-
if ( structKeyExists( url, "testSuites" ) && !isNull( url.testSuites ) ) {
540-
arguments.testSuites.append( listToArray( urlDecode( url.testSuites ) ), true );
541-
}
542-
if ( structKeyExists( url, "testSpecs" ) && !isNull( url.testSpecs ) ) {
543-
arguments.testSpecs.append( listToArray( urlDecode( url.testSpecs ) ), true );
544-
}
545-
if ( structKeyExists( url, "testMethod" ) && !isNull( url.testMethod ) ) {
546-
arguments.testSpecs.append( listToArray( urlDecode( url.testMethod ) ), true );
547-
}
533+
// The `url` scope only exists in a real HTTP request - see the identical param in runRaw().
534+
param name="url" default={};
535+
if ( structKeyExists( url, "testBundles" ) && !isNull( url.testBundles ) ) {
536+
arguments.testBundles.append( listToArray( urlDecode( url.testBundles ) ), true );
537+
}
538+
if ( structKeyExists( url, "testSuites" ) && !isNull( url.testSuites ) ) {
539+
arguments.testSuites.append( listToArray( urlDecode( url.testSuites ) ), true );
540+
}
541+
if ( structKeyExists( url, "testSpecs" ) && !isNull( url.testSpecs ) ) {
542+
arguments.testSpecs.append( listToArray( urlDecode( url.testSpecs ) ), true );
543+
}
544+
if ( structKeyExists( url, "testMethod" ) && !isNull( url.testMethod ) ) {
545+
arguments.testSpecs.append( listToArray( urlDecode( url.testMethod ) ), true );
548546
}
549547

550548
var filterState = new testbox.system.TestResult(

0 commit comments

Comments
 (0)