Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion bin/omarchy-mise-install
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ cat >"$HOME/.local/bin/$command" <<EOF
#!/bin/bash
export MISE_MINIMUM_RELEASE_AGE=0
mise use -g --quiet $package_arg || exit 1
exec mise x $package_arg -- $bin_arg "\$@"

# Resolve the binary to an absolute path. Passing the bare name lets mise
# re-resolve it through PATH, which can land back on this wrapper and exec
# forever when ~/.local/bin precedes mise's install dir.
resolved=\$(mise which $bin_arg 2>/dev/null)
if [[ -n \$resolved ]]; then
exec mise x $package_arg -- "\$resolved" "\$@"
else
exec mise x $package_arg -- $bin_arg "\$@"
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
Comment on lines +63 to +64

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Fallback restores the loop
If mise which returns no path, this branch passes the bare binary name to mise x again. When the wrapper precedes mise's install directory on PATH, that is the same invocation that can select the wrapper and run indefinitely. A failed resolution should not return to the self-recursing path.

fi
EOF

chmod +x "$HOME/.local/bin/$command"
29 changes: 28 additions & 1 deletion test/shell.d/default-agent-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ if [[ $1 == "where" ]]; then
exit
fi

if [[ $1 == "which" ]]; then
[[ -n ${OMARCHY_TEST_MISE_WHICH:-} ]] && printf '%s\n' "$OMARCHY_TEST_MISE_WHICH"
exit
fi

[[ ${OMARCHY_TEST_MISE_FAIL:-false} != "true" ]]
SH

Expand Down Expand Up @@ -137,10 +142,29 @@ assert_lazy_stub() {
"$test_home/.local/bin/$command" --version
mapfile -t mise_calls <"$mise_history"

[[ ${mise_calls[0]} == "use -g --quiet $package" && ${mise_calls[1]} == "x $package -- $command --version" ]] ||
# The stub resolves the binary to an absolute path before exec'ing it, so the
# name is never handed back to mise to look up through PATH.
[[ ${mise_calls[0]} == "use -g --quiet $package" && ${mise_calls[1]} == "which $command" &&
${mise_calls[2]} == "x $package -- $command --version" ]] ||
fail "$command lazy stub preserves its mise package"
}

# A stub must never exec the bare command name when mise can resolve it: with
# ~/.local/bin ahead of mise's install dir on PATH, the name finds the stub
# again and it execs itself forever.
assert_stub_execs_resolved_path() {
local package=$1
local command=$2

: >"$mise_history"
"$ROOT/bin/omarchy-mise-install" "$package" "$command"
OMARCHY_TEST_MISE_WHICH="/opt/resolved/$command" "$test_home/.local/bin/$command" --version
mapfile -t mise_calls <"$mise_history"

[[ ${mise_calls[2]} == "x $package -- /opt/resolved/$command --version" ]] ||
fail "$command lazy stub execs the resolved path, not the bare name"
Comment on lines +167 to +172

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test cannot catch self-execution
The new test supplies a fixed resolved path and checks only what the mise x mock logs. The mock never executes the target, and the wrapper directory is not on the test PATH. A self-exec loop under the PATH ordering this change targets would therefore go undetected. A bounded execution test with the wrapper ahead of the install directory would cover that risk.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

}

assert_lazy_stub "$grok_package" grok
assert_lazy_stub "$omp_package" omp
assert_lazy_stub "$crush_package" crush
Expand All @@ -149,6 +173,9 @@ assert_lazy_stub "$cursor_agent_package" cursor-agent
assert_lazy_stub "$muse_package" muse
pass "custom agent lazy stubs preserve their mise packages"

assert_stub_execs_resolved_path "$grok_package" grok
pass "lazy stubs exec the resolved binary path"

OMARCHY_TEST_MISSING_COMMAND=cursor-agent source "$ROOT/install/user/mise.sh"
grep -Fx "$agy_package agy" "$stub_log" >/dev/null || fail "user setup creates the Antigravity lazy stub"
grep -Fx "$grok_package grok" "$stub_log" >/dev/null || fail "user setup creates the Grok lazy stub"
Expand Down