#!/usr/bin/env bash # SPDX-License-Identifier: AGPL-3.0-or-later # Copyright (C) 2026 David (Corey) Herrera # # serve_response_format_smoke.sh — end-to-end `response_format` gate against a # LIVE serve, on the path the fleet actually runs. # # WHY THIS EXISTS # response_format shipped once looking correct: the unit tests passed, the # grammar was provably right in isolation, and a K80 measurement showed valid # JSON. But that measurement was taken on a CPU build, i.e. the single-user # decode path — while the fleet runs the CUDA BATCHED path, where the # constraint did not engage and the serve still reported "applied". A test # that cannot tell those two paths apart is a test that would have passed # through the whole defect. # # So this script asserts against a real serve and PARSES the body: # 1. when the serve says response_format_status == "applied", the content # MUST parse as JSON — "applied" has to mean applied; # 2. when the content does NOT parse, the status must NOT be "applied" # (a truthful "not_enforced" is a pass — a false "applied" is the bug); # 3. the same on the streaming path, reassembled from the SSE deltas. # It also prints whether the target model is running batched, so a green run # on the wrong path can never again be mistaken for a green run on the fleet's. # # USAGE # tests/serve_response_format_smoke.sh [BASE_URL] [MODEL] # BASE_URL default http://127.0.0.1:8201 # MODEL default nex-n2-mini # # Run it on the serve host (or through a tunnel) against a running serve, and # confirm the serve log shows the model on a batched slot. Exit 0 = pass. # # @status Covers json_object on both the streaming and non-streaming paths. # @issues Needs a live serve + a loaded model; not part of `make test`. # @todo None set -uo pipefail BASE="${1:-http://127.0.0.1:8201}" MODEL="${2:-nex-n2-mini}" PROMPT='Give me a person record: name, age, city.' FAILED=0 say() { printf '%s\n' "$*"; } pass() { printf ' [PASS] %s\n' "$*"; } fail() { printf ' [FAIL] %s\n' "$*"; FAILED=1; } say "=== response_format smoke: $MODEL @ $BASE ===" # --------------------------------------------------------------------------- # Non-streaming # --------------------------------------------------------------------------- body=$(cat < the constraint did not engage on this path") rc = 1 elif status == "applied": print(" [PASS] applied, and the content parses as a JSON object") # (2) not enforced is acceptable ONLY if it says so. elif not is_json and status != "applied": print(" [PASS] content is not JSON, and the serve reported %r (truthful)" % status) elif is_json: print(" [PASS] content parses as JSON (status %r)" % status) sys.exit(rc) ' rc=$?; [ $rc -eq 1 ] && FAILED=1 [ $rc -eq 2 ] && say " (non-streaming skipped)" # --------------------------------------------------------------------------- # Streaming — the same guarantee, reassembled from the deltas # --------------------------------------------------------------------------- say "--- streaming ---" sbody=$(cat <