69 lines
2.5 KiB
Python
69 lines
2.5 KiB
Python
from pathlib import Path
|
|
|
|
from rdb_discovery.templates import CONTEXT_FILES, write_file_if_missing
|
|
|
|
|
|
def test_write_file_if_missing(tmp_path: Path) -> None:
|
|
assert write_file_if_missing(tmp_path, "context/test.md", "hello") is True
|
|
assert (tmp_path / "context" / "test.md").read_text(encoding="utf-8") == "hello"
|
|
assert write_file_if_missing(tmp_path, "context/test.md", "changed") is False
|
|
assert (tmp_path / "context" / "test.md").read_text(encoding="utf-8") == "hello"
|
|
|
|
|
|
def test_all_context_files_have_content() -> None:
|
|
for path, content in CONTEXT_FILES.items():
|
|
assert content.strip(), f"Empty content for {path}"
|
|
|
|
|
|
def test_init_creates_all_files(tmp_path: Path) -> None:
|
|
for relative_path, content in CONTEXT_FILES.items():
|
|
write_file_if_missing(tmp_path, relative_path, content)
|
|
|
|
for relative_path in CONTEXT_FILES:
|
|
assert (tmp_path / relative_path).exists(), f"Missing {relative_path}"
|
|
|
|
|
|
def test_init_skips_existing_files(tmp_path: Path) -> None:
|
|
skipped = []
|
|
|
|
for relative_path, content in CONTEXT_FILES.items():
|
|
target = tmp_path / relative_path
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
target.write_text("existing", encoding="utf-8")
|
|
result = write_file_if_missing(tmp_path, relative_path, content)
|
|
if not result:
|
|
skipped.append(relative_path)
|
|
|
|
assert skipped == list(CONTEXT_FILES)
|
|
assert (tmp_path / "TASKS.md").read_text(encoding="utf-8") == "existing"
|
|
|
|
|
|
def test_required_context_templates_exist() -> None:
|
|
"""Ensure all six required standard context files are defined."""
|
|
required = [
|
|
"context/company-context.md",
|
|
"context/development-context.md",
|
|
"context/infrastructure-context.md",
|
|
"context/agent-guidelines.md",
|
|
"context/project-brief.md",
|
|
"context/architecture.md",
|
|
]
|
|
for rel_path in required:
|
|
assert rel_path in CONTEXT_FILES, f"Missing template: {rel_path}"
|
|
|
|
|
|
def test_required_templates_have_headings_and_guidance() -> None:
|
|
"""Each required context file must contain headings and placeholder guidance."""
|
|
required = [
|
|
"context/company-context.md",
|
|
"context/development-context.md",
|
|
"context/infrastructure-context.md",
|
|
"context/agent-guidelines.md",
|
|
"context/project-brief.md",
|
|
"context/architecture.md",
|
|
]
|
|
for rel_path in required:
|
|
content = CONTEXT_FILES[rel_path]
|
|
assert "# " in content, f"{rel_path} missing H1 heading"
|
|
assert "## " in content, f"{rel_path} missing H2 headings"
|