295089c748
Constellation-themed fiona-assistant git diff, tmp/ gitignore, SPEC 1.18.1. Version 1.17.0. Co-authored-by: Cursor <cursoragent@cursor.com>
112 lines
3.6 KiB
Python
112 lines
3.6 KiB
Python
"""Tests for fiona.gittool.diff_report."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import pathlib
|
|
import subprocess
|
|
|
|
import git
|
|
import pytest
|
|
|
|
from fiona.gittool import diff_report
|
|
from fiona.wiki.ignore import wiki_gitignore_patterns
|
|
|
|
|
|
def _configure_test_repo(repo: git.Repo) -> None:
|
|
"""Set local git identity for commits in tests.
|
|
|
|
Generated by CURSOR: 2026-10-19 - isolated git user for pytest.
|
|
"""
|
|
with repo.config_writer() as config:
|
|
config.set_value("user", "email", "fiona-test@example.com")
|
|
config.set_value("user", "name", "Fiona Test")
|
|
|
|
|
|
@pytest.fixture
|
|
def wiki_git_repo(tmp_path: pathlib.Path) -> pathlib.Path:
|
|
"""Git repo with fiona-settings.json and main + HEAD commits."""
|
|
repo = git.Repo.init(tmp_path)
|
|
_configure_test_repo(repo)
|
|
settings = {
|
|
"fiona": {
|
|
"wiki": {
|
|
"graph": {
|
|
"theme": "night-sky",
|
|
}
|
|
}
|
|
}
|
|
}
|
|
(tmp_path / "fiona-settings.json").write_text(
|
|
json.dumps(settings),
|
|
encoding="utf-8",
|
|
)
|
|
(tmp_path / "README.md").write_text("base\n", encoding="utf-8")
|
|
repo.index.add(["fiona-settings.json", "README.md"])
|
|
repo.index.commit("base on main")
|
|
# Keep ``main`` at the first commit so HEAD can advance for a non-empty diff.
|
|
repo.create_head("main")
|
|
(tmp_path / "README.md").write_text("base\nchanged\n", encoding="utf-8")
|
|
repo.index.add(["README.md"])
|
|
repo.index.commit("feature commit")
|
|
return tmp_path
|
|
|
|
|
|
def test_wiki_gitignore_includes_tmp() -> None:
|
|
"""SPEC 7.12.5: packaged ignore lists wiki tmp/."""
|
|
patterns = wiki_gitignore_patterns()
|
|
assert "tmp/" in patterns
|
|
|
|
|
|
def test_resolve_default_base_uses_main(wiki_git_repo: pathlib.Path) -> None:
|
|
"""Default base is main when it exists."""
|
|
assert diff_report.resolve_default_base(wiki_git_repo) == "main"
|
|
|
|
|
|
def test_theme_css_uses_constellation(wiki_git_repo: pathlib.Path) -> None:
|
|
"""HTML theme CSS reflects night-sky background."""
|
|
css = diff_report.theme_css_for_wiki(wiki_git_repo)
|
|
assert "--bg: #070b14" in css
|
|
|
|
|
|
def test_write_report_under_tmp(wiki_git_repo: pathlib.Path) -> None:
|
|
"""Default output path is wiki tmp/ and HTML includes diff content."""
|
|
out = diff_report.default_output_path(wiki_git_repo, wiki_git_repo, "HEAD")
|
|
assert out.parent == wiki_git_repo / "tmp"
|
|
path = diff_report.write_report(
|
|
wiki_git_repo,
|
|
out,
|
|
base="main",
|
|
head="HEAD",
|
|
title=None,
|
|
subtitle=None,
|
|
open_details=True,
|
|
)
|
|
text = path.read_text(encoding="utf-8")
|
|
assert "changed" in text
|
|
assert "night-sky" not in text # theme name is not embedded; colors are
|
|
assert "--bg: #070b14" in text
|
|
|
|
|
|
def test_main_prints_path(wiki_git_repo: pathlib.Path, monkeypatch) -> None:
|
|
"""CLI exits 0 and prints the report path."""
|
|
monkeypatch.chdir(wiki_git_repo)
|
|
code = diff_report.main(["--base", "main"])
|
|
assert code == 0
|
|
|
|
|
|
def test_git_check_ignore_tmp(wiki_git_repo: pathlib.Path) -> None:
|
|
"""tmp/ is ignored after ensure_wiki_gitignore."""
|
|
from fiona.wiki.ignore import ensure_wiki_gitignore
|
|
|
|
ensure_wiki_gitignore(wiki_git_repo)
|
|
(wiki_git_repo / "tmp").mkdir()
|
|
report = wiki_git_repo / "tmp" / "sample.html"
|
|
report.write_text("<html></html>", encoding="utf-8")
|
|
result = subprocess.run(
|
|
["git", "check-ignore", "-q", "tmp/sample.html"],
|
|
cwd=wiki_git_repo,
|
|
check=False,
|
|
)
|
|
assert result.returncode == 0
|