8000 fix: route uncoached guides by finding language · habit-hooks/habit-hooks@0af5390 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0af5390

Browse files
committed
fix: route uncoached guides by finding language
Keep a language-specific fallback from coaching findings produced by another language plugin; use the generic or core guide instead.
1 parent 59e12b1 commit 0af5390

2 files changed

Lines changed: 87 additions & 1 deletion

File tree

‎src/habit_hooks/rendering.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ def resolve_guide(finding: dict, config: Config, resolver: Resolver) -> Path:
154154
plugins = plugins_for_language(finding.get("language"), config)
155155
guide = resolver.first(plugins, guide_names(finding["smell"], config))
156156
if guide is None:
157-
guide = resolver.guide(UNCOACHED_GUIDE, config.plugins)
157+
# Same language-filtered order: never another language's guide (#150).
158+
guide = resolver.guide(UNCOACHED_GUIDE, plugins)
158159
return guide
159160

160161

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""The uncoached guide fallback is filtered by the finding's language.
2+
3+
``rendering.resolve_guide`` picks the primary guide from
4+
``plugins_for_language`` — the language-matching plugin first, the languageless
5+
plugin (``generic``) last — but the ``uncoached.md`` fallback used to walk the
6+
raw ``config.plugins`` order. A plugin of a *different* language that happened
7+
to be listed first therefore coached the finding: with Ruby first, Ruby's
8+
newly shipped ``uncoached.md`` coached an uncatalogued TypeScript/ESLint
9+
finding (#150). The fallback must walk the same language-filtered order, then
10+
the core's own guide.
11+
"""
12+
13+
from __future__ import annotations
14+
15+
from pathlib import Path
16+
17+
import pytest
18+
19+
from habit_hooks import mapper
20+
from plugin_fixture import write_plugin, write_project_config
21+
22+
_TYPESCRIPT_FINDING = {
23+
"smell": "unmapped-eslint-rule",
24+
"language": "typescript",
25+
"details": {},
26+
"issues": [{"key": "src/a.ts", "details": {"file": "src/a.ts"}}],
27+
}
28+
29+
30+
def test_the_uncoached_fallback_respects_the_findings_language(
31+
tmp_path: Path, capsys: pytest.CaptureFixture[str]
32+
) -> None:
33+
"""With Ruby listed first and only Ruby and generic shipping an
34+
``uncoached.md``, an uncatalogued TypeScript finding is coached by
35+
generic's — never by Ruby's (#150)."""
36+
write_plugin(
37+
tmp_path,
38+
"ruby",
39+
{
40+
"config.toml": 'language = "ruby"\nsensors = []',
41+
"guides/uncoached.md": "Ruby-shaped uncoached guidance.",
42+
},
43+
)
44+
write_plugin(
45+
tmp_path,
46+
"typescript",
47+
{"config.toml": 'language = "typescript"\nsensors = []'},
48+
)
49+
write_plugin(
50+
tmp_path,
51+
"generic",
52+
{
53+
"config.toml": "sensors = []",
54+
"guides/uncoached.md": "Generic uncoached guidance.",
55+
},
56+
)
57+
write_project_config(tmp_path, 'plugins = ["ruby", "typescript", "generic"]')
58+
59+
mapper.run([_TYPESCRIPT_FINDING], tmp_path)
60+
61+
out = capsys.readouterr().out
62+
assert "Generic uncoached guidance." in out
63+
assert "Ruby-shaped uncoached guidance." not in out
64+
65+
66+
def test_the_uncoached_fallback_reaches_the_core_without_a_languageless_plugin(
67+
tmp_path: Path, capsys: pytest.CaptureFixture[str]
68+
) -> None:
69+
"""No languageless plugin configured: the fallback reaches the core's own
70+
``uncoached.md`` rather than a differently-language plugin's (#150)."""
71+
write_plugin(
72+
tmp_path,
73+
"ruby",
74+
{
75+
"config.toml": 'language = "ruby"\nsensors = []',
76+
"guides/uncoached.md": "Ruby-shaped uncoached guidance.",
77+
},
78+
)
79+
write_project_config(tmp_path, 'plugins = ["ruby"]')
80+
81+
mapper.run([_TYPESCRIPT_FINDING], tmp_path)
82+
83+
out = capsys.readouterr().out
84+
assert "General guidance" in out
85+
assert "Ruby-shaped uncoached guidance." not in out

0 commit comments

Comments
 (0)
0