From 0339a31186ad10bdd69d74862c22e0f95b817804 Mon Sep 17 00:00:00 2001 From: Mike-7777777 <41225783+Mike-7777777@users.noreply.github.com> Date: Thu, 10 Sep 2026 16:18:12 +0800 Subject: [PATCH] fix: render an overview before projects exist --- src/generate_project_dashboard.py | 6 +++++- tests/test_project_dashboard.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/generate_project_dashboard.py b/src/generate_project_dashboard.py index 4e69ebc..0702043 100644 --- a/src/generate_project_dashboard.py +++ b/src/generate_project_dashboard.py @@ -781,7 +781,11 @@ def render_one(slug): def render_all(only=None): - slugs = sorted(d.name for d in PROJECTS_DIR.iterdir() if d.is_dir() and (d / "state.md").exists()) + try: + entries = list(PROJECTS_DIR.iterdir()) + except FileNotFoundError: + entries = [] + slugs = sorted(d.name for d in entries if d.is_dir() and (d / "state.md").exists()) selected = set(only) if only is not None else None unknown = sorted(selected - set(slugs)) if selected is not None else [] if unknown: diff --git a/tests/test_project_dashboard.py b/tests/test_project_dashboard.py index b4ac9ac..eec29c0 100644 --- a/tests/test_project_dashboard.py +++ b/tests/test_project_dashboard.py @@ -308,3 +308,34 @@ def test_declared_project_provenance_cannot_silently_disappear(dashboard) -> Non with pytest.raises(dashboard.DashboardDataError, match="declares idea_provenance"): dashboard.load_project("demo") + + +@pytest.mark.parametrize("missing", [True, False]) +def test_cli_renders_an_empty_project_overview(dashboard, monkeypatch, capsys, missing): + if missing: + monkeypatch.setattr(dashboard, "PROJECTS_DIR", dashboard.PROJECT_ROOT / "absent" / "projects") + monkeypatch.setattr(sys, "argv", [str(SCRIPT), "--all"]) + + assert dashboard.main() == 0 + + output = capsys.readouterr() + assert "(0 projects)" in output.out + assert output.err == "" + page = (dashboard.PROJECT_ROOT / "dashboard_index.html").read_text(encoding="utf-8") + assert "0 projects" in page + if missing: + assert not dashboard.PROJECTS_DIR.exists() + + +def test_missing_projects_directory_still_rejects_unknown_filter(dashboard, monkeypatch): + monkeypatch.setattr(dashboard, "PROJECTS_DIR", dashboard.PROJECT_ROOT / "absent" / "projects") + with pytest.raises(SystemExit, match=r"unknown project.*missing.*none"): + dashboard.render_all(only={"missing"}) + + +def test_projects_path_must_be_a_directory(dashboard, monkeypatch): + invalid = dashboard.PROJECT_ROOT / "not-a-directory" + invalid.write_text("invalid", encoding="utf-8") + monkeypatch.setattr(dashboard, "PROJECTS_DIR", invalid) + with pytest.raises(NotADirectoryError): + dashboard.render_all()