Skip to content
Merged
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
6 changes: 5 additions & 1 deletion nixos/home/pm-dashboard-backup-date.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ run_scenario() {
printf '{}\n' >"$home/.local/state/pm-aggregator/actions.json"
# Full required set (#1025): a missing required member now fails
# the run at verify, so the fixture carries every required file.
for f in comments.json fleet-feed.json quota-current.json registry.json quota-gatherer-state.json quota-gatherer-heartbeat.json; do printf '{}\n' >"$home/.local/state/pm-aggregator/$f"; done
for f in actions.json comments.json fleet-feed.json quota-current.json registry.json \
quota-gatherer-state.json quota-gatherer-heartbeat.json events.json \
coverage-snapshot.json aa-last-good.json; do
printf '{}\n' >"$home/.local/state/pm-aggregator/$f"
done
Comment on lines 90 to +97
printf '{}\n' >"$home/atlas/meta-quota-export/latest.json"
printf '{}\n' >"$home/atlas/meta-quota-export/history.jsonl"
HOME="$home" PATH="$BIN:$PATH" BWS_ACCESS_TOKEN="<redacted>" \
Expand Down
25 changes: 18 additions & 7 deletions nixos/home/pm-dashboard-backup-manifest.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
# whatever staging produced — a dataset member deleted/renamed at
# the source silently shrank the backup set with every check green.
# The script now declares the expected set once (EXPECTED_SET):
# 7 aggregator state files + 2 meta-quota-export files are REQUIRED,
# db-dumps is required when the DB dump step ran (optional when it
# did not), and the snapshots tree + 3 journal logs are OPTIONAL.
# 10 aggregator state files are REQUIRED, meta-quota-export files are
# OPTIONAL, and db-dumps is required when the DB dump step ran
# (optional when it did not). The snapshots tree + 2 journal logs are
# OPTIONAL.
# manifest.json records every member's status, and the verify step
# fails the run — naming the member, before any upload, cursor
# unchanged — when a required member is missing.
Expand Down Expand Up @@ -62,6 +63,7 @@ STUB

{ printf '#!%s\n' "$BASH"; cat <<'STUB'
echo "stub journal line"
printf '%s\n' "$*" >>"$HOME/.journalctl-calls"
exit 0
STUB
} >"$BIN/journalctl"
Expand Down Expand Up @@ -199,6 +201,7 @@ assert_member deleted-required aggregator/registry.json required missing

# --- missing-optional completes and is recorded -------------------------------
setup_home missing-optional
rm -rf "$RUN_HOME/atlas/meta-quota-export"
run_backup missing-optional
if [[ "$RC" -eq 0 ]]; then
ok "missing-optional: script exited 0"
Expand All @@ -213,16 +216,22 @@ fi
assert_member missing-optional aggregator/snapshots optional missing
assert_member missing-optional db-dumps optional missing
assert_member missing-optional aggregator/actions.json required present
assert_member missing-optional meta-quota-export/history.jsonl required present
assert_member missing-optional meta-quota-export/latest.json optional missing
assert_member missing-optional meta-quota-export/history.jsonl optional missing
assert_member missing-optional journals/pm-aggregator.log optional present
if grep -q -- 'meta-quota-export.service' "$RUN_HOME/.journalctl-calls"; then
fail "missing-optional: retired meta-quota-export journal was queried"
else
ok "missing-optional: retired meta-quota-export journal was not queried"
fi
if manifest_json missing-optional | python3 -c '
import json, sys
m = json.load(sys.stdin)
sys.exit(0 if len(m.get("expected", [])) == 20 else 1)
sys.exit(0 if len(m.get("expected", [])) == 19 else 1)
'; then
ok "missing-optional: manifest lists all 20 expected members"
ok "missing-optional: manifest lists all 19 expected members"
else
fail "missing-optional: manifest expected list is not the full 20-member set"
fail "missing-optional: manifest expected list is not the full 19-member set"
fi

# --- dump step ran but produced no dir: conditionally required ----------------
Expand Down Expand Up @@ -250,6 +259,8 @@ else
fail "dump-ran-with-dir: expected exit 0, got $RC; log: $(cat "$TMP_ROOT/dump-ran-with-dir.log")"
fi
assert_member dump-ran-with-dir db-dumps required present
assert_member dump-ran-with-dir meta-quota-export/latest.json optional present
assert_member dump-ran-with-dir meta-quota-export/history.jsonl optional present

if (( failures > 0 )); then
echo "pm-dashboard-backup manifest tests: $failures failure(s)" >&2
Expand Down
3 changes: 2 additions & 1 deletion nixos/home/pm-dashboard-backup-prune.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ mkdir -p "$HOME_DIR/.local/state/pm-aggregator" "$HOME_DIR/atlas/meta-quota-expo

# --- fixture data set -------------------------------------------------------
for f in actions.json comments.json fleet-feed.json quota-current.json \
registry.json quota-gatherer-state.json quota-gatherer-heartbeat.json; do
registry.json quota-gatherer-state.json quota-gatherer-heartbeat.json \
events.json coverage-snapshot.json aa-last-good.json; do
echo "{\"fixture\": \"$f\"}" > "$HOME_DIR/.local/state/pm-aggregator/$f"
done
echo '{"fixture": "latest"}' > "$HOME_DIR/atlas/meta-quota-export/latest.json"
Expand Down
18 changes: 8 additions & 10 deletions nixos/home/pm-dashboard-backup-record.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ chmod +x "$BIN/bws" "$BIN/journalctl" "$BIN/rclone"
run_scenario() {
local name="$1" fail_mode="$2" dump_mode="${3:-absent}"
local home="$TMP_ROOT/$name/home"
mkdir -p "$home/backups/dashboard" "$home/.local/state/pm-aggregator" \
"$home/atlas/meta-quota-export"
mkdir -p "$home/backups/dashboard" "$home/.local/state/pm-aggregator"
local dump_script="$home/no-such-dump-script.sh"
if [[ $dump_mode == "ok" ]]; then
dump_script="$home/dump-ok.sh"
Expand All @@ -116,11 +115,11 @@ run_scenario() {
} >"$dump_script"
chmod +x "$dump_script"
fi
for f in actions.json comments.json fleet-feed.json quota-current.json registry.json quota-gatherer-state.json quota-gatherer-heartbeat.json; do
for f in actions.json comments.json fleet-feed.json quota-current.json registry.json \
quota-gatherer-state.json quota-gatherer-heartbeat.json events.json \
coverage-snapshot.json aa-last-good.json; do
printf '{}\n' >"$home/.local/state/pm-aggregator/$f"
done
printf '{}\n' >"$home/atlas/meta-quota-export/latest.json"
printf '{}\n' >"$home/atlas/meta-quota-export/history.jsonl"
HOME="$home" PATH="$BIN:$PATH" BWS_ACCESS_TOKEN="<redacted>" \
RCLONE_FAIL="$fail_mode" RCLONE_STUB_DIR="$TMP_ROOT/$name/rclone-store" \
PM_DB_DUMP_SCRIPT="$dump_script" \
Expand Down Expand Up @@ -202,13 +201,12 @@ check_record r2fail "$TMP_ROOT/assert-r2fail.py"
# exit_code 143 -- never a fresh "complete" record the watchdog would
# accept as healthy (Codex finding on PR 2989).
sig_home="$TMP_ROOT/sigterm/home"
mkdir -p "$sig_home/backups/dashboard" "$sig_home/.local/state/pm-aggregator" \
"$sig_home/atlas/meta-quota-export"
for f in actions.json comments.json fleet-feed.json quota-current.json registry.json quota-gatherer-state.json quota-gatherer-heartbeat.json; do
mkdir -p "$sig_home/backups/dashboard" "$sig_home/.local/state/pm-aggregator"
for f in actions.json comments.json fleet-feed.json quota-current.json registry.json \
quota-gatherer-state.json quota-gatherer-heartbeat.json events.json \
coverage-snapshot.json aa-last-good.json; do
printf '{}\n' >"$sig_home/.local/state/pm-aggregator/$f"
done
printf '{}\n' >"$sig_home/atlas/meta-quota-export/latest.json"
printf '{}\n' >"$sig_home/atlas/meta-quota-export/history.jsonl"
setsid env HOME="$sig_home" PATH="$BIN:$PATH" BWS_ACCESS_TOKEN="<redacted>" \
BWS_BLOCK=1 BWS_BLOCK_MARKER="$TMP_ROOT/sigterm.blocked" \
RCLONE_STUB_DIR="$TMP_ROOT/sigterm/rclone-store" \
Expand Down
17 changes: 8 additions & 9 deletions nixos/home/pm-dashboard-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ mkdir -p "$STAGE/aggregator" "$STAGE/meta-quota-export" "$STAGE/journals" "$OUTD
# the source silently shrank the backup set. Classes preserve the
# intent the staging code below has always had: existing state files
# are required (their WARN-for-missing becomes a failed run at verify);
# the snapshots tree and the journal logs are optional (journals keep
# their tolerated-unavailable placeholder, but are now recorded);
# db-dumps is CONDITIONALLY required — required when the DB dump step
# ran (DUMP_RAN=1), optional otherwise.
# retired meta-quota-export files, the snapshots tree and active journal
# logs are optional; journals keep their tolerated-unavailable
# placeholder, but are now recorded; db-dumps is CONDITIONALLY required
# — required when the DB dump step ran (DUMP_RAN=1), optional otherwise.
EXPECTED_SET="required file aggregator/actions.json
required file aggregator/comments.json
required file aggregator/fleet-feed.json
Expand All @@ -338,14 +338,13 @@ required file aggregator/coverage-snapshot.json
required file aggregator/aa-last-good.json
optional file aggregator/views.json
optional tree aggregator/charge-inputs
required file meta-quota-export/latest.json
required file meta-quota-export/history.jsonl
optional file meta-quota-export/latest.json
optional file meta-quota-export/history.jsonl
conditional tree db-dumps
conditional file projector/pmp_links.sql
optional tree aggregator/snapshots
optional file journals/pm-aggregator.log
optional file journals/quota-gatherer.log
optional file journals/meta-quota-export.log"
optional file journals/quota-gatherer.log"

# --- data set (explicit list only; the aggregator .env is deliberately NOT
# --- included — no config/secret files belong in this archive) ---
Expand Down Expand Up @@ -434,7 +433,7 @@ case "$LAST" in *[!0-9]* | "") LAST=0 ;; esac
W=$((NOW_EPOCH - 86400))
if [ "$LAST" -gt 0 ] && [ "$LAST" -lt "$W" ]; then W="$LAST"; fi
SINCE_STR="$(date -d "@$W" '+%F %T')"
for svc in pm-aggregator quota-gatherer meta-quota-export; do
for svc in pm-aggregator quota-gatherer; do
journalctl --user -u "$svc.service" --since "$SINCE_STR" --no-pager -o short-iso \
>"$STAGE/journals/$svc.log" 2>/dev/null ||
echo "(journal unavailable for $svc)" >"$STAGE/journals/$svc.log"
Expand Down
12 changes: 10 additions & 2 deletions nixos/home/pm-dashboard-backup.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ run_scenario() {
printf '{}\n' >"$home/.local/state/pm-aggregator/actions.json"
# Full required set (#1025): a missing required member now fails
# the run at verify, so the fixture carries every required file.
for f in comments.json fleet-feed.json quota-current.json registry.json quota-gatherer-state.json quota-gatherer-heartbeat.json; do printf '{}\n' >"$home/.local/state/pm-aggregator/$f"; done
for f in actions.json comments.json fleet-feed.json quota-current.json registry.json \
quota-gatherer-state.json quota-gatherer-heartbeat.json events.json \
coverage-snapshot.json aa-last-good.json; do
printf '{}\n' >"$home/.local/state/pm-aggregator/$f"
done
Comment on lines 105 to +112
printf '{}\n' >"$home/atlas/meta-quota-export/latest.json"
printf '{}\n' >"$home/atlas/meta-quota-export/history.jsonl"
echo "$PRESET" >"$home/backups/dashboard/.last-run-epoch"
Expand Down Expand Up @@ -160,7 +164,11 @@ mkdir -p "$tf_home/backups/dashboard" "$tf_home/.local/state/pm-aggregator" \
printf '{}\n' >"$tf_home/.local/state/pm-aggregator/actions.json"
# Full required set (#1025): a missing required member now fails
# the run at verify, so the fixture carries every required file.
for f in comments.json fleet-feed.json quota-current.json registry.json quota-gatherer-state.json quota-gatherer-heartbeat.json; do printf '{}\n' >"$tf_home/.local/state/pm-aggregator/$f"; done
for f in actions.json comments.json fleet-feed.json quota-current.json registry.json \
quota-gatherer-state.json quota-gatherer-heartbeat.json events.json \
coverage-snapshot.json aa-last-good.json; do
printf '{}\n' >"$tf_home/.local/state/pm-aggregator/$f"
done
Comment on lines 164 to +171
printf '{}\n' >"$tf_home/atlas/meta-quota-export/latest.json"
printf '{}\n' >"$tf_home/atlas/meta-quota-export/history.jsonl"
HOME="$tf_home" PATH="$TARBIN:$BIN:$PATH" BWS_ACCESS_TOKEN="<redacted>" \
Expand Down
Loading