The widget hid itself well enough that nobody found it: it only ever appeared if you knew the id and ran `omarchy bar plugin add`, since it was in neither the shipped layout nor any migration. Defaulting it on costs nothing on machines that don't use it. Panel.qml is `visible: providers.length > 0`, and Main.qml only counts a provider that is enabled and has actually recorded prompts, sessions, active days, or a rate limit. A box that has never run Claude Code or Codex draws an empty bar item, and the icon arrives on its own at the first scan that finds usage — which is the behavior the widget already advertised. The migration skips any config that already lists the widget in any section, so a curated bar keeps its own placement rather than gaining a second copy. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
120 lines
4.2 KiB
Bash
Executable File
120 lines
4.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
source "$(dirname "$0")/base-test.sh"
|
|
|
|
require_command jq
|
|
|
|
migration="$ROOT/migrations/1785344985.sh"
|
|
test_dir=$(mktemp -d)
|
|
trap 'rm -rf "$test_dir"' EXIT
|
|
|
|
mkdir -p "$test_dir/bin"
|
|
|
|
cat >"$test_dir/bin/omarchy-cmd-present" <<'STUB'
|
|
#!/bin/bash
|
|
|
|
command -v "$1" >/dev/null
|
|
STUB
|
|
|
|
cat >"$test_dir/bin/omarchy-restart-shell" <<'STUB'
|
|
#!/bin/bash
|
|
|
|
echo restart >>"$SHELL_RESTARTS"
|
|
STUB
|
|
|
|
chmod +x "$test_dir/bin/"*
|
|
|
|
export SHELL_RESTARTS="$test_dir/shell-restarts"
|
|
|
|
home="$test_dir/home"
|
|
config="$home/.config/omarchy/shell.json"
|
|
|
|
run_migration() {
|
|
: >"$SHELL_RESTARTS"
|
|
HOME="$home" PATH="$test_dir/bin:$PATH" bash -euo pipefail "$migration" >/dev/null
|
|
}
|
|
|
|
# The shipped default minus the widget is what every machine installed before
|
|
# this migration has on disk.
|
|
write_config() {
|
|
rm -rf "$home"
|
|
mkdir -p "$home/.config/omarchy"
|
|
jq "${1:-.}" "$ROOT/config/omarchy/shell.json" >"$config"
|
|
}
|
|
|
|
without_widget='del(.bar.layout[][] | select((if type == "object" then .id else . end) == "omarchy.model-usage"))'
|
|
|
|
ids() {
|
|
jq -c --arg section "$1" '[.bar.layout[$section][]? | if type == "object" then .id else . end]' "$config"
|
|
}
|
|
|
|
# ------------------------------------------------------------------ shipped default
|
|
|
|
jq -e '[.bar.layout.right[].id] | index("omarchy.model-usage")' "$ROOT/config/omarchy/shell.json" >/dev/null ||
|
|
fail "shipped config puts model usage in the bar"
|
|
pass "shipped config puts model usage in the bar"
|
|
|
|
# ------------------------------------------------------------------ placement
|
|
|
|
write_config "$without_widget"
|
|
run_migration
|
|
|
|
[[ $(ids right) == '["omarchy.tray","omarchy.model-usage","omarchy.bluetooth","omarchy.network","omarchy.audio","omarchy.monitor","omarchy.power"]' ]] ||
|
|
fail "migration inserts model usage after the tray" "$(ids right)"
|
|
pass "migration inserts model usage after the tray"
|
|
|
|
(($(wc -l <"$SHELL_RESTARTS") == 1)) || fail "migration restarts the shell"
|
|
pass "migration restarts the shell"
|
|
|
|
before=$(sha256sum "$config")
|
|
run_migration
|
|
[[ $before == $(sha256sum "$config") ]] || fail "migration is idempotent" "$(ids right)"
|
|
pass "migration is idempotent"
|
|
|
|
# ------------------------------------------------------------------ curated bars
|
|
|
|
# A user who already placed the widget keeps it exactly where they put it, in
|
|
# whichever section, and never gets a second copy.
|
|
write_config "$without_widget | .bar.layout.center += [{ id: \"omarchy.model-usage\" }]"
|
|
run_migration
|
|
|
|
[[ $(ids center) == *'"omarchy.model-usage"'* ]] || fail "migration leaves a user-placed widget alone" "$(ids center)"
|
|
[[ $(ids right) != *'"omarchy.model-usage"'* ]] || fail "migration does not add a second copy" "$(ids right)"
|
|
pass "migration respects a widget the user already placed"
|
|
|
|
# Layouts written before entries grew options are bare id strings.
|
|
write_config "$without_widget | .bar.layout.right = [\"omarchy.tray\", \"omarchy.model-usage\", \"omarchy.power\"]"
|
|
run_migration
|
|
|
|
[[ $(ids right) == '["omarchy.tray","omarchy.model-usage","omarchy.power"]' ]] ||
|
|
fail "migration reads string-form entries" "$(ids right)"
|
|
pass "migration reads string-form entries"
|
|
|
|
# A tray dropped from the right section must not strand the widget or drop it.
|
|
write_config "$without_widget | del(.bar.layout.right[] | select(.id == \"omarchy.tray\"))"
|
|
run_migration
|
|
|
|
[[ $(ids right) == '["omarchy.model-usage",'* ]] || fail "migration places the widget without a tray" "$(ids right)"
|
|
pass "migration places the widget without a tray"
|
|
|
|
# ------------------------------------------------------------------ everything else
|
|
|
|
write_config "$without_widget"
|
|
cp "$config" "$test_dir/before.json"
|
|
run_migration
|
|
|
|
diff <(jq -S 'del(.bar.layout.right)' "$test_dir/before.json") <(jq -S 'del(.bar.layout.right)' "$config") >/dev/null ||
|
|
fail "migration touches nothing but the right section" "$(diff <(jq -S . "$test_dir/before.json") <(jq -S . "$config"))"
|
|
pass "migration touches nothing but the right section"
|
|
|
|
# A config the migration cannot parse is left alone rather than truncated.
|
|
rm -rf "$home"
|
|
mkdir -p "$home/.config/omarchy"
|
|
printf '{ not json' >"$config"
|
|
run_migration
|
|
|
|
[[ $(cat "$config") == '{ not json' ]] || fail "migration leaves an unparsable config untouched" "$(cat "$config")"
|
|
pass "migration leaves an unparsable config untouched"
|