@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.
- package/package.json +2 -1
- package/skills/crap-gate/launcher.sh +104 -0
- package/skills/crap-gate/run.sh +15 -75
- package/skills/crap-gate/test_launcher.py +39 -0
- package/skills/implement-spec/launcher.sh +104 -0
- package/skills/implement-spec/run.sh +10 -89
- package/skills/implement-spec/tests/test_launcher.py +138 -0
- package/skills/test-weigh-in/SKILL.md +16 -0
- package/skills/test-weigh-in/dashboard.html +112 -0
- package/skills/test-weigh-in/launcher.sh +104 -0
- package/skills/test-weigh-in/rules.toml +134 -0
- package/skills/test-weigh-in/run.sh +21 -0
- package/skills/test-weigh-in/tests/brittle_repo.py +79 -0
- package/skills/test-weigh-in/tests/conftest.py +35 -0
- package/skills/test-weigh-in/tests/fixture_repo.py +99 -0
- package/skills/test-weigh-in/tests/kill_repo.py +87 -0
- package/skills/test-weigh-in/tests/maint_repo.py +139 -0
- package/skills/test-weigh-in/tests/map_fixture.py +56 -0
- package/skills/test-weigh-in/tests/pt_repo.py +46 -0
- package/skills/test-weigh-in/tests/red_repo.py +44 -0
- package/skills/test-weigh-in/tests/rule_repo.py +208 -0
- package/skills/test-weigh-in/tests/rules_fixture.py +65 -0
- package/skills/test-weigh-in/tests/smell_repo.py +138 -0
- package/skills/test-weigh-in/tests/test_brittleness.py +75 -0
- package/skills/test-weigh-in/tests/test_brittleness_history.py +168 -0
- package/skills/test-weigh-in/tests/test_coverage_run.py +201 -0
- package/skills/test-weigh-in/tests/test_coverage_value.py +76 -0
- package/skills/test-weigh-in/tests/test_dashboard_map.py +20 -0
- package/skills/test-weigh-in/tests/test_interpreters.py +115 -0
- package/skills/test-weigh-in/tests/test_kill_matrix.py +126 -0
- package/skills/test-weigh-in/tests/test_maintainability_smells.py +113 -0
- package/skills/test-weigh-in/tests/test_mutation_recovery.py +67 -0
- package/skills/test-weigh-in/tests/test_mutation_sampling.py +53 -0
- package/skills/test-weigh-in/tests/test_mutation_score.py +140 -0
- package/skills/test-weigh-in/tests/test_mutation_stale.py +30 -0
- package/skills/test-weigh-in/tests/test_mutmut_contract.py +43 -0
- package/skills/test-weigh-in/tests/test_ruff_pt_smells.py +45 -0
- package/skills/test-weigh-in/tests/test_runs.py +175 -0
- package/skills/test-weigh-in/tests/test_score.py +26 -0
- package/skills/test-weigh-in/tests/test_scoring.py +154 -0
- package/skills/test-weigh-in/tests/test_smell_rules.py +96 -0
- package/skills/test-weigh-in/tests/test_smells.py +71 -0
- package/skills/test-weigh-in/tests/test_walking_skeleton.py +91 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/demo/__init__.py +0 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/demo/board.py +2 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/demo/config.py +2 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/pyproject.toml +8 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_board.py +19 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_config.py +19 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_parser.py +19 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_render.py +19 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_report.py +17 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_session.py +19 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_store.py +17 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_sync.py +17 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/uv.lock +1 -0
- package/skills/test-weigh-in/weigh.py +133 -0
- package/skills/test-weigh-in/weigh_coverage.py +154 -0
- package/skills/test-weigh-in/weigh_dashboard.py +72 -0
- package/skills/test-weigh-in/weigh_env.py +112 -0
- package/skills/test-weigh-in/weigh_git.py +119 -0
- package/skills/test-weigh-in/weigh_inventory.py +49 -0
- package/skills/test-weigh-in/weigh_mutation.py +190 -0
- package/skills/test-weigh-in/weigh_pytest_plugin.py +56 -0
- package/skills/test-weigh-in/weigh_ruff.py +22 -0
- package/skills/test-weigh-in/weigh_rules.py +65 -0
- package/skills/test-weigh-in/weigh_runs.py +173 -0
- package/skills/test-weigh-in/weigh_score.py +80 -0
- package/skills/test-weigh-in/weigh_smells.py +355 -0
- package/skills/test-weigh-in/weigh_snapshot.py +49 -0
- package/skills-manifest.json +11 -5
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""The Map tab draws the tests that give value: a test that passed only in the plain run (flaky) is not a dot."""
|
|
2
|
+
import json
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
7
|
+
|
|
8
|
+
import map_fixture
|
|
9
|
+
from weigh_dashboard import write_dashboard
|
|
10
|
+
from weigh_rules import load
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_a_flaky_test_is_not_drawn(tmp_path):
|
|
14
|
+
map_fixture.build(tmp_path)
|
|
15
|
+
data = json.loads((tmp_path / "snapshot.json").read_text())
|
|
16
|
+
data["tests"]["tests/test_twin.py::test_twin_1"]["flaky"] = True
|
|
17
|
+
html = write_dashboard(tmp_path, data, load()).read_text()
|
|
18
|
+
page = json.loads(html.split("const data = ", 1)[1].split(";\n", 1)[0])
|
|
19
|
+
drawn = {d["test"] for d in page["map"]}
|
|
20
|
+
assert drawn == set(map_fixture.COVERAGE) - {"tests/test_twin.py::test_twin_1"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import shutil
|
|
2
|
+
import subprocess
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from fixture_repo import FAKECLOCK, build_repo, git, load, snapshots, uv, weigh
|
|
7
|
+
|
|
8
|
+
KEY = "github.com/jesdi/demo"
|
|
9
|
+
MARKER_CONFTEST = "def pytest_sessionstart(session):\n open({marker!r}, 'a').close()\n"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def make_venv(path, pytest_version, python="3.12"):
|
|
13
|
+
"""A venv at `path` holding pytest and the fake clock the default repo's pytest config asks for."""
|
|
14
|
+
subprocess.run([uv(), "venv", "-q", "--python", python, str(path)], check=True)
|
|
15
|
+
subprocess.run([uv(), "pip", "install", "-q", "--python", str(path / "bin" / "python"), f"pytest=={pytest_version}"], check=True)
|
|
16
|
+
site = next((path / "lib").glob("python*/site-packages"))
|
|
17
|
+
(site / "fakeclock.py").write_text(FAKECLOCK)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def commit_all(repo):
|
|
21
|
+
git(repo, "add", "-A")
|
|
22
|
+
git(repo, "commit", "-q", "-m", "reshape")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def plain_repo(tmp_path, venv_dir="venv", pytest_version="8.1.1", python="3.12"):
|
|
26
|
+
"""The default repo reshaped to a requirements.txt project: no uv.lock, its only venv in `venv_dir`."""
|
|
27
|
+
repo = build_repo(tmp_path / "demo")
|
|
28
|
+
shutil.rmtree(repo / ".venv")
|
|
29
|
+
git(repo, "rm", "-q", "uv.lock")
|
|
30
|
+
(repo / "requirements.txt").write_text(f"pytest=={pytest_version}\n")
|
|
31
|
+
if venv_dir:
|
|
32
|
+
make_venv(repo / venv_dir, pytest_version, python)
|
|
33
|
+
commit_all(repo)
|
|
34
|
+
return repo
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def guarded(repo, tmp_path):
|
|
38
|
+
"""Make any pytest session in `repo` leave a marker file; returns the marker's path."""
|
|
39
|
+
marker = tmp_path / "pytest-ran"
|
|
40
|
+
(repo / "conftest.py").write_text(MARKER_CONFTEST.format(marker=str(marker)))
|
|
41
|
+
commit_all(repo)
|
|
42
|
+
return marker
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_uv_repo_without_venv_gets_one_from_its_lock(tmp_path, home, cache):
|
|
46
|
+
repo = build_repo(tmp_path / "demo")
|
|
47
|
+
shutil.rmtree(repo / ".venv")
|
|
48
|
+
(repo / "pyproject.toml").write_text(
|
|
49
|
+
'[project]\nname = "demo"\nversion = "0.0.0"\nrequires-python = ">=3.10"\ndependencies = ["pytest==8.3.5"]\n'
|
|
50
|
+
'[tool.pytest.ini_options]\npythonpath = ["."]\nmarkers = ["e2e: slow end-to-end test"]\n'
|
|
51
|
+
)
|
|
52
|
+
(repo / "uv.lock").unlink() # the template lock is a stub uv cannot parse
|
|
53
|
+
subprocess.run([uv(), "lock", "-q"], cwd=repo, check=True)
|
|
54
|
+
commit_all(repo)
|
|
55
|
+
lock = (repo / "uv.lock").read_bytes()
|
|
56
|
+
result = weigh(repo, home, cache=cache)
|
|
57
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
58
|
+
assert (repo / ".venv" / "bin" / "python").is_file()
|
|
59
|
+
assert (repo / "uv.lock").read_bytes() == lock
|
|
60
|
+
assert len(snapshots(home, KEY)) == 1
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_plain_venv_repo_is_measured_with_its_venv(tmp_path, home, cache):
|
|
64
|
+
repo = plain_repo(tmp_path)
|
|
65
|
+
result = weigh(repo, home, cache=cache)
|
|
66
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
67
|
+
(snap,) = snapshots(home, KEY)
|
|
68
|
+
assert load(snap)["pytest_version"].startswith("8.1")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_no_interpreter_stops_and_names_the_python_flag(tmp_path, home, cache):
|
|
72
|
+
repo = plain_repo(tmp_path, venv_dir=None)
|
|
73
|
+
result = weigh(repo, home, cache=cache)
|
|
74
|
+
assert result.returncode != 0
|
|
75
|
+
assert "--python" in result.stdout + result.stderr
|
|
76
|
+
assert snapshots(home, KEY) == []
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_explicit_python_wins_over_the_repos_venv(tmp_path, home, cache):
|
|
80
|
+
repo = build_repo(tmp_path / "demo")
|
|
81
|
+
make_venv(tmp_path / "py312", "8.2.2")
|
|
82
|
+
result = weigh(repo, home, "--python", str(tmp_path / "py312" / "bin" / "python"), cache=cache)
|
|
83
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
84
|
+
(snap,) = snapshots(home, KEY)
|
|
85
|
+
assert load(snap)["pytest_version"].startswith("8.2")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_pytest_at_the_minimum_is_accepted(tmp_path, home, cache):
|
|
89
|
+
repo = build_repo(tmp_path / "demo", pytest_version="7.0.0")
|
|
90
|
+
result = weigh(repo, home, cache=cache)
|
|
91
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
92
|
+
(snap,) = snapshots(home, KEY)
|
|
93
|
+
assert load(snap)["pytest_version"].startswith("7.0")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_pytest_below_the_minimum_is_refused_before_any_test(tmp_path, home, cache):
|
|
97
|
+
repo = plain_repo(tmp_path, venv_dir=".venv", pytest_version="6.2.5")
|
|
98
|
+
marker = guarded(repo, tmp_path)
|
|
99
|
+
result = weigh(repo, home, cache=cache)
|
|
100
|
+
assert result.returncode != 0
|
|
101
|
+
message = result.stdout + result.stderr
|
|
102
|
+
assert "6.2.5" in message and "7.0" in message
|
|
103
|
+
assert not marker.exists()
|
|
104
|
+
assert snapshots(home, KEY) == []
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def test_python_below_the_minimum_is_refused_before_any_test(tmp_path, home, cache):
|
|
108
|
+
repo = plain_repo(tmp_path, venv_dir=".venv", pytest_version="8.3.5", python="3.9")
|
|
109
|
+
marker = guarded(repo, tmp_path)
|
|
110
|
+
result = weigh(repo, home, cache=cache)
|
|
111
|
+
assert result.returncode != 0
|
|
112
|
+
message = result.stdout + result.stderr
|
|
113
|
+
assert "3.9" in message and "3.10" in message
|
|
114
|
+
assert not marker.exists()
|
|
115
|
+
assert snapshots(home, KEY) == []
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""The sampled kill matrix of `--mutation`, read from the snapshot.
|
|
2
|
+
|
|
3
|
+
Snapshot interface the tests pin (the spec leaves the JSON keys open):
|
|
4
|
+
mutation.sampled list of the sampled mutant ids (mutmut names, e.g. demo.parser.x_parse__mutmut_3)
|
|
5
|
+
mutation.mutants {id: {"line": source line of the mutation}} for the sampled mutants
|
|
6
|
+
mutation.matrix {id: [ids of the tests that kill it]}, a row for every sampled mutant
|
|
7
|
+
tests[node] booleans "subsumed", "hollow" (killed none of >= 2 sampled mutants on its lines)
|
|
8
|
+
and "insufficient_evidence" (fewer than 2 sampled mutants on its lines)
|
|
9
|
+
metrics hollow_tests and subsumed_in_kill_matrix are percentages of all tests
|
|
10
|
+
"""
|
|
11
|
+
import re
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
|
|
15
|
+
from fixture_repo import load, snapshots, weigh
|
|
16
|
+
from kill_repo import matrix_repo, sample_repo, shift_repo
|
|
17
|
+
|
|
18
|
+
KEY = "github.com/jesdi/demo"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def function_of(mutant):
|
|
22
|
+
return re.search(r"\.x_(\w+?)__mutmut_\d+$", mutant)[1]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def mutate(factory, name, tmp_path_factory, cache, *flags, nows=("2026-01-01T00:00:00Z",)):
|
|
26
|
+
home = tmp_path_factory.mktemp(name + "-home")
|
|
27
|
+
repo = factory(tmp_path_factory.mktemp(name) / "demo")
|
|
28
|
+
snaps = []
|
|
29
|
+
for now in nows:
|
|
30
|
+
result = weigh(repo, home, "--mutation", "--no-open", *flags, cache=cache, now=now)
|
|
31
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
32
|
+
snaps.append(load(snapshots(home, KEY)[-1]))
|
|
33
|
+
return snaps
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@pytest.fixture(scope="module")
|
|
37
|
+
def twice(tmp_path_factory, cache):
|
|
38
|
+
return mutate(sample_repo, "twice", tmp_path_factory, cache, nows=("2026-01-01T00:00:00Z", "2026-01-02T00:00:00Z"))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@pytest.fixture(scope="module")
|
|
42
|
+
def everything(tmp_path_factory, cache):
|
|
43
|
+
return mutate(sample_repo, "all", tmp_path_factory, cache, "--matrix-per-function", "all")[0]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@pytest.fixture(scope="module")
|
|
47
|
+
def ops(tmp_path_factory, cache):
|
|
48
|
+
return mutate(matrix_repo, "ops", tmp_path_factory, cache)[0]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@pytest.fixture(scope="module")
|
|
52
|
+
def shift(tmp_path_factory, cache):
|
|
53
|
+
return mutate(shift_repo, "shift", tmp_path_factory, cache)[0]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def by_function(snap, name):
|
|
57
|
+
return [m for m in snap["mutation"]["sampled"] if function_of(m) == name]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_two_runs_list_the_same_sampled_mutants_and_kill_matrix(twice):
|
|
61
|
+
first, second = (s["mutation"] for s in twice)
|
|
62
|
+
assert first["sampled"] and first["matrix"]
|
|
63
|
+
assert first["sampled"] == second["sampled"]
|
|
64
|
+
assert first["matrix"] == second["matrix"]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_at_most_three_mutants_per_function_on_different_lines(twice):
|
|
68
|
+
snap = twice[0]
|
|
69
|
+
parse = by_function(snap, "parse")
|
|
70
|
+
assert len(parse) == 3
|
|
71
|
+
assert len({snap["mutation"]["mutants"][m]["line"] for m in parse}) == 3
|
|
72
|
+
assert len(by_function(snap, "noop")) == 1
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_all_takes_every_mutant_of_the_function(everything):
|
|
76
|
+
matrix = everything["mutation"]["matrix"]
|
|
77
|
+
parse = {m for m in matrix if function_of(m) == "parse"}
|
|
78
|
+
assert len(parse) == 12
|
|
79
|
+
assert len({everything["mutation"]["mutants"][m]["line"] for m in parse}) == 6
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_matrix_row_records_every_killing_test(twice):
|
|
83
|
+
snap = twice[0]
|
|
84
|
+
tests = snap["tests"]
|
|
85
|
+
ok, edge = (next(n for n in tests if n.endswith("::" + t)) for t in ("test_parse_ok", "test_parse_edge"))
|
|
86
|
+
rows = [snap["mutation"]["matrix"][m] for m in by_function(snap, "parse")]
|
|
87
|
+
assert rows
|
|
88
|
+
for row in rows:
|
|
89
|
+
assert {ok, edge} <= set(row)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_test_killing_what_another_kills_is_subsumed(ops):
|
|
93
|
+
tests = ops["tests"]
|
|
94
|
+
a = next(t for n, t in tests.items() if n.endswith("::test_a"))
|
|
95
|
+
assert a["subsumed"] is True
|
|
96
|
+
assert a["insufficient_evidence"] is False
|
|
97
|
+
assert ops["metrics"]["subsumed_in_kill_matrix"]["value"] == pytest.approx(100 * sum(t["subsumed"] for t in tests.values()) / len(tests))
|
|
98
|
+
assert ops["metrics"]["subsumed_in_kill_matrix"]["value"] > 0
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def test_single_sampled_mutant_is_insufficient_evidence_and_counts_nowhere(shift):
|
|
102
|
+
tests = shift["tests"]
|
|
103
|
+
invalid = next(t for n, t in tests.items() if n.endswith("::test_parse_invalid"))
|
|
104
|
+
assert invalid["insufficient_evidence"] is True
|
|
105
|
+
assert invalid["subsumed"] is False
|
|
106
|
+
assert invalid["hollow"] is False
|
|
107
|
+
assert shift["metrics"]["subsumed_in_kill_matrix"]["value"] == 0
|
|
108
|
+
assert shift["metrics"]["hollow_tests"]["value"] == 0
|
|
109
|
+
assert shift["metrics"]["no_unique_coverage"]["value"] == 0
|
|
110
|
+
assert shift["metrics"]["duplicate_clusters"]["value"] == 0
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def test_test_that_kills_none_of_four_sampled_mutants_is_hollow(ops):
|
|
114
|
+
tests = ops["tests"]
|
|
115
|
+
roundtrip = next(t for n, t in tests.items() if n.endswith("::test_session_roundtrip"))
|
|
116
|
+
assert roundtrip["hollow"] is True
|
|
117
|
+
assert roundtrip["insufficient_evidence"] is False
|
|
118
|
+
assert ops["metrics"]["hollow_tests"]["value"] == pytest.approx(100 * sum(t["hollow"] for t in tests.values()) / len(tests))
|
|
119
|
+
assert ops["metrics"]["hollow_tests"]["value"] > 0
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def test_regression_and_economy_get_their_full_weights(twice):
|
|
123
|
+
snap = twice[0]
|
|
124
|
+
assert {"hollow_tests", "pseudo_tested_functions", "subsumed_in_kill_matrix"} <= snap["metrics"].keys()
|
|
125
|
+
assert snap["pillars"]["regression"]["partial"] is False
|
|
126
|
+
assert snap["pillars"]["economy"]["partial"] is False
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""Ticket tw/s5-smells/10: Eager test, Conditional test logic, Mystery guest, Swallowed exception, Real sleep and
|
|
2
|
+
Duplicate body, the partial default tier and the chat summary, through weigh.py.
|
|
3
|
+
|
|
4
|
+
Interface the tests pin (the spec leaves the JSON keys open), on top of test_smells.py and test_coverage_run.py:
|
|
5
|
+
tests[node].smells adds the names "Eager test", "Conditional test logic", "Mystery guest", "Swallowed exception",
|
|
6
|
+
"Real sleep" and "Duplicate body"
|
|
7
|
+
clusters [[node, ...]]: one list of node ids per duplicate-body cluster
|
|
8
|
+
metrics.duplicate_clusters {value, score}: percent of all tests that sit in a duplicate-body cluster
|
|
9
|
+
Stdout: one line per pillar holding its name, its displayed score and the word "partial" when the pillar is partial;
|
|
10
|
+
the inventory line ("<n> tests"); "<n> flaky test(s)"; the node ids of the 3 worst tests of the lowest pillar; the paths
|
|
11
|
+
of the snapshot and the dashboard.
|
|
12
|
+
"""
|
|
13
|
+
import re
|
|
14
|
+
|
|
15
|
+
import pytest
|
|
16
|
+
|
|
17
|
+
from fixture_repo import load, snapshots, weigh
|
|
18
|
+
from maint_repo import cluster_suite, smell_suite, summary_suite
|
|
19
|
+
|
|
20
|
+
KEY = "github.com/jesdi/demo"
|
|
21
|
+
NODE = re.compile(r"tests/[\w/]+\.py::\w+")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def build(tmp_path_factory, cache, name, make):
|
|
25
|
+
root = tmp_path_factory.mktemp(name)
|
|
26
|
+
(root / "home").mkdir()
|
|
27
|
+
result = weigh(make(root / "work" / "demo"), root / "home", cache=cache)
|
|
28
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
29
|
+
path = snapshots(root / "home", KEY)[-1]
|
|
30
|
+
return load(path), result, path, root / "home" / ".test-weigh-in" / KEY / "dashboard.html"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.fixture(scope="module")
|
|
34
|
+
def smells(tmp_path_factory, cache):
|
|
35
|
+
return build(tmp_path_factory, cache, "maint", smell_suite)[0]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@pytest.fixture(scope="module")
|
|
39
|
+
def cluster(tmp_path_factory, cache):
|
|
40
|
+
return build(tmp_path_factory, cache, "cluster", cluster_suite)[0]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@pytest.fixture(scope="module")
|
|
44
|
+
def summary(tmp_path_factory, cache):
|
|
45
|
+
return build(tmp_path_factory, cache, "summary", summary_suite)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def smelly(snap, smell):
|
|
49
|
+
return {n for n, t in snap["tests"].items() if smell in t.get("smells", [])}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_three_act_then_assert_cycles_are_an_eager_test_and_two_are_not(smells):
|
|
53
|
+
assert "smells" in smells["tests"]["tests/test_maint.py::test_flow_2"]
|
|
54
|
+
assert smelly(smells, "Eager test") == {"tests/test_maint.py::test_flow_3"}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_a_loop_over_literals_is_conditional_test_logic(smells):
|
|
58
|
+
assert smelly(smells, "Conditional test logic") == {"tests/test_maint.py::test_parse_all"}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_a_home_path_is_a_mystery_guest_but_tmp_path_is_not(smells):
|
|
62
|
+
assert "smells" in smells["tests"]["tests/test_guest.py::test_a"]
|
|
63
|
+
assert smelly(smells, "Mystery guest") == {"tests/test_guest.py::test_b"}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_a_try_except_that_does_nothing_is_a_swallowed_exception(smells):
|
|
67
|
+
assert smelly(smells, "Swallowed exception") == {"tests/test_maint.py::test_load"}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_a_non_zero_sleep_is_a_real_sleep_and_a_zero_sleep_is_not(smells):
|
|
71
|
+
assert "smells" in smells["tests"]["tests/test_sleep.py::test_a"]
|
|
72
|
+
assert smelly(smells, "Real sleep") == {"tests/test_sleep.py::test_b"}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_tests_differing_in_a_literal_and_a_name_form_one_duplicate_cluster(cluster):
|
|
76
|
+
intents = [f"tests/test_intent.py::test_intent_{i}" for i in range(1, 5)]
|
|
77
|
+
assert cluster["inventory"]["tests"] == 40
|
|
78
|
+
assert [sorted(c) for c in cluster["clusters"]] == [intents]
|
|
79
|
+
assert smelly(cluster, "Duplicate body") == set(intents)
|
|
80
|
+
assert cluster["metrics"]["duplicate_clusters"]["value"] == pytest.approx(10)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_a_run_without_mutation_weights_regression_and_economy_by_their_partial_weights(cluster):
|
|
84
|
+
m, p = cluster["metrics"], cluster["pillars"]
|
|
85
|
+
assert p["regression"]["partial"] and p["economy"]["partial"]
|
|
86
|
+
assert p["regression"]["score"] == pytest.approx(.6 * m["branch_coverage"]["score"] + .4 * m["hollow_tests"]["score"])
|
|
87
|
+
assert p["economy"]["score"] == pytest.approx(.6 * m["no_unique_coverage"]["score"] + .4 * m["duplicate_clusters"]["score"])
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_the_chat_summary_reports_scores_inventory_flaky_worst_tests_and_paths_without_advice(summary):
|
|
91
|
+
snap, result, snapshot, dashboard = summary
|
|
92
|
+
out = result.stdout
|
|
93
|
+
scores = {k: p["score"] for k, p in snap["pillars"].items()}
|
|
94
|
+
assert min(scores, key=lambda k: float("inf") if scores[k] is None else scores[k]) == "economy"
|
|
95
|
+
assert scores["maintainability"] is not None
|
|
96
|
+
names = {"regression": "Protection against regressions", "refactoring": "Resistance to refactoring",
|
|
97
|
+
"feedback": "Fast feedback", "maintainability": "Maintainability", "economy": "Economy"}
|
|
98
|
+
for key, name in names.items():
|
|
99
|
+
(line,) = [l for l in out.splitlines() if l.startswith(name)]
|
|
100
|
+
assert re.search(r"\b\d{1,2}\b", line)
|
|
101
|
+
if key in ("regression", "economy"):
|
|
102
|
+
assert "partial" in line.lower()
|
|
103
|
+
elif key in ("feedback", "maintainability"):
|
|
104
|
+
assert "partial" not in line.lower()
|
|
105
|
+
assert "40 tests" in out
|
|
106
|
+
assert "1 flaky test" in out
|
|
107
|
+
worst = set(NODE.findall(out)) - {"tests/test_retry.py::test_retry"}
|
|
108
|
+
assert len(worst) == 3
|
|
109
|
+
for node in worst:
|
|
110
|
+
t = snap["tests"][node]
|
|
111
|
+
assert "Duplicate body" in t["smells"] or t["unique_coverage"] == 0
|
|
112
|
+
assert str(snapshot) in out and str(dashboard) in out
|
|
113
|
+
assert not re.search(r"\b(consider|should|recommend|suggest|try|fix|improve|you)\b", out, re.I)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""`--mutation` through weigh.py: the score over all mutants, and recovery from a run SIGKILLed while mutmut's own
|
|
2
|
+
processes keep running.
|
|
3
|
+
|
|
4
|
+
Snapshot interface: metrics.mutation_score {value: percent of all mutants killed, score}.
|
|
5
|
+
"""
|
|
6
|
+
import os
|
|
7
|
+
import signal
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
from fixture_repo import HERE, load, snapshots, weigh
|
|
13
|
+
from kill_repo import replaced
|
|
14
|
+
from test_mutation_score import SLOW, commit, start, wait_for_mutmut, worktrees
|
|
15
|
+
|
|
16
|
+
sys.path.insert(0, str(HERE.parent))
|
|
17
|
+
|
|
18
|
+
KEY = "github.com/jesdi/demo"
|
|
19
|
+
# add's mutant is killed, mul's survives (x / y with y == 1), orphan's has no covering test: 1 of 3 killed
|
|
20
|
+
SCORED = "def add(x, y):\n return x + y\n\n\ndef mul(x, y):\n return x * y\n\n\ndef orphan(x, y):\n return x - y\n"
|
|
21
|
+
SCORED_TESTS = "from demo import scored\n\n\ndef test_ops():\n assert scored.add(1, 2) == 3\n assert scored.mul(3, 1) == 3\n"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_score_is_over_all_mutants_killed_surviving_and_uncovered(tmp_path, home, cache):
|
|
25
|
+
from weigh_rules import load as load_rules
|
|
26
|
+
from weigh_score import metric_score
|
|
27
|
+
|
|
28
|
+
repo = replaced(tmp_path / "demo", ("scored.py", SCORED), ("test_scored.py", SCORED_TESTS))
|
|
29
|
+
result = weigh(repo, home, "--mutation", "--no-open", cache=cache)
|
|
30
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
31
|
+
metric = load(snapshots(home, KEY)[-1])["metrics"]["mutation_score"]
|
|
32
|
+
assert metric["value"] == pytest.approx(100 / 3)
|
|
33
|
+
rule = load_rules()["pillars"]["regression"]["metrics"]["mutation_score"]
|
|
34
|
+
assert metric["score"] == pytest.approx(metric_score(100 / 3, rule["target"], rule["bad"], rule.get("log", False)))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def kill_group(pid):
|
|
38
|
+
try:
|
|
39
|
+
os.killpg(pid, signal.SIGKILL)
|
|
40
|
+
except ProcessLookupError:
|
|
41
|
+
pass
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_run_sigkilled_while_mutmut_runs_is_cleaned_up_by_the_next_run(tmp_path, home, cache):
|
|
45
|
+
from fixture_repo import build_repo
|
|
46
|
+
|
|
47
|
+
repo = build_repo(tmp_path / "demo")
|
|
48
|
+
commit(repo, {"tests/test_slow.py": SLOW})
|
|
49
|
+
first = start(repo, home, cache)
|
|
50
|
+
second = None
|
|
51
|
+
try:
|
|
52
|
+
wait_for_mutmut(repo, first)
|
|
53
|
+
first.kill() # weigh.py alone: mutmut and its workers live on, as after a real SIGKILL
|
|
54
|
+
first.wait()
|
|
55
|
+
stale = [l.removeprefix("worktree ") for l in worktrees(repo)[1:]]
|
|
56
|
+
assert len(stale) == 1
|
|
57
|
+
second = start(repo, home, cache)
|
|
58
|
+
fresh = wait_for_mutmut(repo, second, ignore=stale)
|
|
59
|
+
assert [l.removeprefix("worktree ") for l in worktrees(repo)[1:]] == [fresh]
|
|
60
|
+
assert not os.path.exists(stale[0])
|
|
61
|
+
assert second.wait(timeout=900) == 0
|
|
62
|
+
finally:
|
|
63
|
+
kill_group(first.pid)
|
|
64
|
+
if second:
|
|
65
|
+
kill_group(second.pid)
|
|
66
|
+
second.wait()
|
|
67
|
+
assert len(worktrees(repo)) == 1
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Sampling candidates, the mutation settings in the snapshot, and kills after a hung matrix run.
|
|
2
|
+
|
|
3
|
+
Snapshot interface: mutation_settings {mutation: bool, matrix_per_function: N or "all"}; mutation.matrix as in
|
|
4
|
+
test_kill_matrix.py, a row (empty when no test covers the function) for every sampled mutant.
|
|
5
|
+
"""
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
10
|
+
from fixture_repo import HERE, load, snapshots, weigh
|
|
11
|
+
from kill_repo import replaced
|
|
12
|
+
|
|
13
|
+
sys.path.insert(0, str(HERE.parent))
|
|
14
|
+
|
|
15
|
+
KEY = "github.com/jesdi/demo"
|
|
16
|
+
SOURCE = "def add(x, y):\n return x + y\n\n\ndef orphan(x, y):\n return x - y\n"
|
|
17
|
+
TESTS = "from demo import calc\n\n\ndef test_add():\n assert calc.add(1, 2) == 3\n"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@pytest.fixture(scope="module")
|
|
21
|
+
def runs(tmp_path_factory, cache):
|
|
22
|
+
home = tmp_path_factory.mktemp("sampling-home")
|
|
23
|
+
repo = replaced(tmp_path_factory.mktemp("sampling") / "demo", ("calc.py", SOURCE), ("test_calc.py", TESTS))
|
|
24
|
+
snaps = {}
|
|
25
|
+
for now, flags in (("2026-01-01T00:00:00Z", ()), ("2026-01-02T00:00:00Z", ("--matrix-per-function", "all")),
|
|
26
|
+
("2026-01-03T00:00:00Z", None)):
|
|
27
|
+
result = weigh(repo, home, "--no-open", *(("--mutation", *flags) if flags is not None else ()), cache=cache, now=now)
|
|
28
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
29
|
+
snaps[flags] = load(snapshots(home, KEY)[-1])
|
|
30
|
+
return snaps
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.mark.parametrize("flags", [(), ("--matrix-per-function", "all")])
|
|
34
|
+
def test_a_function_no_test_covers_is_sampled_with_an_empty_row(runs, flags):
|
|
35
|
+
matrix = runs[flags]["mutation"]["matrix"]
|
|
36
|
+
orphan = [m for m in matrix if ".x_orphan__mutmut_" in m]
|
|
37
|
+
assert orphan and all(matrix[m] == [] for m in orphan)
|
|
38
|
+
assert any(".x_add__mutmut_" in m and matrix[m] for m in matrix)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_the_snapshot_holds_the_mutation_settings(runs):
|
|
42
|
+
assert runs[()]["mutation_settings"] == {"mutation": True, "matrix_per_function": 3}
|
|
43
|
+
assert runs[("--matrix-per-function", "all")]["mutation_settings"] == {"mutation": True, "matrix_per_function": "all"}
|
|
44
|
+
assert runs[None]["mutation_settings"] == {"mutation": False, "matrix_per_function": 3}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_a_hung_run_credits_only_the_tests_seen_to_fail_or_hang(monkeypatch):
|
|
48
|
+
import weigh_mutation
|
|
49
|
+
|
|
50
|
+
alone = {"t_fail": {"t_fail"}, "t_hang": None, "t_pass": set()}
|
|
51
|
+
monkeypatch.setattr(weigh_mutation, "_failing",
|
|
52
|
+
lambda python, wt, env, mutant, tests, timeout: alone[tests[0]] if len(tests) == 1 else None)
|
|
53
|
+
assert weigh_mutation._kills(None, None, {}, "m", ["t_hang", "t_fail", "t_pass"], 1) == ["t_fail", "t_hang"]
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"""`--mutation` against fixture repos: refusals, a clean run in a temporary worktree, interruption, and the target left untouched."""
|
|
2
|
+
import os
|
|
3
|
+
import signal
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
10
|
+
from fixture_repo import WEIGH, build_repo, git, snapshots, uv
|
|
11
|
+
|
|
12
|
+
KEY = "github.com/jesdi/demo"
|
|
13
|
+
SLOW = "import time\ndef test_slow():\n time.sleep(3)\n"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def marker_conftest(marker):
|
|
17
|
+
return f"def pytest_sessionstart(session):\n open({str(marker)!r}, 'a').write('x')\n"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def commit(repo, files):
|
|
21
|
+
for rel, text in files.items():
|
|
22
|
+
(repo / rel).write_text(text)
|
|
23
|
+
git(repo, "add", "-A")
|
|
24
|
+
git(repo, "commit", "-q", "-m", "more")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def env_for(home, cache):
|
|
28
|
+
env = {k: v for k, v in os.environ.items() if k not in ("VIRTUAL_ENV", "PYTHONPATH")}
|
|
29
|
+
env.update(HOME=str(home), TEST_WEIGH_IN_CACHE_DIR=str(cache), TEST_WEIGH_IN_UV=uv(), BROWSER="true")
|
|
30
|
+
return env
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def mutate(repo, home, cache):
|
|
34
|
+
return subprocess.run([sys.executable, str(WEIGH), str(repo), "--mutation", "--no-open"],
|
|
35
|
+
env=env_for(home, cache), capture_output=True, text=True, timeout=900)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def worktrees(repo):
|
|
39
|
+
return [l for l in git(repo, "worktree", "list", "--porcelain").splitlines() if l.startswith("worktree ")]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def start(repo, home, cache):
|
|
43
|
+
return subprocess.Popen([sys.executable, str(WEIGH), str(repo), "--mutation", "--no-open"], env=env_for(home, cache),
|
|
44
|
+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def wait_for_mutmut(repo, proc, ignore=()):
|
|
48
|
+
"""Poll until a temporary worktree of the repo holds a mutants/ directory, i.e. mutmut is running."""
|
|
49
|
+
deadline = time.time() + 300
|
|
50
|
+
while time.time() < deadline:
|
|
51
|
+
assert proc.poll() is None, "the run ended before mutmut started"
|
|
52
|
+
for line in worktrees(repo)[1:]:
|
|
53
|
+
path = line.removeprefix("worktree ")
|
|
54
|
+
if path not in ignore and os.path.isdir(os.path.join(path, "mutants")):
|
|
55
|
+
return path
|
|
56
|
+
time.sleep(0.1)
|
|
57
|
+
pytest.fail("mutmut never started")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def reap(proc):
|
|
61
|
+
try:
|
|
62
|
+
os.killpg(proc.pid, signal.SIGKILL)
|
|
63
|
+
except ProcessLookupError:
|
|
64
|
+
pass
|
|
65
|
+
proc.wait()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def refused(result, name):
|
|
69
|
+
out = result.stdout + result.stderr
|
|
70
|
+
assert result.returncode != 0, out
|
|
71
|
+
assert name in out, out
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_red_suite_is_refused_naming_the_failing_test(tmp_path, home, cache):
|
|
75
|
+
repo = build_repo(tmp_path / "demo")
|
|
76
|
+
commit(repo, {"tests/test_claim.py": "def test_claim_flow():\n assert False\n"})
|
|
77
|
+
refused(mutate(repo, home, cache), "test_claim_flow")
|
|
78
|
+
assert snapshots(home, KEY) == []
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@pytest.mark.parametrize("dirty, name", [
|
|
82
|
+
({"demo/board.py": "def render(n):\n return str(n) + ''\n"}, "board.py"),
|
|
83
|
+
({"tests/test_new.py": "def test_new():\n assert True\n"}, "tests/test_new.py"),
|
|
84
|
+
])
|
|
85
|
+
def test_dirty_tree_is_refused_before_any_test_runs(tmp_path, home, cache, dirty, name):
|
|
86
|
+
marker = tmp_path / "ran"
|
|
87
|
+
repo = build_repo(tmp_path / "demo")
|
|
88
|
+
commit(repo, {"tests/conftest.py": marker_conftest(marker)})
|
|
89
|
+
for rel, text in dirty.items():
|
|
90
|
+
(repo / rel).write_text(text)
|
|
91
|
+
refused(mutate(repo, home, cache), name)
|
|
92
|
+
assert not marker.exists()
|
|
93
|
+
assert snapshots(home, KEY) == []
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_clean_run_leaves_the_target_untouched(tmp_path, home, cache):
|
|
97
|
+
repo = build_repo(tmp_path / "demo")
|
|
98
|
+
config = (repo / ".git" / "config").read_bytes()
|
|
99
|
+
result = mutate(repo, home, cache)
|
|
100
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
101
|
+
assert not (repo / "mutants").exists()
|
|
102
|
+
assert len(worktrees(repo)) == 1
|
|
103
|
+
assert git(repo, "status", "--porcelain") == ""
|
|
104
|
+
assert (repo / ".git" / "config").read_bytes() == config
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def test_killed_run_is_cleaned_up_by_the_next_run(tmp_path, home, cache):
|
|
108
|
+
repo = build_repo(tmp_path / "demo")
|
|
109
|
+
commit(repo, {"tests/test_slow.py": SLOW})
|
|
110
|
+
proc = start(repo, home, cache)
|
|
111
|
+
try:
|
|
112
|
+
wait_for_mutmut(repo, proc)
|
|
113
|
+
proc.kill()
|
|
114
|
+
finally:
|
|
115
|
+
reap(proc)
|
|
116
|
+
stale = [l.removeprefix("worktree ") for l in worktrees(repo)[1:]]
|
|
117
|
+
assert len(stale) == 1
|
|
118
|
+
second = start(repo, home, cache)
|
|
119
|
+
try:
|
|
120
|
+
fresh = wait_for_mutmut(repo, second, ignore=stale)
|
|
121
|
+
# the second mutation is under way: the interrupted run's worktree is already gone, registration and directory
|
|
122
|
+
assert [l.removeprefix("worktree ") for l in worktrees(repo)[1:]] == [fresh]
|
|
123
|
+
assert not os.path.exists(stale[0])
|
|
124
|
+
assert second.wait(timeout=900) == 0
|
|
125
|
+
finally:
|
|
126
|
+
reap(second)
|
|
127
|
+
assert len(worktrees(repo)) == 1
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def test_ctrl_c_removes_the_worktree(tmp_path, home, cache):
|
|
131
|
+
repo = build_repo(tmp_path / "demo")
|
|
132
|
+
commit(repo, {"tests/test_slow.py": SLOW})
|
|
133
|
+
proc = start(repo, home, cache)
|
|
134
|
+
try:
|
|
135
|
+
wait_for_mutmut(repo, proc)
|
|
136
|
+
os.killpg(proc.pid, signal.SIGINT)
|
|
137
|
+
assert proc.wait(timeout=120) != 0
|
|
138
|
+
finally:
|
|
139
|
+
reap(proc)
|
|
140
|
+
assert len(worktrees(repo)) == 1
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""A refused `--mutation` run still removes the worktree an interrupted run left behind."""
|
|
2
|
+
import subprocess
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from fixture_repo import build_repo, git
|
|
7
|
+
from test_mutation_score import commit, mutate, worktrees
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def plant_stale(repo, cache):
|
|
11
|
+
"""A worktree registered in the repo, under the cache, named after a pid that no longer runs."""
|
|
12
|
+
dead = subprocess.Popen(["true"])
|
|
13
|
+
dead.wait()
|
|
14
|
+
wt = cache / "worktrees" / f"{dead.pid}-stale"
|
|
15
|
+
git(repo, "worktree", "add", "-q", "--detach", str(wt), "HEAD")
|
|
16
|
+
return wt
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@pytest.mark.parametrize("break_it", [
|
|
20
|
+
lambda repo: (repo / "demo" / "board.py").write_text("dirty\n"),
|
|
21
|
+
lambda repo: commit(repo, {"tests/test_claim.py": "def test_claim_flow():\n assert False\n"}),
|
|
22
|
+
], ids=["dirty", "red"])
|
|
23
|
+
def test_refused_run_removes_the_stale_worktree(tmp_path, home, cache, break_it):
|
|
24
|
+
repo = build_repo(tmp_path / "demo")
|
|
25
|
+
wt = plant_stale(repo, cache)
|
|
26
|
+
break_it(repo)
|
|
27
|
+
result = mutate(repo, home, cache)
|
|
28
|
+
assert result.returncode == 1, result.stdout + result.stderr
|
|
29
|
+
assert not wt.exists()
|
|
30
|
+
assert len(worktrees(repo)) == 1
|