Files
connector-popos/smoketest/scenarios/50-sandbox.sh
T
davidandClaude Opus 5.5 c84e6d3aa0 Start opencode's sandbox on Pop!_OS; lint and the smoketest now pass
The first run of lint and the full Docker smoketest since the CoreDesktop
ports found:

- opencode's sandbox didn't start. Its profile didn't allow all Unix sockets,
  so srt added its socket filter, which needs a user namespace inside
  bubblewrap, and Pop!_OS' AppArmor (bwrap-userns-restrict) denies that.
  opencode now allows them and hides their paths (/run/user, /run/dbus,
  Docker, Podman, Tailscale, X11, tmux, ssh-agent), as Hermes and Cline
  Desktop do. 80-security shows it still can't reach the session D-Bus.
- 80-security's agent list was named AGENTS, and 30-agents.sh, loaded later,
  replaced it with its own, so every sandbox check ran a command that
  doesn't exist. It's FAKE_AGENTS now.
- 50-sandbox's "can't" checks would pass if the sandbox never started; a
  check that it starts now comes first.
- shellcheck read a jq variable named done as bash's keyword (SC1010).

TEST.md says to install shellcheck and Docker, which the connector doesn't.
PLAN.md: pin srt, try the real opencode, and settle on 24.04 or 26.04.

make lint passes. smoketest/run --tier all passed every scenario but 50 and
80 before the opencode change, and 50 and 80 pass after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 19:59:14 -07:00

58 lines
2.6 KiB
Bash

# shellcheck shell=bash
# Scenarios set what the runner and items read
# shellcheck disable=SC2034
DESCRIPTION="Node.js and srt download; a stand-in agent in the sandbox"
TIER=all
PRIVILEGED=1
scenario() {
local project="$HOME/Projects/demo" out
source "$CONNECTOR/configure.d/30-agents.sh"
sudo apt-get update > /dev/null && sudo apt-get install -y "${SANDBOX_PACKAGES[@]}" > /dev/null 2>&1
check "bubblewrap works" bwrap_works
step "Node.js and srt"
check_not "Ubuntu's Node.js, if any, isn't new enough or isn't there" node_ok
check "install_srt" install_srt
check "Node.js is in ~/.local/share/federated-connector/node" test -x "$FC_TOOLS/node/bin/node"
check "srt is found" srt_path
step "A stand-in agent"
mkdir -p "$HOME/.local/bin" "$HOME/.ssh" "$project"
echo secret > "$HOME/.ssh/id_test"
cat > "$HOME/.local/bin/opencode" << 'AGENT'
#!/bin/bash
case "$1" in
started) true ;;
read-ssh) cat ~/.ssh/id_test ;;
read-settings) cat ~/.config/federated-connector/core.conf ;;
write-home) echo x > ~/outside ;;
write-here) echo x > ./inside ;;
fetch) curl -sf -o /dev/null --max-time 20 "$2" ;;
esac
AGENT
chmod +x "$HOME/.local/bin/opencode"
cd "$project" || return
mkdir -p "$HOME/.config/federated-connector"
echo 'CORE_DOMAIN=smoke.invalid' > "$HOME/.config/federated-connector/core.conf"
# Without this, the checks that something fails would pass if the sandbox
# itself didn't start
check "its sandbox starts" "$SANDBOX_BIN/opencode" started
check_not "it can't read ~/.ssh" "$SANDBOX_BIN/opencode" read-ssh
check "unsandboxed, Federated Connector's settings are readable" "$SANDBOX_BIN/unsandboxed" opencode read-settings
check_not "it can't read Federated Connector's settings" "$SANDBOX_BIN/opencode" read-settings
check_not "it can't write outside its project" "$SANDBOX_BIN/opencode" write-home
check "it can write in its project" "$SANDBOX_BIN/opencode" write-here
check "it reaches an allowed site" "$SANDBOX_BIN/opencode" fetch https://registry.npmjs.org/
check_not "it doesn't reach others" "$SANDBOX_BIN/opencode" fetch https://example.com/
check "unsandboxed runs it directly" "$SANDBOX_BIN/unsandboxed" opencode write-home
cd "$HOME" || return
out="$("$SANDBOX_BIN/opencode" write-here 2>&1)"
check "it won't start in your home folder" grep -q "Start opencode from a project directory" <<< "$out"
step "Typing its name runs it in the sandbox"
check "put_on_path" put_on_path
check "on_path" on_path
check_eq "a new bash finds the sandboxed one first" "$SANDBOX_BIN/opencode" "$(bash -ic 'command -v opencode' < /dev/null 2> /dev/null)"
}