Files
dstalk/tests/CMakeLists.txt
XiuChengWu 28ae90a6cc
Some checks failed
CI / Determine matrix (push) Has been cancelled
CI / ${{ matrix.os }} / ${{ matrix.build_type }} (push) Has been cancelled
CI / Sanitizer (ASan+UBSan) / ubuntu-24.04 (push) Has been cancelled
CI / Coverage (gcovr) / ubuntu-24.04 (push) Has been cancelled
W23: close mailroom metadata and network validation tests
- Refresh agents STATUS to W22.6 and exclude mailroom from metadata scans
- Add mailroom dispatch checklist and defensive rules
- Register F-23.D-1 and tag network input validation defense-in-depth
- Update network plugin tests for header length limits
- Fix LSP test metadata and remove orphan anthropic_internal.hpp

Verification:
- cmake --build build --config Release: 0 error, 0 warning
- ctest --test-dir build --output-on-failure: 10/10 passed
- ctest --test-dir build -R dstalk_smoke_test --output-on-failure: passed
- python scripts/check_agents_metadata.py --strict: passed

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-03 17:56:45 +08:00

287 lines
8.2 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)
# ============================================================
# dstalk_lsp_plugin_test — LSP 插件单元测试 (hand-rolled CHECK, 新增)
# 覆盖: lsp_trim / lsp_frame_message / lsp_parse_content_length
# ============================================================
add_executable(dstalk_lsp_plugin_test
lsp_plugin_test.cpp
${CMAKE_SOURCE_DIR}/plugins_base/lsp/src/lsp_plugin.cpp
)
target_include_directories(dstalk_lsp_plugin_test
PRIVATE
${CMAKE_SOURCE_DIR}/dstalk_core/include
${CMAKE_SOURCE_DIR}/plugins_base/lsp/src
)
target_compile_definitions(dstalk_lsp_plugin_test
PRIVATE
BOOST_JSON_HEADER_ONLY
BOOST_ALL_NO_LIB
)
target_compile_features(dstalk_lsp_plugin_test
PRIVATE cxx_std_17
)
target_link_libraries(dstalk_lsp_plugin_test
PRIVATE
dstalk
boost::boost
)
add_test(NAME dstalk_lsp_plugin_test COMMAND dstalk_lsp_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()