@@ -473,3 +473,61 @@ def test_version_output(self):
473473 assert result .exit_code == 0
474474 assert "configdrift" in result .stdout
475475 assert "0.1.0" in result .stdout
476+
477+
478+ class TestScanEmptyGuards :
479+ """Regression: scan must not report a false-green 'no drift' when nothing loaded."""
480+
481+ def test_scan_all_dirs_missing_exits_1 (self ):
482+ with tempfile .TemporaryDirectory () as tmpdir :
483+ result = runner .invoke (
484+ app , ["scan" , str (Path (tmpdir ) / "nope1" ), str (Path (tmpdir ) / "nope2" )]
485+ )
486+ assert result .exit_code == 1
487+ # Either the baseline-not-found guard or the empty-scan guard fires.
488+ assert (
489+ "not found" in result .stdout
490+ or "No config files could be loaded" in result .stdout
491+ )
492+
493+ def test_scan_empty_dirs_exits_1 (self ):
494+ with tempfile .TemporaryDirectory () as tmpdir :
495+ dev = Path (tmpdir ) / "dev"
496+ prod = Path (tmpdir ) / "prod"
497+ dev .mkdir ()
498+ prod .mkdir ()
499+ result = runner .invoke (app , ["scan" , str (dev ), str (prod )])
500+ assert result .exit_code == 1
501+ assert "No config files could be loaded" in result .stdout
502+
503+ def test_scan_baseline_dir_missing_exits_1 (self ):
504+ with tempfile .TemporaryDirectory () as tmpdir :
505+ prod = Path (tmpdir ) / "prod"
506+ prod .mkdir ()
507+ (prod / "config.yaml" ).write_text (yaml .dump ({"host" : "prod.example.com" }))
508+ result = runner .invoke (app , ["scan" , str (prod ), "--baseline" , "dev" ])
509+ assert result .exit_code == 1
510+
511+ def test_scan_baseline_loaded_nothing_exits_1 (self ):
512+ """Baseline dir exists but only contains unparseable files -> refuse empty-baseline diff."""
513+ with tempfile .TemporaryDirectory () as tmpdir :
514+ dev = Path (tmpdir ) / "dev"
515+ prod = Path (tmpdir ) / "prod"
516+ dev .mkdir ()
517+ prod .mkdir ()
518+ (dev / "broken.yaml" ).write_text (":::: not yaml :::\n " )
519+ (prod / "config.yaml" ).write_text (yaml .dump ({"host" : "prod.example.com" }))
520+ result = runner .invoke (app , ["scan" , str (dev ), str (prod )])
521+ assert result .exit_code == 1
522+ assert "loaded no config" in result .stdout
523+
524+ def test_scan_healthy_still_works (self ):
525+ with tempfile .TemporaryDirectory () as tmpdir :
526+ dev = Path (tmpdir ) / "dev"
527+ prod = Path (tmpdir ) / "prod"
528+ dev .mkdir ()
529+ prod .mkdir ()
530+ (dev / "config.yaml" ).write_text (yaml .dump ({"host" : "localhost" }))
531+ (prod / "config.yaml" ).write_text (yaml .dump ({"host" : "prod.example.com" }))
532+ result = runner .invoke (app , ["scan" , str (dev ), str (prod )])
533+ assert result .exit_code == 0
0 commit comments