| | @@ -0,0 +1,164 @@ |
| 1 | +import shutifrom unittest.moctil
|
| 2 | +from import UTC, datetime
|
| 3 | +from pathlib import Path
|
| 4 | +
|
| 5 | +import pytest
|
| 6 | +
|
| 7 | +from .models impossilReader, Time
|
| 8 | +# --- Reader tests ---
|
| 9 | +
|
| 10 | +
|
| 11 | +@pytest.mark.django_db
|
| 12 | +class TestFossilReader:
|
| 13 | + @pytest.fixture
|
| 14 | + def repo_path(self, tmp_path):
|
| 15 | + src = Path("/tmp/fossil-setup/frontend-app.fossil")
|
| 16 | + if not src.exists():
|
| 17 | + pytest.skip("Test fossil repo not available")
|
| 18 | + dest = tmp_path / "test.fossil"
|
| 19 | + shutil.copy2(src, dest)
|
| 20 | + return dest
|
| 21 | +
|
| 22 | + def test_get_metadata(self, repo_path):
|
| 23 | + with FossilReader(repo_path) as reader:
|
| 24 | + meta = reader.get_metadata()
|
| 25 | + assert meta.checkin_count >= 2
|
| 26 | +
|
| 27 | + def test_get_timeline(self, repo_path):
|
| 28 | + with FossilReader(repo_path) as reader:
|
| 29 | + entries = reader.get_timeline(limit=10)
|
| 30 | + assert len(entries) > 0
|
| 31 | + assert entries[0].uuid
|
| 32 | + assert entries[0].user
|
| 33 | +
|
| 34 | + def test_get_timeline_filter_by_type(self, repo_path):
|
| 35 | + with FossilReader(repo_path) as reader:
|
| 36 | + checkins = reader.get_timeline(limit=10, event_type="ci")
|
| 37 | + for e in checkins:
|
| 38 | + assert e.event_type == "ci"
|
| 39 | +
|
| 40 | + def test_get_latest_checkin_uuid(self, repo_path):
|
| 41 | + with FossilReader(repo_path) as reader:
|
| 42 | + uuid = reader.get_latest_checkin_uuid()
|
| 43 | + assert uuid is not None
|
| 44 | + assert len(uuid) > 10
|
| 45 | +
|
| 46 | + def test_get_files_at_checkin(self, repo_path):
|
| 47 | + with FossilReader(repo_path) as reader:
|
| 48 | + files = reader.get_files_at_checkin()
|
| 49 | + assert len(files) > 0
|
| 50 | + names = [f.name for f in files]
|
| 51 | + assert any("README" in n or "index" in n or "utils" in n for n in names)
|
| 52 | +
|
| 53 | + def test_get_file_content(self, repo_path):
|
| 54 | + with FossilReader(repo_path) as reader:
|
| 55 | + files = reader.get_files_at_checkin()
|
| 56 | + if files:
|
| 57 | + content = reader.get_file_content(files[0].uuid)
|
| 58 | + assert len(content) > 0
|
| 59 | +
|
| 60 | + def test_get_wiki_pages(self, repo_path):
|
| 61 | + with FossilReader(repo_path) as reader:
|
| 62 | + pages = reader.get_wiki_pages()
|
| 63 | + assert len(pages) >= 2
|
| 64 | + names = [p.name for p in pages]
|
| 65 | + assert "Home" in names
|
| 66 | +
|
| 67 | + def test_get_wiki_page_content(self, repo_path):
|
| 68 | + with FossilReader(repo_path) as reader:
|
| 69 | + page = reader.get_wiki_page("Home")
|
| 70 | + assert page is not None
|
| 71 | + assert len(page.content) > 0
|
| 72 | +
|
| 73 | + def test_get_checkin_detail(self, repo_path):
|
| 74 | + with FossilReader(repo_path) as reader:
|
| 75 | + uuid = reader.get_latest_checkin_uuid()
|
| 76 | + detail = reader.get_checkin_detail(uuid[:8])
|
| 77 | + assert detail is not None
|
| 78 | + assert detail.uuid == uuid
|
| 79 | + assert detail.comment
|
| 80 | + assert len(detail.files_changed) > 0
|
| 81 | +
|
| 82 | + def test_get_commit_activity(self, repo_path):
|
| 83 | + with FossilReader(repo_path) as reader:
|
| 84 | + activity = reader.get_commit_activity(weeks=4)
|
| 85 | + assert len(activity) == 4
|
| 86 | + total = sum(a["count"] for a in activity)
|
| 87 | + assert total > 0
|
| 88 | +
|
| 89 | + def test_get_user_activity(self, repo_path):
|
| 90 | + with FossilReader(repo_path) as reader:
|
| 91 | + activity = reader.get_user_activity("ragelink")
|
| 92 | + assert activity["checkin_count"] > 0
|
| 93 | + assert len(activity["checkins"]) > 0
|
| 94 | +
|
| 95 | +
|
| 96 | +# --- Helper function tests ---
|
| 97 | +
|
| 98 | +
|
| 99 | +class TestExtractWikiContent:
|
| 100 | + def test_basic_extraction(self):
|
| 101 | + artifact = "D 2026-01-01T00:00:00\nL TestPage\nU user\nW 5\nhello\nZ abc123"
|
| 102 | + assert _extract_wiki_content(artifact) == "hello"
|
| 103 | +
|
| 104 | + def test_multiline_content(self):
|
| 105 | + artifact = "D 2026-01-01T00:00:00\nL Page\nU user\nW 11\nhello\nworld\nZ abc123"
|
| 106 | + assert _extract_wiki_content(artifact) == "hello\nworld"
|
| 107 | +
|
| 108 | + def test_empty_content(self):
|
| 109 | + artifact = "D 2026-01-01T00:00:00\nL Page\nU user\nW 0\n\nZ abc123"
|
| 110 | + assert _extract_wiki_content(artifact) == ""
|
| 111 | +
|
| 112 | + def test_no_w_card(self):
|
| 113 | + assert _extract_wiki_content("just some text") == ""
|
| 114 | +
|
| 115 | +
|
| 116 | +class TestApplyFossilDelta:
|
| 117 | + def test_copy_command(self):
|
| 118 | + source = b"Hello, World!"
|
| 119 | + # Delta: output size 5, copy 5 bytes from offset 0
|
| 120 | + # This is a simplified test
|
| 121 | + result = _apply_fossil_delta(source, b"")
|
| 122 | + assert result == source # empty delta returns source
|
| 123 | +
|
| 124 | + def test_empty_delta(self):
|
| 125 | + source = b"test content"
|
| 126 | + result = _apply_fossil_delta(source, b"")
|
| 127 | + asserModel tests ---
|
| 128 | +
|
| 129 | +
|
| 130 | +@pytest.mark.d _make_entry(rid=2, branch="feature", parent_rid=1, rail=1),
|
| 131 | + _make_entry(rid=1, parent_rid=0, rail=0),
|
| 132 | + ]
|
| 133 | + result = _compute_dag_graph(entries)
|
| 134 | + # At row index 1 (rid=3), both rail 0 and rail 1 should be active
|
| 135 | + # because rail 1 spans from index 0 (rid=4) to index 2 (rid=2)
|
| 136 | + # and rail 0 spans from index 1 (rid=3) to index 3 (rid=1)
|
| 137 | + active_xs = {line["x"] for line in result[1]["lines"]}
|
| 138 | + rail_0_x = 20 + 0 * 16 # 20
|
| 139 | + rail_1_x = 20 + 1 * 16 # 36
|
| 140 | + _fals2, branch="feature", parent_rid=1 expected filename
|
| 141 | + repo = FossilRepository.objects.get(proje# The /data/repos di 0 * 16 # 20
|
| 142 | + rail_1_x = 20 + 1 * 16 # 36
|
| 143 | + assert rail_0_x in active_xs
|
| 144 | + assert rail_1_x in active_xs
|
| 145 | +
|
| 146 | + def test_graph_width_accommodates_rails(self):
|
| 147 | + """Graph width should be wide enough for all rails plus padding."""
|
| 148 | + entries = [
|
| 149 | + _make_entry(rid=3, branch="b2", parent_rid=1, rail=2),
|
| 150 | + _make_entry(rid=2, branch="b1", parent_rid=1, rail=1),
|
| 151 | + _make_entry(rid=1, parent_rid=0, rail=0),
|
| 152 | + ]
|
| 153 | + result = _compute_dag_graph(entries)
|
| 154 | + # max_rail=2, graph_width = 20 + (2+2)*16 = 84
|
| 155 | + assert result[0]["graph_width"] == 84
|
| 156 | +
|
| 157 | + def test_connector_geometry(self):
|
| 158 | + """Fork connector left and width should span from the lower rail to the higher rail."""
|
| 159 | + entries = [
|
| 160 | + _make_entry(rid=2, branch="feature", parent_rid=1, rail=2), # fork from rail 0
|
| 161 | + _make_entry(rid=1, parent_rid=0, rail=0),
|
| 162 | + ]
|
| 163 | + result = _compute_dag_graph(entries)
|
| 164 | + |