Phase 6, the last of the fresh-install spec. 159 scripts lose their .sh: 110 contracts, 47 Vicinae commands, 2 compositor contracts. A shebang and the executable bit already select the interpreter. The extension only ever added something that had to stay in sync, and the rename proved the point twice over in the space of an hour. The spec's stated risk was Vicinae's script discovery. One script was renamed and reloaded on its own before the other 46 followed; it came back as scripts:panama.capture and all 47 resolve. What the probe turned up instead is that the extension was never only a filename: Vicinae's command IDs embed it, so every ID changed. Nothing in this repository refers to them, so nothing breaks. The only trace is Vicinae's metadata.json, whose visited map had two Panama entries that are now orphaned -- two commands lost their usage ranking and will earn it back. Worth knowing before anyone renames these again on a machine that has a keybind pointing at one. Rewriting the references by exact filename missed two things it structurally could not see: a name built from a variable, settings-$page.sh, and a glob, -name '*.sh'. Both were in the contract that counts the generated commands, which promptly reported 47 expected and 0 found. The mechanical part of a rename is the part that looks finished. The three subcommands. panama doctor fronts a health check that already existed and already ran at the end of every install but could not be reached from a terminal. panama upgrade re-runs the installer from anywhere. panama test runs the suite, which had no entry point at all -- 121 files that were the main safety net in this repository and were invisible in it. Writing that runner found three tests nothing was running. calendar_agenda_bridge_test, home_assistant_bridge_test and kdeconnect_bridge_test are unittest suites without the executable bit, so no contract invoked them and the first draft of the runner skipped them silently. All three pass, and have passed unobserved for weeks. The runner collects *_test.py as well now, because a runner with a blind spot is worse than no runner for the same reason a dependency checker with one is: it reports PASS. Six worktrees pruned. Each was re-checked rather than trusted to the spec's list, and two needed it: panama-commands is not on feat/panama-commands but on feat/gnome-tweaks-parity, and fix/panama-displays-review reads [ahead 3] -- ahead of its remote, not of main, with every commit patch-equivalent to landed work. roadmap-completion stays; it has five commits that are genuinely unlanded. The branches are left alone: pruning a worktree costs nothing, deleting a branch is a decision. 121 contracts pass. Claude-Session: https://claude.ai/code/session_01NvgBuSWB5sE43yWmg21ozj
218 lines
9.9 KiB
Bash
Executable File
218 lines
9.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
helper="$repo_dir/config/dot/quickshell/scripts/panama-home-assistant-config"
|
|
service="$repo_dir/config/dot/quickshell/services/HomeAssistantConfig.qml"
|
|
page="$repo_dir/config/dot/quickshell/modules/settings/HomePhonePage.qml"
|
|
password_field="$repo_dir/config/dot/quickshell/modules/settings/PasswordField.qml"
|
|
harness_fixture="$repo_dir/tests/quickshell/HomeAssistantConfigHarness.qml"
|
|
work="$(mktemp -d /tmp/panama-ha-config.XXXXXX)"
|
|
env_file="$work/env"
|
|
|
|
fail() {
|
|
printf 'Home Assistant config contract: %s\n' "$1" >&2
|
|
exit 1
|
|
}
|
|
|
|
cleanup() {
|
|
if declare -F qs_for_test >/dev/null; then
|
|
qs_for_test kill >/dev/null 2>&1 || true
|
|
fi
|
|
rm -rf "$work"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
[[ -x "$helper" ]] || fail 'credential helper is missing or not executable'
|
|
[[ -f "$service" ]] || fail 'credential service is missing'
|
|
[[ -f "$harness_fixture" ]] || fail 'credential runtime harness is missing'
|
|
|
|
rg -Fq 'stdinEnabled: true' "$service" || fail 'credential writes do not use process stdin'
|
|
rg -Fq 'writeProc.write(root.pendingPayload + "\n")' "$service" || fail 'credential payload is not written over stdin'
|
|
rg -Fq 'root.pendingPayload = ""' "$service" || fail 'credential payload remains in service memory after write'
|
|
if rg -q 'command:.*(token|pendingPayload)' "$service"; then
|
|
fail 'credential data can reach a process command line'
|
|
fi
|
|
rg -Fq 'PasswordField {' "$page" || fail 'Home Assistant token is not entered through the masked field'
|
|
rg -Fq 'activeFocusOnTab: true' "$password_field" || fail 'masked credential field is not keyboard reachable'
|
|
rg -Fq 'HomeAssistantConfig.save(' "$page" || fail 'Home Assistant configuration cannot be saved from Settings'
|
|
rg -Fq 'HomeAssistantConfig.clearToken()' "$page" || fail 'stored Home Assistant token cannot be cleared'
|
|
rg -Fq 'id: clearTokenButton' "$page" || fail 'clear-token action has no keyboard control identity'
|
|
rg -Fq 'id: saveHomeConfigButton' "$page" || fail 'save action has no keyboard control identity'
|
|
rg -Fq 'activeFocusOnTab: enabled' "$page" || fail 'credential actions are not in tab order'
|
|
rg -Fq 'Keys.onReturnPressed:' "$page" || fail 'credential actions have no keyboard activation'
|
|
|
|
cat >"$env_file" <<'EOF'
|
|
# Existing private shell settings must survive byte-for-byte.
|
|
export KEEP_ME='untouched value'
|
|
export JIRA_CREDENTIALS='unrelated-secret'
|
|
export PANAMA_HOME_ASSISTANT_URL='https://old.example.test'
|
|
export PANAMA_HOME_ASSISTANT_TOKEN='old-token'
|
|
export PANAMA_HOME_ASSISTANT_ENTITIES='light.old'
|
|
EOF
|
|
chmod 0644 "$env_file"
|
|
|
|
run_helper() {
|
|
PANAMA_HOME_ASSISTANT_ENV_FILE="$env_file" "$helper" "$@"
|
|
}
|
|
|
|
status="$(run_helper status)" || fail 'status failed for a valid private env file'
|
|
jq -e '.configured == true and .tokenConfigured == true
|
|
and .url == "https://old.example.test"
|
|
and .entities == ["light.old"] and (has("token") | not)' \
|
|
<<<"$status" >/dev/null || fail "status exposed or misread credentials: $status"
|
|
if rg -q 'old-token|unrelated-secret' <<<"$status"; then
|
|
fail 'status output leaked a secret'
|
|
fi
|
|
|
|
secret='ha-secret-must-never-appear-in-ps-or-output'
|
|
payload="$work/payload.json"
|
|
jq -cn --arg token "$secret" '{
|
|
url: "https://home.example.test/",
|
|
token: $token,
|
|
entities: ["light.kitchen", "light.desk", "light.kitchen"]
|
|
}' >"$payload"
|
|
|
|
# Keep stdin open long enough to prove the token is absent from the helper's
|
|
# process arguments. The secret lives only in the private payload file/stdin.
|
|
fifo="$work/input.fifo"
|
|
mkfifo "$fifo"
|
|
PANAMA_HOME_ASSISTANT_ENV_FILE="$env_file" "$helper" write <"$fifo" >"$work/write.out" 2>"$work/write.err" &
|
|
helper_pid=$!
|
|
for _ in $(seq 1 30); do
|
|
kill -0 "$helper_pid" 2>/dev/null && break
|
|
sleep 0.05
|
|
done
|
|
if ps -o args= -p "$helper_pid" | rg -Fq "$secret"; then
|
|
fail 'token appeared in the credential helper process arguments'
|
|
fi
|
|
cp "$payload" "$fifo"
|
|
wait "$helper_pid" || fail 'stdin credential write failed'
|
|
|
|
write_result="$(cat "$work/write.out")"
|
|
jq -e '.ok == true and .configured == true and .tokenConfigured == true
|
|
and .url == "https://home.example.test"
|
|
and .entities == ["light.kitchen", "light.desk"] and (has("token") | not)' \
|
|
<<<"$write_result" >/dev/null || fail "write returned unsafe or incorrect state: $write_result"
|
|
if rg -q "$secret|old-token|unrelated-secret" "$work/write.out" "$work/write.err"; then
|
|
fail 'credential helper output leaked a secret'
|
|
fi
|
|
|
|
[[ "$(stat -c '%a' "$env_file")" == "600" ]] || fail 'private env file is not mode 0600'
|
|
rg -Fxq "export KEEP_ME='untouched value'" "$env_file" || fail 'unrelated env content changed'
|
|
rg -Fxq "export JIRA_CREDENTIALS='unrelated-secret'" "$env_file" || fail 'unrelated secret changed'
|
|
rg -Fq "$secret" "$env_file" || fail 'new token was not stored'
|
|
|
|
# Omitting token preserves it; an explicit empty token clears it.
|
|
printf '%s\n' '{"url":"https://new.example.test","entities":"light.office, light.hall"}' \
|
|
| run_helper write >/dev/null || fail 'non-secret update failed'
|
|
rg -Fq "$secret" "$env_file" || fail 'blank token field unexpectedly erased the stored token'
|
|
|
|
printf '%s\n' '{"token":""}' | run_helper write >/dev/null || fail 'token clear failed'
|
|
cleared="$(run_helper status)"
|
|
jq -e '.configured == false and .tokenConfigured == false
|
|
and .url == "https://new.example.test"
|
|
and .entities == ["light.office", "light.hall"]' \
|
|
<<<"$cleared" >/dev/null || fail "cleared state is wrong: $cleared"
|
|
|
|
before_hash="$(sha256sum "$env_file" | cut -d' ' -f1)"
|
|
printf '%s\n' '{"url":"file:///etc/passwd"}' | run_helper write >/dev/null 2>&1 \
|
|
&& fail 'invalid URL was accepted'
|
|
after_hash="$(sha256sum "$env_file" | cut -d' ' -f1)"
|
|
[[ "$before_hash" == "$after_hash" ]] || fail 'rejected input still modified the private env file'
|
|
|
|
# Exercise the actual QML Process.write() boundary with a pre-existing token.
|
|
# The IPC carries only non-secret fields; the helper must preserve the token.
|
|
config_path="$work/quickshell"
|
|
harness="$config_path/home-assistant-config-harness.qml"
|
|
cp -a "$repo_dir/config/dot/quickshell" "$config_path"
|
|
cp "$harness_fixture" "$harness"
|
|
printf '%s\n' \
|
|
"export PANAMA_HOME_ASSISTANT_URL='https://qml-old.example.test'" \
|
|
"export PANAMA_HOME_ASSISTANT_TOKEN=''" \
|
|
"export PANAMA_HOME_ASSISTANT_ENTITIES='light.old'" >"$env_file"
|
|
chmod 0600 "$env_file"
|
|
qml_token_file="$work/qml-token"
|
|
printf '%s' 'qml-private-token' >"$qml_token_file"
|
|
chmod 0600 "$qml_token_file"
|
|
|
|
qs_for_test() {
|
|
PANAMA_HOME_ASSISTANT_ENV_FILE="$env_file" \
|
|
PANAMA_TEST_TOKEN_FILE="$qml_token_file" \
|
|
XDG_CONFIG_HOME="$work/config" XDG_STATE_HOME="$work/state" \
|
|
qs -p "$harness" "$@"
|
|
}
|
|
|
|
stop_harness() {
|
|
qs_for_test kill >/dev/null 2>&1 || true
|
|
}
|
|
|
|
qs_for_test --daemonize >/dev/null
|
|
for _ in $(seq 1 60); do
|
|
qs_for_test ipc show 2>/dev/null | rg -q '^target home-assistant-config-test$' && break
|
|
sleep 0.1
|
|
done
|
|
qs_for_test ipc show 2>/dev/null | rg -q '^target home-assistant-config-test$' \
|
|
|| fail 'credential QML harness did not start'
|
|
|
|
for _ in $(seq 1 60); do
|
|
qml_status="$(qs_for_test ipc call home-assistant-config-test status)"
|
|
jq -e '.busy == false and .url == "https://qml-old.example.test"' <<<"$qml_status" >/dev/null && break
|
|
sleep 0.1
|
|
done
|
|
jq -e '.configured == false and .tokenConfigured == false and .pendingPayloadEmpty == true' \
|
|
<<<"$qml_status" >/dev/null || fail "QML service did not load redacted state: $qml_status"
|
|
|
|
qs_for_test ipc call home-assistant-config-test saveWithToken \
|
|
https://qml-new.example.test 'light.office,light.hall' >/dev/null \
|
|
|| fail 'QML service refused a private token-file update'
|
|
for _ in $(seq 1 60); do
|
|
qml_status="$(qs_for_test ipc call home-assistant-config-test status)"
|
|
jq -e '.busy == false and .configured == true and .tokenConfigured == true
|
|
and .refreshCalls > 0' <<<"$qml_status" >/dev/null && break
|
|
sleep 0.1
|
|
done
|
|
jq -e '.configured == true and .tokenConfigured == true
|
|
and .url == "https://qml-new.example.test"
|
|
and .entities == ["light.office", "light.hall"]
|
|
and .pendingPayloadEmpty == true and .lastError == "" and .refreshCalls > 0' \
|
|
<<<"$qml_status" >/dev/null || fail "QML secret stdin save did not settle safely: $qml_status"
|
|
rg -Fq 'qml-private-token' "$env_file" || fail 'QML secret stdin save did not store the token'
|
|
if ps -o args= -p "$(qs_for_test list | awk '/Process ID:/ {print $3; exit}')" | rg -Fq 'qml-private-token'; then
|
|
fail 'QML token appeared in the shell process arguments'
|
|
fi
|
|
|
|
qs_for_test ipc call home-assistant-config-test save \
|
|
https://qml-final.example.test 'light.bedroom,light.hall' >/dev/null \
|
|
|| fail 'QML service refused a non-secret update'
|
|
for _ in $(seq 1 60); do
|
|
qml_status="$(qs_for_test ipc call home-assistant-config-test status)"
|
|
jq -e '.busy == false and .url == "https://qml-final.example.test"
|
|
and .entities == ["light.bedroom", "light.hall"]' <<<"$qml_status" >/dev/null && break
|
|
sleep 0.1
|
|
done
|
|
jq -e '.configured == true and .tokenConfigured == true
|
|
and .pendingPayloadEmpty == true and .lastError == ""' \
|
|
<<<"$qml_status" >/dev/null || fail "QML stdin save did not settle safely: $qml_status"
|
|
rg -Fq 'qml-private-token' "$env_file" || fail 'QML non-secret save erased the stored token'
|
|
|
|
qs_for_test ipc call home-assistant-config-test clearToken >/dev/null \
|
|
|| fail 'QML service refused token clear'
|
|
for _ in $(seq 1 60); do
|
|
qml_status="$(qs_for_test ipc call home-assistant-config-test status)"
|
|
jq -e '.busy == false and .tokenConfigured == false' <<<"$qml_status" >/dev/null && break
|
|
sleep 0.1
|
|
done
|
|
jq -e '.configured == false and .tokenConfigured == false
|
|
and .pendingPayloadEmpty == true and .lastError == ""' \
|
|
<<<"$qml_status" >/dev/null || fail "QML token clear did not settle safely: $qml_status"
|
|
if rg -Fq 'qml-private-token' "$env_file"; then
|
|
fail 'QML token clear left the old token in the private env file'
|
|
fi
|
|
stop_harness
|
|
|
|
trap - EXIT
|
|
cleanup
|
|
printf 'Home Assistant config contract: PASS\n'
|