@jesdi/skills 0.0.82 → 0.0.84
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 +1 -1
- package/skills/test-weigh-in/tests/test_mutation_recovery.py +4 -4
- package/skills/test-weigh-in/tests/test_mutation_score.py +24 -8
- package/skills/test-weigh-in/tests/test_runs.py +33 -14
- package/skills/test-weigh-in/weigh.py +2 -0
- package/skills/test-weigh-in/weigh_mutation.py +1 -1
- package/skills/test-weigh-in/weigh_pytest_plugin.py +1 -15
- package/skills/test-weigh-in/weigh_runs.py +62 -23
- package/skills-manifest.json +3 -3
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@ import pytest
|
|
|
11
11
|
|
|
12
12
|
from fixture_repo import HERE, load, snapshots, weigh
|
|
13
13
|
from kill_repo import replaced
|
|
14
|
-
from test_mutation_score import SLOW, commit, start, wait_for_mutmut, worktrees
|
|
14
|
+
from test_mutation_score import SLOW, commit, finish, start, wait_for_mutmut, worktrees
|
|
15
15
|
|
|
16
16
|
sys.path.insert(0, str(HERE.parent))
|
|
17
17
|
|
|
@@ -46,7 +46,7 @@ def test_run_sigkilled_while_mutmut_runs_is_cleaned_up_by_the_next_run(tmp_path,
|
|
|
46
46
|
|
|
47
47
|
repo = build_repo(tmp_path / "demo")
|
|
48
48
|
commit(repo, {"tests/test_slow.py": SLOW})
|
|
49
|
-
first = start(repo, home, cache)
|
|
49
|
+
first = start(repo, home, cache, tmp_path / "first.err")
|
|
50
50
|
second = None
|
|
51
51
|
try:
|
|
52
52
|
wait_for_mutmut(repo, first)
|
|
@@ -54,11 +54,11 @@ def test_run_sigkilled_while_mutmut_runs_is_cleaned_up_by_the_next_run(tmp_path,
|
|
|
54
54
|
first.wait()
|
|
55
55
|
stale = [l.removeprefix("worktree ") for l in worktrees(repo)[1:]]
|
|
56
56
|
assert len(stale) == 1
|
|
57
|
-
second = start(repo, home, cache)
|
|
57
|
+
second = start(repo, home, cache, tmp_path / "second.err")
|
|
58
58
|
fresh = wait_for_mutmut(repo, second, ignore=stale)
|
|
59
59
|
assert [l.removeprefix("worktree ") for l in worktrees(repo)[1:]] == [fresh]
|
|
60
60
|
assert not os.path.exists(stale[0])
|
|
61
|
-
assert second.
|
|
61
|
+
assert finish(second, tmp_path / "second.err", 900) == 0
|
|
62
62
|
finally:
|
|
63
63
|
kill_group(first.pid)
|
|
64
64
|
if second:
|
|
@@ -39,9 +39,25 @@ def worktrees(repo):
|
|
|
39
39
|
return [l for l in git(repo, "worktree", "list", "--porcelain").splitlines() if l.startswith("worktree ")]
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
def start(repo, home, cache):
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
def start(repo, home, cache, log):
|
|
43
|
+
"""weigh.py --mutation in its own process group, stderr to the file log (where `finish` reads its stack dump)."""
|
|
44
|
+
with open(log, "w") as err:
|
|
45
|
+
return subprocess.Popen([sys.executable, str(WEIGH), str(repo), "--mutation", "--no-open"], env=env_for(home, cache),
|
|
46
|
+
stdout=subprocess.DEVNULL, stderr=err, start_new_session=True)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def finish(proc, log, timeout):
|
|
50
|
+
"""proc's exit code. A run still going after timeout fails the test with weigh.py's Python stacks (faulthandler, on
|
|
51
|
+
SIGUSR1) and its process group, so a hang shows where it waits."""
|
|
52
|
+
try:
|
|
53
|
+
return proc.wait(timeout=timeout)
|
|
54
|
+
except subprocess.TimeoutExpired:
|
|
55
|
+
os.kill(proc.pid, signal.SIGUSR1)
|
|
56
|
+
time.sleep(2)
|
|
57
|
+
ps = subprocess.run(["ps", "-A", "-o", "pid,ppid,pgid,stat,etime,args"], capture_output=True, text=True).stdout.splitlines()
|
|
58
|
+
group = [l for l in ps[1:] if l.split()[2] == str(proc.pid)]
|
|
59
|
+
pytest.fail(f"weigh.py still running {timeout} s on\n--- its stderr ---\n{open(log).read()}\n--- its process group ---\n"
|
|
60
|
+
+ "\n".join(ps[:1] + group))
|
|
45
61
|
|
|
46
62
|
|
|
47
63
|
def wait_for_mutmut(repo, proc, ignore=()):
|
|
@@ -107,7 +123,7 @@ def test_clean_run_leaves_the_target_untouched(tmp_path, home, cache):
|
|
|
107
123
|
def test_killed_run_is_cleaned_up_by_the_next_run(tmp_path, home, cache):
|
|
108
124
|
repo = build_repo(tmp_path / "demo")
|
|
109
125
|
commit(repo, {"tests/test_slow.py": SLOW})
|
|
110
|
-
proc = start(repo, home, cache)
|
|
126
|
+
proc = start(repo, home, cache, tmp_path / "first.err")
|
|
111
127
|
try:
|
|
112
128
|
wait_for_mutmut(repo, proc)
|
|
113
129
|
proc.kill()
|
|
@@ -115,13 +131,13 @@ def test_killed_run_is_cleaned_up_by_the_next_run(tmp_path, home, cache):
|
|
|
115
131
|
reap(proc)
|
|
116
132
|
stale = [l.removeprefix("worktree ") for l in worktrees(repo)[1:]]
|
|
117
133
|
assert len(stale) == 1
|
|
118
|
-
second = start(repo, home, cache)
|
|
134
|
+
second = start(repo, home, cache, tmp_path / "second.err")
|
|
119
135
|
try:
|
|
120
136
|
fresh = wait_for_mutmut(repo, second, ignore=stale)
|
|
121
137
|
# the second mutation is under way: the interrupted run's worktree is already gone, registration and directory
|
|
122
138
|
assert [l.removeprefix("worktree ") for l in worktrees(repo)[1:]] == [fresh]
|
|
123
139
|
assert not os.path.exists(stale[0])
|
|
124
|
-
assert second.
|
|
140
|
+
assert finish(second, tmp_path / "second.err", 900) == 0
|
|
125
141
|
finally:
|
|
126
142
|
reap(second)
|
|
127
143
|
assert len(worktrees(repo)) == 1
|
|
@@ -130,11 +146,11 @@ def test_killed_run_is_cleaned_up_by_the_next_run(tmp_path, home, cache):
|
|
|
130
146
|
def test_ctrl_c_removes_the_worktree(tmp_path, home, cache):
|
|
131
147
|
repo = build_repo(tmp_path / "demo")
|
|
132
148
|
commit(repo, {"tests/test_slow.py": SLOW})
|
|
133
|
-
proc = start(repo, home, cache)
|
|
149
|
+
proc = start(repo, home, cache, tmp_path / "weigh.err")
|
|
134
150
|
try:
|
|
135
151
|
wait_for_mutmut(repo, proc)
|
|
136
152
|
os.killpg(proc.pid, signal.SIGINT)
|
|
137
|
-
assert proc.
|
|
153
|
+
assert finish(proc, tmp_path / "weigh.err", 120) != 0
|
|
138
154
|
finally:
|
|
139
155
|
reap(proc)
|
|
140
156
|
assert len(worktrees(repo)) == 1
|
|
@@ -119,18 +119,19 @@ def test_an_origin_that_climbs_out_of_the_snapshot_dir_is_refused(tmp_path, home
|
|
|
119
119
|
|
|
120
120
|
|
|
121
121
|
@pytest.mark.parametrize("args", ["--junitxml=report.xml", "-q --junit-xml report.xml", "--log-file=report.log",
|
|
122
|
-
"--basetemp=tmp"])
|
|
123
|
-
def
|
|
122
|
+
"--basetemp=tmp", "--debug"])
|
|
123
|
+
def test_file_writing_pytest_args_leave_the_repo_as_it_was(tmp_path, home, cache, args):
|
|
124
124
|
repo = build_repo(tmp_path / "demo")
|
|
125
125
|
result = weigh(repo, home, f"--pytest-args={args}", cache=cache)
|
|
126
126
|
assert result.returncode == 0, result.stdout + result.stderr
|
|
127
127
|
assert git(repo, "status", "--porcelain") == ""
|
|
128
128
|
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
@pytest.mark.parametrize("addopts", ["--junitxml=report.xml", "--debug"])
|
|
131
|
+
def test_file_writers_configured_by_the_repo_leave_it_as_it_was(tmp_path, home, cache, addopts):
|
|
131
132
|
repo = build_repo(tmp_path / "demo")
|
|
132
133
|
pyproject = repo / "pyproject.toml"
|
|
133
|
-
pyproject.write_text(pyproject.read_text().replace('"-p fakeclock"', '"-p fakeclock
|
|
134
|
+
pyproject.write_text(pyproject.read_text().replace('"-p fakeclock"', f'"-p fakeclock {addopts}"')
|
|
134
135
|
+ 'log_file = "report.log"\n')
|
|
135
136
|
git(repo, "commit", "-q", "-am", "writers")
|
|
136
137
|
result = weigh(repo, home, cache=cache)
|
|
@@ -138,19 +139,37 @@ def test_file_writers_configured_by_the_repo_write_outside_it(tmp_path, home, ca
|
|
|
138
139
|
assert git(repo, "status", "--porcelain") == ""
|
|
139
140
|
|
|
140
141
|
|
|
141
|
-
def
|
|
142
|
-
repo =
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
assert
|
|
142
|
+
def test_a_test_that_writes_where_it_runs_leaves_the_repo_as_it_was(tmp_path, home, cache):
|
|
143
|
+
repo = committed(tmp_path, {"tests/test_leak.py": "from pathlib import Path\n\n\ndef test_leak():\n"
|
|
144
|
+
" Path('leak.txt').write_text('x')\n"})
|
|
145
|
+
result = weigh(repo, home, cache=cache)
|
|
146
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
146
147
|
assert git(repo, "status", "--porcelain") == ""
|
|
147
|
-
assert snapshots(home, KEY)
|
|
148
|
+
assert "tests/test_leak.py::test_leak" in load(snapshots(home, KEY)[0])["tests"]
|
|
148
149
|
|
|
149
150
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
@pytest.mark.parametrize("target", ["demo/board.py", "out.log"])
|
|
152
|
+
def test_a_run_that_changes_the_repo_anyway_is_refused(tmp_path, home, cache, target):
|
|
153
|
+
"""Written by absolute path, past the copy: an already-dirty tracked file or an ignored one, both invisible to git status."""
|
|
154
|
+
repo = tmp_path / "demo"
|
|
155
|
+
committed(tmp_path, {".gitignore": "*.log\n", "tests/test_leak.py": f"def test_leak():\n"
|
|
156
|
+
f" with open({str(repo / target)!r}, 'a') as f:\n f.write('# leaked\\n')\n"})
|
|
157
|
+
with (repo / "demo/board.py").open("a") as f:
|
|
158
|
+
f.write("# dirty before the run\n")
|
|
153
159
|
result = weigh(repo, home, cache=cache)
|
|
154
160
|
assert result.returncode != 0
|
|
155
|
-
assert "changed the target repo" in result.stderr and
|
|
161
|
+
assert "changed the target repo" in result.stderr and target in result.stderr
|
|
156
162
|
assert snapshots(home, KEY) == []
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def test_source_imported_from_the_repo_itself_is_measured(tmp_path, home, cache):
|
|
166
|
+
"""An editable install points at the repo, not the copy the run uses: its code still counts, under its repo path."""
|
|
167
|
+
repo = committed(tmp_path, {"src/editable/__init__.py": "def double(n):\n return 2 * n\n",
|
|
168
|
+
"tests/test_editable.py": "from editable import double\n\n\ndef test_double():\n"
|
|
169
|
+
" assert double(2) == 4\n"})
|
|
170
|
+
site = next((repo / ".venv" / "lib").glob("python*/site-packages"))
|
|
171
|
+
(site / "editable.pth").write_text(str(repo / "src") + "\n") # the venv ignores itself: the tree stays clean
|
|
172
|
+
result = weigh(repo, home, cache=cache)
|
|
173
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
174
|
+
test = load(snapshots(home, KEY)[0])["tests"]["tests/test_editable.py::test_double"]
|
|
175
|
+
assert test["coverage"] == {"src/editable/__init__.py": [2]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Weigh a repo's test suite: `weigh.py <repo-path> [--pytest-args "..."]`."""
|
|
2
2
|
import argparse
|
|
3
|
+
import faulthandler
|
|
3
4
|
import signal
|
|
4
5
|
import sys
|
|
5
6
|
import webbrowser
|
|
@@ -127,6 +128,7 @@ def _terminate(signum, frame):
|
|
|
127
128
|
|
|
128
129
|
if __name__ == "__main__":
|
|
129
130
|
signal.signal(signal.SIGTERM, _terminate)
|
|
131
|
+
faulthandler.register(signal.SIGUSR1, all_threads=True) # `kill -USR1 <pid>` prints every thread's stack to stderr
|
|
130
132
|
try:
|
|
131
133
|
sys.exit(main())
|
|
132
134
|
except KeyboardInterrupt: # the temporary worktree is removed on the way out
|
|
@@ -105,7 +105,7 @@ def _failing(python, wt, env, mutant, tests, timeout):
|
|
|
105
105
|
"""The tests (params folded) that fail with the mutant active, every one of them run (pytest without -x); None when the run hangs."""
|
|
106
106
|
with tempfile.TemporaryDirectory() as tmp:
|
|
107
107
|
out = os.path.join(tmp, "cases.json")
|
|
108
|
-
run_env = {**env, "MUTANT_UNDER_TEST": mutant, "TEST_WEIGH_IN_OUT": out
|
|
108
|
+
run_env = {**env, "MUTANT_UNDER_TEST": mutant, "TEST_WEIGH_IN_OUT": out}
|
|
109
109
|
try:
|
|
110
110
|
subprocess.run([str(python), "-m", "pytest", "-p", "no:randomly", "-p", "no:cacheprovider", "--maxfail=1000000", "-p", "weigh_pytest_plugin", *tests],
|
|
111
111
|
cwd=wt / "mutants", env=run_env, capture_output=True, timeout=timeout)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
"""Pytest plugin loaded into the target's interpreter: writes each case's outcome and duration to TEST_WEIGH_IN_OUT
|
|
2
|
-
and sends the files pytest would write into the repo to TEST_WEIGH_IN_ARTIFACTS."""
|
|
1
|
+
"""Pytest plugin loaded into the target's interpreter: writes each case's outcome and duration to TEST_WEIGH_IN_OUT."""
|
|
3
2
|
import json
|
|
4
3
|
import os
|
|
5
4
|
import sys
|
|
@@ -9,19 +8,6 @@ import pytest
|
|
|
9
8
|
|
|
10
9
|
_cases = {}
|
|
11
10
|
_start = time.perf_counter()
|
|
12
|
-
# Option dests of core and common-plugin file writers (junitxml, logging, basetemp, pytest-reportlog, pytest-html,
|
|
13
|
-
# pytest-json-report). They are read from the effective config, so addopts, PYTEST_ADDOPTS and ini values are covered.
|
|
14
|
-
# ponytail: a writer of an unknown plugin still gets through; weigh_runs refuses the run when the repo changed.
|
|
15
|
-
WRITERS = ("xmlpath", "log_file", "basetemp", "report_log", "htmlpath", "json_report_file")
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@pytest.hookimpl(tryfirst=True)
|
|
19
|
-
def pytest_configure(config):
|
|
20
|
-
artifacts = os.environ["TEST_WEIGH_IN_ARTIFACTS"]
|
|
21
|
-
for dest in WRITERS:
|
|
22
|
-
set_by_ini = dest == "log_file" and config.getini("log_file")
|
|
23
|
-
if getattr(config.option, dest, None) or set_by_ini:
|
|
24
|
-
setattr(config.option, dest, os.path.join(artifacts, dest))
|
|
25
11
|
|
|
26
12
|
|
|
27
13
|
def _context(item, when):
|
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
import json
|
|
3
3
|
import os
|
|
4
4
|
import shlex
|
|
5
|
+
import shutil
|
|
6
|
+
import stat
|
|
5
7
|
import subprocess
|
|
6
8
|
import tempfile
|
|
9
|
+
from contextlib import contextmanager
|
|
10
|
+
from pathlib import Path
|
|
7
11
|
|
|
8
12
|
from weigh_coverage import contexts_regex
|
|
9
13
|
from weigh_env import SetupError
|
|
@@ -13,30 +17,52 @@ from weigh_snapshot import git
|
|
|
13
17
|
PYTEST = ["-m", "pytest", "-p", "no:randomly", "-p", "no:cacheprovider", "-p", "weigh_pytest_plugin"]
|
|
14
18
|
# Paths inside the repo that the coverage run leaves out: environments, and the test files.
|
|
15
19
|
OMIT = (".venv/**", "venv/**") + TEST_GLOBS
|
|
20
|
+
# Environments find_interpreter looks for: the interpreter runs from the repo, so the copy leaves them out.
|
|
21
|
+
ENVS = (".venv", "venv")
|
|
16
22
|
# pytest exit codes of a run that executed its tests: all passed, some failed.
|
|
17
23
|
RAN = (0, 1)
|
|
18
24
|
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
@contextmanager
|
|
27
|
+
def _copy(repo):
|
|
28
|
+
"""A throwaway copy of the repo's working tree, uncommitted and ignored files included, that a run works in: whatever
|
|
29
|
+
pytest, its config or the tests write relative to where they run lands there, never in the repo."""
|
|
30
|
+
# ponytail: a full copy per run; clone the files (APFS clonefile, reflink) if big trees make it slow
|
|
31
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
32
|
+
work = Path(tmp).resolve() / repo.name
|
|
33
|
+
shutil.copytree(repo, work, symlinks=True, ignore=lambda d, names: [n for n in names if n in ENVS] if Path(d) == repo else [])
|
|
34
|
+
yield work
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _state(repo):
|
|
38
|
+
"""{path: (size, mtime)} of everything under the repo but .git, so a change to an ignored or already-dirty file shows."""
|
|
39
|
+
found = {}
|
|
40
|
+
for folder, dirs, files in os.walk(repo):
|
|
41
|
+
dirs[:] = [d for d in dirs if d != ".git"]
|
|
42
|
+
for name in dirs + files:
|
|
43
|
+
path = os.path.join(folder, name)
|
|
44
|
+
st = os.lstat(path)
|
|
45
|
+
found[os.path.relpath(path, repo)] = "dir" if stat.S_ISDIR(st.st_mode) else (st.st_size, st.st_mtime_ns)
|
|
46
|
+
return found
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _pytest(python, repo, work, overlay, pytest_args, tmp, runner=(), env=None):
|
|
50
|
+
"""One pytest run in the copy; a run that still changed the repo itself (an absolute path into it) is refused."""
|
|
26
51
|
out = os.path.join(tmp, "cases.json")
|
|
27
|
-
env = {**os.environ, **(env or {}), "PYTHONPATH": str(overlay), "PYTHONDONTWRITEBYTECODE": "1",
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if
|
|
32
|
-
|
|
33
|
-
|
|
52
|
+
env = {**os.environ, **(env or {}), "PYTHONPATH": str(overlay), "PYTHONDONTWRITEBYTECODE": "1", "TEST_WEIGH_IN_OUT": out}
|
|
53
|
+
before = git(repo, "status", "--porcelain"), _state(repo)
|
|
54
|
+
proc = subprocess.run([str(python), *runner, *PYTEST, *shlex.split(pytest_args)], cwd=work, env=env, capture_output=True, text=True)
|
|
55
|
+
after = git(repo, "status", "--porcelain"), _state(repo)
|
|
56
|
+
if after != before:
|
|
57
|
+
changed = sorted(p for p in before[1].keys() | after[1].keys() if before[1].get(p) != after[1].get(p))
|
|
58
|
+
raise SetupError("pytest changed the target repo by an absolute path; drop the test, plugin or option that writes there:\n"
|
|
59
|
+
+ "\n".join(changed or [after[0]]))
|
|
34
60
|
return proc, out
|
|
35
61
|
|
|
36
62
|
|
|
37
63
|
def plain_run(python, repo, overlay, pytest_args):
|
|
38
|
-
with tempfile.TemporaryDirectory() as tmp:
|
|
39
|
-
proc, out = _pytest(python, repo, overlay, pytest_args, tmp)
|
|
64
|
+
with tempfile.TemporaryDirectory() as tmp, _copy(repo) as work:
|
|
65
|
+
proc, out = _pytest(python, repo, work, overlay, pytest_args, tmp)
|
|
40
66
|
if proc.returncode not in RAN or not os.path.exists(out):
|
|
41
67
|
raise SetupError(f"pytest exited {proc.returncode} without running the tests:\n" + proc.stdout + proc.stderr)
|
|
42
68
|
with open(out) as f:
|
|
@@ -65,15 +91,15 @@ def coverage_run(python, repo, overlay, pytest_args, eligible):
|
|
|
65
91
|
"""Pytest under branch coverage with a context per test phase, as a dict: cases; report, the coverage json report of
|
|
66
92
|
the passing cases; value_report, the same of the eligible tests that also passed under coverage; arcs, the arcs of
|
|
67
93
|
each passing case's call context. A coverage report that fails is an error, so no metric comes from missing data."""
|
|
68
|
-
with tempfile.TemporaryDirectory() as tmp:
|
|
94
|
+
with tempfile.TemporaryDirectory() as tmp, _copy(repo) as work:
|
|
69
95
|
rc = os.path.join(tmp, "rc")
|
|
70
96
|
open(rc, "w").close()
|
|
71
|
-
data = os.path.join(tmp, "data")
|
|
72
|
-
#
|
|
73
|
-
# named tests above it excludes nothing
|
|
74
|
-
omit = ",".join(f"{
|
|
75
|
-
run, out = _pytest(python, repo, overlay, pytest_args, tmp, env={"COVERAGE_RCFILE": rc},
|
|
76
|
-
runner=["-m", "coverage", "run", "--branch", f"--data-file={
|
|
97
|
+
data, raw = os.path.join(tmp, "data"), os.path.join(tmp, "raw")
|
|
98
|
+
# the copy, and the repo for code imported from it (an editable install points there). Test files are the cost
|
|
99
|
+
# being weighed, not the code under test; anchored in each root, so a folder named tests above it excludes nothing
|
|
100
|
+
omit = ",".join(f"{root}/**/{p}" for root in (work, repo) for p in OMIT)
|
|
101
|
+
run, out = _pytest(python, repo, work, overlay, pytest_args, tmp, env={"COVERAGE_RCFILE": rc},
|
|
102
|
+
runner=["-m", "coverage", "run", "--branch", f"--data-file={raw}", f"--source={work},{repo}", f"--omit={omit}"])
|
|
77
103
|
if run.returncode not in RAN or not os.path.exists(out):
|
|
78
104
|
raise SetupError(f"pytest under coverage exited {run.returncode} without running the tests:\n" + run.stdout + run.stderr)
|
|
79
105
|
with open(out) as f:
|
|
@@ -81,6 +107,7 @@ def coverage_run(python, repo, overlay, pytest_args, eligible):
|
|
|
81
107
|
eligible = eligible & {n for n, t in aggregate(cases).items() if t["outcome"] == "passed"}
|
|
82
108
|
env = {**os.environ, "PYTHONPATH": str(overlay), "PYTHONDONTWRITEBYTECODE": "1", "COVERAGE_RCFILE": rc}
|
|
83
109
|
coverage = lambda *a: subprocess.run([str(python), *a], cwd=repo, env=env, capture_output=True, text=True)
|
|
110
|
+
_combine(coverage, rc, raw, data, repo, work)
|
|
84
111
|
passing = contexts_regex(cases)
|
|
85
112
|
return {"cases": cases,
|
|
86
113
|
"report": _report(coverage, rc, data, os.path.join(tmp, "report.json"), passing),
|
|
@@ -88,6 +115,16 @@ def coverage_run(python, repo, overlay, pytest_args, eligible):
|
|
|
88
115
|
"arcs": _arcs(coverage, data, os.path.join(tmp, "arcs.json"), passing)}
|
|
89
116
|
|
|
90
117
|
|
|
118
|
+
def _combine(coverage, rc, raw, data, repo, work):
|
|
119
|
+
"""The run's data with each path in the copy named as the repo's, merged with the same file's entry in the repo (listed
|
|
120
|
+
unexecuted by --source, or run through an editable install): one file per source file, read where the repo holds it."""
|
|
121
|
+
with open(rc, "w") as f:
|
|
122
|
+
f.write(f"[paths]\nsource =\n {repo}\n {work}\n")
|
|
123
|
+
proc = coverage("-m", "coverage", "combine", f"--data-file={data}", raw)
|
|
124
|
+
if proc.returncode or not os.path.exists(data):
|
|
125
|
+
raise SetupError(f"coverage combine exited {proc.returncode}:\n" + proc.stdout + proc.stderr)
|
|
126
|
+
|
|
127
|
+
|
|
91
128
|
def _report(coverage, rc, data, out, regex):
|
|
92
129
|
# coverage splits a config list at each comma and expands $NAME in it: write both as regex escapes that
|
|
93
130
|
# match the same characters (re.escape writes a literal $ as \$)
|
|
@@ -99,7 +136,9 @@ def _report(coverage, rc, data, out, regex):
|
|
|
99
136
|
if proc.returncode or not os.path.exists(out):
|
|
100
137
|
raise SetupError(f"coverage json exited {proc.returncode}:\n" + proc.stdout + proc.stderr)
|
|
101
138
|
with open(out) as f:
|
|
102
|
-
|
|
139
|
+
report = json.load(f)
|
|
140
|
+
# combined data that holds no arc has no branch mode: no source file ran there either
|
|
141
|
+
return report if "num_branches" in report["totals"] else {"files": {}, "totals": {"covered_branches": 0, "num_branches": 0}}
|
|
103
142
|
|
|
104
143
|
|
|
105
144
|
# Runs in the target's interpreter: coverage json has per-context lines but not per-context arcs.
|
package/skills-manifest.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-11-
|
|
3
|
+
"generatedAt": "2026-11-03T12:00:34.732Z",
|
|
4
4
|
"skills": [
|
|
5
5
|
{
|
|
6
6
|
"name": "agents-wayfinder",
|
|
@@ -106,8 +106,8 @@
|
|
|
106
106
|
},
|
|
107
107
|
{
|
|
108
108
|
"name": "test-weigh-in",
|
|
109
|
-
"version": "0.1.
|
|
110
|
-
"hash": "sha256-
|
|
109
|
+
"version": "0.1.2",
|
|
110
|
+
"hash": "sha256-3f0a00b5a362a869c0c9e12bfa6a9e11674338f24b5b2248ec9479b0e0581ed1",
|
|
111
111
|
"description": "Measure a Python/pytest suite and score it on five pillars (Protection against regressions, Resistance to refactoring, Fast feedback, Maintainability, Economy), writing a JSON snapshot and a static HTML dashboard. Read-only. Use when the user asks to weigh, measure or score their test suite."
|
|
112
112
|
},
|
|
113
113
|
{
|