Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions comparisons/_meta/search-smoke.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
schema_version: 1
cases:
- comparison: containers-docker-containerd
query: image build responsibility
- comparison: github-actions-argocd
query: runner jobs drift reconciliation
- comparison: kubernetes-helm-argocd
Expand Down
35 changes: 35 additions & 0 deletions scripts/check_source_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
USER_AGENT = "OpenDevIndex-SourceHealth/1.0 (+https://github.com/BLCCoreStudio/OpenDevIndex)"
RESTRICTED_CODES = {401, 403, 407, 423, 425, 429, 451}
BROKEN_CODES = {404, 410}
HEALTH_SEVERITY = {
"healthy": 0,
"restricted": 1,
"transient": 2,
"broken": 3,
}


def static_public_https_url(url: str) -> tuple[bool, str]:
Expand Down Expand Up @@ -186,18 +192,47 @@ def collect_urls(entries: list[dict]) -> dict[str, set[str]]:
return contexts


def module_health_summary(results: list[dict]) -> Counter[str]:
"""Count modules by their worst source-health classification."""
worst_by_module: dict[str, str] = {}
for result in results:
classification = result.get("classification")
if classification not in HEALTH_SEVERITY:
continue
for context in result.get("contexts", []):
if not isinstance(context, str) or ":" not in context:
continue
module_ref, _ = context.rsplit(":", 1)
current = worst_by_module.get(module_ref)
if current is None or HEALTH_SEVERITY[classification] > HEALTH_SEVERITY[current]:
worst_by_module[module_ref] = classification
return Counter(worst_by_module.values())


def render_markdown(results: list[dict], checked_at: str) -> str:
counts = Counter(result["classification"] for result in results)
module_counts = module_health_summary(results)
lines = [
"# OpenDevIndex Source Health",
"",
f"Checked at **{checked_at}**.",
"",
"## URL results",
"",
f"- Healthy: **{counts.get('healthy', 0)}**",
f"- Restricted/anti-bot: **{counts.get('restricted', 0)}**",
f"- Transient: **{counts.get('transient', 0)}**",
f"- Broken: **{counts.get('broken', 0)}**",
"",
"## Module impact",
"",
"Each module is counted once using the worst classification among its homepage, repository, and source URLs.",
"",
f"- Healthy: **{module_counts.get('healthy', 0)}**",
f"- Restricted/anti-bot: **{module_counts.get('restricted', 0)}**",
f"- Transient: **{module_counts.get('transient', 0)}**",
f"- Broken: **{module_counts.get('broken', 0)}**",
"",
]

notable = [result for result in results if result["classification"] != "healthy"]
Expand Down
58 changes: 57 additions & 1 deletion tests/test_source_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
if str(SCRIPTS) not in sys.path:
sys.path.insert(0, str(SCRIPTS))

from check_source_health import classify_http_code, static_public_https_url # noqa: E402
from check_source_health import ( # noqa: E402
classify_http_code,
module_health_summary,
render_markdown,
static_public_https_url,
)
from url_safety import is_safe_https_url # noqa: E402


Expand Down Expand Up @@ -42,6 +47,57 @@ def test_http_classification(self) -> None:
self.assertEqual(classify_http_code(410), "broken")
self.assertEqual(classify_http_code(503), "transient")

def test_module_health_uses_worst_classification_once_per_module(self) -> None:
results = [
{
"classification": "healthy",
"contexts": ["tool/git:homepage", "tool/docker:homepage"],
},
{
"classification": "restricted",
"contexts": ["tool/git:repository"],
},
{
"classification": "transient",
"contexts": ["tool/docker:source"],
},
{
"classification": "broken",
"contexts": ["tool/git:source"],
},
]

summary = module_health_summary(results)

self.assertEqual(summary["broken"], 1)
self.assertEqual(summary["transient"], 1)
self.assertEqual(summary["healthy"], 0)
self.assertEqual(summary["restricted"], 0)

def test_markdown_reports_module_impact(self) -> None:
results = [
{
"url": "https://example.com/a",
"classification": "healthy",
"http_status": 200,
"contexts": ["tool/git:homepage"],
"detail": "reachable",
},
{
"url": "https://example.com/b",
"classification": "broken",
"http_status": 404,
"contexts": ["tool/git:source", "tool/docker:source"],
"detail": "Not Found",
},
]

markdown = render_markdown(results, "2026-09-07T00:00:00+00:00")

self.assertIn("## Module impact", markdown)
self.assertIn("Each module is counted once", markdown)
self.assertIn("- Broken: **2**", markdown)


if __name__ == "__main__":
unittest.main()
Loading