- Introduced comprehensive unit tests for the OpenAI plugin, covering SSE parsing, sentinel matching, delta extraction, request building, and more. - Created a new markdown file detailing coding and naming conventions for the dstalk project, including guidelines for comments, naming rules, code organization, and memory management practices.
248 lines
7.1 KiB
CMake
248 lines
7.1 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/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
|
|
)
|
|
|
|
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
|
|
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
|
|
)
|
|
|
|
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
|
|
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()
|