fix(editor): require explicit draft tool targets

This commit is contained in:
sligter
2026-07-05 20:24:24 +08:00
parent e7659d7d08
commit f94bac03bd
2 changed files with 31 additions and 1 deletions
@@ -582,7 +582,11 @@ class SlideEditToolRunner:
return soup.select_one(selector), None
except Exception as exc:
return None, self._invalid_selector_error(tool_name, selector, exc)
return soup.find(True), None
return None, {
"success": False,
"tool": tool_name,
"error": "target element requires element_id, selected element id, or selector",
}
def _tool_replace_slide_html(self, tool_input: Dict[str, Any]) -> Dict[str, Any]:
html = str(tool_input.get("html") or tool_input.get("value") or "").strip()
+26
View File
@@ -222,6 +222,32 @@ async def test_tool_runner_replace_element_missing_id_fails_without_mutating_dra
assert runner.current_html == original_html
@pytest.mark.asyncio
async def test_tool_runner_update_text_missing_target_fails_without_mutating_draft():
runner = SlideEditToolRunner(_tool_context())
original_html = runner.current_html
result = await runner.execute_tool("update_text", {"text": "Short Title"})
assert result["success"] is False
assert result["tool"] == "update_text"
assert "requires" in result["error"]
assert runner.current_html == original_html
@pytest.mark.asyncio
async def test_tool_runner_delete_element_missing_target_fails_without_mutating_draft():
runner = SlideEditToolRunner(_tool_context())
original_html = runner.current_html
result = await runner.execute_tool("delete_element", {})
assert result["success"] is False
assert result["tool"] == "delete_element"
assert "requires" in result["error"]
assert runner.current_html == original_html
@pytest.mark.asyncio
async def test_tool_runner_replace_element_rejects_unsafe_fragment_without_mutating_draft():
runner = SlideEditToolRunner(