#!/usr/bin/env bats load test_helper # sandbox/agent runs a fake agent through a fake srt, which sets NO_PROXY the # way the real one does, saves the settings it was given and runs the command. setup() { common_setup SANDBOX="$HOME/.local/share/coredesktop/sandbox" mkdir -p "$SANDBOX/bin" "$SANDBOX/config" "$BATS_TEST_TMPDIR/project" cp "$REPO/sandbox/config/base.json" "$SANDBOX/config/" ln -s "$REPO/sandbox/agent" "$SANDBOX/bin/fakeagent" export XDG_RUNTIME_DIR="$BATS_TEST_TMPDIR/run" mkdir -p "$XDG_RUNTIME_DIR" export SETTINGS_COPY="$BATS_TEST_TMPDIR/settings.json" stub srt 'cp "$2" "$SETTINGS_COPY" while [ "$1" != "--" ]; do shift; done shift export NO_PROXY=localhost,127.0.0.1,::1,10.0.0.0/8,192.168.0.0/16 no_proxy=localhost,192.168.0.0/16 exec "$@"' stub fakeagent 'echo "NO_PROXY=$NO_PROXY no_proxy=$no_proxy args=$*"' cd "$BATS_TEST_TMPDIR/project" } @test "an agent connects directly only to loopback, so allowed LAN addresses go through the proxy" { run "$SANDBOX/bin/fakeagent" one "two words" [ "$status" -eq 0 ] [ "$output" = "NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 args=one two words" ] } @test "a server allowed in your own base.json is in the agent's settings" { mkdir -p "$HOME/.config/coredesktop/sandbox" echo '{"network": {"allowedDomains": ["llm.local:11434"]}}' > "$HOME/.config/coredesktop/sandbox/base.json" run "$SANDBOX/bin/fakeagent" [ "$status" -eq 0 ] jq -e '.network.allowedDomains | index("llm.local:11434") and index("github.com")' "$SETTINGS_COPY" }