Some checks failed
CI / skinny-install (aco) (push) Successful in 1m18s
CI / skinny-install (api) (push) Successful in 40s
CI / skinny-install (bcda) (push) Successful in 35s
CI / skinny-install (bib) (push) Successful in 38s
CI / skinny-install (cli) (push) Successful in 46s
CI / skinny-install (conf) (push) Successful in 36s
CI / skinny-install (opps) (push) Successful in 38s
CI / skinny-install (pfs) (push) Successful in 47s
CI / skinny-install (rex) (push) Successful in 35s
Infra CI / notebooks (push) Successful in 3m17s
CI / lint-test (push) Failing after 3m30s
CI / skinny-install (bls) (push) Successful in 34s
CI / skinny-install (ccw) (push) Successful in 45s
CI / skinny-install (cms) (push) Successful in 32s
CI / skinny-install (perf) (push) Successful in 43s
Deploy / build-scan-report (push) Has been cancelled
Infra CI / docs (push) Failing after 20s
Infra CI / api (push) Successful in 16s
Infra CI / mc (push) Successful in 12s
Package Supply Chain / pkg-supply-chain (push) Successful in 1m27s
Infra CI / zotero (push) Successful in 6m10s
148 lines
3.5 KiB
Bash
148 lines
3.5 KiB
Bash
#!/usr/bin/env bats
|
|
# Tests for state management (resume, checkpointing)
|
|
|
|
load test_helper
|
|
|
|
setup() {
|
|
setup_test_work
|
|
source_nanny_functions
|
|
}
|
|
|
|
teardown() {
|
|
teardown_test_work
|
|
}
|
|
|
|
# ─── state_done ───
|
|
|
|
@test "state_done returns false for unmarked state" {
|
|
run state_done "drive_sata_1"
|
|
assert_failure
|
|
}
|
|
|
|
@test "state_done returns true for marked state" {
|
|
echo "drive_sata_1" >> "$STATE"
|
|
run state_done "drive_sata_1"
|
|
assert_success
|
|
}
|
|
|
|
@test "state_done is exact match — partial names don't match" {
|
|
echo "drive_sata_1" >> "$STATE"
|
|
run state_done "drive_sata_10"
|
|
assert_failure
|
|
}
|
|
|
|
@test "state_done is exact match — substrings don't match" {
|
|
echo "drive_sata_1" >> "$STATE"
|
|
run state_done "drive_sata"
|
|
assert_failure
|
|
}
|
|
|
|
@test "state_done works with empty state file" {
|
|
> "$STATE"
|
|
run state_done "anything"
|
|
assert_failure
|
|
}
|
|
|
|
@test "state_done works when state file missing" {
|
|
rm -f "$STATE"
|
|
run state_done "anything"
|
|
assert_failure
|
|
}
|
|
|
|
# ─── state_mark ───
|
|
|
|
@test "state_mark writes step to state file" {
|
|
state_mark "drive_sata_1"
|
|
run grep -x "drive_sata_1" "$STATE"
|
|
assert_success
|
|
}
|
|
|
|
@test "state_mark writes timestamp to log" {
|
|
state_mark "drive_sata_1"
|
|
run grep "STATE: drive_sata_1 completed" "$LOG"
|
|
assert_success
|
|
}
|
|
|
|
@test "state_mark is idempotent — no duplicate entries" {
|
|
state_mark "drive_sata_1"
|
|
state_mark "drive_sata_1"
|
|
state_mark "drive_sata_1"
|
|
local count
|
|
count=$(grep -cx "drive_sata_1" "$STATE")
|
|
assert_equal "$count" "1"
|
|
}
|
|
|
|
@test "state_mark preserves existing state" {
|
|
state_mark "phase1_init"
|
|
state_mark "drive_sata_1"
|
|
state_mark "drive_sata_2"
|
|
run grep -c "." "$STATE"
|
|
assert_output "3"
|
|
}
|
|
|
|
# ─── Resume scenarios ───
|
|
|
|
@test "resume: all phase 1 drive states are checkpointed independently" {
|
|
local steps=(
|
|
"phase1_init"
|
|
"drive_sata_1" "drive_sata_2" "drive_sata_3"
|
|
"drive_sata_4" "drive_sata_5" "drive_sata_6"
|
|
"drive_nvme" "drive_hdd"
|
|
"phase1_resolver"
|
|
)
|
|
for step in "${steps[@]}"; do
|
|
state_mark "$step"
|
|
done
|
|
for step in "${steps[@]}"; do
|
|
run state_done "$step"
|
|
assert_success
|
|
done
|
|
}
|
|
|
|
@test "resume: partial state correctly identifies remaining work" {
|
|
state_mark "phase1_init"
|
|
state_mark "drive_sata_1"
|
|
state_mark "drive_sata_2"
|
|
# drives 3-6, nvme, hdd should be pending
|
|
run state_done "drive_sata_3"
|
|
assert_failure
|
|
run state_done "drive_nvme"
|
|
assert_failure
|
|
run state_done "drive_hdd"
|
|
assert_failure
|
|
}
|
|
|
|
@test "resume: cloudflare steps are independent of drive steps" {
|
|
state_mark "cf_account"
|
|
state_mark "cf_tunnel"
|
|
run state_done "cf_account"
|
|
assert_success
|
|
run state_done "cf_routes"
|
|
assert_failure
|
|
run state_done "drive_sata_1"
|
|
assert_failure
|
|
}
|
|
|
|
@test "resume: state file survives across source reloads" {
|
|
state_mark "drive_sata_1"
|
|
state_mark "yubikey_1"
|
|
# Re-source functions (simulates script restart)
|
|
source_nanny_functions
|
|
run state_done "drive_sata_1"
|
|
assert_success
|
|
run state_done "yubikey_1"
|
|
assert_success
|
|
}
|
|
|
|
@test "state file ordering is preserved" {
|
|
state_mark "phase1_init"
|
|
state_mark "drive_sata_1"
|
|
state_mark "drive_sata_2"
|
|
local first_line
|
|
first_line=$(head -1 "$STATE")
|
|
assert_equal "$first_line" "phase1_init"
|
|
local third_line
|
|
third_line=$(sed -n '3p' "$STATE")
|
|
assert_equal "$third_line" "drive_sata_2"
|
|
}
|