@jesdi/skills 0.0.78 → 0.0.79
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
CHANGED
|
@@ -134,11 +134,15 @@ when `prune` exited 1 (the status keeps that failure, so the job still goes red)
|
|
|
134
134
|
`python3 <skill-dir>/prune.py strengthen-commit --item <item id>` as soon as its tests are
|
|
135
135
|
written. Never run `git commit` yourself: the command commits every change under
|
|
136
136
|
`backend/tests/` with the item's trailer, one item per call (an item may take several calls),
|
|
137
|
-
and refuses an unknown or closed item, any change outside `backend/tests/`,
|
|
138
|
-
commit
|
|
137
|
+
and refuses an unknown or closed item, any change outside `backend/tests/`, nothing to
|
|
138
|
+
commit, or a change to a function or a created file another open item already changed: each
|
|
139
|
+
test belongs to one item, so write another item's tests as new functions. Leave the tree clean.
|
|
139
140
|
3. `strengthen-verify` rejects commits without a known trailer or outside `backend/tests/`, then
|
|
140
141
|
proves each item on a cold run: every named id survived on the base and is killed on the
|
|
141
|
-
head. Unproven items are reverted and closed: a later commit for a closed item is refused.
|
|
142
|
+
head. Unproven items are reverted and closed: a later commit for a closed item is refused.
|
|
143
|
+
When `git revert` conflicts with a later item's lines, the item's functions are removed or
|
|
144
|
+
restored instead and its created files deleted; an item that changed anything else in a file
|
|
145
|
+
still stops the run with exit 1. It
|
|
142
146
|
writes `<state>/strengthen-proof.json`, including the proven head. On failure HEAD stays
|
|
143
147
|
where the commits are (detached, unattended): fix and rerun. A rejection names the recovery
|
|
144
148
|
that needs no reset: `git checkout <start>`, then commit each item again with
|
|
@@ -220,6 +220,54 @@ def delete_tests(source: str, targets: set[tuple[tuple[str, ...], str]]) -> str:
|
|
|
220
220
|
return "".join(line for number, line in enumerate(lines, 1) if number not in removed)
|
|
221
221
|
|
|
222
222
|
|
|
223
|
+
def _function_nodes(body: list[ast.stmt], scope: tuple[str, ...] = ()):
|
|
224
|
+
"""((classes, name), node) for every function defined at module or class level."""
|
|
225
|
+
for node in body:
|
|
226
|
+
if isinstance(node, FUNCS):
|
|
227
|
+
yield (scope, node.name), node
|
|
228
|
+
elif isinstance(node, ast.ClassDef):
|
|
229
|
+
yield from _function_nodes(node.body, scope + (node.name,))
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def functions(source: str) -> dict[tuple[tuple[str, ...], str], str]:
|
|
233
|
+
"""(classes, name) → source (decorators included) of every module- or class-level function."""
|
|
234
|
+
lines = source.splitlines()
|
|
235
|
+
return {key: "\n".join(lines[_span(node)[0] - 1:node.end_lineno])
|
|
236
|
+
for key, node in _function_nodes(ast.parse(source).body)}
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def _strip(body: list[ast.stmt]) -> list[ast.stmt]:
|
|
240
|
+
kept = []
|
|
241
|
+
for node in body:
|
|
242
|
+
if isinstance(node, (*FUNCS, ast.Import, ast.ImportFrom)):
|
|
243
|
+
continue
|
|
244
|
+
if isinstance(node, ast.ClassDef):
|
|
245
|
+
node.body = _strip(node.body)
|
|
246
|
+
if not (node.body[1:] if ast.get_docstring(node) is not None else node.body):
|
|
247
|
+
continue
|
|
248
|
+
kept.append(node)
|
|
249
|
+
return kept
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def skeleton(source: str) -> str:
|
|
253
|
+
"""The file without its functions, its imports and the classes that leave only a docstring: equal
|
|
254
|
+
before and after a change confined to functions and imports."""
|
|
255
|
+
tree = ast.parse(source)
|
|
256
|
+
tree.body = _strip(tree.body)
|
|
257
|
+
return ast.dump(tree)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def restore_functions(source: str, before: str, keys: set) -> str:
|
|
261
|
+
"""source with each function in keys ({(classes, name)}) put back to its text in before."""
|
|
262
|
+
old = functions(before)
|
|
263
|
+
lines = source.splitlines(keepends=True)
|
|
264
|
+
spans = sorted(((_span(node), key) for key, node in _function_nodes(ast.parse(source).body) if key in keys),
|
|
265
|
+
reverse=True)
|
|
266
|
+
for (start, end), key in spans:
|
|
267
|
+
lines[start - 1:end] = [old[key] + "\n"]
|
|
268
|
+
return "".join(lines)
|
|
269
|
+
|
|
270
|
+
|
|
223
271
|
def test_sources(source: str) -> dict[str, str]:
|
|
224
272
|
"""`[Class::]name` → source of every test function in the file."""
|
|
225
273
|
out: dict[str, str] = {}
|
|
@@ -8,7 +8,7 @@ import re
|
|
|
8
8
|
|
|
9
9
|
from prune_repo import KILLED, SURVIVING, BadInput, Fail, Repo, ratchet_lines
|
|
10
10
|
from prune_review import check_reviews, equivalents_section, suggestions_section
|
|
11
|
-
from prune_source import test_sources
|
|
11
|
+
from prune_source import delete_tests, functions, restore_functions, skeleton, test_sources
|
|
12
12
|
|
|
13
13
|
TRAILER = "Test-Prune-Item"
|
|
14
14
|
# Read from the whole message, not git's trailer block: git only takes trailers from the
|
|
@@ -105,6 +105,47 @@ def _commits(repo, st: dict) -> list:
|
|
|
105
105
|
return [(sha, items[0]) for sha, items, _ in history]
|
|
106
106
|
|
|
107
107
|
|
|
108
|
+
def _units(path: str, before: str | None, after: str | None) -> set:
|
|
109
|
+
"""What one file change claims for its item: every function it adds or changes, or the whole file
|
|
110
|
+
when the change creates it, deletes it, or the file is not Python the AST can split. No two items
|
|
111
|
+
may claim the same unit, so closing one item never has to undo another's lines."""
|
|
112
|
+
if before is None or after is None or not path.endswith(".py"):
|
|
113
|
+
return {path}
|
|
114
|
+
try:
|
|
115
|
+
old, new = functions(before), functions(after)
|
|
116
|
+
except SyntaxError:
|
|
117
|
+
return {path}
|
|
118
|
+
return {"::".join((path, *classes, name)) for classes, name in old.keys() | new.keys()
|
|
119
|
+
if old.get((classes, name)) != new.get((classes, name))}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _paths(repo, sha: str) -> list:
|
|
123
|
+
return repo.git("diff-tree", "--no-commit-id", "--name-only", "-r", sha).split()
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _owners(repo, st: dict) -> dict:
|
|
127
|
+
"""unit → the still-open item whose commits claimed it first."""
|
|
128
|
+
owners: dict = {}
|
|
129
|
+
for sha, items, paths in _history(repo, st["start"]):
|
|
130
|
+
if len(items) == 1 and st["status"].get(items[0]) in ("open", "proven"):
|
|
131
|
+
for path in paths:
|
|
132
|
+
for unit in _units(path, repo.show(f"{sha}^", path), repo.show(sha, path)):
|
|
133
|
+
owners.setdefault(unit, items[0])
|
|
134
|
+
return owners
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _require_unowned(repo, st: dict, item_id: str, changed: list) -> None:
|
|
138
|
+
owners = _owners(repo, st)
|
|
139
|
+
for path in changed:
|
|
140
|
+
current = repo.root / path
|
|
141
|
+
after = current.read_text() if current.is_file() else None
|
|
142
|
+
for unit in sorted(_units(path, repo.show("HEAD", path), after) | {path}):
|
|
143
|
+
owner = owners.get(unit, item_id)
|
|
144
|
+
if owner != item_id:
|
|
145
|
+
raise BadInput(f"{unit} is {owner}'s: each test and each created file belongs to one item. "
|
|
146
|
+
f"Discard this change, or write {item_id}'s tests as new functions.")
|
|
147
|
+
|
|
148
|
+
|
|
108
149
|
def strengthen_commit(ctx) -> int:
|
|
109
150
|
"""Commit the working tree's changes under backend/tests/ as one commit for one open item; the
|
|
110
151
|
trailer is written here, so a commit can never name two items."""
|
|
@@ -119,19 +160,63 @@ def strengthen_commit(ctx) -> int:
|
|
|
119
160
|
raise BadInput("changes outside backend/tests/, discard them first:\n" + "\n".join(outside))
|
|
120
161
|
if not changed:
|
|
121
162
|
raise BadInput(f"nothing to commit for {item_id}: write its tests under backend/tests/ first")
|
|
163
|
+
_require_unowned(repo, st, item_id, changed)
|
|
122
164
|
repo.git("add", "-A", "--", "backend/tests/")
|
|
123
165
|
repo.git("commit", "-q", "-m", f"test: strengthen {item_id}", "-m", f"{TRAILER}: {item_id}")
|
|
124
166
|
ctx.state.emit(repo.head())
|
|
125
167
|
return 0
|
|
126
168
|
|
|
127
169
|
|
|
170
|
+
def _confined(repo, item_id: str, shas: list) -> dict:
|
|
171
|
+
"""{path: (text before the item's first commit to it, the item's function keys in it)}; Fail when a
|
|
172
|
+
commit changes anything but functions and imports, or deletes a function."""
|
|
173
|
+
out: dict = {}
|
|
174
|
+
for sha in shas:
|
|
175
|
+
for path in _paths(repo, sha):
|
|
176
|
+
before, after = repo.show(f"{sha}^", path), repo.show(sha, path)
|
|
177
|
+
entry = out.setdefault(path, (before, set()))
|
|
178
|
+
if entry[0] is None:
|
|
179
|
+
continue # the item created the file: removing the file undoes it whole
|
|
180
|
+
keys = _function_change(path, before, after)
|
|
181
|
+
if keys is None:
|
|
182
|
+
raise Fail(f"reverting strengthen item {item_id} conflicts with a later item's commits, and "
|
|
183
|
+
f"{sha[:12]} changes {path} beyond adding or editing functions and imports")
|
|
184
|
+
entry[1].update(keys)
|
|
185
|
+
return out
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _function_change(path: str, before: str | None, after: str | None) -> set | None:
|
|
189
|
+
"""The function keys a commit's change to path adds or edits, or None when it changes anything but
|
|
190
|
+
functions and imports, or deletes a function."""
|
|
191
|
+
if before is None or after is None or not path.endswith(".py") or skeleton(before) != skeleton(after):
|
|
192
|
+
return None
|
|
193
|
+
old, new = functions(before), functions(after)
|
|
194
|
+
return None if old.keys() - new.keys() else {k for k in new if old.get(k) != new[k]}
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _remove(repo, item_id: str, shas: list) -> None:
|
|
198
|
+
"""Undo the item's commits by function instead of by line, when a later item's lines sit next to
|
|
199
|
+
its own and `git revert` conflicts: delete the functions it added, restore the ones it changed, and
|
|
200
|
+
remove the files it created. Every unit is the item's alone (see _units)."""
|
|
201
|
+
for path, (before, keys) in _confined(repo, item_id, shas).items():
|
|
202
|
+
current = repo.show("HEAD", path)
|
|
203
|
+
if before is None:
|
|
204
|
+
if current is not None:
|
|
205
|
+
repo.git("rm", "-q", "--", path)
|
|
206
|
+
continue
|
|
207
|
+
old = functions(before)
|
|
208
|
+
text = restore_functions(current, before, {k for k in keys if k in old})
|
|
209
|
+
(repo.root / path).write_text(delete_tests(text, {k for k in keys if k not in old}))
|
|
210
|
+
repo.git("add", "--", path)
|
|
211
|
+
|
|
212
|
+
|
|
128
213
|
def _revert(repo, item_id: str, commits: list, why: str) -> None:
|
|
129
214
|
shas = [sha for sha, item in reversed(commits) if item == item_id]
|
|
130
215
|
if not shas:
|
|
131
216
|
return
|
|
132
217
|
if repo.run_git("revert", "--no-commit", *shas).returncode:
|
|
133
218
|
repo.run_git("revert", "--abort")
|
|
134
|
-
|
|
219
|
+
_remove(repo, item_id, shas[::-1])
|
|
135
220
|
repo.git("commit", "-q", "--allow-empty", "-m", f"Revert test-prune item {item_id}", "-m", why,
|
|
136
221
|
"-m", f"{TRAILER}: {item_id}")
|
|
137
222
|
|
|
@@ -336,3 +336,96 @@ def test_strengthen_commit_refuses_a_head_off_the_strengthen_start(target):
|
|
|
336
336
|
target.git("commit", "-q", "-m", "unrelated root")
|
|
337
337
|
write_test(target, COMPUTE_TEST)
|
|
338
338
|
refused(target, COMPUTE, "does not descend")
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
# --- closing an item removes its tests, even under a later item's commits ---------------------
|
|
342
|
+
|
|
343
|
+
def test_an_unproven_item_committed_before_a_proven_one_is_removed_without_a_conflict(target):
|
|
344
|
+
# Both items append to the end of one file: `git revert` of the earlier one conflicts.
|
|
345
|
+
two_items(target, drift_ids=("x_apply_drift__mutmut_2", "x_apply_drift__mutmut_4"))
|
|
346
|
+
for item, source in [(DRIFT, DRIFT_TEST), (COMPUTE, COMPUTE_TEST)]:
|
|
347
|
+
write_test(target, source)
|
|
348
|
+
target.ok("strengthen-commit", "--item", item)
|
|
349
|
+
|
|
350
|
+
target.ok("strengthen-verify")
|
|
351
|
+
|
|
352
|
+
assert target.read_state("strengthen.json")["status"] == {COMPUTE: "proven", DRIFT: "reverted"}
|
|
353
|
+
source = (target.root / TESTS_FILE).read_text()
|
|
354
|
+
assert "def test_compute_trades_rounding(targets):" in source
|
|
355
|
+
assert "test_apply_drift_new" not in source
|
|
356
|
+
assert source == target.show(target.base, TESTS_FILE) + "\n\n" + COMPUTE_TEST.strip("\n") + "\n"
|
|
357
|
+
trailers = target.git("log", "-1", "--format=%(trailers:key=Test-Prune-Item,valueonly)").split()
|
|
358
|
+
assert trailers == [DRIFT]
|
|
359
|
+
assert target.git("status", "--porcelain").strip() == ""
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def test_a_new_file_left_without_tests_by_a_closed_item_is_deleted(target):
|
|
363
|
+
two_items(target, drift_ids=("x_apply_drift__mutmut_2", "x_apply_drift__mutmut_4"))
|
|
364
|
+
new_file = "backend/tests/test_drift_new.py"
|
|
365
|
+
(target.root / new_file).write_text("from services.rebalancer import apply_drift\n" + DRIFT_TEST)
|
|
366
|
+
write_test(target, DRIFT_TEST.replace("_new", "_also")) # the append COMPUTE's append conflicts with
|
|
367
|
+
target.ok("strengthen-commit", "--item", DRIFT)
|
|
368
|
+
(target.root / new_file).write_text((target.root / new_file).read_text() + COMPUTE_TEST)
|
|
369
|
+
refused(target, COMPUTE, new_file) # another item's file
|
|
370
|
+
target.git("checkout", "-q", "--", new_file)
|
|
371
|
+
write_test(target, COMPUTE_TEST)
|
|
372
|
+
target.ok("strengthen-commit", "--item", COMPUTE)
|
|
373
|
+
|
|
374
|
+
target.ok("strengthen-verify")
|
|
375
|
+
|
|
376
|
+
assert not (target.root / new_file).exists()
|
|
377
|
+
assert (target.root / TESTS_FILE).read_text() == \
|
|
378
|
+
target.show(target.base, TESTS_FILE) + "\n\n" + COMPUTE_TEST.strip("\n") + "\n"
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def test_a_test_a_closed_item_changed_is_free_for_another_item(target):
|
|
382
|
+
two_items(target, drift_ids=("x_apply_drift__mutmut_2", "x_apply_drift__mutmut_4"))
|
|
383
|
+
path = target.root / TESTS_FILE
|
|
384
|
+
path.write_text(path.read_text().rstrip("\n") + "\n assert apply_drift(-0.5) == 0\n")
|
|
385
|
+
target.ok("strengthen-commit", "--item", DRIFT)
|
|
386
|
+
write_test(target, COMPUTE_TEST)
|
|
387
|
+
target.ok("strengthen-commit", "--item", COMPUTE)
|
|
388
|
+
target.ok("strengthen-verify") # DRIFT leaves _4 alive: reverted, test_drift_scales is back to the base
|
|
389
|
+
scales = " assert apply_drift(base) <= base\n"
|
|
390
|
+
path.write_text(path.read_text().replace(scales, scales + " assert apply_drift(base) >= 0\n"))
|
|
391
|
+
|
|
392
|
+
target.ok("strengthen-commit", "--item", COMPUTE)
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
def test_strengthen_commit_refuses_a_test_another_item_already_changed(target):
|
|
396
|
+
two_items(target)
|
|
397
|
+
write_test(target, COMPUTE_TEST)
|
|
398
|
+
target.ok("strengthen-commit", "--item", COMPUTE)
|
|
399
|
+
path = target.root / TESTS_FILE
|
|
400
|
+
path.write_text(path.read_text().replace("== 0.267", "== 0.267 # pinned"))
|
|
401
|
+
write_test(target, DRIFT_TEST)
|
|
402
|
+
|
|
403
|
+
refused(target, DRIFT, f"test_compute_trades_rounding is {COMPUTE}'s")
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def test_a_test_the_closed_item_changed_is_restored_under_a_later_items_test(target):
|
|
407
|
+
two_items(target, drift_ids=("x_apply_drift__mutmut_2", "x_apply_drift__mutmut_4"))
|
|
408
|
+
path = target.root / TESTS_FILE
|
|
409
|
+
path.write_text(path.read_text().rstrip("\n") + "\n assert apply_drift(-0.5) == 0\n")
|
|
410
|
+
target.ok("strengthen-commit", "--item", DRIFT)
|
|
411
|
+
write_test(target, COMPUTE_TEST)
|
|
412
|
+
target.ok("strengthen-commit", "--item", COMPUTE)
|
|
413
|
+
|
|
414
|
+
target.ok("strengthen-verify")
|
|
415
|
+
|
|
416
|
+
assert target.read_state("strengthen.json")["status"] == {COMPUTE: "proven", DRIFT: "reverted"}
|
|
417
|
+
assert path.read_text() == target.show(target.base, TESTS_FILE) + "\n\n" + COMPUTE_TEST.strip("\n") + "\n"
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def test_a_closed_item_that_changed_more_than_functions_still_stops_the_run_on_a_conflict(target):
|
|
421
|
+
two_items(target, drift_ids=("x_apply_drift__mutmut_2", "x_apply_drift__mutmut_4"))
|
|
422
|
+
write_test(target, "LIMIT = -0.5\n" + DRIFT_TEST)
|
|
423
|
+
target.ok("strengthen-commit", "--item", DRIFT)
|
|
424
|
+
write_test(target, COMPUTE_TEST)
|
|
425
|
+
target.ok("strengthen-commit", "--item", COMPUTE)
|
|
426
|
+
|
|
427
|
+
verify = target.run("strengthen-verify")
|
|
428
|
+
|
|
429
|
+
assert verify.returncode == 1, verify.stdout + verify.stderr
|
|
430
|
+
assert f"changes {TESTS_FILE} beyond adding or editing functions" in verify.stdout + verify.stderr
|
|
431
|
+
assert target.git("status", "--porcelain").strip() == ""
|
package/skills-manifest.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-
|
|
3
|
+
"generatedAt": "2026-11-02T00:19:48.022Z",
|
|
4
4
|
"skills": [
|
|
5
5
|
{
|
|
6
6
|
"name": "agents-wayfinder",
|
|
@@ -100,8 +100,8 @@
|
|
|
100
100
|
},
|
|
101
101
|
{
|
|
102
102
|
"name": "test-prune",
|
|
103
|
-
"version": "0.1.
|
|
104
|
-
"hash": "sha256-
|
|
103
|
+
"version": "0.1.4",
|
|
104
|
+
"hash": "sha256-127f1b28add5b6039a306f3a16d7111bc3d1e196ed076da28565f04d269d4cd4",
|
|
105
105
|
"description": "Mutation-guided test pruning: a fixer proposes deleting redundant tests and strengthening weak ones, an independent reviewer accepts or rejects each proposal, and prune.py applies the accepted batch behind a cold mutation run and the ratchet. Use when the user says \"prune tests\", \"test-prune\", \"mutation test pruning\" or \"strengthen weak tests\", or when a scheduled job runs it with `--unattended`."
|
|
106
106
|
},
|
|
107
107
|
{
|