Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -23,7 +23,16 @@ cat >"$HOME/.local/bin/$command" <<EOF
#!/bin/bash
export MISE_MINIMUM_RELEASE_AGE=0
mise use -g --quiet "$package" || exit 1
exec mise x "$package" -- "$bin" "\$@"

# 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" 2>/dev/null)
if [[ -n \$resolved ]]; then
exec mise x "$package" -- "\$resolved" "\$@"
else
exec mise x "$package" -- "$bin" "\$@"
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 @@ -61,6 +61,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 @@ -108,16 +113,38 @@ 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
assert_lazy_stub "$ori_package" ori
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"

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