11"""Checks for the local atlas preview helper."""
22
3+ import sys
34from pathlib import Path
45
6+ from scripts import serve_atlas
7+
58ROOT = Path (__file__ ).resolve ().parents [1 ]
69SERVER_PATH = ROOT / "scripts" / "serve_atlas.py"
710MAKEFILE_PATH = ROOT / "Makefile"
@@ -25,6 +28,51 @@ def test_preview_server_enables_address_reuse_before_binding():
2528 assert "server.allow_reuse_address = True" not in script
2629
2730
31+ def test_preview_server_reports_root_url_when_serving_atlas_directory (tmp_path , monkeypatch , capsys ):
32+ atlas_dir = tmp_path / "atlas"
33+ atlas_dir .mkdir ()
34+ (atlas_dir / "index.html" ).write_text ("<!doctype html>" , encoding = "utf-8" )
35+
36+ class FakeServer :
37+ def __init__ (self , address , handler ):
38+ self .address = address
39+ self .handler = handler
40+
41+ def serve_forever (self ):
42+ raise KeyboardInterrupt
43+
44+ monkeypatch .setattr (serve_atlas , "QuietAtlasServer" , FakeServer )
45+ monkeypatch .setattr (sys , "argv" , ["serve_atlas.py" , "4321" , "--directory" , str (atlas_dir )])
46+
47+ serve_atlas .main ()
48+
49+ output = capsys .readouterr ().out
50+ assert f"Serving atlas preview from { atlas_dir .resolve ()} at http://localhost:4321/" in output
51+ assert "http://localhost:4321/atlas/" not in output
52+
53+
54+ def test_preview_server_reports_atlas_url_when_serving_repo_root (tmp_path , monkeypatch , capsys ):
55+ atlas_dir = tmp_path / "atlas"
56+ atlas_dir .mkdir ()
57+ (atlas_dir / "index.html" ).write_text ("<!doctype html>" , encoding = "utf-8" )
58+
59+ class FakeServer :
60+ def __init__ (self , address , handler ):
61+ self .address = address
62+ self .handler = handler
63+
64+ def serve_forever (self ):
65+ raise KeyboardInterrupt
66+
67+ monkeypatch .setattr (serve_atlas , "QuietAtlasServer" , FakeServer )
68+ monkeypatch .setattr (sys , "argv" , ["serve_atlas.py" , "4321" , "--directory" , str (tmp_path )])
69+
70+ serve_atlas .main ()
71+
72+ output = capsys .readouterr ().out
73+ assert f"Serving atlas preview from { tmp_path .resolve ()} at http://localhost:4321/atlas/" in output
74+
75+
2876def test_makefile_exposes_atlas_preview_target ():
2977 makefile = MAKEFILE_PATH .read_text (encoding = "utf-8" )
3078
0 commit comments