add_executable(vdsim_realtime realtime_server.cpp world_scenario.cpp scene_loader.cpp)
target_include_directories(vdsim_realtime PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(vdsim_realtime PRIVATE vdsim::core)
target_compile_definitions(vdsim_realtime PRIVATE
    VDSIM_SOURCE_DIR="${CMAKE_SOURCE_DIR}")
if(WIN32)
    target_link_libraries(vdsim_realtime PRIVATE ws2_32)   # Winsock2
endif()
# Flat output dir for every config so the GUI finds build/bin/vdsim_realtime[.exe]
# (VS multi-config would otherwise nest it under build/bin/Release).
set_target_properties(vdsim_realtime PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY                ${CMAKE_BINARY_DIR}/bin
    RUNTIME_OUTPUT_DIRECTORY_DEBUG          ${CMAKE_BINARY_DIR}/bin
    RUNTIME_OUTPUT_DIRECTORY_RELEASE        ${CMAKE_BINARY_DIR}/bin
    RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/bin)

find_package(Python3 COMPONENTS Interpreter QUIET)
if(Python3_FOUND)
    target_compile_definitions(vdsim_realtime PRIVATE
        VDSIM_PYTHON="${Python3_EXECUTABLE}")
    add_test(NAME cosim_multi_vehicle
        COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/cosim/test_multi_vehicle.py)
    set_tests_properties(cosim_multi_vehicle PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 30
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_SOURCE_DIR}/python")
    # Work order 36: --monitor starts the browser monitor's page server with the
    # simulator and takes it down on every exit path (end, SIGINT, SIGTERM, kill).
    add_test(NAME realtime_monitor
        COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tests/scripts/test_realtime_monitor.py)
    set_tests_properties(realtime_monitor PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 180
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_SOURCE_DIR}/python")
    add_test(NAME l3_scenario_susp_paths
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_l3_scenario_paths.py)
    set_tests_properties(l3_scenario_susp_paths PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
    add_test(NAME runconfig_roundtrip
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_runconfig_roundtrip.py)
    set_tests_properties(runconfig_roundtrip PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/cosim:${CMAKE_SOURCE_DIR}/gui")
    add_test(NAME catalog_resolver
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_catalog_resolver.py)
    set_tests_properties(catalog_resolver PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME scene_materialize
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_scene_materialize.py)
    set_tests_properties(scene_materialize PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME catalog_api
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_catalog_api.py)
    set_tests_properties(catalog_api PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python:${CMAKE_SOURCE_DIR}/cosim:${CMAKE_SOURCE_DIR}/gui")
    add_test(NAME import_part_pack
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_import_part_pack.py)
    set_tests_properties(import_part_pack PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME level_names
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_level_names.py)
    set_tests_properties(level_names PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME module_workshop
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_module_workshop.py)
    set_tests_properties(module_workshop PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME assembly_api
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_assembly_api.py)
    set_tests_properties(assembly_api PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME part_store
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_part_store.py)
    set_tests_properties(part_store PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME blueprint_roundtrip
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_blueprint_roundtrip.py)
    set_tests_properties(blueprint_roundtrip PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME multi_vehicle_compare
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_compare.py)
    set_tests_properties(multi_vehicle_compare PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME experiment_api
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_experiment_api.py)
    set_tests_properties(experiment_api PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    # The campaign runner spawns one child process per run, so it needs the
    # compiled core on the path it hands those children.
    add_test(NAME campaign_runner
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_campaign_runner.py)
    set_tests_properties(campaign_runner PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 600
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME cmdl1_binding
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_cmdl1_binding.py)
    set_tests_properties(cmdl1_binding PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME vla_plant
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_vla_plant.py)
    set_tests_properties(vla_plant PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME plant_actuator
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_plant_actuator.py)
    set_tests_properties(plant_actuator PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME cascade_sensor
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_cascade_sensor.py)
    set_tests_properties(cascade_sensor PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    # Closed-loop evaluation modes (work order 31): sync and virtual_async
    # bit-identity, seeded latency and overrun schedules.
    add_test(NAME closedloop_eval
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_closedloop_eval.py)
    set_tests_properties(closedloop_eval PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 300
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    # Per-element aero, Python side (work order 42): binding, refusals,
    # drag-height None/0.0, opt-in trace channels.
    add_test(NAME aero_elements
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_aero_elements.py)
    set_tests_properties(aero_elements PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 300
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    # Closed-loop evaluation extensions (work order 34): early stop in the
    # virtual-clock modes, realized steer observation and trace channel.
    add_test(NAME closedloop_ext
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_closedloop_ext.py)
    set_tests_properties(closedloop_ext PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 300
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    # Live 3D monitor (work order 35): OSM placement, HTTP/WebSocket page
    # server, publisher attach/embed and the Windows shortcut. Own free ports.
    add_test(NAME livemonitor
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_livemonitor.py)
    set_tests_properties(livemonitor PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 120
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    # Live monitor in code runs (work order 37): monitor= off adds nothing,
    # world / fleet protocol, VDSimPlant and VDSimVecEnv attach, failures that
    # must not stop the run. Own free ports.
    add_test(NAME livemonitor_world
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_livemonitor_world.py)
    set_tests_properties(livemonitor_world PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 180
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    # Closed-loop mode C (wallclock): thread shutdown, argument checks and the
    # watchdog. Wall-clock pacing, so it never shares the host with other tests.
    add_test(NAME closedloop_wallclock
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_closedloop_wallclock.py core)
    set_tests_properties(closedloop_wallclock PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 300
        RUN_SERIAL TRUE
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    # Mode C timing verdicts (S6 real-time factor band, S7 tick floor). Their
    # outcome depends on host load, so label `timing` keeps them out of the
    # `validation` preset and the CI build steps; evidence is a local low-load
    # run (`ctest -L timing`). Thresholds are not relaxed here.
    add_test(NAME closedloop_wallclock_timing
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_closedloop_wallclock.py timing)
    set_tests_properties(closedloop_wallclock_timing PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 300
        RUN_SERIAL TRUE
        LABELS timing
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    # GUI v3 is a deferred (node-stack) component. Its tests are excluded from
    # the canonical `validation` preset as a component, not one target at a
    # time, and are listed by name on the `excluded:` lines of
    # docs/VALIDATION.md (07_p0_demo.md 6.4(2)).
    if(VDSIM_BUILD_GUI_V3_TESTS)
        add_test(NAME gui_v3_api_smoke
            COMMAND ${Python3_EXECUTABLE}
                ${CMAKE_SOURCE_DIR}/tests/scripts/test_gui_v3_api_smoke.py)
        set_tests_properties(gui_v3_api_smoke PROPERTIES
            WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
            ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python:${CMAKE_SOURCE_DIR}/cosim:${CMAKE_SOURCE_DIR}/gui")
            add_test(NAME gui_v3_e2e
                COMMAND ${Python3_EXECUTABLE}
                    ${CMAKE_SOURCE_DIR}/tests/scripts/test_gui_v3_e2e.py)
            set_tests_properties(gui_v3_e2e PROPERTIES
                WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
                TIMEOUT 180
                ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python:${CMAKE_SOURCE_DIR}/cosim:${CMAKE_SOURCE_DIR}/gui")
    endif()
    add_test(NAME vla_plant_demo
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/examples/vla_plant_demo.py)
    set_tests_properties(vla_plant_demo PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    # vdsim_rl: torch-free checks only (gymnasium API, termination codes, obs
    # buffer, vehicle preset input).  A missing gymnasium fails the test; the
    # SB3 PPO smoke (tests/rl/smoke_sb3_ppo.py) stays outside ctest.
    add_test(NAME rl_env
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/rl/test_rl_env.py)
    set_tests_properties(rl_env PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 300
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};VDSIM_BUILD_PY=${CMAKE_BINARY_DIR}/python;PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    # Work order 33: actuator and road declared in EnvConfig reach the
    # VecSession (vdsim_rl._Core only -- no gymnasium needed).
    add_test(NAME rl_connection
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/rl/test_rl_connection.py)
    set_tests_properties(rl_connection PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 300
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};VDSIM_BUILD_PY=${CMAKE_BINARY_DIR}/python;PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME control_ladder
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/examples/control_ladder_demo.py)
    set_tests_properties(control_ladder PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME trace_roundtrip
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_trace_roundtrip.py)
    set_tests_properties(trace_roundtrip PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_SOURCE_DIR}/python")
    # The trace tests deliberately do NOT put build/python on the path: reading
    # and rendering a trace must work where the compiled core cannot be built.
    add_test(NAME trace_render
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_trace_render.py)
    set_tests_properties(trace_render PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 180
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_SOURCE_DIR}/python")
    add_test(NAME trace_render_multi
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_trace_multi_render.py)
    set_tests_properties(trace_render_multi PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 300
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_SOURCE_DIR}/python")
    add_test(NAME render_presets
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_render_presets.py)
    set_tests_properties(render_presets PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 300
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_SOURCE_DIR}/python")
    # The 3D replay reads the container only, so like the other trace tests it
    # runs without build/python on the path.
    add_test(NAME render3d
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_render3d.py)
    set_tests_properties(render3d PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 600
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_SOURCE_DIR}/python")
    # trace_schema_0_3 needs the compiled core on the path: it measures what the
    # dynamics actually does with the road normal and fails if the declared
    # contact_scope drifts away from it.
    add_test(NAME trace_schema_0_3
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_trace_0_3.py)
    set_tests_properties(trace_schema_0_3 PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 300
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    # trace_schema_0_5 measures the compiled core's own channel declarations:
    # L1/L2 runs must hold all-zero rp_rate/wheel_travel under not_modeled@<level>.
    add_test(NAME trace_schema_0_5
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_trace_0_5.py)
    set_tests_properties(trace_schema_0_5 PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 300
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    add_test(NAME trace_horizons
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_trace_horizons.py)
    set_tests_properties(trace_horizons PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 300
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_SOURCE_DIR}/python")
    # AC M1 is a standalone Python importer: synthetic data only, no core/KN5.
    add_test(NAME ac_fast_lane_importer
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_ac_fast_lane_importer.py)
    set_tests_properties(ac_fast_lane_importer PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 120
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_SOURCE_DIR}/python")
    # Text TX templates end-to-end: json + nmea_gga must reach a UDP socket.
    add_test(NAME comms_tx_templates
        COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/tests/scripts/test_comms_tx_templates.py)
    set_tests_properties(comms_tx_templates PROPERTIES
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        TIMEOUT 60
        ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_BINARY_DIR}/python:${CMAKE_SOURCE_DIR}/python")
    # Registered only when its driver script is present in the tree: the CarMaker
    # ROS interface compatibility check ships with the optional cmrosif bridge.
    if(EXISTS ${CMAKE_SOURCE_DIR}/tests/scripts/test_cmrosif_compat.py)
        add_test(NAME cmrosif_compat
            COMMAND ${Python3_EXECUTABLE}
                ${CMAKE_SOURCE_DIR}/tests/scripts/test_cmrosif_compat.py)
        set_tests_properties(cmrosif_compat PROPERTIES
            WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
            ENVIRONMENT "VDSIM_BUILD_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_SOURCE_DIR}/cosim")
    endif()
endif()
