fix(scripts): resolve race condition in state-sync and mark stress test as complete
All checks were successful
Check / eval-and-lint (push) Successful in 7m9s

This commit is contained in:
Bernardo Magri
2026-06-01 18:48:17 +01:00
parent d242d1ea88
commit 6ed2ca3d78
3 changed files with 12 additions and 13 deletions

View File

@@ -90,20 +90,18 @@ LOCK_FILE="${STATE_FILE}.lock"
# Validate JSON before moving
if jq empty "$TMP_FILE" 2>/dev/null; then
mv "$TMP_FILE" "$STATE_FILE"
# Sync to the Nix configuration while still holding the lock.
# This prevents desyncs where a newer JSON state is overwritten by an
# older Nix state during concurrent writes.
if [[ "$STATE_FILE" == "$HOME/.config/nomarchy/state.json" ]]; then
if command -v nomarchy-sync-nix-state >/dev/null 2>&1; then
nomarchy-sync-nix-state
fi
fi
else
echo "Error: Failed to generate valid JSON"
exit 1
fi
) 200>"$LOCK_FILE"
# Clean up lock file
rm -f "$LOCK_FILE"
# If we just updated the main home state file, sync it to the Nix configuration.
# This bridges the gap between runtime UI changes and declarative Nix.
if [[ "$STATE_FILE" == "$HOME/.config/nomarchy/state.json" ]]; then
if command -v nomarchy-sync-nix-state >/dev/null 2>&1; then
nomarchy-sync-nix-state
fi
fi