refactor(harvest): rename revert_last_harvest → revert_all_auto_harvests to match behavior
- SHA
45f30cfeeda9827088fc7e3231a1e1f4b15a7d0a- Parents
-
44dc34f - Tree
60bbbd5
45f30cf
45f30cfeeda9827088fc7e3231a1e1f4b15a7d0a44dc34f
60bbbd5| Status | File | + | - |
|---|---|---|---|
| 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( | ||
| 3572 | 3572 | build_plan, |
| 3573 | 3573 | read_sway_report, |
| 3574 | 3574 | render_plan, |
| 3575 | - revert_last_harvest, | |
| 3575 | + revert_all_auto_harvests, | |
| 3576 | 3576 | ) |
| 3577 | 3577 | |
| 3578 | 3578 | console = Console(stderr=True) |
@@ -3597,10 +3597,10 @@ def harvest_cmd( | ||
| 3597 | 3597 | raise typer.Exit(code=1) from exc |
| 3598 | 3598 | |
| 3599 | 3599 | if revert: |
| 3600 | - summary = revert_last_harvest(parsed, target=path) | |
| 3600 | + summary = revert_all_auto_harvests(parsed, target=path) | |
| 3601 | 3601 | 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)" | |
| 3604 | 3604 | ) |
| 3605 | 3605 | return |
| 3606 | 3606 | |
src/dlm/harvest/__init__.pymodified@@ -13,13 +13,13 @@ Public surface: | ||
| 13 | 13 | - :func:`build_plan` / :class:`HarvestPlan` — dedup candidates |
| 14 | 14 | against the current document, materialize Sections. |
| 15 | 15 | - :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 | |
| 17 | 17 | plan to disk (or strip auto-harvested sections on revert). |
| 18 | 18 | """ |
| 19 | 19 | |
| 20 | 20 | from __future__ import annotations |
| 21 | 21 | |
| 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 | |
| 23 | 23 | from dlm.harvest.diff import ( |
| 24 | 24 | HarvestPlan, |
| 25 | 25 | PlannedAddition, |
@@ -49,5 +49,5 @@ __all__ = [ | ||
| 49 | 49 | "build_plan", |
| 50 | 50 | "read_sway_report", |
| 51 | 51 | "render_plan", |
| 52 | - "revert_last_harvest", | |
| 52 | + "revert_all_auto_harvests", | |
| 53 | 53 | ] |
src/dlm/harvest/applier.pymodified@@ -22,7 +22,7 @@ from dlm.io.atomic import write_text as atomic_write_text | ||
| 22 | 22 | |
| 23 | 23 | @dataclass(frozen=True) |
| 24 | 24 | 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`.""" | |
| 26 | 26 | |
| 27 | 27 | target: Path |
| 28 | 28 | added: int |
@@ -49,13 +49,17 @@ def apply_plan(parsed: ParsedDlm, plan: HarvestPlan, *, target: Path) -> Harvest | ||
| 49 | 49 | ) |
| 50 | 50 | |
| 51 | 51 | |
| 52 | -def revert_last_harvest(parsed: ParsedDlm, *, target: Path) -> HarvestSummary: | |
| 52 | +def revert_all_auto_harvests(parsed: ParsedDlm, *, target: Path) -> HarvestSummary: | |
| 53 | 53 | """Strip every `auto_harvest=True` section and rewrite `target`. |
| 54 | 54 | |
| 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. | |
| 59 | 63 | """ |
| 60 | 64 | survivors = tuple(s for s in parsed.sections if not s.auto_harvest) |
| 61 | 65 | 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: | ||
| 189 | 189 | # Then revert |
| 190 | 190 | result = runner.invoke(app, ["--home", str(tmp_path), "harvest", str(doc), "--revert"]) |
| 191 | 191 | 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 | |
| 193 | 194 | |
| 194 | 195 | from dlm.doc.parser import parse_file |
| 195 | 196 | |
tests/unit/harvest/test_applier.pymodified@@ -9,7 +9,7 @@ from dlm.harvest import ( | ||
| 9 | 9 | HarvestCandidate, |
| 10 | 10 | apply_plan, |
| 11 | 11 | build_plan, |
| 12 | - revert_last_harvest, | |
| 12 | + revert_all_auto_harvests, | |
| 13 | 13 | ) |
| 14 | 14 | |
| 15 | 15 | _FRONTMATTER = """--- |
@@ -88,7 +88,7 @@ class TestRevertLastHarvest: | ||
| 88 | 88 | # Now revert |
| 89 | 89 | parsed_with_harvest = parse_file(target) |
| 90 | 90 | 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) | |
| 92 | 92 | |
| 93 | 93 | assert summary.added == 0 |
| 94 | 94 | # summary.added_section_ids carries the IDs of the REMOVED sections |
@@ -103,7 +103,7 @@ class TestRevertLastHarvest: | ||
| 103 | 103 | target = tmp_path / "doc.dlm" |
| 104 | 104 | _write_dlm(target, "## hello\n") |
| 105 | 105 | parsed = parse_file(target) |
| 106 | - summary = revert_last_harvest(parsed, target=target) | |
| 106 | + summary = revert_all_auto_harvests(parsed, target=target) | |
| 107 | 107 | |
| 108 | 108 | assert summary.added == 0 |
| 109 | 109 | assert summary.added_section_ids == () |