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
30 changes: 24 additions & 6 deletions nixos/home/laptop-repo-keeper.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,18 @@ printf 'upstream\n' >>"$ADV2/flake.lock"
git -C "$ADV2" commit -q -am upstream
git -C "$ADV2" push -q origin main
local_head_before="$(git -C "$R11" rev-parse HEAD)"
short_hash="$(git -C "$R11" rev-parse --short HEAD)"
rbranch="rebuild/$(hostname -s)-$short_hash"
run_keeper "$H11" "$TMP_ROOT/diverged.log"
# The keeper names the branch rebuild/<host>-<short HEAD> from its OWN
# hostname lookup (with a 'host' fallback when the lookup fails). This
# suite must not repeat that lookup to predict the name: the two calls
# are independent, and under load one can fail while the other
# succeeds, leaving the suite expecting rebuild/-<hash> for a branch
# the keeper pushed under a different name (code#17813). Discover the
# pushed branch from the bare origin instead: exactly one rebuild/*
# branch may exist, pointing at the local HEAD.
rbranch="$(git --git-dir="$ORIGIN2_BARE" for-each-ref --format='%(refname:short)' 'refs/heads/rebuild/*')"
check 'diverged case: exactly one rebuild branch pushed' \
"1" "$(git --git-dir="$ORIGIN2_BARE" for-each-ref 'refs/heads/rebuild/*' | wc -l)"
check 'diverged case: local commits pushed to the rebuild branch' \
"$local_head_before" "$(git --git-dir="$ORIGIN2_BARE" rev-parse "$rbranch")"
check 'diverged case: local main untouched' \
Expand All @@ -279,10 +288,19 @@ git -C "$ADV2" commit -q -am 'upstream again'
git -C "$ADV2" push -q origin main
printf 'uncommitted edit\n' >>"$R12/flake.lock"
run_keeper "$H12" "$TMP_ROOT/diverged-dirty.log"
dirty_short="$(git -C "$R12" rev-parse --short HEAD)"
if git --git-dir="$ORIGIN2_BARE" rev-parse -q --verify "rebuild/$(hostname -s)-$dirty_short" >/dev/null; then
fail 'diverged-dirty case: dirty tree pushed a rebuild branch'
fi
# Same discovery rule as the clean case (code#17813): the dirty tree's
# HEAD must not appear on any rebuild/* branch in the bare origin
# (the one rebuild branch there is the clean case's, at a different
# commit).
dirty_head="$(git -C "$R12" rev-parse HEAD)"
while IFS= read -r ref; do
[ -n "$ref" ] || continue
if [ "$(git --git-dir="$ORIGIN2_BARE" rev-parse "$ref")" = "$dirty_head" ]; then
fail 'diverged-dirty case: dirty tree pushed a rebuild branch'
fi
done <<EOF_REFS
$(git --git-dir="$ORIGIN2_BARE" for-each-ref --format='%(refname)' 'refs/heads/rebuild/*')
EOF_REFS
grep -Fq -- 'DIVERGED' "$TMP_ROOT/diverged-dirty.log" ||
fail 'diverged-dirty case: report missing diverged line'

Expand Down
18 changes: 17 additions & 1 deletion nixos/home/oc-password-sync.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,23 @@ grep -q "periodic: openchamber not running" "$LOGF" || fail "3: log should say w
# A stand-in OpenChamber process holding the OLD password.
env OPENCODE_PASSWORD=old-secret sleep 300 &
STANDIN_PID=$!
sleep 0.2
# Wait until the stand-in is actually observable the way the script
# observes it: /proc/<pid>/environ readable AND already holding
# OPENCODE_PASSWORD. A fixed sleep races the stand-in's exec under
# load — before exec, its environ is still this shell's (no
# OPENCODE_PASSWORD), so the script intermittently saw an empty
# current password and reported a running OpenChamber as not running
# (code#17813). Poll for the real condition instead, and fail loudly
# if it never materialises.
standin_ready=0
for _ in $(seq 1 100); do
if [ -r "/proc/$STANDIN_PID/environ" ] && tr '\0' '\n' <"/proc/$STANDIN_PID/environ" 2>/dev/null | grep -q '^OPENCODE_PASSWORD='; then
standin_ready=1
break
fi
sleep 0.1
done
[ "$standin_ready" -eq 1 ] || fail "stand-in OpenChamber (pid $STANDIN_PID) never presented OPENCODE_PASSWORD in /proc environ"

# 4. periodic run, running OpenChamber holds a stale password
out=$(FAKE_MAINPID=$STANDIN_PID run_sync env OC_SYNC_PERIODIC=1)
Expand Down