fischer-agentkit/tests
chiguyong 2932ee51ed feat(tools): add str_replace_editor tool with workspace-root security (U1, R1)
Replaces the broken write_file placeholder (no real implementation, only
_FakeTool stubs in cli/benchmark.py) with a structured editor offering four
commands: create, str_replace, insert_at_line, view.

Security model (file-system analog of the 6-layer terminal security paradigm,
reject-by-default + prefix match):
  1. Reject absolute paths (force relative interpretation vs workspace root).
  2. Reject any .. path component (path traversal).
  3. Path.resolve() follows symlinks, then relative_to(workspace_root)
     rejects symlink escape and residual traversal.

Data-loss guard: create refuses to overwrite existing files. str_replace
requires a unique anchor (0 or >1 matches error). insert_at_line is 1-based
(0 = prepend, > EOF = append). All FS I/O wrapped in asyncio.to_thread.

Registers str_replace_editor in _DEFAULT_CORE_TOOLS (replacing write_file)
so its full description is always injected into the LLM prompt. Updates
test_tool_search.py which used write_file as a sample core tool.

Tests: 34 cases in test_str_replace_editor.py cover happy path, edge cases
(empty file, multi-match, insert at 0/beyond EOF, view range), error paths
(overwrite refusal, anchor not found, path traversal, absolute path, symlink
escape, unknown command, missing args), and integration contract (in
_DEFAULT_CORE_TOOLS, exported from agentkit.tools, schema enum, prompt
injection via _build_tool_use_prompt).

Verification: ruff check clean; targeted regression suite 412 passed
(the single failure in test_calendar_tool.py is a pre-existing date-sensitive
bug in an untouched file, today 2026-07-03 Friday makes the next-Wednesday
assertion fail).
2026-07-03 11:42:59 +08:00
..
documents feat(documents): add document processing capability (U1-U9) 2026-06-23 15:05:01 +08:00
e2e refactor: remove all emoji from source code (#20) 2026-07-03 02:46:40 +08:00
integration fix(review): apply ce-code-review findings 2026-06-30 12:42:15 +08:00
manual test(u6): add L4 real-LLM smoke test for ReAct tool-use prompt 2026-07-02 22:08:45 +08:00
routes feat(documents): add document processing capability (U1-U9) 2026-06-23 15:05:01 +08:00
tools feat(documents): add document processing capability (U1-U9) 2026-06-23 15:05:01 +08:00
unit feat(tools): add str_replace_editor tool with workspace-root security (U1, R1) 2026-07-03 11:42:59 +08:00
__init__.py feat: initial fischer-agentkit package with unified agent architecture 2026-06-04 22:24:06 +08:00
conftest.py fix: 私董会数据持久化修复 + emoji 移除计划 2026-07-02 01:07:12 +08:00
test_routing_chain.py feat: accumulated frontend enhancements, docs, and static assets 2026-06-14 16:35:01 +08:00