CMakeLists.txt 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. # Tests for smartbotic-database
  2. # yyjson (v1.10+) — Phase A swaps nlohmann::json::parse for parse_to_nlohmann
  3. # at hot paths in wal.cpp, snapshot.cpp, history_store.cpp, etc. Any test
  4. # target that compiles those files now also needs json_parse.cpp linked and
  5. # yyjson linked. Resolve once at file scope so every test target below can
  6. # use ${yyjson_LIBRARIES} / ${yyjson_INCLUDE_DIRS}.
  7. if(NOT yyjson_FOUND)
  8. find_package(PkgConfig REQUIRED)
  9. pkg_check_modules(yyjson REQUIRED yyjson)
  10. endif()
  11. # LMDB (v2.0 storage substrate) — resolve once at file scope, mirroring the
  12. # yyjson pattern. liblmdb does not ship pkg-config on Debian 13, so use
  13. # find_path/find_library. Each test target that pulls in storage/ sources
  14. # adds ${LMDB_INCLUDE_DIR} / ${LMDB_LIBRARY} to its link/include flags.
  15. if(NOT LMDB_INCLUDE_DIR OR NOT LMDB_LIBRARY)
  16. find_path(LMDB_INCLUDE_DIR lmdb.h)
  17. find_library(LMDB_LIBRARY NAMES lmdb)
  18. if(NOT LMDB_INCLUDE_DIR OR NOT LMDB_LIBRARY)
  19. message(FATAL_ERROR "LMDB not found. Install liblmdb-dev.")
  20. endif()
  21. endif()
  22. # Vector storage integration test
  23. # Compiles memory_store.cpp directly — no dependency on the full service executable.
  24. set(TEST_VECTOR_SOURCES
  25. test_vector_storage.cpp
  26. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  27. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  28. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  29. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  30. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  31. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  32. )
  33. add_executable(test_vector_storage ${TEST_VECTOR_SOURCES})
  34. target_include_directories(test_vector_storage PRIVATE
  35. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  36. )
  37. # nlohmann/json
  38. if(TARGET nlohmann_json::nlohmann_json)
  39. target_link_libraries(test_vector_storage PRIVATE nlohmann_json::nlohmann_json)
  40. else()
  41. target_include_directories(test_vector_storage PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  42. endif()
  43. # spdlog
  44. if(TARGET spdlog::spdlog)
  45. target_link_libraries(test_vector_storage PRIVATE spdlog::spdlog)
  46. else()
  47. target_link_libraries(test_vector_storage PRIVATE ${SPDLOG_LIBRARIES})
  48. target_include_directories(test_vector_storage PRIVATE ${SPDLOG_INCLUDE_DIRS})
  49. endif()
  50. # Threads (required by MemoryStore background threads)
  51. find_package(Threads REQUIRED)
  52. target_link_libraries(test_vector_storage PRIVATE Threads::Threads)
  53. # yyjson (wal.cpp uses parse_to_nlohmann from v1.10+)
  54. target_link_libraries(test_vector_storage PRIVATE ${yyjson_LIBRARIES})
  55. target_include_directories(test_vector_storage PRIVATE ${yyjson_INCLUDE_DIRS})
  56. # View projection unit test
  57. set(TEST_VIEWS_SOURCES
  58. test_views.cpp
  59. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/views/projection.cpp
  60. )
  61. add_executable(test_views ${TEST_VIEWS_SOURCES})
  62. target_include_directories(test_views PRIVATE
  63. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  64. )
  65. # nlohmann/json
  66. if(TARGET nlohmann_json::nlohmann_json)
  67. target_link_libraries(test_views PRIVATE nlohmann_json::nlohmann_json)
  68. else()
  69. target_include_directories(test_views PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  70. endif()
  71. # Per-collection timestamp precision test
  72. set(TEST_TIMESTAMP_PRECISION_SOURCES
  73. test_timestamp_precision.cpp
  74. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  75. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  76. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  77. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  78. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  79. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  80. )
  81. add_executable(test_timestamp_precision ${TEST_TIMESTAMP_PRECISION_SOURCES})
  82. target_include_directories(test_timestamp_precision PRIVATE
  83. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  84. )
  85. if(TARGET nlohmann_json::nlohmann_json)
  86. target_link_libraries(test_timestamp_precision PRIVATE nlohmann_json::nlohmann_json)
  87. else()
  88. target_include_directories(test_timestamp_precision PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  89. endif()
  90. if(TARGET spdlog::spdlog)
  91. target_link_libraries(test_timestamp_precision PRIVATE spdlog::spdlog)
  92. else()
  93. target_link_libraries(test_timestamp_precision PRIVATE ${SPDLOG_LIBRARIES})
  94. target_include_directories(test_timestamp_precision PRIVATE ${SPDLOG_INCLUDE_DIRS})
  95. endif()
  96. find_package(Threads REQUIRED)
  97. target_link_libraries(test_timestamp_precision PRIVATE Threads::Threads)
  98. # yyjson (wal.cpp uses parse_to_nlohmann from v1.10+)
  99. target_link_libraries(test_timestamp_precision PRIVATE ${yyjson_LIBRARIES})
  100. target_include_directories(test_timestamp_precision PRIVATE ${yyjson_INCLUDE_DIRS})
  101. # Snapshot durability + fallback integration test
  102. # Exercises SnapshotManager directly; pulls in memory_store.cpp, snapshot.cpp,
  103. # and wal.cpp (for the crc32 helpers used by snapshot.cpp).
  104. set(TEST_SNAPSHOT_DURABILITY_SOURCES
  105. test_snapshot_durability.cpp
  106. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  107. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  108. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/snapshot.cpp
  109. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  110. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  111. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  112. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  113. )
  114. add_executable(test_snapshot_durability ${TEST_SNAPSHOT_DURABILITY_SOURCES})
  115. target_include_directories(test_snapshot_durability PRIVATE
  116. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  117. )
  118. if(TARGET nlohmann_json::nlohmann_json)
  119. target_link_libraries(test_snapshot_durability PRIVATE nlohmann_json::nlohmann_json)
  120. else()
  121. target_include_directories(test_snapshot_durability PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  122. endif()
  123. if(TARGET spdlog::spdlog)
  124. target_link_libraries(test_snapshot_durability PRIVATE spdlog::spdlog)
  125. else()
  126. target_link_libraries(test_snapshot_durability PRIVATE ${SPDLOG_LIBRARIES})
  127. target_include_directories(test_snapshot_durability PRIVATE ${SPDLOG_INCLUDE_DIRS})
  128. endif()
  129. find_package(Threads REQUIRED)
  130. target_link_libraries(test_snapshot_durability PRIVATE Threads::Threads)
  131. # yyjson (wal.cpp/snapshot.cpp use parse_to_nlohmann from v1.10+)
  132. target_link_libraries(test_snapshot_durability PRIVATE ${yyjson_LIBRARIES})
  133. target_include_directories(test_snapshot_durability PRIVATE ${yyjson_INCLUDE_DIRS})
  134. # LZ4 — snapshot.cpp #includes <lz4.h> unless DISABLE_LZ4 is defined, so link it.
  135. find_package(PkgConfig QUIET)
  136. if(PKG_CONFIG_FOUND)
  137. pkg_check_modules(TEST_LZ4 QUIET liblz4)
  138. endif()
  139. if(TEST_LZ4_FOUND)
  140. target_link_libraries(test_snapshot_durability PRIVATE ${TEST_LZ4_LIBRARIES})
  141. target_include_directories(test_snapshot_durability PRIVATE ${TEST_LZ4_INCLUDE_DIRS})
  142. else()
  143. # Fallback: assume liblz4 is installed at a standard location
  144. target_link_libraries(test_snapshot_durability PRIVATE lz4)
  145. endif()
  146. # Config drop-in loader test (v1.7.0 T1 → T12)
  147. # Exercises loadLayeredConfig() in isolation.
  148. set(TEST_CONFIG_DROPINS_SOURCES
  149. test_config_dropins.cpp
  150. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/config_loader.cpp
  151. )
  152. add_executable(test_config_dropins ${TEST_CONFIG_DROPINS_SOURCES})
  153. target_include_directories(test_config_dropins PRIVATE
  154. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  155. )
  156. if(TARGET nlohmann_json::nlohmann_json)
  157. target_link_libraries(test_config_dropins PRIVATE nlohmann_json::nlohmann_json)
  158. else()
  159. target_include_directories(test_config_dropins PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  160. endif()
  161. if(TARGET spdlog::spdlog)
  162. target_link_libraries(test_config_dropins PRIVATE spdlog::spdlog)
  163. else()
  164. target_link_libraries(test_config_dropins PRIVATE ${SPDLOG_LIBRARIES})
  165. target_include_directories(test_config_dropins PRIVATE ${SPDLOG_INCLUDE_DIRS})
  166. endif()
  167. # Eviction test (v1.7.0 T4+T5+T6 → T12)
  168. # Exercises chunked eviction, per-collection priorities, and the hot-write
  169. # floor directly through MemoryStore. Mirrors the link deps of test_timestamp_precision.
  170. set(TEST_EVICTION_SOURCES
  171. test_eviction.cpp
  172. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  173. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  174. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  175. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  176. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  177. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  178. )
  179. add_executable(test_eviction ${TEST_EVICTION_SOURCES})
  180. target_include_directories(test_eviction PRIVATE
  181. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  182. )
  183. if(TARGET nlohmann_json::nlohmann_json)
  184. target_link_libraries(test_eviction PRIVATE nlohmann_json::nlohmann_json)
  185. else()
  186. target_include_directories(test_eviction PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  187. endif()
  188. if(TARGET spdlog::spdlog)
  189. target_link_libraries(test_eviction PRIVATE spdlog::spdlog)
  190. else()
  191. target_link_libraries(test_eviction PRIVATE ${SPDLOG_LIBRARIES})
  192. target_include_directories(test_eviction PRIVATE ${SPDLOG_INCLUDE_DIRS})
  193. endif()
  194. find_package(Threads REQUIRED)
  195. target_link_libraries(test_eviction PRIVATE Threads::Threads)
  196. # yyjson (wal.cpp uses parse_to_nlohmann from v1.10+)
  197. target_link_libraries(test_eviction PRIVATE ${yyjson_LIBRARIES})
  198. target_include_directories(test_eviction PRIVATE ${yyjson_INCLUDE_DIRS})
  199. # yyjson → nlohmann bridge helper test (v1.10 Phase A T2)
  200. # Exercises parse_to_nlohmann() in isolation against nlohmann::json::parse
  201. # for a corpus of production-shaped docs. yyjson is configured at the
  202. # service/ scope; re-resolve it here so the test target can find it
  203. # independently of the service build.
  204. if(NOT yyjson_FOUND)
  205. find_package(PkgConfig REQUIRED)
  206. pkg_check_modules(yyjson REQUIRED yyjson)
  207. endif()
  208. add_executable(test_json_parse
  209. test_json_parse.cpp
  210. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  211. )
  212. target_include_directories(test_json_parse PRIVATE
  213. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  214. ${yyjson_INCLUDE_DIRS}
  215. )
  216. if(TARGET nlohmann_json::nlohmann_json)
  217. target_link_libraries(test_json_parse PRIVATE nlohmann_json::nlohmann_json)
  218. else()
  219. target_include_directories(test_json_parse PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  220. endif()
  221. target_link_libraries(test_json_parse PRIVATE ${yyjson_LIBRARIES})
  222. # Binary doc encoder/decoder test (v1.11 Phase B T2)
  223. # Exercises doc_binary::Doc, encode, decode, get_field, to_json_text against
  224. # nlohmann::json round-trips. yyjson resolution is shared at file scope above.
  225. add_executable(test_doc_binary
  226. test_doc_binary.cpp
  227. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  228. )
  229. target_include_directories(test_doc_binary PRIVATE
  230. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  231. ${yyjson_INCLUDE_DIRS}
  232. )
  233. if(TARGET nlohmann_json::nlohmann_json)
  234. target_link_libraries(test_doc_binary PRIVATE nlohmann_json::nlohmann_json)
  235. else()
  236. target_include_directories(test_doc_binary PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  237. endif()
  238. target_link_libraries(test_doc_binary PRIVATE ${yyjson_LIBRARIES})
  239. # Parse-time micro-benchmark (v1.10 Phase A T8) — manual bench, NOT
  240. # registered with CTest. Run as ./build/tests/bench_json_parse <corpus>.
  241. add_executable(bench_json_parse
  242. bench_json_parse.cpp
  243. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  244. )
  245. target_include_directories(bench_json_parse PRIVATE
  246. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  247. ${yyjson_INCLUDE_DIRS}
  248. )
  249. if(TARGET nlohmann_json::nlohmann_json)
  250. target_link_libraries(bench_json_parse PRIVATE nlohmann_json::nlohmann_json)
  251. else()
  252. target_include_directories(bench_json_parse PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  253. endif()
  254. target_link_libraries(bench_json_parse PRIVATE ${yyjson_LIBRARIES})
  255. # RSS bench (v1.11 Phase B T8) — manual bench, NOT registered with CTest.
  256. # Run as ./build/tests/bench_doc_memory [N].
  257. add_executable(bench_doc_memory
  258. bench_doc_memory.cpp
  259. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  260. )
  261. target_include_directories(bench_doc_memory PRIVATE
  262. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  263. ${yyjson_INCLUDE_DIRS}
  264. )
  265. if(TARGET nlohmann_json::nlohmann_json)
  266. target_link_libraries(bench_doc_memory PRIVATE nlohmann_json::nlohmann_json)
  267. else()
  268. target_include_directories(bench_doc_memory PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  269. endif()
  270. target_link_libraries(bench_doc_memory PRIVATE ${yyjson_LIBRARIES})
  271. # LMDB environment unit test (v2.0 storage Phase C Stage 1, Tasks 1.2 / 1.3).
  272. # Compiles the storage/ sources directly — no dependency on the service
  273. # executable.
  274. add_executable(test_lmdb_env
  275. test_lmdb_env.cpp
  276. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_env.cpp
  277. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_txn.cpp
  278. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_dbi.cpp
  279. )
  280. target_include_directories(test_lmdb_env PRIVATE
  281. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  282. ${LMDB_INCLUDE_DIR}
  283. )
  284. target_link_libraries(test_lmdb_env PRIVATE ${LMDB_LIBRARY})
  285. # DocumentStore + LmdbDocumentStore unit test (v2.0 storage Phase C Stage 2).
  286. # Same shape as test_lmdb_env: links the storage/ sources and a couple of
  287. # helpers (doc_binary, json_parse) directly. No dependency on the full
  288. # service executable.
  289. add_executable(test_document_store
  290. test_document_store.cpp
  291. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_env.cpp
  292. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_txn.cpp
  293. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_dbi.cpp
  294. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/document_store_lmdb.cpp
  295. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/relations/relation_index.cpp
  296. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/secondary_index.cpp
  297. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/subdb_identity.cpp
  298. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  299. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  300. )
  301. target_include_directories(test_document_store PRIVATE
  302. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  303. ${LMDB_INCLUDE_DIR}
  304. ${yyjson_INCLUDE_DIRS}
  305. )
  306. target_link_libraries(test_document_store PRIVATE ${LMDB_LIBRARY})
  307. target_link_libraries(test_document_store PRIVATE ${yyjson_LIBRARIES})
  308. if(TARGET nlohmann_json::nlohmann_json)
  309. target_link_libraries(test_document_store PRIVATE nlohmann_json::nlohmann_json)
  310. else()
  311. target_include_directories(test_document_store PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  312. endif()
  313. # v1.x → v2.0 migration tool unit test (v2.0 storage Phase C Stage 3).
  314. # Pulls in both the v1.x persistence stack (snapshot.cpp, wal.cpp, history_store.cpp,
  315. # memory_store.cpp) and the v2.0 storage stack (LMDB primitives + DocumentStore +
  316. # migrate_v1_to_v2). Each side is independent of the other at link time except
  317. # for the migration .cpp itself, which is the bridge.
  318. add_executable(test_migrate_v1_to_v2
  319. test_migrate_v1_to_v2.cpp
  320. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  321. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  322. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/snapshot.cpp
  323. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  324. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  325. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  326. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  327. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_env.cpp
  328. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_txn.cpp
  329. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_dbi.cpp
  330. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/document_store_lmdb.cpp
  331. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/relations/relation_index.cpp
  332. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/secondary_index.cpp
  333. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/subdb_identity.cpp
  334. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/migrate_v1_to_v2.cpp
  335. )
  336. target_include_directories(test_migrate_v1_to_v2 PRIVATE
  337. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  338. ${LMDB_INCLUDE_DIR}
  339. ${yyjson_INCLUDE_DIRS}
  340. )
  341. target_link_libraries(test_migrate_v1_to_v2 PRIVATE ${LMDB_LIBRARY})
  342. target_link_libraries(test_migrate_v1_to_v2 PRIVATE ${yyjson_LIBRARIES})
  343. if(TARGET nlohmann_json::nlohmann_json)
  344. target_link_libraries(test_migrate_v1_to_v2 PRIVATE nlohmann_json::nlohmann_json)
  345. else()
  346. target_include_directories(test_migrate_v1_to_v2 PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  347. endif()
  348. if(TARGET spdlog::spdlog)
  349. target_link_libraries(test_migrate_v1_to_v2 PRIVATE spdlog::spdlog)
  350. else()
  351. target_link_libraries(test_migrate_v1_to_v2 PRIVATE ${SPDLOG_LIBRARIES})
  352. target_include_directories(test_migrate_v1_to_v2 PRIVATE ${SPDLOG_INCLUDE_DIRS})
  353. endif()
  354. find_package(Threads REQUIRED)
  355. target_link_libraries(test_migrate_v1_to_v2 PRIVATE Threads::Threads)
  356. # LZ4 — snapshot.cpp uses LZ4 compression
  357. if(PKG_CONFIG_FOUND)
  358. pkg_check_modules(MIGRATE_LZ4 QUIET liblz4)
  359. endif()
  360. if(MIGRATE_LZ4_FOUND)
  361. target_link_libraries(test_migrate_v1_to_v2 PRIVATE ${MIGRATE_LZ4_LIBRARIES})
  362. target_include_directories(test_migrate_v1_to_v2 PRIVATE ${MIGRATE_LZ4_INCLUDE_DIRS})
  363. else()
  364. target_link_libraries(test_migrate_v1_to_v2 PRIVATE lz4)
  365. endif()
  366. # v2.0 Stage 4 — dual-write mirror unit + integration test.
  367. # Links the MemoryStore + LMDB substrate the same way test_migrate_v1_to_v2 does,
  368. # but skips persistence/snapshot/wal since the mirror helper does not touch them.
  369. add_executable(test_dual_write_mirror
  370. test_dual_write_mirror.cpp
  371. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  372. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  373. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  374. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  375. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  376. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  377. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_env.cpp
  378. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_txn.cpp
  379. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_dbi.cpp
  380. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/document_store_lmdb.cpp
  381. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/relations/relation_index.cpp
  382. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/secondary_index.cpp
  383. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/subdb_identity.cpp
  384. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/snapshot.cpp
  385. )
  386. # v2.21.2 - snapshot.cpp, for the released-vector snapshot round trip.
  387. if(TEST_LZ4_FOUND)
  388. target_link_libraries(test_dual_write_mirror PRIVATE ${TEST_LZ4_LIBRARIES})
  389. target_include_directories(test_dual_write_mirror PRIVATE ${TEST_LZ4_INCLUDE_DIRS})
  390. else()
  391. target_link_libraries(test_dual_write_mirror PRIVATE lz4)
  392. endif()
  393. target_include_directories(test_dual_write_mirror PRIVATE
  394. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  395. ${LMDB_INCLUDE_DIR}
  396. ${yyjson_INCLUDE_DIRS}
  397. )
  398. target_link_libraries(test_dual_write_mirror PRIVATE ${LMDB_LIBRARY})
  399. target_link_libraries(test_dual_write_mirror PRIVATE ${yyjson_LIBRARIES})
  400. if(TARGET nlohmann_json::nlohmann_json)
  401. target_link_libraries(test_dual_write_mirror PRIVATE nlohmann_json::nlohmann_json)
  402. else()
  403. target_include_directories(test_dual_write_mirror PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  404. endif()
  405. if(TARGET spdlog::spdlog)
  406. target_link_libraries(test_dual_write_mirror PRIVATE spdlog::spdlog)
  407. else()
  408. target_link_libraries(test_dual_write_mirror PRIVATE ${SPDLOG_LIBRARIES})
  409. target_include_directories(test_dual_write_mirror PRIVATE ${SPDLOG_INCLUDE_DIRS})
  410. endif()
  411. find_package(Threads REQUIRED)
  412. target_link_libraries(test_dual_write_mirror PRIVATE Threads::Threads)
  413. # Five test files assert via assert(), which CMAKE_BUILD_TYPE=Release compiles
  414. # out via -DNDEBUG. That silently reduced 104 assertions across test_views,
  415. # test_eviction, test_snapshot_durability, test_timestamp_precision and
  416. # test_config_dropins to no-ops: the suites ran, printed PASS, and checked
  417. # nothing. Strip NDEBUG from test targets so assertions are live in every
  418. # build type. Production targets are unaffected.
  419. foreach(_t
  420. test_vector_storage test_views test_timestamp_precision
  421. test_snapshot_durability test_config_dropins test_eviction
  422. test_json_parse test_doc_binary test_lmdb_env test_document_store
  423. test_migrate_v1_to_v2 test_dual_write_mirror)
  424. target_compile_options(${_t} PRIVATE -UNDEBUG)
  425. endforeach()
  426. # Register with CTest
  427. enable_testing()
  428. add_test(NAME vector_storage COMMAND test_vector_storage)
  429. add_test(NAME views COMMAND test_views)
  430. add_test(NAME timestamp_precision COMMAND test_timestamp_precision)
  431. add_test(NAME snapshot_durability COMMAND test_snapshot_durability)
  432. add_test(NAME config_dropins COMMAND test_config_dropins)
  433. add_test(NAME eviction COMMAND test_eviction)
  434. add_test(NAME json_parse COMMAND test_json_parse)
  435. add_test(NAME doc_binary COMMAND test_doc_binary)
  436. add_test(NAME lmdb_env COMMAND test_lmdb_env)
  437. add_test(NAME document_store COMMAND test_document_store)
  438. add_test(NAME migrate_v1_to_v2 COMMAND test_migrate_v1_to_v2)
  439. add_test(NAME dual_write_mirror COMMAND test_dual_write_mirror)
  440. # v2.3 — project addressing (header-only parser; no link deps).
  441. add_executable(test_project_addressing test_project_addressing.cpp)
  442. target_include_directories(test_project_addressing PRIVATE
  443. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  444. )
  445. add_test(NAME project_addressing COMMAND test_project_addressing)
  446. # v2.3 Stage F — project CRUD placeholders (header-only filesystem helpers;
  447. # no link deps beyond std::filesystem). Exercises listProjects /
  448. # createProject / dropProject against a tmp data dir. Stage B replaces the
  449. # placeholder with a project-registry-backed implementation; this test
  450. # will be retargeted then.
  451. add_executable(test_project_crud test_project_crud.cpp)
  452. target_include_directories(test_project_crud PRIVATE
  453. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  454. )
  455. add_test(NAME project_crud COMMAND test_project_crud)
  456. # v2.4.4 — sub-db identity sentinel. Regression cover for the misbound-MDB_dbi
  457. # incident in which writes for one collection landed in another's sub-db.
  458. add_executable(test_subdb_identity
  459. test_subdb_identity.cpp
  460. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_env.cpp
  461. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_txn.cpp
  462. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_dbi.cpp
  463. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/subdb_identity.cpp
  464. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/document_store_lmdb.cpp
  465. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/relations/relation_index.cpp
  466. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/secondary_index.cpp
  467. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  468. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  469. )
  470. target_include_directories(test_subdb_identity PRIVATE
  471. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  472. ${LMDB_INCLUDE_DIR}
  473. ${yyjson_INCLUDE_DIRS}
  474. )
  475. target_link_libraries(test_subdb_identity PRIVATE ${LMDB_LIBRARY})
  476. target_link_libraries(test_subdb_identity PRIVATE ${yyjson_LIBRARIES})
  477. if(TARGET nlohmann_json::nlohmann_json)
  478. target_link_libraries(test_subdb_identity PRIVATE nlohmann_json::nlohmann_json)
  479. else()
  480. target_include_directories(test_subdb_identity PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  481. endif()
  482. add_test(NAME test_subdb_identity COMMAND test_subdb_identity)
  483. # v2.13.0 - export_scan vector states (incl. MISSING/UNKNOWN, which only a
  484. # direct write can produce), resume cursor, count, and put_with_vector.
  485. add_executable(test_export_scan
  486. test_export_scan.cpp
  487. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_env.cpp
  488. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_txn.cpp
  489. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_dbi.cpp
  490. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/subdb_identity.cpp
  491. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/document_store_lmdb.cpp
  492. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/relations/relation_index.cpp
  493. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/secondary_index.cpp
  494. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  495. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  496. )
  497. target_include_directories(test_export_scan PRIVATE
  498. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  499. ${LMDB_INCLUDE_DIR}
  500. ${yyjson_INCLUDE_DIRS}
  501. )
  502. target_link_libraries(test_export_scan PRIVATE ${LMDB_LIBRARY} ${yyjson_LIBRARIES})
  503. if(TARGET nlohmann_json::nlohmann_json)
  504. target_link_libraries(test_export_scan PRIVATE nlohmann_json::nlohmann_json)
  505. else()
  506. target_include_directories(test_export_scan PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  507. endif()
  508. add_test(NAME test_export_scan COMMAND test_export_scan)
  509. # v2.11.0 T2 — relation reverse index (parent id -> child ids, DUPSORT).
  510. # Only the sources relation_index_{add,remove,child_count,children} actually
  511. # need: the LMDB store itself plus its direct dependencies. No relations/
  512. # relation_manager.cpp here - the storage layer is deliberately free of that
  513. # dependency (see relations/relation_index.hpp).
  514. add_executable(test_relation_index
  515. test_relation_index.cpp
  516. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_env.cpp
  517. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_txn.cpp
  518. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_dbi.cpp
  519. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/subdb_identity.cpp
  520. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/document_store_lmdb.cpp
  521. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/secondary_index.cpp
  522. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/relations/relation_index.cpp
  523. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  524. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  525. )
  526. target_include_directories(test_relation_index PRIVATE
  527. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  528. ${LMDB_INCLUDE_DIR}
  529. ${yyjson_INCLUDE_DIRS}
  530. )
  531. target_link_libraries(test_relation_index PRIVATE ${LMDB_LIBRARY})
  532. target_link_libraries(test_relation_index PRIVATE ${yyjson_LIBRARIES})
  533. if(TARGET nlohmann_json::nlohmann_json)
  534. target_link_libraries(test_relation_index PRIVATE nlohmann_json::nlohmann_json)
  535. else()
  536. target_include_directories(test_relation_index PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  537. endif()
  538. add_test(NAME test_relation_index COMMAND test_relation_index)
  539. # v2.11.0 T3/T4 — relation reverse-index maintenance on child writes (T3),
  540. # plus restrict/no_action delete enforcement (T4). T4 needs the declaration
  541. # registry (RelationManager, backed by a MemoryStore) alongside the LMDB
  542. # reverse index, so unlike test_relation_index this target does pull in
  543. # relations/relation_manager.cpp and memory_store.cpp and their dependencies.
  544. add_executable(test_relation_enforcement
  545. test_relation_enforcement.cpp
  546. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_env.cpp
  547. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_txn.cpp
  548. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/lmdb_dbi.cpp
  549. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/subdb_identity.cpp
  550. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/document_store_lmdb.cpp
  551. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/secondary_index.cpp
  552. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/relations/relation_index.cpp
  553. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/relations/relation_manager.cpp
  554. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/relations/relation_enforcement.cpp
  555. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/relations/relation_cascade.cpp
  556. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  557. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/views/view_manager.cpp
  558. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/views/projection.cpp
  559. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  560. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  561. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  562. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/snapshot.cpp
  563. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/persistence_manager.cpp
  564. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  565. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  566. )
  567. target_include_directories(test_relation_enforcement PRIVATE
  568. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  569. ${LMDB_INCLUDE_DIR}
  570. ${yyjson_INCLUDE_DIRS}
  571. )
  572. target_link_libraries(test_relation_enforcement PRIVATE ${LMDB_LIBRARY})
  573. target_link_libraries(test_relation_enforcement PRIVATE ${yyjson_LIBRARIES})
  574. if(TARGET nlohmann_json::nlohmann_json)
  575. target_link_libraries(test_relation_enforcement PRIVATE nlohmann_json::nlohmann_json)
  576. else()
  577. target_include_directories(test_relation_enforcement PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  578. endif()
  579. if(TARGET spdlog::spdlog)
  580. target_link_libraries(test_relation_enforcement PRIVATE spdlog::spdlog)
  581. else()
  582. target_link_libraries(test_relation_enforcement PRIVATE ${SPDLOG_LIBRARIES})
  583. target_include_directories(test_relation_enforcement PRIVATE ${SPDLOG_INCLUDE_DIRS})
  584. endif()
  585. find_package(Threads REQUIRED)
  586. target_link_libraries(test_relation_enforcement PRIVATE Threads::Threads)
  587. # v2.11.0 T12 — persistence_manager.cpp now linked in (WAL-first cascade
  588. # tests need a real PersistenceManager); it pulls in snapshot.cpp, which
  589. # uses LZ4 compression, same as test_migrate_v1_to_v2 above.
  590. if(PKG_CONFIG_FOUND)
  591. pkg_check_modules(RELENF_LZ4 QUIET liblz4)
  592. endif()
  593. if(RELENF_LZ4_FOUND)
  594. target_link_libraries(test_relation_enforcement PRIVATE ${RELENF_LZ4_LIBRARIES})
  595. target_include_directories(test_relation_enforcement PRIVATE ${RELENF_LZ4_INCLUDE_DIRS})
  596. else()
  597. target_link_libraries(test_relation_enforcement PRIVATE lz4)
  598. endif()
  599. add_test(NAME test_relation_enforcement COMMAND test_relation_enforcement)
  600. # v2.9.0 — secondary index key encoding. Pins the one property that matters:
  601. # an index key comparison must mean the same thing as the scan's comparison,
  602. # because two paths answering one question that disagree return wrong data
  603. # rather than an error.
  604. add_executable(test_secondary_index_keys
  605. test_secondary_index_keys.cpp
  606. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/storage/secondary_index.cpp
  607. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  608. )
  609. target_include_directories(test_secondary_index_keys PRIVATE
  610. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  611. ${yyjson_INCLUDE_DIRS}
  612. )
  613. target_link_libraries(test_secondary_index_keys PRIVATE ${yyjson_LIBRARIES})
  614. if(TARGET nlohmann_json::nlohmann_json)
  615. target_link_libraries(test_secondary_index_keys PRIVATE nlohmann_json::nlohmann_json)
  616. else()
  617. target_include_directories(test_secondary_index_keys PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  618. endif()
  619. add_test(NAME test_secondary_index_keys COMMAND test_secondary_index_keys)
  620. # v2.6.0 — project-scoped file storage. Covers cross-project id isolation and
  621. # the per-project deduplicated flag (global dedup would otherwise be a
  622. # cross-project existence oracle).
  623. add_executable(test_file_project_scope
  624. test_file_project_scope.cpp
  625. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/files/file_manager.cpp
  626. )
  627. target_include_directories(test_file_project_scope PRIVATE
  628. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  629. )
  630. find_package(OpenSSL REQUIRED)
  631. target_link_libraries(test_file_project_scope PRIVATE OpenSSL::SSL OpenSSL::Crypto)
  632. if(TARGET nlohmann_json::nlohmann_json)
  633. target_link_libraries(test_file_project_scope PRIVATE nlohmann_json::nlohmann_json)
  634. else()
  635. target_include_directories(test_file_project_scope PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  636. endif()
  637. if(TARGET spdlog::spdlog)
  638. target_link_libraries(test_file_project_scope PRIVATE spdlog::spdlog)
  639. else()
  640. target_link_libraries(test_file_project_scope PRIVATE ${SPDLOG_LIBRARIES})
  641. target_include_directories(test_file_project_scope PRIVATE ${SPDLOG_INCLUDE_DIRS})
  642. endif()
  643. find_package(Threads REQUIRED)
  644. target_link_libraries(test_file_project_scope PRIVATE Threads::Threads)
  645. add_test(NAME test_file_project_scope COMMAND test_file_project_scope)
  646. # v2.8.0 — access policy engine. The critical assertions are the safety ones:
  647. # security off allows everything (so upgrades are inert), enabling is refused
  648. # without an admin policy, the last admin cannot be removed, and audit mode
  649. # evaluates honestly but allows.
  650. add_executable(test_policy_manager
  651. test_policy_manager.cpp
  652. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/security/policy_manager.cpp
  653. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  654. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  655. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  656. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  657. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  658. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  659. )
  660. target_include_directories(test_policy_manager PRIVATE
  661. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  662. ${yyjson_INCLUDE_DIRS}
  663. )
  664. target_link_libraries(test_policy_manager PRIVATE ${yyjson_LIBRARIES})
  665. if(TARGET nlohmann_json::nlohmann_json)
  666. target_link_libraries(test_policy_manager PRIVATE nlohmann_json::nlohmann_json)
  667. else()
  668. target_include_directories(test_policy_manager PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  669. endif()
  670. if(TARGET spdlog::spdlog)
  671. target_link_libraries(test_policy_manager PRIVATE spdlog::spdlog)
  672. else()
  673. target_link_libraries(test_policy_manager PRIVATE ${SPDLOG_LIBRARIES})
  674. target_include_directories(test_policy_manager PRIVATE ${SPDLOG_INCLUDE_DIRS})
  675. endif()
  676. find_package(Threads REQUIRED)
  677. target_link_libraries(test_policy_manager PRIVATE Threads::Threads)
  678. add_test(NAME test_policy_manager COMMAND test_policy_manager)
  679. # v2.8.0 — document TTL across write paths. Pins that update() preserves an
  680. # existing expiry: it used to wipe it, so any TTL'd document that was ever
  681. # updated became permanent.
  682. add_executable(test_document_ttl
  683. test_document_ttl.cpp
  684. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  685. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  686. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  687. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  688. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  689. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  690. )
  691. target_include_directories(test_document_ttl PRIVATE
  692. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  693. ${yyjson_INCLUDE_DIRS}
  694. )
  695. target_link_libraries(test_document_ttl PRIVATE ${yyjson_LIBRARIES})
  696. if(TARGET nlohmann_json::nlohmann_json)
  697. target_link_libraries(test_document_ttl PRIVATE nlohmann_json::nlohmann_json)
  698. else()
  699. target_include_directories(test_document_ttl PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  700. endif()
  701. if(TARGET spdlog::spdlog)
  702. target_link_libraries(test_document_ttl PRIVATE spdlog::spdlog)
  703. else()
  704. target_link_libraries(test_document_ttl PRIVATE ${SPDLOG_LIBRARIES})
  705. target_include_directories(test_document_ttl PRIVATE ${SPDLOG_INCLUDE_DIRS})
  706. endif()
  707. find_package(Threads REQUIRED)
  708. target_link_libraries(test_document_ttl PRIVATE Threads::Threads)
  709. add_test(NAME test_document_ttl COMMAND test_document_ttl)
  710. # v2.8.0 — ViewManager persistence. test_views only exercises applyProjection()
  711. # in-process, so nothing covered loadFromStore's paging: a bare Query stops at
  712. # 100 views and silently loses the rest.
  713. add_executable(test_view_manager_paging
  714. test_view_manager_paging.cpp
  715. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/views/view_manager.cpp
  716. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/views/projection.cpp
  717. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  718. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  719. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  720. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  721. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  722. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  723. )
  724. target_include_directories(test_view_manager_paging PRIVATE
  725. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  726. ${yyjson_INCLUDE_DIRS}
  727. )
  728. target_link_libraries(test_view_manager_paging PRIVATE ${yyjson_LIBRARIES})
  729. if(TARGET nlohmann_json::nlohmann_json)
  730. target_link_libraries(test_view_manager_paging PRIVATE nlohmann_json::nlohmann_json)
  731. else()
  732. target_include_directories(test_view_manager_paging PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  733. endif()
  734. if(TARGET spdlog::spdlog)
  735. target_link_libraries(test_view_manager_paging PRIVATE spdlog::spdlog)
  736. else()
  737. target_link_libraries(test_view_manager_paging PRIVATE ${SPDLOG_LIBRARIES})
  738. target_include_directories(test_view_manager_paging PRIVATE ${SPDLOG_INCLUDE_DIRS})
  739. endif()
  740. find_package(Threads REQUIRED)
  741. target_link_libraries(test_view_manager_paging PRIVATE Threads::Threads)
  742. add_test(NAME test_view_manager_paging COMMAND test_view_manager_paging)
  743. # v2.11.0 T1 — RelationManager: the declaration registry for referential
  744. # integrity relations. Same paging trap as ViewManager/PolicyManager/
  745. # CollectionConfigManager — loadFromStore() must page explicitly.
  746. add_executable(test_relation_manager
  747. test_relation_manager.cpp
  748. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/relations/relation_manager.cpp
  749. # v2.11.0 close-out — the create_relation migration op is tested here rather
  750. # than in a binary of its own: MigrationRunner needs exactly the MemoryStore
  751. # + ViewManager + RelationManager trio this target already links.
  752. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/migrations/migration_runner.cpp
  753. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/views/view_manager.cpp
  754. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/views/projection.cpp
  755. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/memory_store.cpp
  756. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/config/collection_config_manager.cpp
  757. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  758. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  759. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  760. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  761. )
  762. target_include_directories(test_relation_manager PRIVATE
  763. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  764. ${yyjson_INCLUDE_DIRS}
  765. )
  766. target_link_libraries(test_relation_manager PRIVATE ${yyjson_LIBRARIES})
  767. if(TARGET nlohmann_json::nlohmann_json)
  768. target_link_libraries(test_relation_manager PRIVATE nlohmann_json::nlohmann_json)
  769. else()
  770. target_include_directories(test_relation_manager PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  771. endif()
  772. if(TARGET spdlog::spdlog)
  773. target_link_libraries(test_relation_manager PRIVATE spdlog::spdlog)
  774. else()
  775. target_link_libraries(test_relation_manager PRIVATE ${SPDLOG_LIBRARIES})
  776. target_include_directories(test_relation_manager PRIVATE ${SPDLOG_INCLUDE_DIRS})
  777. endif()
  778. target_link_libraries(test_relation_manager PRIVATE Threads::Threads)
  779. # migration_runner.cpp uses RAND_bytes for the generate_secret op.
  780. target_link_libraries(test_relation_manager PRIVATE OpenSSL::Crypto)
  781. add_test(NAME test_relation_manager COMMAND test_relation_manager)
  782. # v2.16.0 - collection schema validator + suggester.
  783. add_executable(test_json_schema
  784. test_json_schema.cpp
  785. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/schema/json_schema.cpp
  786. )
  787. find_path(TEST_RE2_INCLUDE_DIR re2/re2.h REQUIRED)
  788. find_library(TEST_RE2_LIBRARY re2 REQUIRED)
  789. target_include_directories(test_json_schema PRIVATE
  790. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src
  791. ${TEST_RE2_INCLUDE_DIR}
  792. )
  793. target_link_libraries(test_json_schema PRIVATE ${TEST_RE2_LIBRARY})
  794. if(TARGET nlohmann_json::nlohmann_json)
  795. target_link_libraries(test_json_schema PRIVATE nlohmann_json::nlohmann_json)
  796. else()
  797. target_include_directories(test_json_schema PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  798. endif()
  799. add_test(NAME test_json_schema COMMAND test_json_schema)
  800. # v2.17.1 - the read-only history scan holds no append lock (encryption-verify
  801. # on a live server stalled every history-recording write with rewrite()).
  802. add_executable(test_history_audit_scan
  803. test_history_audit_scan.cpp
  804. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
  805. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
  806. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
  807. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
  808. )
  809. target_include_directories(test_history_audit_scan PRIVATE
  810. ${CMAKE_CURRENT_SOURCE_DIR}/../service/src ${yyjson_INCLUDE_DIRS})
  811. if(TARGET nlohmann_json::nlohmann_json)
  812. target_link_libraries(test_history_audit_scan PRIVATE nlohmann_json::nlohmann_json)
  813. else()
  814. target_include_directories(test_history_audit_scan PRIVATE ${NLOHMANN_JSON_INCLUDE_DIRS})
  815. endif()
  816. if(TARGET spdlog::spdlog)
  817. target_link_libraries(test_history_audit_scan PRIVATE spdlog::spdlog)
  818. else()
  819. target_link_libraries(test_history_audit_scan PRIVATE ${SPDLOG_LIBRARIES})
  820. target_include_directories(test_history_audit_scan PRIVATE ${SPDLOG_INCLUDE_DIRS})
  821. endif()
  822. target_link_libraries(test_history_audit_scan PRIVATE Threads::Threads ${yyjson_LIBRARIES})
  823. target_compile_options(test_history_audit_scan PRIVATE -UNDEBUG)
  824. add_test(NAME test_history_audit_scan COMMAND test_history_audit_scan)
  825. # v2.20.0 - filter_eval.hpp (REGEX filters) uses RE2, and memory_store.cpp,
  826. # document_store_lmdb.cpp and relation_cascade.cpp include it, so every test
  827. # that compiles one of them needs RE2. Linked to every target here rather than
  828. # tracking which ones do.
  829. get_property(_sbdb_test_targets DIRECTORY PROPERTY BUILDSYSTEM_TARGETS)
  830. foreach(_t IN LISTS _sbdb_test_targets)
  831. get_target_property(_type ${_t} TYPE)
  832. if(_type STREQUAL "EXECUTABLE")
  833. target_include_directories(${_t} PRIVATE ${TEST_RE2_INCLUDE_DIR})
  834. target_link_libraries(${_t} PRIVATE ${TEST_RE2_LIBRARY})
  835. endif()
  836. endforeach()