@jesdi/skills 0.0.81 → 0.0.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/package.json +2 -1
  2. package/skills/crap-gate/launcher.sh +104 -0
  3. package/skills/crap-gate/run.sh +15 -75
  4. package/skills/crap-gate/test_launcher.py +39 -0
  5. package/skills/implement-spec/launcher.sh +104 -0
  6. package/skills/implement-spec/run.sh +10 -89
  7. package/skills/implement-spec/tests/test_launcher.py +138 -0
  8. package/skills/test-weigh-in/SKILL.md +16 -0
  9. package/skills/test-weigh-in/dashboard.html +112 -0
  10. package/skills/test-weigh-in/launcher.sh +104 -0
  11. package/skills/test-weigh-in/rules.toml +134 -0
  12. package/skills/test-weigh-in/run.sh +21 -0
  13. package/skills/test-weigh-in/tests/brittle_repo.py +79 -0
  14. package/skills/test-weigh-in/tests/conftest.py +35 -0
  15. package/skills/test-weigh-in/tests/fixture_repo.py +99 -0
  16. package/skills/test-weigh-in/tests/kill_repo.py +87 -0
  17. package/skills/test-weigh-in/tests/maint_repo.py +139 -0
  18. package/skills/test-weigh-in/tests/map_fixture.py +56 -0
  19. package/skills/test-weigh-in/tests/pt_repo.py +46 -0
  20. package/skills/test-weigh-in/tests/red_repo.py +44 -0
  21. package/skills/test-weigh-in/tests/rule_repo.py +208 -0
  22. package/skills/test-weigh-in/tests/rules_fixture.py +65 -0
  23. package/skills/test-weigh-in/tests/smell_repo.py +138 -0
  24. package/skills/test-weigh-in/tests/test_brittleness.py +75 -0
  25. package/skills/test-weigh-in/tests/test_brittleness_history.py +168 -0
  26. package/skills/test-weigh-in/tests/test_coverage_run.py +201 -0
  27. package/skills/test-weigh-in/tests/test_coverage_value.py +76 -0
  28. package/skills/test-weigh-in/tests/test_dashboard_map.py +20 -0
  29. package/skills/test-weigh-in/tests/test_interpreters.py +115 -0
  30. package/skills/test-weigh-in/tests/test_kill_matrix.py +126 -0
  31. package/skills/test-weigh-in/tests/test_maintainability_smells.py +113 -0
  32. package/skills/test-weigh-in/tests/test_mutation_recovery.py +67 -0
  33. package/skills/test-weigh-in/tests/test_mutation_sampling.py +53 -0
  34. package/skills/test-weigh-in/tests/test_mutation_score.py +140 -0
  35. package/skills/test-weigh-in/tests/test_mutation_stale.py +30 -0
  36. package/skills/test-weigh-in/tests/test_mutmut_contract.py +43 -0
  37. package/skills/test-weigh-in/tests/test_ruff_pt_smells.py +45 -0
  38. package/skills/test-weigh-in/tests/test_runs.py +175 -0
  39. package/skills/test-weigh-in/tests/test_score.py +26 -0
  40. package/skills/test-weigh-in/tests/test_scoring.py +154 -0
  41. package/skills/test-weigh-in/tests/test_smell_rules.py +96 -0
  42. package/skills/test-weigh-in/tests/test_smells.py +71 -0
  43. package/skills/test-weigh-in/tests/test_walking_skeleton.py +91 -0
  44. package/skills/test-weigh-in/tests/testdata/default_repo/demo/__init__.py +0 -0
  45. package/skills/test-weigh-in/tests/testdata/default_repo/demo/board.py +2 -0
  46. package/skills/test-weigh-in/tests/testdata/default_repo/demo/config.py +2 -0
  47. package/skills/test-weigh-in/tests/testdata/default_repo/pyproject.toml +8 -0
  48. package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_board.py +19 -0
  49. package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_config.py +19 -0
  50. package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_parser.py +19 -0
  51. package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_render.py +19 -0
  52. package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_report.py +17 -0
  53. package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_session.py +19 -0
  54. package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_store.py +17 -0
  55. package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_sync.py +17 -0
  56. package/skills/test-weigh-in/tests/testdata/default_repo/uv.lock +1 -0
  57. package/skills/test-weigh-in/weigh.py +133 -0
  58. package/skills/test-weigh-in/weigh_coverage.py +154 -0
  59. package/skills/test-weigh-in/weigh_dashboard.py +72 -0
  60. package/skills/test-weigh-in/weigh_env.py +112 -0
  61. package/skills/test-weigh-in/weigh_git.py +119 -0
  62. package/skills/test-weigh-in/weigh_inventory.py +49 -0
  63. package/skills/test-weigh-in/weigh_mutation.py +190 -0
  64. package/skills/test-weigh-in/weigh_pytest_plugin.py +56 -0
  65. package/skills/test-weigh-in/weigh_ruff.py +22 -0
  66. package/skills/test-weigh-in/weigh_rules.py +65 -0
  67. package/skills/test-weigh-in/weigh_runs.py +173 -0
  68. package/skills/test-weigh-in/weigh_score.py +80 -0
  69. package/skills/test-weigh-in/weigh_smells.py +355 -0
  70. package/skills/test-weigh-in/weigh_snapshot.py +49 -0
  71. package/skills-manifest.json +11 -5
