Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
17 changes: 13 additions & 4 deletions test/shell.d/agent-account-exec-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,17 @@ SH
chmod +x "$real_bin/$provider"
done

# Only Omarchy's wrapper declarations: mise installs a declared lazy tool
# before it runs that tool's wrapper, so with omarchy-tools.toml in place it
# would try to fetch the real CLI instead of reaching the fake one.
mise_system_config="$test_tmp/etc/mise"
mkdir -p "$mise_system_config/conf.d"
cp "$ROOT/etc/mise/conf.d/omarchy-agent-accounts.toml" "$mise_system_config/conf.d/"

run_isolated() {
env -i HOME="$account_test_home" \
XDG_CONFIG_HOME="$test_tmp/config" XDG_DATA_HOME="$test_tmp/data" XDG_CACHE_HOME="$test_tmp/cache" \
MISE_DATA_DIR="$mise_data" MISE_SYSTEM_CONFIG_DIR="$ROOT/etc/mise" MISE_OFFLINE=1 \
MISE_DATA_DIR="$mise_data" MISE_SYSTEM_CONFIG_DIR="$mise_system_config" MISE_OFFLINE=1 \
OMARCHY_PATH="$ROOT" PATH="$mise_data/command-wrappers/bin:$ROOT/bin:$real_bin:/usr/bin" \
"$@"
}
Expand Down Expand Up @@ -165,6 +172,8 @@ run_isolated env OMARCHY_TEST_AGENT_EXIT=42 claude >/dev/null || status=$?
pass "account dispatch preserves the agent exit status"

# A dispatcher alone must not prevent the CLI from being installed on first use.
# mise itself refuses a wrapper whose tool has no binary yet, so call account
# dispatch the way mise hands off to it: with its wrapper directory off PATH.
# Omarchy declares the agent, so installing it must leave the user's config
# alone; without that declaration, the user's config selects it.
mv "$real_bin/grok" "$test_tmp/grok-fixture"
Expand All @@ -186,18 +195,18 @@ SH
chmod +x "$real_bin/mise"
select_account grok side
declarations="$ROOT/etc/mise/conf.d/omarchy-tools.toml"
output=$(run_isolated env OMARCHY_MISE_CONFIG_PATH="$declarations" OMARCHY_TEST_EXPECTED_INSTALL="install --quiet grok" grok)
output=$(run_isolated env OMARCHY_MISE_CONFIG_PATH="$declarations" OMARCHY_TEST_EXPECTED_INSTALL="install --quiet grok" PATH="$ROOT/bin:$real_bin:/usr/bin" omarchy-agent-account-exec grok)
[[ $output == "$test_tmp/accounts/grok side" ]] || fail "a dispatcher without a CLI installs Omarchy's declared agent and uses the selected account" "$output"
pass "a dispatcher without a CLI installs Omarchy's declared agent and uses the selected account"

rm "$real_bin/grok"
output=$(run_isolated env OMARCHY_MISE_CONFIG_PATH="$test_tmp/no-declarations.toml" OMARCHY_TEST_EXPECTED_INSTALL="use -g --quiet grok" grok)
output=$(run_isolated env OMARCHY_MISE_CONFIG_PATH="$test_tmp/no-declarations.toml" OMARCHY_TEST_EXPECTED_INSTALL="use -g --quiet grok" PATH="$ROOT/bin:$real_bin:/usr/bin" omarchy-agent-account-exec grok)
[[ $output == "$test_tmp/accounts/grok side" ]] || fail "a dispatcher without Omarchy's declaration selects the agent in the user config" "$output"
pass "a dispatcher without Omarchy's declaration selects the agent in the user config"

