- Consolidated CLI commands into [build](cci:1://file:///c:/Users/vishe/WorkSpace/code/aetos/doc-forge/docforge/cli/mkdocs/logic.py:48:0-58:46) and [serve](cci:1://file:///c:/Users/vishe/WorkSpace/code/aetos/doc-forge/docforge/cli/commands.py:70:0-92:32) using `--mkdocs` and `--mcp` flags. - Separated CLI orchestration logic into [docforge/cli/mkdocs/logic.py](cci:7://file:///c:/Users/vishe/WorkSpace/code/aetos/doc-forge/docforge/cli/mkdocs/logic.py:0:0-0:0) and [docforge/cli/mcp/logic.py](cci:7://file:///c:/Users/vishe/WorkSpace/code/aetos/doc-forge/docforge/cli/mcp/logic.py:0:0-0:0). - Moved command definitions to [docforge/cli/commands.py](cci:7://file:///c:/Users/vishe/WorkSpace/code/aetos/doc-forge/docforge/cli/commands.py:0:0-0:0), making [main.py](cci:7://file:///c:/Users/vishe/WorkSpace/code/aetos/doc-forge/docforge/cli/main.py:0:0-0:0) a thin entry point. - Aligned [.pyi](cci:7://file:///c:/Users/vishe/WorkSpace/code/aetos/doc-forge/docforge/cli/main.pyi:0:0-0:0) type stubs with [.py](cci:7://file:///c:/Users/vishe/WorkSpace/code/aetos/doc-forge/tests/conftest.py:0:0-0:0) implementations across the package. - Added missing docstrings to internal helper functions and core classes. - Restructured tests into `tests/mkdocs/` and `tests/mcp/`. - Updated navigation specification to reflect the new project structure.
127 lines
2.6 KiB
Python
127 lines
2.6 KiB
Python
import sys
|
|
import json
|
|
import pytest
|
|
from pathlib import Path
|
|
|
|
from click.testing import CliRunner
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_package(tmp_path: Path):
|
|
"""
|
|
Creates a temporary Python package and adds it to sys.path.
|
|
"""
|
|
pkg = tmp_path / "testpkg"
|
|
pkg.mkdir()
|
|
(pkg / "__init__.py").write_text('"""Test package."""\n')
|
|
|
|
sys.path.insert(0, str(tmp_path))
|
|
yield pkg
|
|
sys.path.remove(str(tmp_path))
|
|
|
|
|
|
@pytest.fixture
|
|
def cli_runner() -> CliRunner:
|
|
"""Click CLI runner."""
|
|
return CliRunner()
|
|
|
|
|
|
@pytest.fixture
|
|
def fake_mkdocs_yml(tmp_path: Path) -> Path:
|
|
"""Create a minimal mkdocs.yml file."""
|
|
yml = tmp_path / "mkdocs.yml"
|
|
yml.write_text(
|
|
"""
|
|
site_name: Test Docs
|
|
nav: []
|
|
plugins:
|
|
- mkdocstrings
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
return yml
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_mkdocs_load_config(monkeypatch):
|
|
"""Mock mkdocs.config.load_config."""
|
|
def fake_load_config(path):
|
|
return object() # dummy config object
|
|
|
|
monkeypatch.setattr(
|
|
"mkdocs.config.load_config",
|
|
fake_load_config,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_mkdocs_build(monkeypatch):
|
|
called = {"value": False}
|
|
|
|
def fake_build(config):
|
|
called["value"] = True
|
|
|
|
monkeypatch.setattr(
|
|
"mkdocs.commands.build.build",
|
|
fake_build,
|
|
)
|
|
return lambda: called["value"]
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_mkdocs_serve(monkeypatch):
|
|
called = {"value": False}
|
|
|
|
def fake_serve(*args, **kwargs):
|
|
called["value"] = True
|
|
|
|
monkeypatch.setattr(
|
|
"mkdocs.commands.serve.serve",
|
|
fake_serve,
|
|
)
|
|
return lambda: called["value"]
|
|
|
|
@pytest.fixture
|
|
def fake_mcp_docs(tmp_path: Path) -> Path:
|
|
"""
|
|
Create a minimal valid MCP bundle in mcp_docs/.
|
|
"""
|
|
mcp_root = tmp_path / "mcp_docs"
|
|
modules_dir = mcp_root / "modules"
|
|
modules_dir.mkdir(parents=True)
|
|
|
|
(mcp_root / "index.json").write_text(
|
|
json.dumps({"project": "test", "type": "docforge-model"}),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
(mcp_root / "nav.json").write_text(
|
|
json.dumps([]),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
(modules_dir / "test.mod.json").write_text(
|
|
json.dumps({"module": "test.mod", "content": {}}),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
return mcp_root
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_mcp_server_run(monkeypatch):
|
|
"""
|
|
Mock MCPServer.run so no real server is started.
|
|
"""
|
|
called = {"value": False}
|
|
|
|
def fake_run(self, transport="streamable-http"):
|
|
called["value"] = True
|
|
|
|
monkeypatch.setattr(
|
|
"docforge.servers.MCPServer.run",
|
|
fake_run,
|
|
)
|
|
|
|
return lambda: called["value"]
|