# tests/ — one ctest target per test-*.{cpp,mm}. GLOB CONFIGURE_DEPENDS makes the
# filesystem the registry: drop a test-foo.cpp here and the next build runs it —
# zero edits. add_mlx_test() handles the .cpp/.mm (ARC) distinction + registration.
file(GLOB _tests CONFIGURE_DEPENDS
    ${CMAKE_CURRENT_SOURCE_DIR}/test-*.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/test-*.mm)
foreach(_t ${_tests})
    add_mlx_test(${_t})
endforeach()

# PLAN12 14.07 — leading-BOS scenarios live in a directory hierarchy (family/version/behavior),
# not flat test-*.cpp files, so they need path-derived target names — own subdir, own registration.
add_subdirectory(chat-format/bos)

# PLAN12 11.06 — the storage-quant tests exercise the fp8 codec, whose registrar is a
# file-scope static in the LIBRARY (src/infer/kv-storage-codec-fp8-encode.cpp). A test exe
# links mlx-magic-lib WITHOUT -force_load (see cmake/ForceLoad.cmake + test-arch-registry.cpp),
# so that TU — referenced only by its static initializer — is dead-stripped and "fp8" never
# registers. Force-load ONLY these three targets (not add_mlx_test globally, to keep every
# other test's minimal-link scope intact) so the codec is present at runtime. Same pattern the
# registrar-dependent bench proofs use.
# test-vision-encoder uses the static VisionEncoderRegistrar in the library.
foreach(_reg test-vision-encoder)
    if(TARGET ${_reg})
        mlxm_force_load(${_reg})
    endif()
endforeach()

foreach(_reg test-kv-storage-fp8 test-kv-storage-serde test-kv-storage-tier-chain)
    if(TARGET ${_reg})
        mlxm_force_load(${_reg})
    endif()
endforeach()

# PLAN12 14.05C — the dual-path fixture drives the REAL registered LlamaForCausalLM
# forward, whose ArchRegistrar is a file-scope static in the library and is therefore
# dead-stripped without -force_load (identical reason to the blocks above). Without
# this the tests throw "unknown arch 'LlamaForCausalLM'" instead of comparing paths.
foreach(_reg test-weight-stream-dual-path test-weight-stream-dual-determinism
             test-weight-stream-shard-failures test-weight-stream-transport
             test-weight-stream-real-model test-weight-stream-oversized
             test-weight-stream-metrics test-weight-stream-resident-embed
             test-weight-stream-compressed-infer test-weight-stream-codec-isolation)
    if(TARGET ${_reg})
        mlxm_force_load(${_reg})
    endif()
endforeach()

# PLAN12 14.04 — test-arch-pack-comments validates the REAL shipped packs (not just fixtures),
# so it needs their source path. A shipped pack that fails to parse silently sent every tensor
# into the "other" split group; this test is the guard against that returning.
if(TARGET test-arch-pack-comments)
    target_compile_definitions(test-arch-pack-comments PRIVATE
        MLXM_SHIPPED_PACKS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../src/infer/weight-stream/arch-compat/packs")
endif()

# PLAN12 15.04 — test-native-ext-probe exercises the native-extension ABI/symbol probe against
# REAL loadable images. fixtures/*.cpp build as MODULE libs (dlopen-only, never linked); their
# on-disk paths are injected as compile definitions so the test needs no path guessing at runtime.
if(TARGET test-native-ext-probe)
    add_library(ext-probe-good  MODULE fixtures/ext-probe-good.cpp)    # healthy: ABI v1 + both symbols
    add_library(ext-probe-stale MODULE fixtures/ext-probe-stale.cpp)   # skewed: ABI v999, missing a symbol
    target_compile_definitions(test-native-ext-probe PRIVATE
        EXT_PROBE_GOOD_LIB="$<TARGET_FILE:ext-probe-good>"
        EXT_PROBE_STALE_LIB="$<TARGET_FILE:ext-probe-stale>")
    add_dependencies(test-native-ext-probe ext-probe-good ext-probe-stale)  # fixtures must exist before ctest runs
endif()

# PLAN12 11.10 — per-arch-pack tests in a MIRROR of src/arch/ (path-derived target names).
add_subdirectory(arch)
