from pathlib import Path from docforge.cli.main import cli def test_mkdocs_build_full_flow( cli_runner, mock_mkdocs_build, mock_mkdocs_load_config, tmp_path, ): # This test covers what used to be generate + mkdocs + build with cli_runner.isolated_filesystem(): cwd = Path.cwd() pkg = cwd / "testpkg" pkg.mkdir() (pkg / "__init__.py").write_text("") (pkg / "mod.py").write_text("def f(): ...\n") nav_file = cwd / "docforge.nav.yml" nav_file.write_text("home: testpkg/index.md\ngroups: {}\n") # We need to create a dummy testpkg/index.md for nav resolution if it's there # But generate_sources will create it. # Wait, the current logic runs generate_sources first, THEN generate_config. result = cli_runner.invoke( cli, [ "build", "--mkdocs", "--module", "testpkg", "--site-name", "Test Site", "--docs-dir", "docs", "--mkdocs-yml", "mkdocs.yml", ], ) assert result.exit_code == 0 assert mock_mkdocs_build() is True assert (cwd / "mkdocs.yml").exists() assert (cwd / "docs" / "testpkg" / "mod.md").exists() def test_mkdocs_build_missing_module_fails(cli_runner): result = cli_runner.invoke(cli, ["build", "--mkdocs", "--site-name", "Test"]) assert result.exit_code != 0 assert "--module is required" in result.output def test_mkdocs_build_without_site_name_uses_module_as_default_full_flow( cli_runner, mock_mkdocs_build, mock_mkdocs_load_config, ): # Full integration test: real generation, real config, mocked mkdocs build with cli_runner.isolated_filesystem(): cwd = Path.cwd() # Create a minimal Python package pkg = cwd / "testpkg" pkg.mkdir() (pkg / "__init__.py").write_text("") (pkg / "mod.py").write_text("def f(): ...\n") # Create nav spec expected by generate_config nav_file = cwd / "docforge.nav.yml" nav_file.write_text( "home: testpkg/index.md\ngroups: {}\n", encoding="utf-8", ) result = cli_runner.invoke( cli, [ "build", "--mkdocs", "--module", "testpkg", "--docs-dir", "docs", "--mkdocs-yml", "mkdocs.yml", ], ) assert result.exit_code == 0 assert mock_mkdocs_build() is True # MkDocs config must exist mkdocs_yml = cwd / "mkdocs.yml" assert mkdocs_yml.exists() # Site name must default to module name content = mkdocs_yml.read_text() assert "site_name: testpkg" in content # Docs must be generated assert (cwd / "docs" / "testpkg" / "mod.md").exists()