- New plugins_upper/ai_common/ static library: shared PluginConfig, ToolCallAccum, StreamContext, secure_zero, extract_host_port, serialize_tool_calls, free_chat_result - Refactored openai/anthropic plugins to use dstalk_ai:: namespace from ai_common - Fixed anthropic g_config raw pointer → std::atomic (data race) - Added SSE parse error counter with threshold abort (kMaxSseParseErrors=5) - Fixed missing closing brace in both plugins' error-body catch block - Updated test targets: ai_common include path + link, using namespace dstalk_ai - plugin_loader_test: added stub_unreg + service_registry.cpp for unregister_service - Includes pre-existing uncommitted changes from prior waves Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
253 lines
7.3 KiB
CMake
253 lines
7.3 KiB
CMake
# ============================================================
|
|
# tests — 单元测试
|
|
# ============================================================
|
|
|
|
add_executable(dstalk_smoke_test
|
|
smoke_test.cpp
|
|
)
|
|
|
|
target_link_libraries(dstalk_smoke_test
|
|
PRIVATE dstalk
|
|
)
|
|
|
|
add_test(NAME dstalk_smoke_test COMMAND dstalk_smoke_test)
|
|
|
|
# ============================================================
|
|
# dstalk_host_api_test — host API 单元测试
|
|
# ============================================================
|
|
|
|
add_executable(dstalk_host_api_test
|
|
host_api_test.cpp
|
|
${CMAKE_SOURCE_DIR}/dstalk_core/src/service_registry.cpp
|
|
)
|
|
|
|
target_include_directories(dstalk_host_api_test
|
|
PRIVATE ${CMAKE_SOURCE_DIR}/dstalk_core/src
|
|
)
|
|
|
|
target_compile_features(dstalk_host_api_test
|
|
PRIVATE cxx_std_17
|
|
)
|
|
|
|
target_link_libraries(dstalk_host_api_test
|
|
PRIVATE dstalk
|
|
)
|
|
|
|
add_test(NAME dstalk_host_api_test COMMAND dstalk_host_api_test)
|
|
|
|
# ============================================================
|
|
# dstalk_event_bus_test — EventBus 单元测试
|
|
# ============================================================
|
|
|
|
add_executable(dstalk_event_bus_test
|
|
event_bus_test.cpp
|
|
${CMAKE_SOURCE_DIR}/dstalk_core/src/event_bus.cpp
|
|
)
|
|
|
|
target_include_directories(dstalk_event_bus_test
|
|
PRIVATE ${CMAKE_SOURCE_DIR}/dstalk_core/src
|
|
)
|
|
|
|
target_compile_features(dstalk_event_bus_test
|
|
PRIVATE cxx_std_17
|
|
)
|
|
|
|
add_test(NAME dstalk_event_bus_test COMMAND dstalk_event_bus_test)
|
|
|
|
# ============================================================
|
|
# dstalk_service_registry_test — ServiceRegistry 补充单元测试
|
|
# ============================================================
|
|
|
|
add_executable(dstalk_service_registry_test
|
|
service_registry_test.cpp
|
|
${CMAKE_SOURCE_DIR}/dstalk_core/src/service_registry.cpp
|
|
)
|
|
|
|
target_include_directories(dstalk_service_registry_test
|
|
PRIVATE ${CMAKE_SOURCE_DIR}/dstalk_core/src
|
|
)
|
|
|
|
target_compile_features(dstalk_service_registry_test
|
|
PRIVATE cxx_std_17
|
|
)
|
|
|
|
add_test(NAME dstalk_service_registry_test COMMAND dstalk_service_registry_test)
|
|
|
|
# ============================================================
|
|
# dstalk_context_plugin_test — Context 插件单元测试
|
|
# W18.1 (qa-wang + architect-lin): 覆盖 token 计数/trim/UTF-8 边界
|
|
# ============================================================
|
|
|
|
add_executable(dstalk_context_plugin_test
|
|
context_plugin_test.cpp
|
|
)
|
|
|
|
target_link_libraries(dstalk_context_plugin_test
|
|
PRIVATE dstalk
|
|
)
|
|
|
|
add_test(NAME dstalk_context_plugin_test COMMAND dstalk_context_plugin_test)
|
|
|
|
# ============================================================
|
|
# dstalk_plugin_loader_test — PluginLoader 安全回归测试
|
|
# W20.3 (qa-xu): 覆盖 W19 F-18.3-1~5 修复验证
|
|
# ============================================================
|
|
|
|
add_executable(dstalk_plugin_loader_test
|
|
plugin_loader_test.cpp
|
|
${CMAKE_SOURCE_DIR}/dstalk_core/src/plugin_loader.cpp
|
|
${CMAKE_SOURCE_DIR}/dstalk_core/src/service_registry.cpp
|
|
${CMAKE_SOURCE_DIR}/dstalk_core/src/boost_json.cpp
|
|
)
|
|
|
|
target_include_directories(dstalk_plugin_loader_test
|
|
PRIVATE ${CMAKE_SOURCE_DIR}/dstalk_core/src
|
|
)
|
|
|
|
target_compile_features(dstalk_plugin_loader_test
|
|
PRIVATE cxx_std_17
|
|
)
|
|
|
|
find_package(Boost REQUIRED CONFIG)
|
|
|
|
target_compile_definitions(dstalk_plugin_loader_test
|
|
PRIVATE
|
|
BOOST_JSON_HEADER_ONLY
|
|
BOOST_ALL_NO_LIB
|
|
DSTALK_TEST_PLUGINS_DIR="${CMAKE_BINARY_DIR}/plugins"
|
|
)
|
|
|
|
target_link_libraries(dstalk_plugin_loader_test
|
|
PRIVATE
|
|
dstalk
|
|
boost::boost
|
|
)
|
|
|
|
add_test(NAME dstalk_plugin_loader_test COMMAND dstalk_plugin_loader_test)
|
|
|
|
# ============================================================
|
|
# dstalk_anthropic_plugin_test — Anthropic AI 插件单元测试
|
|
# W21.6 (qa-wang): 通过 #include source 访问 static 函数
|
|
# ============================================================
|
|
|
|
add_executable(dstalk_anthropic_plugin_test
|
|
anthropic_plugin_test.cpp
|
|
)
|
|
|
|
target_include_directories(dstalk_anthropic_plugin_test
|
|
PRIVATE ${CMAKE_SOURCE_DIR}/dstalk_core/include
|
|
PRIVATE ${CMAKE_SOURCE_DIR}/plugins_upper/ai_common/include
|
|
)
|
|
|
|
target_compile_definitions(dstalk_anthropic_plugin_test
|
|
PRIVATE
|
|
BOOST_JSON_HEADER_ONLY
|
|
BOOST_ALL_NO_LIB
|
|
)
|
|
|
|
target_link_libraries(dstalk_anthropic_plugin_test
|
|
PRIVATE
|
|
dstalk
|
|
ai_common
|
|
boost::boost
|
|
)
|
|
|
|
add_test(NAME dstalk_anthropic_plugin_test COMMAND dstalk_anthropic_plugin_test)
|
|
|
|
# ============================================================
|
|
# dstalk_openai_plugin_test — OpenAI 兼容 AI 插件单元测试
|
|
# W21.6 (qa-wang): 通过 #include source 访问 static 函数
|
|
# ============================================================
|
|
|
|
add_executable(dstalk_openai_plugin_test
|
|
openai_plugin_test.cpp
|
|
)
|
|
|
|
target_include_directories(dstalk_openai_plugin_test
|
|
PRIVATE ${CMAKE_SOURCE_DIR}/dstalk_core/include
|
|
PRIVATE ${CMAKE_SOURCE_DIR}/plugins_upper/ai_common/include
|
|
)
|
|
|
|
target_compile_definitions(dstalk_openai_plugin_test
|
|
PRIVATE
|
|
BOOST_JSON_HEADER_ONLY
|
|
BOOST_ALL_NO_LIB
|
|
)
|
|
|
|
target_link_libraries(dstalk_openai_plugin_test
|
|
PRIVATE
|
|
dstalk
|
|
ai_common
|
|
boost::boost
|
|
)
|
|
|
|
add_test(NAME dstalk_openai_plugin_test COMMAND dstalk_openai_plugin_test)
|
|
|
|
# ============================================================
|
|
# dstalk_network_plugin_test — Network 插件单元测试
|
|
# W22.2 (qa-xu): 通过 #include source 访问 static 函数
|
|
# ============================================================
|
|
|
|
find_package(OpenSSL REQUIRED CONFIG)
|
|
|
|
add_executable(dstalk_network_plugin_test
|
|
network_plugin_test.cpp
|
|
)
|
|
|
|
target_include_directories(dstalk_network_plugin_test
|
|
PRIVATE ${CMAKE_SOURCE_DIR}/dstalk_core/include
|
|
)
|
|
|
|
target_compile_definitions(dstalk_network_plugin_test
|
|
PRIVATE
|
|
BOOST_ALL_NO_LIB
|
|
)
|
|
|
|
target_link_libraries(dstalk_network_plugin_test
|
|
PRIVATE
|
|
dstalk
|
|
boost::boost
|
|
openssl::openssl
|
|
)
|
|
|
|
add_test(NAME dstalk_network_plugin_test COMMAND dstalk_network_plugin_test)
|
|
|
|
# ============================================================
|
|
# coverage — gcovr 覆盖率报告 (HTML + 终端摘要)
|
|
# 用法: cmake --build <dir> --target coverage
|
|
# 前提: 已用 --coverage flag 构建并通过 ctest 运行测试
|
|
# ============================================================
|
|
|
|
find_program(GCOVR_EXECUTABLE gcovr)
|
|
find_program(GCOV_EXECUTABLE gcov)
|
|
find_program(LLVM_COV_EXECUTABLE llvm-cov-18 llvm-cov)
|
|
|
|
if(GCOVR_EXECUTABLE)
|
|
if(LLVM_COV_EXECUTABLE)
|
|
set(GCOV_CMD "${LLVM_COV_EXECUTABLE} gcov")
|
|
elseif(GCOV_EXECUTABLE)
|
|
set(GCOV_CMD "${GCOV_EXECUTABLE}")
|
|
else()
|
|
set(GCOV_CMD "")
|
|
endif()
|
|
|
|
add_custom_target(coverage
|
|
COMMAND ${GCOVR_EXECUTABLE} -r ${CMAKE_SOURCE_DIR}
|
|
--object-directory=${CMAKE_BINARY_DIR}
|
|
--gcov-executable "${GCOV_CMD}"
|
|
--print-summary
|
|
COMMAND ${GCOVR_EXECUTABLE} -r ${CMAKE_SOURCE_DIR}
|
|
--object-directory=${CMAKE_BINARY_DIR}
|
|
--gcov-executable "${GCOV_CMD}"
|
|
--html --html-details
|
|
-o ${CMAKE_BINARY_DIR}/coverage/index.html
|
|
COMMENT "Coverage: HTML report -> ${CMAKE_BINARY_DIR}/coverage/index.html"
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
)
|
|
else()
|
|
add_custom_target(coverage
|
|
COMMAND ${CMAKE_COMMAND} -E echo "gcovr not found. Install: pip install gcovr"
|
|
COMMENT "Coverage target unavailable (gcovr not found)"
|
|
)
|
|
endif()
|