mirror of
https://github.com/sligter/LandPPT.git
synced 2026-09-01 15:06:44 +08:00
fix(editor): require explicit draft tool targets
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user