From d974b91144d1e6e11eaed9c6bf0a153e61eb2600 Mon Sep 17 00:00:00 2001 From: David Young Date: Mon, 16 Nov 2026 16:13:32 -0700 Subject: [PATCH] configure: treat an empty settings file like a missing one edit_json created a settings file from its default only when it was missing. jq reads no JSON from an empty file and writes nothing back, so configure ai-servers said a server was added while the sandbox still blocked it. Co-Authored-By: Claude Opus 5.5 --- configure.d/lib/json.sh | 5 +++-- tests/network.bats | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/configure.d/lib/json.sh b/configure.d/lib/json.sh index 6a15c10..7fa449d 100644 --- a/configure.d/lib/json.sh +++ b/configure.d/lib/json.sh @@ -2,13 +2,14 @@ # # Purpose : Edit JSON settings files for configure.d items. Source this file. -# Edit a JSON file in place with jq, creating it from $2 if it's missing. +# Edit a JSON file in place with jq, creating it from $2 if it's missing or +# empty (jq reads no JSON from an empty file, and would write nothing back). # Leaves the file alone if it isn't valid JSON or jq fails. edit_json() { local file="$1" empty="$2" tmp shift 2 mkdir -p "$(dirname "$file")" || return 1 - [ -f "$file" ] || echo "$empty" > "$file" + [ -s "$file" ] || echo "$empty" > "$file" tmp="$(mktemp "$file.XXXXXX")" || return 1 if jq "$@" "$file" > "$tmp"; then mv -f "$tmp" "$file" diff --git a/tests/network.bats b/tests/network.bats index 4c1f926..ff493d3 100644 --- a/tests/network.bats +++ b/tests/network.bats @@ -96,6 +96,14 @@ setup_ai() { [ "$(cat "$SANDBOX_CONF")" = "not json" ] } +@test "sandbox_allow adds a server to an empty file" { + setup_ai + mkdir -p "$(dirname "$SANDBOX_CONF")" + : > "$SANDBOX_CONF" + sandbox_allow llm.local:11434 + [ "$(jq -c '.network.allowedDomains' "$SANDBOX_CONF")" = '["llm.local:11434"]' ] +} + @test "claude_allow starts from the default domains when Claude has no list, and keeps their order" { setup_ai mkdir -p "$HOME/.claude"