diff --git a/tests/test_repair_foreign_links.py b/tests/test_repair_foreign_links.py index ea40ea63..3d4e47e5 100644 --- a/tests/test_repair_foreign_links.py +++ b/tests/test_repair_foreign_links.py @@ -261,6 +261,9 @@ class DryRunTests(RepairFixture): self.assertEqual(wal.stat().st_size if wal.exists() else 0, 0) markdown = Path(self.tmp, "plan.md").read_text(encoding="utf-8") self.assertIn(f"| {self.rows['A']} |", markdown) + long_path = os.path.join("dataset", NAME.format(1)) + self.assertIn(f"| {long_path} |", markdown, "file paths are never cut") + self.assertIn(generate_prompt_hash(TEXTS[1])[:12], markdown) self.assertIn("new", markdown) self.assertIn("would lose every link", markdown) diff --git a/tools/repair_foreign_links.py b/tools/repair_foreign_links.py index b9de90c0..8b4162a4 100644 --- a/tools/repair_foreign_links.py +++ b/tools/repair_foreign_links.py @@ -457,8 +457,10 @@ def _summary(plan): ) -def _cell(text): - return " ".join(str(text).split())[:EXCERPT].replace("|", "\\|") +def _cell(text, limit=EXCERPT): + """One table cell: whitespace folded, cut to ``limit`` (None: whole).""" + folded = " ".join(str(text).split()) + return (folded if limit is None else folded[:limit]).replace("|", "\\|") def markdown(plan, prompt_texts): @@ -473,21 +475,23 @@ def markdown(plan, prompt_texts): "", f"## Relink ({sum(i['action'] == 'relink' for i in rows)})", "", - "| row | file | linked prompt | linked text | target | target text |", - "|---:|---|---:|---|---|---|", + "| row | file | linked prompt | linked text | target | target hash " + "| target text |", + "|---:|---|---:|---|---|---|---|", ] for item in (i for i in rows if i["action"] == "relink"): lines.append( - f"| {item['row_id']} | {_cell(rel(item['file']))} | " + f"| {item['row_id']} | {_cell(rel(item['file']), None)} | " f"{item['current_prompt_id']} | " f"{_cell(prompt_texts.get(item['current_prompt_id'], ''))} | " - f"{item['target_prompt_id']} | {_cell(item['target_text'])} |" + f"{item['target_prompt_id']} | `{item['target_hash'][:12]}` | " + f"{_cell(item['target_text'])} |" ) lines += ["", f"## Keep ({sum(i['action'] == 'keep' for i in rows)})", ""] lines += ["| row | file | prompt |", "|---:|---|---:|"] for item in (i for i in rows if i["action"] == "keep"): lines.append( - f"| {item['row_id']} | {_cell(rel(item['file']))} | " + f"| {item['row_id']} | {_cell(rel(item['file']), None)} | " f"{item['current_prompt_id']} |" ) lines += ["", f"## Skip ({sum(i['action'] == 'skip' for i in rows)})", ""] @@ -497,7 +501,7 @@ def markdown(plan, prompt_texts): f" ({item['decision']})" if item.get("decision") else "" ) lines.append( - f"| {item['row_id']} | {_cell(rel(item['file']))} | " + f"| {item['row_id']} | {_cell(rel(item['file']), None)} | " f"{item['current_prompt_id']} | {reason} |" ) choice = "ON (--delete-orphans)" if plan["delete_orphans"] else "OFF"