#!/usr/bin/env bash # scripts/test-reasoning.sh # # Validates that reasoning parameters are correctly serialized for each # provider across all supported effort levels. # # Usage: ./scripts/test-reasoning.sh set -uo pipefail # ─── colors ─────────────────────────────────────────────────────────────────── BOLD='\033[1m' RESET='\033[0m' GREEN='\033[32m' RED='\033[31m' YELLOW='\033[33m' CYAN='\033[36m' DIM='\033[2m' # ─── state ──────────────────────────────────────────────────────────────────── PASS=0 FAIL=0 SKIP=0 BINARY="target/debug/forge" WORK_DIR="$(mktemp -d)" SEQ=0 RESULT_FILES=() CURRENT_RF="" cleanup() { rm -rf "$WORK_DIR"; } trap cleanup EXIT # ─── output helpers ─────────────────────────────────────────────────────────── # Each helper writes a tagged line to stdout. Within a background subshell, # stdout is redirected to a per-job result file; the main process reads it back # after wait to tally counts and emit colour output in the original order. log_header() { printf "HEADER\t%s\n" "$1"; } log_pass() { printf "PASS\t%s\n" "$1"; } log_fail() { printf "FAIL\t%s\n" "$1"; } log_skip() { printf "SKIP\t%s\n" "$1"; } # ─── json helpers ───────────────────────────────────────────────────────────── # json_get # Prints the JSON value at the given path, or "null" if absent/null. # Uses raw_decode to parse only the first JSON object in the file, which # correctly handles both single-document JSON and NDJSON (even when multiple # objects appear on the same line without a newline separator). json_get() { python3 - "$1" "$2" <<'PY' import json, sys with open(sys.argv[1]) as f: raw = f.read().strip() # raw_decode stops after the first complete JSON value regardless of trailing # content (extra objects, newlines, null bytes, etc.). decoder = json.JSONDecoder() d, _ = decoder.raw_decode(raw) keys = sys.argv[2].split('.') v = d for k in keys: v = v.get(k) if isinstance(v, dict) else None if v is None: break print(json.dumps(v)) PY } # assert_field