rm "$real_bin/grok"
status=0
run_isolated env OMARCHY_MISE_CONFIG_PATH="$declarations" OMARCHY_TEST_EXPECTED_INSTALL="install --quiet grok" OMARCHY_TEST_INSTALL_FAIL=yes grok >/dev/null || status=$?
run_isolated env OMARCHY_MISE_CONFIG_PATH="$declarations" OMARCHY_TEST_EXPECTED_INSTALL="install --quiet grok" OMARCHY_TEST_INSTALL_FAIL=yes PATH="$ROOT/bin:$real_bin:/usr/bin" omarchy-agent-account-exec grok >/dev/null || status=$?
(( status == 42 )) || fail "a failed first-run install stops dispatch" "$status"
pass "a failed first-run install stops dispatch"
rm "$real_bin/mise"
7 changes: 5 additions & 2 deletions test/shell.d/agent-usage-kimchi-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,14 @@ expect("a budget cached under its old name is read, elapsed at zero and an unclo
sandbox()
sessions = harness() / "sessions" / "--home-me--"
now = iso_in(0)
# A repeated entry is the same id at the same time. Two calls could stamp it a
# millisecond apart, which would make it two replies.
repeated = reply("a-1", "minimax-m3", {"input": 100, "output": 20, "cacheRead": 800, "cacheWrite": 5, "totalTokens": 925})
write_pi_session(sessions / "today.jsonl", [
{"type": "session", "id": "s-1"},
{"type": "message", "id": "u-1", "timestamp": now, "message": {"role": "user", "content": "hi", "usage": {"input": 999}}},
reply("a-1", "minimax-m3", {"input": 100, "output": 20, "cacheRead": 800, "cacheWrite": 5, "totalTokens": 925}),
reply("a-1", "minimax-m3", {"input": 100, "output": 20, "cacheRead": 800, "cacheWrite": 5, "totalTokens": 925}),
repeated,
repeated,
reply("a-2", "glm-5.3", {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 75}),
{"type": "custom", "id": "c-1", "timestamp": now, "data": {"usage": {"input": 999}}},
{"type": "message", "id": "a-3", "message": {"role": "assistant", "model": "glm-5.3", "timestamp": ms_in(0), "usage": {"input": 10, "output": 5}}},
Expand Down
25 changes: 23 additions & 2 deletions test/shell.d/base-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,34 @@ QML_FIXTURE_TMP=""
QML_FIXTURE_PID=""
QML_FIXTURE_LOG=""

# The fixture's Quickshell and every process it started, deepest last.
qml_fixture_tree() {
local pid=$1 child
printf '%s\n' "$pid"
for child in $(pgrep -P "$pid" 2>/dev/null); do
qml_fixture_tree "$child"
done
}

qml_fixture_cleanup() {
local -a tree=()
local attempt
if [[ -n $QML_FIXTURE_PID ]] && kill -0 "$QML_FIXTURE_PID" 2>/dev/null; then
kill "$QML_FIXTURE_PID" 2>/dev/null || true
# Processes a fixture started outlive Quickshell and can still be writing
# into its HOME while that is removed, so stop them with it.
mapfile -t tree < <(qml_fixture_tree "$QML_FIXTURE_PID")
kill "${tree[@]}" 2>/dev/null || true

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 Crashed fixtures leave children running

qml_fixture_cleanup still skips child cleanup if Quickshell has already crashed, such as after a compositor disconnect. The kill -0 check fails, so the new tree walk never runs. The plugin-registry fixture starts a persistent inotifywait, and its QML cleanup cannot cover crashes. Failed runs can therefore leave background processes behind.

Track fixture processes independently of the live parent, using a unique fixture marker or process group, so cleanup also covers crashes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in fcf4bd8. Each fixture's Quickshell now starts with setsid and leads its own process group. Cleanup (and a second fixture replacing the first) signals that group instead of walking down from a live Quickshell, so children left to init after a crash are still stopped. To check, I SIGKILLed the manifest fixture's Quickshell: its inotifywait stayed in the group, and cleanup stopped it. The full suite passes (403/403) with no inotifywait left behind.

wait "$QML_FIXTURE_PID" 2>/dev/null || true
fi
QML_FIXTURE_PID=""
[[ -n $QML_FIXTURE_TMP && -d $QML_FIXTURE_TMP ]] && rm -rf "$QML_FIXTURE_TMP"
if [[ -n $QML_FIXTURE_TMP && -d $QML_FIXTURE_TMP ]]; then
# A child that was mid-write when it got the signal can still add a file.
for attempt in {1..20}; do
rm -rf "$QML_FIXTURE_TMP" 2>/dev/null && break
sleep 0.1
done
[[ ! -e $QML_FIXTURE_TMP ]] || echo "Could not remove $QML_FIXTURE_TMP" >&2
fi
return 0
}

Expand Down
22 changes: 15 additions & 7 deletions test/shell.d/i18n-startup-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,17 @@ persian = dict(english, language='fa', locale='fa-IR', number='۱۳٫۵', rtl=Tr
french_fallback = dict(english, language='fr', locale='fr-FR', number='13,5')


def write_json(path, data):
# The shell watches these files and reloads them as they change, so replace
# each one whole: a file written in place can be read while still empty.
def write_text(path, text):
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(data, ensure_ascii=False), encoding='utf-8')
staged = path.with_name(path.name + '.tmp')
staged.write_text(text, encoding='utf-8')
os.replace(staged, path)


def write_json(path, data):
write_text(path, json.dumps(data, ensure_ascii=False))


class Probe:
Expand Down Expand Up @@ -159,7 +167,7 @@ try:
try:
probe.wait(english)
for language, expected in [('da', danish), ('pt-BR', portuguese), ('fr', french_fallback), ('en', english)]:
probe.language.write_text(language)
write_text(probe.language, language)
probe.wait(expected)
print('ok - live language changes update shell, plugin, and locale bindings', flush=True)

Expand All @@ -175,21 +183,21 @@ try:

other = probe.path / 'other-plugin'
write_json(other / 'en.json', dict(en_catalog, **{'test.hello': 'Other %1', 'test.baseOnly': 'English base'}))
probe.directory.write_text(str(other))
write_text(probe.directory, str(other))
changed = dict(changed, pluginText='Other Ada')
probe.wait(changed)
probe.directory.write_text(str(probe.plugin))
write_text(probe.directory, str(probe.plugin))
changed = dict(changed, pluginText='Plugin Ada')
probe.wait(changed)
print('ok - changing the plugin catalog directory refreshes existing bindings', flush=True)

probe.language.write_text('da')
write_text(probe.language, 'da')
probe.wait(danish)
probe.language.unlink()
probe.wait(changed)
print('ok - deleting the language selection restores English', flush=True)

probe.language.write_text('da')
write_text(probe.language, 'da')
probe.wait(danish)
(probe.catalogs / 'da/shell.json').unlink()
(probe.plugin / 'da.json').unlink()
Expand Down
13 changes: 13 additions & 0 deletions test/shell.d/input-indicator-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,19 @@ print("ok - the watched profile follows Fcitx's FCITX_CONFIG_HOME override")
os.makedirs(scratch.name + "/daemon/fcitx")
daemon = subprocess.Popen(["sleep", "30"], cwd=scratch.name,
env={"HOME": scratch.name, "FCITX_CONFIG_HOME": "daemon/fcitx"})
# Popen returns while the exec is still under way, and until it finishes the
# child's /proc environ reads empty, is refused, or is the parent's. Fcitx owns
# its bus name only well after its exec, so wait for the environment here too.
def daemon_environment():
try:
with open(f"/proc/{daemon.pid}/environ", "rb") as file:
return file.read()
except PermissionError:
return b""
for _ in range(500):
if b"FCITX_CONFIG_HOME=" in daemon_environment():
break
time.sleep(0.01)
class OwnerBus:
def call_sync(self, name, path, interface, method, args, *rest):
assert method == "GetConnectionUnixProcessID" and args.unpack() == (indicator.BUS,)
Expand Down
43 changes: 26 additions & 17 deletions test/shell.d/runtime-smoke-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,23 @@ bar_background() {
HOME="$SCRATCH_HOME" OMARCHY_PATH="$SCRATCH_ROOT" PATH="$ROOT/bin:$PATH" "$ROOT/bin/omarchy-bar" background "$@"
}

# Elsewhen saves its first-run cities once its probe returns, and that save
# writes the shell's whole config back to shell.json. Landing after an edit
# from outside the shell, it puts the old config back, so wait for it before
# editing shell.json. A machine slower than a desktop returns the probe late.
wait_for_elsewhen_cities() {
local saved='any(.bar.layout[][]; .id? == "omarchy.elsewhen" and .cities? != null)'
local config="$SCRATCH_HOME/.config/omarchy/shell.json"

for _ in {1..300}; do
jq -e "$saved" "$config" >/dev/null 2>&1 && return 0
kill -0 "$SCRATCH_PID" 2>/dev/null || fail_with_log "test shell exited before Elsewhen saved its cities"
sleep 0.1
done
fail_with_log "Elsewhen saves its first-run cities before shell.json is edited"
}

wait_for_elsewhen_cities
bar_background none >/dev/null
for _ in {1..50}; do
(( $(text_color_count) > 0 )) && break
Expand Down Expand Up @@ -632,40 +649,32 @@ pass "bar put leaves a widget already on the bar alone"
# A hand edit that drops the closing brace puts the shell on the defaults,
# which have no omarchy.microphone. A bar change then applies for the session
# only, leaving the file as the user left it until they fix it.
config="$test_home/.config/omarchy/shell.json"
# Elsewhen saves its first-run cities once its probe returns. Landing between
# the edit and the shell's reload, that save would write valid JSON back.
for _ in {1..80}; do
jq -e 'any(.bar.layout[][]; .id? == "omarchy.elsewhen" and .cities? != null)' "$config" >/dev/null 2>&1 && break
kill -0 "$QS_PID" 2>/dev/null || fail_with_log "test shell exited before Elsewhen saved its cities"
sleep 0.1
done
jq -e 'any(.bar.layout[][]; .id? == "omarchy.elsewhen" and .cities? != null)' "$config" >/dev/null ||
fail_with_log "Elsewhen saves its first-run cities before shell.json is edited"
config="$SCRATCH_HOME/.config/omarchy/shell.json"
wait_for_elsewhen_cities
sed -i '$ d' "$config"
cp "$config" "$TMPDIR/broken.json"
cp "$config" "$SCRATCH_DIR/broken.json"
for _ in {1..80}; do
[[ $(center_ids) != *omarchy.microphone* ]] && break
kill -0 "$QS_PID" 2>/dev/null || fail_with_log "test shell exited while reading an unreadable shell.json"
kill -0 "$SCRATCH_PID" 2>/dev/null || fail_with_log "test shell exited while reading an unreadable shell.json"
sleep 0.1
done
[[ $(center_ids) != *omarchy.microphone* ]] || fail_with_log "shell falls back to defaults on an unreadable shell.json"
[[ $(shell_ipc shell setBarWidget omarchy.clock format '"HH:mm"' '{}') == "ok" ]] ||
[[ $(scratch_ipc shell setBarWidget omarchy.clock format '"HH:mm"' '{}') == "ok" ]] ||
fail_with_log "bar widget setting is applied while shell.json is unreadable"
jq -e 'any(.bar.layout[][]; .id? == "omarchy.clock" and .format? == "HH:mm")' \
<<<"$(shell_ipc shell listShellConfig)" >/dev/null ||
<<<"$(scratch_ipc shell listShellConfig)" >/dev/null ||
fail_with_log "a bar change still applies in memory while shell.json is unreadable"
sleep 0.5
cmp -s "$config" "$TMPDIR/broken.json" || fail "a bar change leaves an unreadable shell.json as the user left it" "$(cat "$config")"
cmp -s "$config" "$SCRATCH_DIR/broken.json" || fail "a bar change leaves an unreadable shell.json as the user left it" "$(cat "$config")"
pass "a bar change leaves an unreadable shell.json as the user left it"

printf '}\n' >>"$config"
for _ in {1..80}; do
[[ $(center_ids) == *omarchy.microphone* ]] && break
kill -0 "$QS_PID" 2>/dev/null || fail_with_log "test shell exited while reading a fixed shell.json"
kill -0 "$SCRATCH_PID" 2>/dev/null || fail_with_log "test shell exited while reading a fixed shell.json"
sleep 0.1
done
[[ $(shell_ipc shell setBarWidget omarchy.clock format '"H:mm"' '{}') == "ok" ]] ||
[[ $(scratch_ipc shell setBarWidget omarchy.clock format '"H:mm"' '{}') == "ok" ]] ||
fail_with_log "bar widget setting is applied once shell.json is fixed"
saved='any(.bar.layout[][]; (.id? // .) == "omarchy.microphone") and any(.bar.layout[][]; .id? == "omarchy.clock" and .format? == "H:mm")'
for _ in {1..40}; do
Expand Down
Loading