ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import pytest
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ch5_tools_dir = Path(__file__).resolve().parent.parent / "chapter5" / "coding-agent"
|
||||
if str(ch5_tools_dir) not in sys.path:
|
||||
sys.path.insert(0, str(ch5_tools_dir))
|
||||
|
||||
from tools.notebook_edit_tool import NotebookEditTool # noqa: E402
|
||||
from system_state import SystemState # noqa: E402
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def temp_notebook(tmp_path):
|
||||
nb_path = tmp_path / "test_zero_id.ipynb"
|
||||
nb_data = {
|
||||
"cells": [
|
||||
{
|
||||
"id": "0",
|
||||
"cell_type": "code",
|
||||
"metadata": {},
|
||||
"execution_count": None,
|
||||
"outputs": [],
|
||||
"source": ["print('original')\n"],
|
||||
}
|
||||
],
|
||||
"metadata": {},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5,
|
||||
}
|
||||
nb_path.write_text(json.dumps(nb_data), encoding="utf-8")
|
||||
return nb_path
|
||||
|
||||
|
||||
def test_notebook_edit_accepts_integer_zero_cell_id(temp_notebook):
|
||||
state = SystemState()
|
||||
tool = NotebookEditTool(state)
|
||||
result = tool.execute({
|
||||
"notebook_path": str(temp_notebook),
|
||||
"cell_id": 0,
|
||||
"new_source": "print('updated')",
|
||||
"edit_mode": "replace",
|
||||
})
|
||||
assert result.success is True, f"Execution failed: {result.data}"
|
||||
assert result.data.get("action") == "replaced"
|
||||
|
||||
nb_content = json.loads(temp_notebook.read_text(encoding="utf-8"))
|
||||
assert "".join(nb_content["cells"][0]["source"]) == "print('updated')"
|
||||
Reference in New Issue
Block a user