Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion bin/omarchy-voxtype-install
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if gum confirm "Install Voxtype + AI model (~150MB) to enable dictation?"; then

voxtype setup --download --no-post-install
if omarchy-hw-vulkan; then
voxtype setup gpu --enable || true
sudo voxtype setup gpu --enable
fi
voxtype setup systemd

Expand Down
24 changes: 24 additions & 0 deletions migrations/1786873661.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
echo "Enable Vulkan GPU acceleration for Voxtype dictation"

# omarchy-voxtype-install used to run `voxtype setup gpu --enable` without sudo,
# which failed to repoint the root-owned /usr/bin/voxtype symlink and was
# swallowed by `|| true`, leaving the CPU backend selected on Vulkan hardware.

voxtype_bin="${OMARCHY_VOXTYPE_BIN:-/usr/bin/voxtype}"

omarchy-cmd-present voxtype || exit 0
omarchy-hw-vulkan || exit 0

# Only repair installs still on a CPU Whisper backend; a Vulkan or ONNX target
# means GPU setup already ran or the user deliberately switched engines.
case $(basename "$(readlink -f "$voxtype_bin")") in
voxtype-avx2 | voxtype-avx512) ;;
*) exit 0 ;;
esac

sudo voxtype setup gpu --enable

# Pick up the Vulkan binary without waiting for the next login.
if systemctl --user is-active --quiet voxtype; then
systemctl --user restart voxtype
fi
128 changes: 128 additions & 0 deletions test/shell.d/voxtype-vulkan-migration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

migration="$ROOT/migrations/1786873661.sh"

test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT

stub_bin="$test_tmp/bin"
calls="$test_tmp/calls.log"
mkdir -p "$stub_bin"

cat >"$stub_bin/omarchy-cmd-present" <<'SH'
#!/bin/bash

(( ${VOXTYPE_INSTALLED:-1} == 1 ))
SH

cat >"$stub_bin/omarchy-hw-vulkan" <<'SH'
#!/bin/bash

(( ${VULKAN_AVAILABLE:-1} == 1 ))
SH

cat >"$stub_bin/sudo" <<'SH'
#!/bin/bash

printf 'sudo' >>"$TEST_LOG"
printf '\t%s' "$@" >>"$TEST_LOG"
printf '\n' >>"$TEST_LOG"
SH

cat >"$stub_bin/systemctl" <<'SH'
#!/bin/bash

if [[ "$1 $2 $3" == "--user is-active --quiet" ]]; then
(( ${VOXTYPE_SERVICE_ACTIVE:-1} == 1 ))
else
printf 'systemctl' >>"$TEST_LOG"
printf '\t%s' "$@" >>"$TEST_LOG"
printf '\n' >>"$TEST_LOG"
fi
SH

chmod +x "$stub_bin"/*

voxtype_lib="$test_tmp/lib"
voxtype_bin="$test_tmp/voxtype"
mkdir -p "$voxtype_lib"
touch "$voxtype_lib"/{voxtype-avx2,voxtype-avx512,voxtype-vulkan,voxtype-onnx-avx512}

set_backend() {
ln -sfn "$voxtype_lib/$1" "$voxtype_bin"
}

run_migration() {
PATH="$stub_bin:$PATH" \
TEST_LOG="$calls" \
OMARCHY_VOXTYPE_BIN="$voxtype_bin" \
bash -euo pipefail "$migration" >/dev/null
}

sudo_enable=$'sudo\tvoxtype\tsetup\tgpu\t--enable'
service_restart=$'systemctl\t--user\trestart\tvoxtype'

# A CPU Whisper backend on Vulkan hardware is the state the buggy installer
# left behind: enable the GPU and restart the running service.
set_backend voxtype-avx512
: >"$calls"
run_migration

grep -Fxq "$sudo_enable" "$calls" ||
fail "a CPU Whisper backend enables the GPU" "$(cat "$calls")"
grep -Fxq "$service_restart" "$calls" ||
fail "an active voxtype service is restarted" "$(cat "$calls")"
pass "migration enables Vulkan and restarts an active service on a CPU backend"

set_backend voxtype-avx2
: >"$calls"
run_migration

grep -Fxq "$sudo_enable" "$calls" ||
fail "the avx2 CPU backend is repaired too" "$(cat "$calls")"
pass "migration repairs both CPU Whisper backends"

# Without a running service there is nothing to restart; the enable still runs
# and the next login picks up the Vulkan binary.
: >"$calls"
VOXTYPE_SERVICE_ACTIVE=0 run_migration

grep -Fxq "$sudo_enable" "$calls" ||
fail "an inactive service still gets the GPU enabled" "$(cat "$calls")"
if grep -Fxq "$service_restart" "$calls"; then
fail "an inactive voxtype service is not restarted" "$(cat "$calls")"
fi
pass "migration skips the restart when the service is not running"

# Already on Vulkan: GPU setup ran before, nothing to repair.
set_backend voxtype-vulkan
: >"$calls"
run_migration

[[ ! -s $calls ]] || fail "a Vulkan backend is left alone" "$(cat "$calls")"
pass "migration skips an install already on Vulkan"

# An ONNX target is a deliberate engine switch; forcing Vulkan would undo it.
set_backend voxtype-onnx-avx512
: >"$calls"
run_migration

[[ ! -s $calls ]] || fail "a deliberate ONNX engine switch is preserved" "$(cat "$calls")"
pass "migration preserves a deliberate ONNX engine switch"

set_backend voxtype-avx512

: >"$calls"
VOXTYPE_INSTALLED=0 run_migration

[[ ! -s $calls ]] || fail "installs without voxtype are skipped" "$(cat "$calls")"

: >"$calls"
VULKAN_AVAILABLE=0 run_migration

[[ ! -s $calls ]] || fail "machines without Vulkan are skipped" "$(cat "$calls")"
pass "migration skips installs it does not apply to"