Skip to content

Commit 7f86245

Browse files
committed
fix: pass --no-sandbox via ELECTRON_EXTRA_LAUNCH_ARGS instead of argv
Go's flag.Parse() in agy-bin rejects unknown flags at startup, causing 'flags provided but not defined: -no-sandbox' whenever the TUI is launched inside the Workshop LXD container. Replace argv injection with ELECTRON_EXTRA_LAUNCH_ARGS so Electron's process spawner picks up --no-sandbox before the Chromium subprocess starts, bypassing Go's flag parser entirely. Also suppress sandbox injection for non-interactive modes (--print, -p, --prompt, --prompt-interactive, -i) since they do not launch the Electron TUI at all. Update tests/unit/agy-wrapper.sh to verify the env var is set rather than the argv flag, and adjust expectations for non-interactive cases.
1 parent b822ffd commit 7f86245

2 files changed

Lines changed: 42 additions & 10 deletions

File tree

bin/agy

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ARGS=()
77
HAS_SANDBOX=false
88
HAS_NO_SANDBOX=false
99
HAS_UTILITY_FLAG=false
10+
HAS_NONINTERACTIVE=false
1011
COMMAND_TOKEN=""
1112
IS_SUBCOMMAND=false
1213
SKIP_NEXT=false
@@ -27,6 +28,15 @@ VALUE_FLAGS=(
2728
-p
2829
)
2930

31+
# Non-interactive/print modes that don't launch the Electron TUI
32+
NONINTERACTIVE_FLAGS=(
33+
--print
34+
--prompt
35+
--prompt-interactive
36+
-p
37+
-i
38+
)
39+
3040
contains() {
3141
local needle=$1
3242
shift
@@ -59,11 +69,17 @@ for arg in "$@"; do
5969
;;
6070
--*=*)
6171
flag_name=${arg%%=*}
72+
if contains "$flag_name" "${NONINTERACTIVE_FLAGS[@]}"; then
73+
HAS_NONINTERACTIVE=true
74+
fi
6275
if contains "$flag_name" "${VALUE_FLAGS[@]}"; then
6376
continue
6477
fi
6578
;;
6679
-*)
80+
if contains "$arg" "${NONINTERACTIVE_FLAGS[@]}"; then
81+
HAS_NONINTERACTIVE=true
82+
fi
6783
if contains "$arg" "${VALUE_FLAGS[@]}"; then
6884
SKIP_NEXT=true
6985
fi
@@ -80,12 +96,17 @@ if [[ -n "$COMMAND_TOKEN" ]] && contains "$COMMAND_TOKEN" "${SUBCOMMANDS[@]}"; t
8096
IS_SUBCOMMAND=true
8197
fi
8298

83-
# Only inject --no-sandbox for interactive/non-interactive modes, not subcommands
99+
# For bare TUI invocations in a container/headless environment, Electron's
100+
# Chromium subprocess needs --no-sandbox. Pass it via ELECTRON_EXTRA_LAUNCH_ARGS
101+
# so it is picked up by Electron's process spawner rather than Go's flag.Parse(),
102+
# which rejects unknown flags. Do not inject for subcommands, utility flags,
103+
# explicit sandbox override, or non-interactive print/prompt modes.
84104
if [[ "$HAS_SANDBOX" == "false" \
85105
&& "$HAS_NO_SANDBOX" == "false" \
86106
&& "$HAS_UTILITY_FLAG" == "false" \
107+
&& "$HAS_NONINTERACTIVE" == "false" \
87108
&& "$IS_SUBCOMMAND" == "false" ]]; then
88-
ARGS=("--no-sandbox" "${ARGS[@]}")
109+
export ELECTRON_EXTRA_LAUNCH_ARGS="--no-sandbox${ELECTRON_EXTRA_LAUNCH_ARGS:+ $ELECTRON_EXTRA_LAUNCH_ARGS}"
89110
fi
90111

91112
# Locate the actual binary (installed as agy-bin in the same bin directory)

tests/unit/agy-wrapper.sh

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ install_wrapper() {
1111

1212
cat >"$TMPDIR/agy-bin" <<'EOF'
1313
#!/usr/bin/env bash
14-
printf '<%s>\n' "$@"
14+
if [[ -n "${ELECTRON_EXTRA_LAUNCH_ARGS:-}" ]]; then
15+
printf '<ENV:ELECTRON_EXTRA_LAUNCH_ARGS=%s>\n' "$ELECTRON_EXTRA_LAUNCH_ARGS"
16+
fi
17+
[[ $# -gt 0 ]] && printf '<%s>\n' "$@" || true
1518
EOF
1619
chmod +x "$TMPDIR/agy-bin"
1720
}
@@ -34,27 +37,35 @@ assert_output() {
3437

3538
install_wrapper
3639

37-
assert_output '<--no-sandbox>'
38-
assert_output '<--no-sandbox>
39-
<-p>
40+
# Bare TUI invocation: --no-sandbox goes via ELECTRON_EXTRA_LAUNCH_ARGS, not argv
41+
assert_output '<ENV:ELECTRON_EXTRA_LAUNCH_ARGS=--no-sandbox>'
42+
43+
# Non-interactive flags (-p, --prompt, -i, --prompt-interactive) do not trigger injection
44+
assert_output '<-p>
4045
<install>' -p install
41-
assert_output '<--no-sandbox>
42-
<--prompt=install>' --prompt=install
43-
assert_output '<--no-sandbox>
44-
<--model>
46+
assert_output '<--prompt=install>' --prompt=install
47+
assert_output '<--model>
4548
<install>
4649
<-p>
4750
<help>' --model install -p help
51+
52+
# Subcommands: no injection
4853
assert_output '<install>' install
4954
assert_output '<models>' models
5055
assert_output '<plugin>
5156
<install>' plugin install
57+
58+
# Explicit --sandbox: suppresses env var injection
5259
assert_output '<--sandbox>
5360
<-p>
5461
<install>' --sandbox -p install
62+
63+
# Explicit --no-sandbox: suppresses env var injection (user passed it themselves)
5564
assert_output '<--no-sandbox>
5665
<-p>
5766
<install>' --no-sandbox -p install
67+
68+
# Utility flags: no injection
5869
assert_output '<--version>' --version
5970
assert_output '<--help>' --help
6071

0 commit comments

Comments
 (0)