feat: 工作流记忆与内置工具、知你客服脚本、Agent管理技能展示与能力配置、文档与Windows启动脚本;忽略 redis_temp 二进制目录
Made-with: Cursor
This commit is contained in:
61
backend/scripts/test_write_user_data_aaa_md.py
Normal file
61
backend/scripts/test_write_user_data_aaa_md.py
Normal file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
测试在 D:\\aaa\\aiagent\\user_data 下创建 aaa.md(与线上一致的 file_write_tool)。
|
||||
|
||||
用法(在 backend 目录):
|
||||
.\\venv\\Scripts\\python.exe scripts\\test_write_user_data_aaa_md.py
|
||||
|
||||
可选环境变量:
|
||||
TEST_MD_CONTENT 写入内容,默认一行时间戳
|
||||
TEST_USE_ABSPATH 设为 1 时使用绝对路径 D:\\aaa\\aiagent\\user_data\\aaa.md,否则用相对路径 user_data/aaa.md
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
BACKEND_DIR = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def main() -> int:
|
||||
os.chdir(BACKEND_DIR)
|
||||
sys.path.insert(0, str(BACKEND_DIR))
|
||||
|
||||
from app.services.builtin_tools import _local_file_workspace_root, file_write_tool
|
||||
|
||||
root = _local_file_workspace_root()
|
||||
content = os.environ.get(
|
||||
"TEST_MD_CONTENT",
|
||||
f"# aaa\\n\\nwritten by test_write_user_data_aaa_md.py at {datetime.now(timezone.utc).isoformat()}\\n",
|
||||
).replace("\\n", "\n")
|
||||
|
||||
if os.environ.get("TEST_USE_ABSPATH", "").strip() in ("1", "true", "yes"):
|
||||
target = root / "user_data" / "aaa.md"
|
||||
file_path_arg = str(target)
|
||||
else:
|
||||
file_path_arg = "user_data/aaa.md"
|
||||
|
||||
print("workspace root:", root)
|
||||
print("file_path:", file_path_arg)
|
||||
print("content bytes (utf-8):", len(content.encode("utf-8")))
|
||||
|
||||
raw = asyncio.run(file_write_tool(file_path_arg, content, "w"))
|
||||
print("tool return:", raw)
|
||||
|
||||
resolved = (root / "user_data" / "aaa.md").resolve()
|
||||
if not resolved.is_file():
|
||||
print("FAIL: file missing:", resolved, file=sys.stderr)
|
||||
return 2
|
||||
on_disk = resolved.read_text(encoding="utf-8", errors="replace")
|
||||
print("OK: on disk", resolved)
|
||||
print("--- file head ---")
|
||||
print(on_disk[:500])
|
||||
print("---")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user