From 4adac43f6f5900baf442a7d5551d30457b300c72 Mon Sep 17 00:00:00 2001 From: Pascal Date: Thu, 16 Apr 2026 19:46:21 +0200 Subject: [PATCH] server: tests: fetch random media marker via /apply-template (#21962) (#21980) * server: tests: fetch random media marker via /apply-template (#21962 fix) * server: allow pinning media marker via LLAMA_MEDIA_MARKER env var get_media_marker() checks LLAMA_MEDIA_MARKER at first call and uses it as-is if set, falling back to the random marker otherwise. Tests no longer need to fetch the marker dynamically via /apply-template: the fixture sets LLAMA_MEDIA_MARKER=<__media__> so the hardcoded prompts work as before. Address review feedback from ngxson * server: make get_media_marker() thread-safe via magic statics Use a C++11 static local with a lambda initializer instead of a global static with an empty-check. The runtime guarantees initialization exactly once without explicit locking. Address review feedback from ggerganov * nits * nits --- tools/server/server-common.cpp | 14 +++++++++----- tools/server/tests/unit/test_vision_api.py | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/server/server-common.cpp b/tools/server/server-common.cpp index fd417393f..f66b1f255 100644 --- a/tools/server/server-common.cpp +++ b/tools/server/server-common.cpp @@ -84,12 +84,16 @@ std::string gen_tool_call_id() { return random_string(); } -static std::string media_marker = ""; const char * get_media_marker() { - if (media_marker.empty()) { - media_marker = "<__media_" + random_string() + "__>"; - } - return media_marker.c_str(); + static const std::string marker = []() { + // allow user to pin a reproducible marker via env var + const char * env = getenv("LLAMA_MEDIA_MARKER"); + if (env && env[0] != '\0') { + return std::string(env); + } + return std::string("<__media_") + random_string() + "__>"; + }(); + return marker.c_str(); } // diff --git a/tools/server/tests/unit/test_vision_api.py b/tools/server/tests/unit/test_vision_api.py index 9408116d1..fb77084c8 100644 --- a/tools/server/tests/unit/test_vision_api.py +++ b/tools/server/tests/unit/test_vision_api.py @@ -37,6 +37,7 @@ JSON_PROMPT_STRING_KEY = "prompt_string" @pytest.fixture(autouse=True) def create_server(): global server + os.environ['LLAMA_MEDIA_MARKER'] = '<__media__>' server = ServerPreset.tinygemma3() def test_models_supports_multimodal_capability():