@@ -0,0 +1,139 @@
1
+ """Fixture suites for ticket tw/s5-smells/10, built on the default repo with its tests replaced by a controlled set.
2
+
3
+ Every suite has exactly 40 tests, all passing unless a docstring says otherwise. The filler tests are structurally
4
+ distinct from each other (test_fill_NN asserts `board.render(1) == "1"` plus NN empty-string additions), so they never
5
+ form a duplicate-body cluster and carry none of the six smells. test_pick covers both arms of demo/pick.py.
6
+
7
+ smell_suite: tests/test_maint.py test_flow_2 (2 act-then-assert cycles), test_flow_3 (3), test_parse_all (for over a
8
+ literal list), test_load (try/except Exception: pass)
9
+ tests/test_guest.py test_a (opens tmp_path / "x.json"), test_b (opens "~/.cache/app.json", a file
10
+ committed at that relative path)
11
+ tests/test_sleep.py test_a (time.sleep(0)), test_b (time.sleep(2))
12
+ cluster_suite: tests/test_intent.py test_intent_1..4 (differ only in a string literal and a variable name) and
13
+ test_cousin (same shape, calls str instead of board.render: it must not join the cluster)
14
+ summary_suite: tests/test_dups.py 12 clones; tests/test_retry.py test_retry (flaky: passes plain, fails under coverage)
15
+ perfect_suite: fillers and test_pick only: 0% hollow, 100% branch coverage, 0% duplicate clusters
16
+ clone_suite: 40 clones: 100% duplicate-body cluster, 100% without unique coverage
17
+ """
18
+ import re
19
+
20
+ from fixture_repo import build_repo, git
21
+
22
+ PICK = "def pick(x):\n if x:\n return 1\n return 2\n"
23
+ PICK_TEST = "def test_pick():\n assert pick.pick(True) + pick.pick(False) == 3\n"
24
+ HEADER = "from demo import board, pick\n\n\n"
25
+
26
+
27
+ def filler(k):
28
+ return f'def test_fill_{k:02d}():\n assert board.render(1) == "1"' + ' + ""' * k + "\n"
29
+
30
+
31
+ def clone(i):
32
+ return f'def test_clone_{i:02d}():\n v{i} = board.render(1)\n assert v{i} in "1 {i}"\n'
33
+
34
+
35
+ def suite(path, files, total=40):
36
+ repo = build_repo(path)
37
+ for old in (repo / "tests").glob("test_*.py"):
38
+ old.unlink()
39
+ (repo / "demo" / "config.py").unlink()
40
+ (repo / "demo" / "pick.py").write_text(PICK)
41
+ own = 0
42
+ for rel, text in files.items():
43
+ (repo / rel).parent.mkdir(parents=True, exist_ok=True)
44
+ (repo / rel).write_text(text)
45
+ own += len(re.findall(r"^def test_", text, re.M))
46
+ fillers = [filler(k) for k in range(total - own - 1)]
47
+ (repo / "tests" / "test_fill.py").write_text(HEADER + "\n\n".join(fillers + [PICK_TEST]))
48
+ git(repo, "add", "-A")
49
+ git(repo, "commit", "-q", "-m", "suite")
50
+ return repo
51
+
52
+
53
+ MAINT = '''from demo import board
54
+
55
+
56
+ def test_flow_2():
57
+ first = board.render(1)
58
+ assert first == "1"
59
+ second = board.render(2)
60
+ assert second == "2"
61
+
62
+
63
+ def test_flow_3():
64
+ first = board.render(1)
65
+ assert first == "1"
66
+ second = board.render(2)
67
+ assert second == "2"
68
+ third = board.render(3)
69
+ assert third == "3"
70
+
71
+
72
+ def test_parse_all():
73
+ for s in ["a", "b"]:
74
+ assert board.render(s) == s
75
+
76
+
77
+ def test_load():
78
+ try:
79
+ board.render(1)
80
+ except Exception:
81
+ pass
82
+ '''
83
+ GUEST = '''import json
84
+
85
+
86
+ def test_a(tmp_path):
87
+ path = tmp_path / "x.json"
88
+ path.write_text("{}")
89
+ with open(path) as handle:
90
+ assert json.load(handle) == {}
91
+
92
+
93
+ def test_b():
94
+ with open("~/.cache/app.json") as handle:
95
+ assert json.load(handle) == {}
96
+ '''
97
+ SLEEP = '''import time
98
+
99
+
100
+ def test_a():
101
+ time.sleep(0)
102
+ assert time.monotonic() > 0
103
+
104
+
105
+ def test_b():
106
+ time.sleep(2)
107
+ assert time.monotonic() > 0
108
+ '''
109
+ INTENT = "from demo import board\n\n\n" + "\n\n".join(
110
+ f'def test_intent_{i}():\n {name} = board.render(1)\n assert {name} in "1 {lit}"\n'
111
+ for i, name, lit in ((1, "first", "a"), (2, "second", "b"), (3, "third", "c"), (4, "fourth", "d"))
112
+ ) + '\n\ndef test_cousin():\n fifth = str(1)\n assert fifth in "1 e"\n'
113
+ RETRY = 'import sys\n\n\ndef test_retry():\n assert "coverage" not in sys.modules\n'
114
+
115
+
116
+ def smell_suite(path):
117
+ repo = suite(path, {"tests/test_maint.py": MAINT, "tests/test_guest.py": GUEST, "tests/test_sleep.py": SLEEP})
118
+ (repo / "~" / ".cache").mkdir(parents=True)
119
+ (repo / "~" / ".cache" / "app.json").write_text("{}")
120
+ git(repo, "add", "-A")
121
+ git(repo, "commit", "-q", "-m", "guest file")
122
+ return repo
123
+
124
+
125
+ def cluster_suite(path):
126
+ return suite(path, {"tests/test_intent.py": INTENT})
127
+
128
+
129
+ def summary_suite(path):
130
+ dups = "from demo import board\n\n\n" + "\n\n".join(clone(i) for i in range(12))
131
+ return suite(path, {"tests/test_dups.py": dups, "tests/test_retry.py": RETRY})
132
+
133
+
134
+ def perfect_suite(path):
135
+ return suite(path, {})
136
+
137
+
138
+ def clone_suite(path):
139
+ return suite(path, {"tests/test_clone.py": "from demo import board\n\n\n" + "\n\n".join(clone(i) for i in range(39))})
@@ -0,0 +1,56 @@
1
+ """Ticket tw/s4-coverage/08: render dashboard.html from a fixture snapshot (no repo run): `map_fixture.py <out-dir>`.
2
+
3
+ Ten passing tests over demo/a.py. test_intent_1 and its twins test_twin_1..3 cover lines 1-10 (similarity 1.0);
4
+ test_other_1..4 cover lines 1-4 (similarity 0.4 with each of those four: 4 shared of 10 in the union).
5
+ test_edge_at covers lines 1-6 (similarity exactly 0.6 with test_intent_1), test_edge_below lines 1-5 (0.5 with it).
6
+ Overlaps (Jaccard >= 0.9) holds the 6 pairs among test_intent_1 and its twins and the 6 among test_other_1..4, each 1.0;
7
+ no pair with an edge test reaches 0.9 (at most 5 of 6 lines).
8
+ Writes the fixture snapshot to <out-dir>/snapshot.json and the page to <out-dir>/dashboard.html.
9
+ """
10
+ import json
11
+ import sys
12
+ from pathlib import Path
13
+
14
+ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
15
+
16
+ from weigh_dashboard import write_dashboard
17
+ from weigh_rules import load
18
+ from weigh_score import feedback_values, score
19
+
20
+ WIDE = list(range(1, 11))
21
+ NARROW = list(range(1, 5))
22
+ COVERAGE = {
23
+ "tests/test_intent.py::test_intent_1": WIDE,
24
+ "tests/test_twin.py::test_twin_1": WIDE,
25
+ "tests/test_twin.py::test_twin_2": WIDE,
26
+ "tests/test_twin.py::test_twin_3": WIDE,
27
+ "tests/test_other.py::test_other_1": NARROW,
28
+ "tests/test_other.py::test_other_2": NARROW,
29
+ "tests/test_other.py::test_other_3": NARROW,
30
+ "tests/test_other.py::test_other_4": NARROW,
31
+ "tests/test_edge.py::test_edge_at": list(range(1, 7)),
32
+ "tests/test_edge.py::test_edge_below": list(range(1, 6)),
33
+ }
34
+
35
+
36
+ def jaccard(a, b):
37
+ return len(set(a) & set(b)) / len(set(a) | set(b))
38
+
39
+
40
+ def build(out):
41
+ rules = load()
42
+ tests = {n: {"outcome": "passed", "duration": 0.05 * (i + 1), "coverage": {"demo/a.py": lines}, "unique_coverage": 0, "flaky": False, "smells": [], "lines": 2}
43
+ for i, (n, lines) in enumerate(COVERAGE.items())}
44
+ metrics, pillars = score(rules, {**feedback_values(tests, 1.0), "no_unique_coverage": 100.0})
45
+ names = list(COVERAGE)
46
+ pairs = [{"tests": [a, b], "jaccard": j} for i, a in enumerate(names) for b in names[i + 1:]
47
+ if (j := jaccard(COVERAGE[a], COVERAGE[b])) >= 0.9]
48
+ data = {"commit": "abc1234", "dirty": False, "inventory": {"tests": 10, "cases": 10, "test_files": 3, "test_lines": 24, "source_lines": 10, "runtime_seconds": 1.0},
49
+ "metrics": metrics, "pillars": pillars, "tests": tests, "overlaps": pairs}
50
+ out.mkdir(parents=True, exist_ok=True)
51
+ (out / "snapshot.json").write_text(json.dumps(data))
52
+ write_dashboard(out, data, rules)
53
+
54
+
55
+ if __name__ == "__main__":
56
+ build(Path(sys.argv[1]))
@@ -0,0 +1,46 @@
1
+ """Fixture suite for ticket tw/s5-smells/11: the default repo's tests replaced by a controlled set of exactly 40 tests.
2
+
3
+ pt_suite: tests/test_pt.py test_raises pytest.raises(Exception) without match (PT011): the only smell
4
+ test_board uses the fixture board_rows, declared `@pytest.fixture()` (PT001, style-only)
5
+ test_uses_helper calls expect_failure(), a helper outside any test that holds a PT011
6
+ ruff.toml the target repo's own ruff configuration: selects PT001 and ignores PT011. It must change
7
+ nothing: PT011 still counts and PT001 still does not.
8
+ Every other test is a filler with no smell.
9
+ """
10
+ from fixture_repo import git
11
+ from maint_repo import suite
12
+
13
+ PT = '''import pytest
14
+
15
+ from demo import board
16
+
17
+
18
+ @pytest.fixture()
19
+ def board_rows():
20
+ return [1]
21
+
22
+
23
+ def expect_failure():
24
+ with pytest.raises(Exception):
25
+ int("x")
26
+
27
+
28
+ def test_raises():
29
+ with pytest.raises(Exception):
30
+ board.render(int("x"))
31
+
32
+
33
+ def test_board(board_rows):
34
+ assert board.render(board_rows[0]) == "1"
35
+
36
+
37
+ def test_uses_helper():
38
+ expect_failure()
39
+ assert board.render(2) == "2"
40
+ '''
41
+ RUFF = '[lint]\nselect = ["PT001"]\nignore = ["PT011"]\n'
42
+
43
+
44
+ def pt_suite(path):
45
+ repo = suite(path, {"tests/test_pt.py": PT, "ruff.toml": RUFF})
46
+ return repo
@@ -0,0 +1,44 @@
1
+ """Fixture suites that are not green, built on the default repo (40 tests), for the coverage-run tests.
2
+
3
+ red_suite: 3 of 40 tests fail (test_board_3, test_board_4, test_pick_false). test_pick_false is the only test that
4
+ takes the false arm of demo/pick.py, so a suite coverage that counts failing tests would read 100 and not 50.
5
+ skipped_suite: 4 of 40 tests are skipped.
6
+ """
7
+ from fixture_repo import build_repo, git
8
+
9
+ FAILING = ("tests/test_board.py::test_board_3", "tests/test_board.py::test_board_4", "tests/test_render.py::test_pick_false")
10
+ SKIPPED = ("tests/test_config.py::test_config_2", "tests/test_config.py::test_config_3",
11
+ "tests/test_config.py::test_config_4", "tests/test_render.py::test_render_2")
12
+
13
+
14
+ def _commit(repo):
15
+ git(repo, "add", "-A")
16
+ git(repo, "commit", "-q", "-m", "suite")
17
+ return repo
18
+
19
+
20
+ def _edit(repo, rel, old, new):
21
+ path = repo / rel
22
+ path.write_text(path.read_text().replace(old, new))
23
+
24
+
25
+ def red_suite(path):
26
+ repo = build_repo(path)
27
+ (repo / "demo" / "pick.py").write_text("def pick(x):\n if x:\n return 1\n return 2\n")
28
+ render = (repo / "tests" / "test_render.py").read_text()
29
+ kept = render[render.index("def test_render_2"):]
30
+ (repo / "tests" / "test_render.py").write_text(
31
+ "import pytest\nfrom demo import board, config, pick\n"
32
+ "def test_pick_true():\n assert pick.pick(True) == 1\n"
33
+ "def test_pick_false():\n assert pick.pick(False) == 1\n" + kept)
34
+ for n in (3, 4):
35
+ _edit(repo, "tests/test_board.py", f'def test_board_{n}():\n assert board.render({n}) == "{n}"',
36
+ f"def test_board_{n}():\n assert board.render({n}) == 'x'")
37
+ return _commit(repo)
38
+
39
+
40
+ def skipped_suite(path):
41
+ repo = build_repo(path)
42
+ for rel, n in (("test_config", 2), ("test_config", 3), ("test_config", 4), ("test_render", 2)):
43
+ _edit(repo, f"tests/{rel}.py", f"def {rel}_{n}():", f"@pytest.mark.skip\ndef {rel}_{n}():")
44
+ return _commit(repo)
@@ -0,0 +1,208 @@
1
+ """Fixture suite for the boundaries of the smell rules, built on the default repo (40 tests, no smells).
2
+
3
+ rules_suite adds tests/conftest.py, demo/_queue.py, data/app.json, tests/test_rules.py and tests/test_maint_rules.py.
4
+ Expected smells by test of test_rules.py:
5
+ No assertion: TestA::test_board (TestB::test_board, same name, asserts),
6
+ TestOther::test_inherited (TestChild::test_inherited, from Base, asserts),
7
+ TestDiamond::test_diamond (Python takes it from DRight, which does not assert; DBase does)
8
+ Interaction-only: test_call_count, test_call_args (test_mixed and test_tuple_mixed also assert on a result;
9
+ test_empty_equal compares two empty lists, a plain check)
10
+ Mock-heavy: test_setattr_4 (4 monkeypatch.setattr; test_setattr_3 has 3)
11
+ Private access: test_module_private (demo._queue._requeue through a module alias),
12
+ test_local_private (the same through a function-local alias `module`)
13
+ No smell: test_check (check_equal from conftest), test_expect (expect_equal from conftest),
14
+ test_conftest_private (conftest._conftest_private through `from tests import conftest`),
15
+ test_local_conftest (the same through a function-local alias `module`, defined after test_local_private).
16
+ Expected smells by test of test_maint_rules.py:
17
+ Mystery guest: test_guest_name (open(path), path a literal), test_guest_path (Path from a literal, then read_text)
18
+ Eager test: test_eager_helpers (3 act-then-check_equal cycles)
19
+ No smell: test_swallow_checked (its handler calls check_equal), test_long (54 lines of asserts, a long test).
20
+ Every call takes 1.125 s (fakeclock), so every test is slow.
21
+ """
22
+ from fixture_repo import build_repo, git
23
+
24
+ CONFTEST = '''def check_equal(a, b):
25
+ assert a == b
26
+
27
+
28
+ def expect_equal(a, b):
29
+ assert a == b
30
+
31
+
32
+ def _conftest_private():
33
+ return 1
34
+ '''
35
+ RULES = '''import os
36
+ from unittest.mock import MagicMock, call
37
+
38
+ import demo._queue as queue
39
+ from demo import board
40
+ from tests import conftest
41
+ from tests.conftest import check_equal, expect_equal
42
+
43
+
44
+ def test_check():
45
+ check_equal(board.render(1), "1")
46
+
47
+
48
+ def test_expect():
49
+ expect_equal(board.render(1), "1")
50
+
51
+
52
+ def test_call_count():
53
+ sender = MagicMock()
54
+ sender.send("hi")
55
+ assert sender.send.call_count == 1
56
+
57
+
58
+ def test_call_args():
59
+ sender = MagicMock()
60
+ sender.send("hi")
61
+ assert sender.send.call_args == call("hi")
62
+
63
+
64
+ def test_setattr_3(monkeypatch):
65
+ monkeypatch.setattr(os, "getcwd", lambda: "/")
66
+ monkeypatch.setattr(os, "getpid", lambda: 1)
67
+ monkeypatch.setattr(os, "getppid", lambda: 1)
68
+ assert os.getpid() == 1
69
+
70
+
71
+ def test_setattr_4(monkeypatch):
72
+ monkeypatch.setattr(os, "getcwd", lambda: "/")
73
+ monkeypatch.setattr(os, "getpid", lambda: 1)
74
+ monkeypatch.setattr(os, "getppid", lambda: 1)
75
+ monkeypatch.setattr(os, "getuid", lambda: 1)
76
+ assert os.getpid() == 1
77
+
78
+
79
+ def test_conftest_private():
80
+ assert conftest._conftest_private() == 1
81
+
82
+
83
+ def test_module_private():
84
+ assert queue._requeue() == 1
85
+
86
+
87
+ def test_local_private():
88
+ import demo._queue as module
89
+ assert module._requeue() == 1
90
+
91
+
92
+ def test_local_conftest():
93
+ from tests import conftest as module
94
+ assert module._conftest_private() == 1
95
+
96
+
97
+ def test_mixed():
98
+ sender = MagicMock()
99
+ result = board.render(1)
100
+ sender.send(result)
101
+ assert result == "1" and sender.send.call_count == 1
102
+
103
+
104
+ def test_tuple_mixed():
105
+ sender = MagicMock()
106
+ result = board.render(1)
107
+ sender.send(result)
108
+ assert (result, sender.send.call_count) == ("1", 1)
109
+
110
+
111
+ def test_empty_equal():
112
+ sender = MagicMock()
113
+ sender.send(board.render(1))
114
+ assert [] == []
115
+
116
+
117
+ class TestA:
118
+ def test_board(self):
119
+ board.render(1)
120
+
121
+
122
+ class TestB:
123
+ def test_board(self):
124
+ assert board.render(1) == "1"
125
+
126
+
127
+ class Base:
128
+ def test_inherited(self):
129
+ assert board.render(1) == "1"
130
+
131
+
132
+ class TestOther:
133
+ def test_inherited(self):
134
+ board.render(1)
135
+
136
+
137
+ class TestChild(Base):
138
+ pass
139
+
140
+
141
+ class DBase:
142
+ def test_diamond(self):
143
+ assert board.render(1) == "1"
144
+
145
+
146
+ class DLeft(DBase):
147
+ pass
148
+
149
+
150
+ class DRight(DBase):
151
+ def test_diamond(self):
152
+ board.render(1)
153
+
154
+
155
+ class TestDiamond(DLeft, DRight):
156
+ pass
157
+ '''
158
+
159
+ MAINT = """from pathlib import Path
160
+
161
+ from demo import board
162
+ from tests.conftest import check_equal
163
+
164
+
165
+ def test_guest_name():
166
+ path = "data/app.json"
167
+ with open(path) as handle:
168
+ assert handle.read() == "{}"
169
+
170
+
171
+ def test_guest_path():
172
+ source = Path("data/app.json")
173
+ copied = source
174
+ assert copied.read_text() == "{}"
175
+
176
+
177
+ def test_eager_helpers():
178
+ first = board.render(1)
179
+ check_equal(first, "1")
180
+ second = board.render(2)
181
+ check_equal(second, "2")
182
+ third = board.render(3)
183
+ check_equal(third, "3")
184
+
185
+
186
+ def test_swallow_checked():
187
+ try:
188
+ board.render(1)
189
+ except Exception as error:
190
+ check_equal(str(error), "")
191
+
192
+
193
+ def test_long():
194
+ """ + "".join(f" assert board.render({i}) == '{i}'\n" for i in range(53))
195
+
196
+
197
+ def rules_suite(path):
198
+ repo = build_repo(path)
199
+ (repo / "tests" / "__init__.py").write_text("")
200
+ (repo / "tests" / "conftest.py").write_text(CONFTEST)
201
+ (repo / "demo" / "_queue.py").write_text("def _requeue():\n return 1\n")
202
+ (repo / "tests" / "test_rules.py").write_text(RULES)
203
+ (repo / "tests" / "test_maint_rules.py").write_text(MAINT)
204
+ (repo / "data").mkdir()
205
+ (repo / "data" / "app.json").write_text("{}")
206
+ git(repo, "add", "-A")
207
+ git(repo, "commit", "-q", "-m", "suite")
208
+ return repo
@@ -0,0 +1,65 @@
1
+ """Rules file the scoring tests hand to weigh.py through TEST_WEIGH_IN_RULES=<path>.
2
+
3
+ Interface the tests pin (the spec leaves the TOML keys and the snapshot JSON keys open):
4
+ rules.toml: version = 1; [pillars.<key>] name = "..."; [pillars.<key>.metrics.<id>] name, weight,
5
+ optional partial_weight, target, bad, optional log = true. Percentages are 0-100,
6
+ durations are seconds. Pillar keys: regression, refactoring, feedback,
7
+ maintainability, economy.
8
+ snapshot: rules {version, sha256}; metrics {<id>: {value, score}}; pillars {<key>: {score, partial}}.
9
+ Scores are unrounded floats; only the dashboard rounds and clamps.
10
+ """
11
+ import hashlib
12
+
13
+ # pillar key: (name, [(metric id, name, weight, partial weight, target, bad, log scale)])
14
+ STARTER = {
15
+ "regression": ("Protection against regressions", [
16
+ ("mutation_score", "Mutation score", .45, None, 80, 40, False),
17
+ ("branch_coverage", "Branch coverage", .25, .60, 90, 50, False),
18
+ ("hollow_tests", "Hollow tests", .20, .40, 0, 10, False),
19
+ ("pseudo_tested_functions", "Pseudo-tested functions", .10, None, 0, 15, False),
20
+ ]),
21
+ "refactoring": ("Resistance to refactoring", [
22
+ ("brittle_test_files", "Brittle test files", .40, None, 15, 60, False),
23
+ ("private_access", "Tests with private access", .25, None, 2, 30, False),
24
+ ("mock_heavy", "Mock-heavy tests", .20, None, 5, 30, False),
25
+ ("interaction_only", "Interaction-only tests", .15, None, 5, 30, False),
26
+ ]),
27
+ "feedback": ("Fast feedback", [
28
+ ("total_runtime", "Total runtime", .40, None, 60, 600, True),
29
+ ("p95_duration", "p95 test duration", .30, None, .1, 2, True),
30
+ ("slowest_decile_share", "Runtime share of slowest 10% of tests", .15, None, 40, 90, False),
31
+ ("tests_over_10s", "Tests over 10 s", .15, None, 0, 2, False),
32
+ ]),
33
+ "maintainability": ("Maintainability", [
34
+ ("smelly_tests", "Tests with a maintainability smell", .50, None, 5, 40, False),
35
+ ("long_tests", "Tests longer than 50 lines", .20, None, 2, 20, False),
36
+ ("test_source_ratio", "Test : source lines-of-code ratio", .30, None, 1.5, 4.0, False),
37
+ ]),
38
+ "economy": ("Economy", [
39
+ ("no_unique_coverage", "Tests with no unique coverage", .35, .60, 10, 50, False),
40
+ ("subsumed_in_kill_matrix", "Tests subsumed in the kill matrix", .40, None, 5, 35, False),
41
+ ("duplicate_clusters", "Tests in a duplicate-body cluster", .25, .40, 2, 20, False),
42
+ ]),
43
+ }
44
+
45
+
46
+ def write_rules(path, **overrides):
47
+ """Write the version 1 starter rules; overrides are `<metric id>={weight=..., target=..., bad=...}`."""
48
+ lines = ["version = 1", ""]
49
+ for key, (name, metrics) in STARTER.items():
50
+ lines += [f"[pillars.{key}]", f'name = "{name}"', ""]
51
+ for mid, mname, weight, partial, target, bad, log in metrics:
52
+ m = {**dict(weight=weight, target=target, bad=bad), **overrides.get(mid, {})}
53
+ lines += [f"[pillars.{key}.metrics.{mid}]", f'name = "{mname}"']
54
+ lines += [f"{k} = {v!r}" for k, v in m.items()]
55
+ if partial is not None:
56
+ lines.append(f"partial_weight = {partial!r}")
57
+ if log:
58
+ lines.append("log = true")
59
+ lines.append("")
60
+ path.write_text("\n".join(lines))
61
+ return path
62
+
63
+
64
+ def sha256(path):
65
+ return hashlib.sha256(path.read_bytes()).hexdigest()