fix: SessionStart hook 添加 suppressOutput,防止原始 JSON 显示在对话中

- context handler 返回值增加 suppressOutput:!0,与 session-init 行为一致
- 回归测试脚本增加 Chroma-MCP 服务连通性、日志健康检查、Embedding 功能验证
This commit is contained in:
2026-05-06 01:19:47 +08:00
parent b84d163af1
commit df1348a675
2 changed files with 68 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
#!/bin/bash
# ============================================================
# codebuddy-mem 全功能回归测试
# 测试范围: 基础设施 / 数据库 / MCP API / Chroma / 配置
# 测试范围: 基础设施 / 数据库 / MCP API / Chroma / Chroma-MCP 服务 / 配置
# 使用方式: bash scripts/regression-test.sh
# 或对话中说 "执行 codebuddy-mem 回归测试"
# ============================================================
@@ -50,7 +50,7 @@ check "test -f $DATA_DIR/worker.pid" \
"worker.pid 存在"
check "[ -n \"\$(cat $DATA_DIR/worker.pid 2>/dev/null | python3 -c 'import sys,json; print(json.load(sys.stdin)[\"pid\"])' 2>/dev/null)\" ] && kill -0 \$(cat $DATA_DIR/worker.pid 2>/dev/null | python3 -c 'import sys,json; print(json.load(sys.stdin)[\"pid\"])' 2>/dev/null) 2>/dev/null" \
"Worker 进程运行中"
check "pgrep -f 'chroma-mcp.*codebuddy-mem' > /dev/null" \
check "pgrep -f 'chroma-mcp' > /dev/null" \
"Chroma-MCP 进程运行中"
# ============================================================
@@ -157,6 +157,71 @@ check "test -f $DATA_DIR/chroma/chroma.sqlite3 && sqlite3 $DATA_DIR/chroma/chrom
check "sqlite3 $DATA_DIR/chroma/chroma.sqlite3 'SELECT count(*) FROM collections;' | grep -q '[1-9]'" \
"Chroma collections 有数据"
# Chroma-MCP 服务连通性
check "pgrep -f 'uvx.*chroma-mcp' > /dev/null || pgrep -f 'chroma-mcp.*persistent' > /dev/null || pgrep -f 'chroma-mcp.*data-dir' > /dev/null" \
"chroma-mcp 进程运行中 (uvx 模式)"
# 日志健康: 最近 1 小时内无 chroma-mcp 连接失败
LATEST_LOG=$(ls -t $DATA_DIR/logs/*.log 2>/dev/null | head -1)
if [ -n "$LATEST_LOG" ]; then
check "python3 -c \"
import time, sys
cutoff = time.time() - 3600
with open('$LATEST_LOG') as f:
for line in f:
if 'CHROMA_MCP' in line and ('Connection failed' in line or 'Connection attempt failed' in line):
try:
ts = line[1:24]
t = time.mktime(time.strptime(ts, '%Y-%m-%d %H:%M:%S.%f'))
if t > cutoff:
sys.exit(1)
except SystemExit:
raise
except:
pass
\"" \
"chroma-mcp 最近 1 小时无连接失败"
else
_warn "无日志文件,跳过 chroma-mcp 日志检查"
fi
# 日志健康: 无 chroma-mcp 重试退避 (backoff)
if [ -n "$LATEST_LOG" ]; then
check "python3 -c \"
import time, sys
cutoff = time.time() - 3600
with open('$LATEST_LOG') as f:
for line in f:
if 'chroma-mcp connection in backoff' in line:
try:
ts = line[1:24]
t = time.mktime(time.strptime(ts, '%Y-%m-%d %H:%M:%S.%f'))
if t > cutoff:
sys.exit(1)
except SystemExit:
raise
except:
pass
\"" \
"chroma-mcp 最近 1 小时无重试退避"
fi
# Embedding 功能: 验证向量生成能力
CHROMA_PYTHON=$(ps aux | grep "chroma-mcp" | grep -v grep | grep -o '/[^ ]*bin/python[0-9.]*' | head -1)
if [ -n "$CHROMA_PYTHON" ]; then
check "$CHROMA_PYTHON -c \"
import chromadb
from chromadb.utils import embedding_functions
ef = embedding_functions.DefaultEmbeddingFunction()
result = ef(['codebuddy-mem regression test embedding'])
assert len(result) == 1 and len(result[0]) == 384, f'Expected (1,384) got {len(result)}x{len(result[0]) if result else 0}'
print('OK')
\"" \
"Embedding 函数可用 (生成 384 维向量)"
else
_warn "无法定位 chroma-mcp Python 环境,跳过 Embedding 测试"
fi
# ============================================================
_header "7. 配置文件"