gabriel / musehub public
test_repo_card_performance.py python
145 lines 5.1 KB
Raw
sha256:fc04e4cae9e1774d6a21b65c45daeed0e6787eb581d13aa1b03bfe9384a34226 Merge branch 'fix/two-column-scroll-layout' into dev Human 9 days ago
1 """
2 Tier 7 — Performance tests for enrich_repo_cards().
3
4 These tests establish latency baselines that should hold on the CI database.
5 They are deliberately conservative — failing here signals a query regression,
6 not a slow machine.
7
8 Test IDs
9 --------
10 T700 — single-repo enrichment completes in < 100 ms
11 T701 — 10-repo batch completes in < 200 ms (sub-linear scaling)
12 T702 — p95 latency across 20 repeated single-repo calls is < 80 ms
13 T703 — enriching an empty repo (no intel) is faster than one with full data
14 """
15 from __future__ import annotations
16
17 import statistics
18 import time
19 from datetime import datetime, timedelta, timezone
20
21 import pytest
22 from sqlalchemy.ext.asyncio import AsyncSession
23
24 from musehub.db.musehub_intel_models import MusehubIntelBreakageMeta, MusehubIntelDead, MusehubSymbolIntel
25 from musehub.services.repo_card_enrichment import enrich_repo_cards
26 from tests.factories import create_commit, create_repo
27
28
29 def _utc_now() -> datetime:
30 return datetime.now(tz=timezone.utc)
31
32
33 async def _seed_full_repo(db: AsyncSession) -> str:
34 """Seed a repo with commits, symbols, dead rows, and breakage meta."""
35 repo = await create_repo(db, visibility="public")
36 for i in range(10):
37 await create_commit(db, repo.repo_id, timestamp=_utc_now() - timedelta(days=i))
38 for i in range(20):
39 db.add(MusehubSymbolIntel(
40 repo_id=repo.repo_id,
41 address=f"src/mod.py::fn_{i}",
42 churn_30d=i,
43 blast=i * 2,
44 ))
45 db.add(MusehubIntelDead(
46 repo_id=repo.repo_id,
47 address="src/old.py::dead_fn",
48 kind="function",
49 confidence="high",
50 ref="main",
51 ))
52 db.add(MusehubIntelBreakageMeta(
53 repo_id=repo.repo_id,
54 total_issues=1,
55 error_count=0,
56 warning_count=1,
57 file_count=1,
58 ref="main",
59 ))
60 await db.commit()
61 return repo.repo_id
62
63
64 # ---------------------------------------------------------------------------
65 # T700 — single-repo enrichment < 100 ms
66 # ---------------------------------------------------------------------------
67
68 @pytest.mark.asyncio
69 async def test_t700_single_repo_under_100ms(db_session: AsyncSession) -> None:
70 """T700: enriching one fully-populated repo completes in < 100 ms."""
71 repo_id = await _seed_full_repo(db_session)
72
73 t0 = time.monotonic()
74 await enrich_repo_cards(db_session, [repo_id])
75 elapsed_ms = (time.monotonic() - t0) * 1000
76
77 assert elapsed_ms < 100, f"Single-repo enrichment took {elapsed_ms:.1f} ms"
78
79
80 # ---------------------------------------------------------------------------
81 # T701 — 10-repo batch < 200 ms
82 # ---------------------------------------------------------------------------
83
84 @pytest.mark.asyncio
85 async def test_t701_ten_repo_batch_under_200ms(db_session: AsyncSession) -> None:
86 """T701: enriching 10 repos completes in < 200 ms (sub-linear vs T700)."""
87 repo_ids = [await _seed_full_repo(db_session) for _ in range(10)]
88
89 t0 = time.monotonic()
90 await enrich_repo_cards(db_session, repo_ids)
91 elapsed_ms = (time.monotonic() - t0) * 1000
92
93 assert elapsed_ms < 200, f"10-repo batch took {elapsed_ms:.1f} ms"
94
95
96 # ---------------------------------------------------------------------------
97 # T702 — p95 latency across 20 calls < 80 ms
98 # ---------------------------------------------------------------------------
99
100 @pytest.mark.asyncio
101 async def test_t702_p95_single_repo_under_80ms(db_session: AsyncSession) -> None:
102 """T702: p95 latency across 20 repeated single-repo calls is < 80 ms."""
103 repo_id = await _seed_full_repo(db_session)
104
105 latencies = []
106 for _ in range(20):
107 t0 = time.monotonic()
108 await enrich_repo_cards(db_session, [repo_id])
109 latencies.append((time.monotonic() - t0) * 1000)
110
111 p95 = statistics.quantiles(latencies, n=20)[18] # 95th percentile
112 assert p95 < 80, f"p95 latency was {p95:.1f} ms — expected < 80 ms"
113
114
115 # ---------------------------------------------------------------------------
116 # T703 — empty repo faster than full repo
117 # ---------------------------------------------------------------------------
118
119 @pytest.mark.asyncio
120 async def test_t703_empty_repo_faster_than_full_repo(db_session: AsyncSession) -> None:
121 """T703: enriching an empty repo is not slower than a fully-populated one."""
122 full_id = await _seed_full_repo(db_session)
123 empty_repo = await create_repo(db_session, visibility="public")
124 empty_id = empty_repo.repo_id
125
126 samples_full = []
127 samples_empty = []
128
129 for _ in range(10):
130 t0 = time.monotonic()
131 await enrich_repo_cards(db_session, [full_id])
132 samples_full.append(time.monotonic() - t0)
133
134 t0 = time.monotonic()
135 await enrich_repo_cards(db_session, [empty_id])
136 samples_empty.append(time.monotonic() - t0)
137
138 median_full = statistics.median(samples_full) * 1000
139 median_empty = statistics.median(samples_empty) * 1000
140
141 # Empty should be no more than 2× slower than full (same 5 queries run)
142 assert median_empty < median_full * 2, (
143 f"Empty repo ({median_empty:.1f} ms) unexpectedly slower than "
144 f"full repo ({median_full:.1f} ms) by > 2×"
145 )
File History 13 commits
sha256:fc04e4cae9e1774d6a21b65c45daeed0e6787eb581d13aa1b03bfe9384a34226 Merge branch 'fix/two-column-scroll-layout' into dev Human 9 days ago
sha256:408916fc5973ba59c6e4eebaa80ebdcc801c0a63205651e25009d11548f79454 chore: bump version to 0.2.0.dev2 — nightly.2, matching muse Sonnet 4.6 patch 11 days ago
sha256:d035733f21ccff27735fddebfbbe0ed24565a32a22db8de5885402262671ecd2 chore: bump version to 0.2.0rc15 for musehub#113 fix release Sonnet 4.6 patch 15 days ago
sha256:0032d6cfa33bc3c8367436ad768e7dd0e339b4332153160247da8266cb5fa352 Merge branch 'task/version-tags-phase3-server' into dev Human 17 days ago
sha256:4669620efda9ff41c55bdefd1f7bfe1c239d468428744c84ead9957e5a003a53 merge: rescue snapshot-recovery hardening (c00aa21d) into d… Opus 4.8 minor 30 days ago
sha256:a59da49c4611b970fc4b6ae48678ce4943261c213a07ddbd73ce9201df869b4a fix: remove false-positive proposal_comments index drop fro… Sonnet 4.6 patch 34 days ago
sha256:0a240d6dbff234f07d98a28a4a9a68db702f3f9ff9260196f24219bdb1c0b6f3 feat: render markdown mists as HTML with heading anchor links Sonnet 4.6 patch 34 days ago
sha256:24a7d47486ebc4ebd1832830580e177ec6f877b48dced8c000e198cdec4ce9d6 Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump … Human 35 days ago
sha256:b9ff931d147e0114a1f17060f415b89ed551c170a91ff226c70437aa5c85f9ee Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump … Human 35 days ago
sha256:d1122d21e73471879b460037b22c0b50fded7c423444a176f248428f75dac39c Merge 'task/fix-issue-pagination-cursor' into 'dev' — propo… Human 35 days ago
sha256:01e18975e73d2b3cd5b6db7929c895bef9aa6e0d4391dc5b2adfc548b41318dd Merge 'feat/adding-debug-logs-to-staging' into 'dev' — prop… Human 36 days ago
sha256:6b1949fc2797ca4c1936a637a4cbfec828ef56cf52398a2e74ca3c4f494e728f fix: use wire_bytes not mpack_bytes_raw in compute_object_b… Sonnet 4.6 patch 48 days ago
sha256:b99f2455dc346966d040133f5203297e6e3ef5803a93728a2c30568d0a0f7583 rename: delta_add → delta_upsert across wire format, models… Sonnet 4.6 patch 50 days ago