@@ -433,5 +433,49 @@ describe('Dev Containers CLI', function () {
433433 const details = JSON . parse ( ( await shellExec ( `docker inspect ${ response . imageName } ` ) ) . stdout ) [ 0 ] as ImageDetails ;
434434 assert . strictEqual ( details . Config . Labels ?. test_build_options , 'success' ) ;
435435 } ) ;
436+
437+ it ( 'should use current directory for build when no workspace-folder provided' , async function ( ) {
438+ const testFolder = `${ __dirname } /configs/image` ; // Use simpler config without features
439+ const absoluteTmpPath = path . resolve ( __dirname , 'tmp' ) ;
440+ const absoluteCli = `npx --prefix ${ absoluteTmpPath } devcontainer` ;
441+ const originalCwd = process . cwd ( ) ;
442+ console . log ( `Original cwd: ${ originalCwd } ` ) ;
443+ console . log ( `Changing to test folder: ${ testFolder } ` ) ;
444+ try {
445+ process . chdir ( testFolder ) ;
446+ const res = await shellExec ( `${ absoluteCli } build` ) ;
447+ const response = JSON . parse ( res . stdout ) ;
448+ assert . equal ( response . outcome , 'success' ) ;
449+ assert . ok ( response . imageName ) ;
450+ } finally {
451+ process . chdir ( originalCwd ) ;
452+ }
453+ } ) ;
454+
455+ it ( 'should fail gracefully when no workspace-folder and no config in current directory' , async function ( ) {
456+ const tempDir = path . join ( os . tmpdir ( ) , 'devcontainer-build-test-' + Date . now ( ) ) ;
457+ await shellExec ( `mkdir -p ${ tempDir } ` ) ;
458+ const absoluteTmpPath = path . resolve ( __dirname , 'tmp' ) ;
459+ const absoluteCli = `npx --prefix ${ absoluteTmpPath } devcontainer` ;
460+ const originalCwd = process . cwd ( ) ;
461+ try {
462+ process . chdir ( tempDir ) ;
463+ let success = false ;
464+ try {
465+ await shellExec ( `${ absoluteCli } build` ) ;
466+ success = true ;
467+ } catch ( error ) {
468+ assert . equal ( error . error . code , 1 , 'Should fail with exit code 1' ) ;
469+ const res = JSON . parse ( error . stdout ) ;
470+ assert . equal ( res . outcome , 'error' ) ;
471+ assert . match ( res . message , / D e v c o n t a i n e r c o n f i g .* n o t f o u n d / ) ;
472+ }
473+ assert . equal ( success , false , 'expect non-successful call' ) ;
474+ } finally {
475+ process . chdir ( originalCwd ) ;
476+ await shellExec ( `rm -rf ${ tempDir } ` ) ;
477+ }
478+ } ) ;
479+
436480 } ) ;
437481} ) ;
0 commit comments