Skip to content

The agent that grows with you

fix(desktop-update): read macOS creation times with /bin/date under GNU coreutils

PRATHAMESH7552223a33d21d
diff --git a/scripts/desktop-update/marker.sh b/scripts/desktop-update/marker.sh
index bbf05693cc2..c7f6bd59d08 100644
--- a/scripts/desktop-update/marker.sh
+++ b/scripts/desktop-update/marker.sh
@@ -51,10 +51,12 @@ proc_ct() { # pid -> creation time (unix seconds, 3 decimals), or nothing
LC_ALL=C awk -v b="$btime" -v s="$start" -v h="$hz" 'BEGIN{printf "%.3f\n", b + s / h}'
elif [ "$(uname)" = "Darwin" ]; then
# ps prints lstart in local time: render AND parse it in UTC so a DST
- # fall-back hour cannot shift the identity by 3600 s.
+ # fall-back hour cannot shift the identity by 3600 s. `-j -f` is BSD-only:
+ # pin /bin/date so GNU coreutils first on the login PATH (Homebrew gnubin)
+ # cannot blank every creation time and fail the bridge-marker claim (#137925).
lstart="$(TZ=UTC0 LC_ALL=C ps -o lstart= -p "$pid" 2>/dev/null | sed 's/^ *//;s/ *$//')"
[ -n "$lstart" ] || return 0
- secs="$(TZ=UTC0 LC_ALL=C date -j -f '%a %b %e %T %Y' "$lstart" +%s 2>/dev/null)" || return 0
+ secs="$(TZ=UTC0 LC_ALL=C /bin/date -j -f '%a %b %e %T %Y' "$lstart" +%s 2>/dev/null)" || return 0
[ -n "$secs" ] && printf '%s.000\n' "$secs"
fi
}
diff --git a/tests/scripts/desktop_update/test_desktop_update_marker_gnu_date.py b/tests/scripts/desktop_update/test_desktop_update_marker_gnu_date.py
new file mode 100644
index 00000000000..7fc0de44905
--- /dev/null
+++ b/tests/scripts/desktop_update/test_desktop_update_marker_gnu_date.py
@@ -0,0 +1,51 @@
+"""marker.sh reads macOS creation times with BSD date even under GNU coreutils (#137925).
+
+Desktop hands the update off with the user's login-shell PATH. With Homebrew's
+coreutils `gnubin` first on it, a bare `date` is GNU date, which has no `-j`:
+`proc_ct` printed nothing, the bridge-marker identity check refused the claim and
+`posix.sh` exited 2 on every update. A `date` that rejects `-j` sits first on
+PATH here; the creation time must still match the one read with the system PATH.
+"""
+
+from __future__ import annotations
+
+import os
+from pathlib import Path
+import shlex
+import subprocess
+
+import pytest
+
+MARKER_SH = Path(__file__).resolve().parents[3] / "scripts" / "desktop-update" / "marker.sh"
+
+
+def _proc_ct(path: str) -> str:
+ script = f"log() {{ :; }}; . {shlex.quote(str(MARKER_SH))}; proc_ct {os.getpid()}"
+ proc = subprocess.run(
+ ["/bin/bash", "-c", script],
+ capture_output=True,
+ text=True,
+ timeout=60,
+ check=False,
+ env={**os.environ, "PATH": path},
+ )
+ assert proc.returncode == 0, proc.stderr
+ return proc.stdout.strip()
+
+
+def test_proc_ct_ignores_a_gnu_date_first_on_path(tmp_path):
+ gnubin = tmp_path / "gnubin"
+ gnubin.mkdir()
+ fake = gnubin / "date"
+ fake.write_text(
+ '#!/bin/sh\nfor a in "$@"; do [ "$a" = -j ] && { echo "date: invalid option -- \'j\'" >&2; exit 1; }; done\n'
+ 'exec /bin/date "$@"\n',
+ encoding="utf-8",
+ )
+ fake.chmod(0o755)
+
+ system_path = "/usr/bin:/bin:/usr/sbin:/sbin"
+ baseline = _proc_ct(system_path)
+ assert baseline, "proc_ct must read a creation time with the system PATH"
+ assert _proc_ct(f"{gnubin}:{system_path}") == baseline