From d8a7dc252f0aec833da23caf8ae7c127402ce73e Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Fri, 26 Jun 2026 13:51:05 +0200 Subject: [PATCH] test(smoke): parse escaped-JSON tool results (index-cli/index-status) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The multi-platform smoke run flagged index-cli + index-status as empty/not-ready even though the binary indexed fine (nodes>0, status ready) — the MCP tool result wraps its payload as a JSON STRING with escaped quotes (\"nodes\":N), but the checks grepped for unescaped "nodes":N. Strip backslashes/quotes before matching and tolerate the nodes= log form. (Binary was healthy; this was a script-parsing gap the wide-matrix smoke surfaced.) Signed-off-by: Martin Vogel --- scripts/smoke-invariants.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/smoke-invariants.sh b/scripts/smoke-invariants.sh index 1d5717d0d..fc35e0d2f 100755 --- a/scripts/smoke-invariants.sh +++ b/scripts/smoke-invariants.sh @@ -298,13 +298,14 @@ inv_index_cli() { fail "index-cli" "index_repository crashed (signal $((CLI_RC-128)))" return fi - # The text payload carries {"...","nodes":N,...}. Pull the max integer that - # follows a "nodes": key. + # The tool result wraps its payload as a JSON STRING, so the node count appears + # escaped (\"nodes\":N) and the logs use nodes=N. Strip backslashes + quotes and + # match either "nodes": / nodes= form; any nodes>0 satisfies "graph non-empty". local nodes nodes="$(printf '%s' "$CLI_OUT" | "$PY" -c ' import sys,re -t=sys.stdin.read() -m=re.findall(r"\"nodes\"\s*:\s*(\d+)", t) +t=sys.stdin.read().replace("\\","").replace("\"","") +m=re.findall(r"nodes\s*[:=]\s*(\d+)", t) print(max((int(x) for x in m), default=0))' 2>/dev/null)" if [ "${nodes:-0}" -gt 0 ] 2>/dev/null; then pass "index-cli (nodes=$nodes, rc=$CLI_RC)" @@ -320,8 +321,12 @@ inv_index_status_cli() { fail "index-status" "crashed (signal $((CLI_RC-128)))" return fi - if printf '%s' "$CLI_OUT" | grep -q '"status":"ready"' && \ - printf '%s' "$CLI_OUT" | grep -qE '"nodes":[1-9]'; then + # Result payload is a JSON string with escaped quotes (\"status\":\"ready\"); strip + # backslashes so the unescaped greps match. + local st_clean + st_clean="$(printf '%s' "$CLI_OUT" | tr -d '\\')" + if printf '%s' "$st_clean" | grep -q '"status":"ready"' && \ + printf '%s' "$st_clean" | grep -qE '"nodes":[1-9]'; then pass "index-status (ready, non-empty)" else fail "index-status" "not ready/non-empty; out=[$(printf '%s' "$CLI_OUT" | tr '\n' ' ' | cut -c1-200)]"