test: 新增第10层 Hook 配置与连通性测试
- settings.json hook 事件完整性 - hook 命令 DATA_DIR 环境变量校验 - 仓库 hooks.json 格式与 DATA_DIR 校验 - CAPTURE_BROKEN 残留检测 - Hook 链路连通性 (bun-runner → worker-service)
This commit is contained in:
@@ -212,6 +212,78 @@ if [ -n "$PORT" ]; then
|
||||
"Worker HTTP 健康检查 (port $PORT) 返回 200"
|
||||
fi
|
||||
|
||||
# ============================================================
|
||||
_header "10. Hook 配置与连通性"
|
||||
|
||||
CB_SETTINGS="${HOME}/.codebuddy/settings.json"
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
# 10.1 settings.json hook 事件完整性
|
||||
check "python3 -c \"
|
||||
import json
|
||||
with open('${CB_SETTINGS}') as f: s = json.load(f)
|
||||
hooks = s.get('hooks', {})
|
||||
required = ['PreToolUse', 'PostToolUse', 'UserPromptSubmit', 'Stop', 'SessionStart']
|
||||
for h in required:
|
||||
assert h in hooks, f'{h} missing'
|
||||
assert hooks['SessionStart'][0].get('matcher') == 'startup|clear|compact'
|
||||
print('OK')
|
||||
\"" \
|
||||
"settings.json 包含全部 5 类 hook 事件"
|
||||
|
||||
# 10.2 hook 命令包含数据目录环境变量
|
||||
check "python3 -c \"
|
||||
import json
|
||||
with open('${CB_SETTINGS}') as f: s = json.load(f)
|
||||
cmds = []
|
||||
for event in ['PreToolUse','PostToolUse','UserPromptSubmit','Stop','SessionStart']:
|
||||
for g in s['hooks'].get(event,[]):
|
||||
for h in g.get('hooks',[]):
|
||||
cmds.append(h['command'])
|
||||
bun_cmds = [c for c in cmds if 'bun-runner.js' in c]
|
||||
assert len(bun_cmds) >= 6, f'expected >=6 bun-runner hooks, got {len(bun_cmds)}'
|
||||
for c in bun_cmds:
|
||||
assert 'CLAUDE_MEM_DATA_DIR' in c, f'missing CLAUDE_MEM_DATA_DIR'
|
||||
assert 'CODEBUDDY_MEM_DATA_DIR' in c, f'missing CODEBUDDY_MEM_DATA_DIR'
|
||||
print(f'{len(bun_cmds)} hook commands OK')
|
||||
\"" \
|
||||
"settings.json hook 命令全部包含 DATA_DIR 环境变量"
|
||||
|
||||
# 10.3 仓库 hooks.json 存在且格式正确
|
||||
check "test -f ${REPO_ROOT}/hooks/hooks.json && python3 -c 'import json; json.load(open(\"${REPO_ROOT}/hooks/hooks.json\"))' 2>/dev/null" \
|
||||
"仓库 hooks.json 存在且格式正确"
|
||||
|
||||
# 10.4 仓库 hooks.json 也包含 DATA_DIR
|
||||
check "python3 -c \"
|
||||
import json
|
||||
with open('${REPO_ROOT}/hooks/hooks.json') as f: s = json.load(f)
|
||||
cmds = []
|
||||
for event in ['PreToolUse','PostToolUse','UserPromptSubmit','Stop','SessionStart']:
|
||||
for g in s['hooks'].get(event,[]):
|
||||
for h in g.get('hooks',[]):
|
||||
cmds.append(h['command'])
|
||||
bun_cmds = [c for c in cmds if 'bun-runner.js' in c]
|
||||
assert len(bun_cmds) >= 6
|
||||
for c in bun_cmds:
|
||||
assert 'CLAUDE_MEM_DATA_DIR' in c
|
||||
print(f'{len(bun_cmds)} hook commands OK')
|
||||
\"" \
|
||||
"仓库 hooks.json 所有 hook 命令包含 DATA_DIR"
|
||||
|
||||
# 10.5 无残留 CAPTURE_BROKEN
|
||||
CAPTURE_BROKEN="${DATA_DIR}/CAPTURE_BROKEN"
|
||||
if [ -f "$CAPTURE_BROKEN" ]; then
|
||||
_warn "CAPTURE_BROKEN 文件存在,表明近期 hook 执行异常"
|
||||
echo " $(head -3 $CAPTURE_BROKEN)"
|
||||
else
|
||||
_ok "无 CAPTURE_BROKEN 残留"
|
||||
fi
|
||||
|
||||
# 10.6 Hook 连通性: 执行一次 session-init
|
||||
check "export CLAUDE_MEM_DATA_DIR='${DATA_DIR}' CODEBUDDY_MEM_DATA_DIR='${DATA_DIR}' PATH=\"\$($SHELL -lc 'echo \$PATH' 2>/dev/null):\$PATH\" _R='${REPO_ROOT}' && node \"\$_R/scripts/bun-runner.js\" \"\$_R/scripts/worker-service.cjs\" hook codebuddy session-init 2>&1 | grep -q 'bun-runner'; rm -f '${DATA_DIR}/CAPTURE_BROKEN'" \
|
||||
"Hook 链路连通 (bun-runner → worker-service)"
|
||||
|
||||
# ============================================================
|
||||
# 汇总
|
||||
# ============================================================
|
||||
@@ -235,7 +307,7 @@ else
|
||||
fi
|
||||
|
||||
# ============================================================
|
||||
# 第 10 层: MCP API 测试 (由 CodeBuddy Code 助手执行)
|
||||
# 第 11 层: MCP API 测试 (由 CodeBuddy Code 助手执行)
|
||||
# 以下测试无法通过 bash 脚本完成,需对话中执行:
|
||||
#
|
||||
# mcp__codebuddy-mem__search { query:"观星阁", limit:5 }
|
||||
|
||||
Reference in New Issue
Block a user