tenseleyflow/documentlanguagemodel / 45f30cf

Browse files

refactor(harvest): rename revert_last_harvest → revert_all_auto_harvests to match behavior

Authored by espadonne
SHA
45f30cfeeda9827088fc7e3231a1e1f4b15a7d0a
Parents
44dc34f
Tree
60bbbd5

5 changed files

StatusFile+-
M src/dlm/cli/commands.py 4 4
M src/dlm/harvest/__init__.py 3 3
M src/dlm/harvest/applier.py 10 6
M tests/unit/cli/test_harvest_cmd.py 2 1
M tests/unit/harvest/test_applier.py 3 3
src/dlm/cli/commands.pymodified
@@ -3572,7 +3572,7 @@ def harvest_cmd(
35723572
         build_plan,
35733573
         read_sway_report,
35743574
         render_plan,
3575
-        revert_last_harvest,
3575
+        revert_all_auto_harvests,
35763576
     )
35773577
 
35783578
     console = Console(stderr=True)
@@ -3597,10 +3597,10 @@ def harvest_cmd(
35973597
         raise typer.Exit(code=1) from exc
35983598
 
35993599
     if revert:
3600
-        summary = revert_last_harvest(parsed, target=path)
3600
+        summary = revert_all_auto_harvests(parsed, target=path)
36013601
         out_console.print(
3602
-            f"[green]harvest:[/green] reverted {len(summary.added_section_ids)} "
3603
-            f"auto-harvested section(s) from {path}"
3602
+            f"[green]harvest:[/green] stripped {len(summary.added_section_ids)} "
3603
+            f"auto-harvested section(s) from {path} (all harvest runs, not just last)"
36043604
         )
36053605
         return
36063606
 
src/dlm/harvest/__init__.pymodified
@@ -13,13 +13,13 @@ Public surface:
1313
 - :func:`build_plan` / :class:`HarvestPlan` — dedup candidates
1414
   against the current document, materialize Sections.
1515
 - :func:`render_plan` — plain-text diff for ``--dry-run``.
16
-- :func:`apply_plan` / :func:`revert_last_harvest` — commit the
16
+- :func:`apply_plan` / :func:`revert_all_auto_harvests` — commit the
1717
   plan to disk (or strip auto-harvested sections on revert).
1818
 """
1919
 
2020
 from __future__ import annotations
2121
 
22
-from dlm.harvest.applier import HarvestSummary, apply_plan, revert_last_harvest
22
+from dlm.harvest.applier import HarvestSummary, apply_plan, revert_all_auto_harvests
2323
 from dlm.harvest.diff import (
2424
     HarvestPlan,
2525
     PlannedAddition,
@@ -49,5 +49,5 @@ __all__ = [
4949
     "build_plan",
5050
     "read_sway_report",
5151
     "render_plan",
52
-    "revert_last_harvest",
52
+    "revert_all_auto_harvests",
5353
 ]
src/dlm/harvest/applier.pymodified
@@ -22,7 +22,7 @@ from dlm.io.atomic import write_text as atomic_write_text
2222
 
2323
 @dataclass(frozen=True)
2424
 class HarvestSummary:
25
-    """Outcome of :func:`apply_plan` or :func:`revert_last_harvest`."""
25
+    """Outcome of :func:`apply_plan` or :func:`revert_all_auto_harvests`."""
2626
 
2727
     target: Path
2828
     added: int
@@ -49,13 +49,17 @@ def apply_plan(parsed: ParsedDlm, plan: HarvestPlan, *, target: Path) -> Harvest
4949
     )
5050
 
5151
 
52
-def revert_last_harvest(parsed: ParsedDlm, *, target: Path) -> HarvestSummary:
52
+def revert_all_auto_harvests(parsed: ParsedDlm, *, target: Path) -> HarvestSummary:
5353
     """Strip every `auto_harvest=True` section and rewrite `target`.
5454
 
55
-    Coarser than "undo the last harvest" — any auto-harvested section
56
-    is removed regardless of which harvest run added it. This matches
57
-    the sprint spec's `--revert HEAD` UX: users audit the diff before
58
-    applying, so "undo all auto-edits" is the safe escape hatch.
55
+    Coarser than an "undo-the-most-recent-harvest" operation — any
56
+    auto-harvested section is removed, regardless of which harvest run
57
+    added it. We don't track per-run provenance in the section tags, so
58
+    fine-grained per-harvest rollback isn't possible without schema
59
+    work. "Undo all auto-edits" is the safe escape hatch users reach
60
+    for after reviewing a diff anyway; if fine-grained rollback becomes
61
+    a real need, a follow-up adds a run_id tag and a
62
+    `revert_by_run(run_id)` sibling.
5963
     """
6064
     survivors = tuple(s for s in parsed.sections if not s.auto_harvest)
6165
     removed_ids = tuple(s.section_id for s in parsed.sections if s.auto_harvest)
tests/unit/cli/test_harvest_cmd.pymodified
@@ -189,7 +189,8 @@ class TestHarvestCmd:
189189
         # Then revert
190190
         result = runner.invoke(app, ["--home", str(tmp_path), "harvest", str(doc), "--revert"])
191191
         assert result.exit_code == 0, result.output
192
-        assert "reverted 1" in result.output
192
+        assert "stripped 1" in result.output
193
+        assert "all harvest runs" in result.output
193194
 
194195
         from dlm.doc.parser import parse_file
195196
 
tests/unit/harvest/test_applier.pymodified
@@ -9,7 +9,7 @@ from dlm.harvest import (
99
     HarvestCandidate,
1010
     apply_plan,
1111
     build_plan,
12
-    revert_last_harvest,
12
+    revert_all_auto_harvests,
1313
 )
1414
 
1515
 _FRONTMATTER = """---
@@ -88,7 +88,7 @@ class TestRevertLastHarvest:
8888
         # Now revert
8989
         parsed_with_harvest = parse_file(target)
9090
         assert any(s.auto_harvest for s in parsed_with_harvest.sections)
91
-        summary = revert_last_harvest(parsed_with_harvest, target=target)
91
+        summary = revert_all_auto_harvests(parsed_with_harvest, target=target)
9292
 
9393
         assert summary.added == 0
9494
         # summary.added_section_ids carries the IDs of the REMOVED sections
@@ -103,7 +103,7 @@ class TestRevertLastHarvest:
103103
         target = tmp_path / "doc.dlm"
104104
         _write_dlm(target, "## hello\n")
105105
         parsed = parse_file(target)
106
-        summary = revert_last_harvest(parsed, target=target)
106
+        summary = revert_all_auto_harvests(parsed, target=target)
107107
 
108108
         assert summary.added == 0
109109
         assert summary.added_section_ids == ()