|
| 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