Add regression tests for the unclassified share warning

Covers detect() directly: the warning fires once both the absolute
floor and the fraction threshold are crossed, and stays silent just
under either one on its own, a tiny sliver of unsupported files in a
large corpus, or a small corpus where two stray files already look
large by percentage alone. Also covers watch's own rebuild function,
one of the console paths that carries the warning through, and
GRAPH_REPORT.md's Corpus Check section printing or omitting the line
depending on whether detect() set it.

(cherry picked from commit 76d1d49174)
This commit is contained in:
ayushcodes10 authored and safishamsi committed 2026-11-05 12:11:24 +00:00
1 parent 918b4b7558
commit d329bcdfdb
3 files changed
+85

No files matched your search

+43
View File
@@ -3657,6 +3657,49 @@ def test_detect_unclassified_empty_when_all_supported(tmp_path):
assert res.get("unclassified", []) == []
def test_unclassified_warning_fires_when_most_of_the_corpus_has_no_extractor(tmp_path):
# #2942: a repo whose business logic lives in a language graphify cannot
# parse (here: generic .xml) produces a graph that looks complete but
# represents only part of the codebase. Past the absolute-count floor
# and the fraction threshold, detect() must say so plainly, not just
# report a bare count that reads as routine lockfile/binary noise.
for i in range(30):
(tmp_path / f"doc{i}.xml").write_text("<root/>\n")
for i in range(10):
(tmp_path / f"code{i}.py").write_text("x = 1\n")
res = detect(tmp_path)
assert len(res["unclassified"]) == 30
warning = res.get("unclassified_warning")
assert warning is not None
assert "30 of 40" in warning
assert "75%" in warning
def test_unclassified_warning_silent_under_the_absolute_floor(tmp_path):
# Two stray unsupported files out of many is routine, not a structural
# gap -- the loud warning must not fire just because SOME fraction of a
# tiny handful of unclassified files happens to be large.
(tmp_path / "odd1.xml").write_text("<root/>\n")
(tmp_path / "odd2.xml").write_text("<root/>\n")
for i in range(20):
(tmp_path / f"code{i}.py").write_text("x = 1\n")
res = detect(tmp_path)
assert len(res["unclassified"]) == 2
assert res.get("unclassified_warning") is None
def test_unclassified_warning_silent_under_the_fraction_threshold(tmp_path):
# Past the absolute floor but still a small share of a large, mostly
# supported corpus -- still routine, must stay silent.
for i in range(25):
(tmp_path / f"odd{i}.xml").write_text("<root/>\n")
for i in range(400):
(tmp_path / f"code{i}.py").write_text("x = 1\n")
res = detect(tmp_path)
assert len(res["unclassified"]) == 25
assert res.get("unclassified_warning") is None
def test_graphifyinclude_is_inert_and_not_unclassified(tmp_path, capsys):
"""#2112: .graphifyinclude support was removed (dead since #873).
+26
View File
@@ -52,6 +52,32 @@ def test_report_omits_unclassified_line_when_none():
report = generate(G, communities, cohesion, labels, gods, surprises, detection, tokens, "./project")
assert "Unclassified:" not in report
def test_report_surfaces_the_unclassified_warning_next_to_the_count():
"""#2942: a bare count reads as routine even when it is most of the
corpus. When detect() decided the share was large enough to warn about,
the report must say so right in the Corpus Check section, not bury it."""
G, communities, cohesion, labels, gods, surprises, detection, tokens = make_inputs()
detection = {
**detection,
"unclassified": ["a.xml", "b.xml", "c.xml"],
"unclassified_warning": (
"3 of 4 files seen (75%) have no supported extractor and are "
"missing from this graph entirely."
),
}
report = generate(G, communities, cohesion, labels, gods, surprises, detection, tokens, "./project")
assert "WARNING: 3 of 4 files seen (75%)" in report
def test_report_omits_the_unclassified_warning_when_detect_did_not_set_one():
"""Backward compatible: detect() decided the share was routine (or the
key is simply absent, matching old cached detection dicts), no new line."""
G, communities, cohesion, labels, gods, surprises, detection, tokens = make_inputs()
detection = {**detection, "unclassified": ["a.toml"]}
report = generate(G, communities, cohesion, labels, gods, surprises, detection, tokens, "./project")
assert "WARNING:" not in report
def test_report_contains_god_nodes():
G, communities, cohesion, labels, gods, surprises, detection, tokens = make_inputs()
report = generate(G, communities, cohesion, labels, gods, surprises, detection, tokens, "./project")
+16
View File
@@ -201,6 +201,22 @@ def test_rebuild_code_reports_unclassified_files(tmp_path, capsys):
assert "Util.lean" in out
def test_rebuild_code_warns_loudly_when_most_of_the_corpus_is_unclassified(tmp_path, capsys):
"""#2942: a bare count reads as routine even when it is most of the
corpus. The update/watch rebuild path must carry detect()'s louder
warning through to its own console output, same as `graphify extract`."""
corpus = tmp_path / "corpus"
corpus.mkdir()
for i in range(30):
(corpus / f"doc{i}.xml").write_text("<root/>\n", encoding="utf-8")
for i in range(10):
(corpus / f"code{i}.py").write_text(f"def f{i}(): pass\n", encoding="utf-8")
assert _rebuild_code(corpus, acquire_lock=False) is True
out = capsys.readouterr().out
assert "warning: 30 of 40 files seen (75%)" in out
# --- watch() import error without watchdog ---
def test_check_update_no_flag_returns_true(tmp_path):