Commit 7a001c4

Eric Bower  ·  2026-08-11 11:04:23 -0400 EDT
parent e4e7ad7
fix(daemon): sync pwd on IPC queries and add wait_for_cwd test helper

Ensure daemon.cwd is updated from the terminal emulator state when handling
IPC Info and History requests. This prevents zmx list from reporting stale
working directory state if queried before the PTY read loop calls setPwd.

Also add a deterministic wait_for_cwd helper to test_helper.bash so BATS
OSC 7 tests poll zmx list until the expected CWD is populated, fixing host-side
test race conditions.
3 files changed,  +22, -3
+6, -3
......@@ -469,7 +469,7 @@ fn daemonLoop(daemon: *Daemon, gpa: std.mem.Allocator, io: std.Io, server_sock_f
469469 .Kill => {
470470 break :daemon_loop;
471471 },
472- .Info => try daemon.handleInfo(gpa, client),
472+ .Info => try daemon.handleInfo(gpa, client, &term),
473473 .LabelGet => try daemon.handleLabelGet(gpa, client),
474474 .LabelSet => try daemon.handleLabelSet(gpa, client, msg.payload),
475475 .LabelClear => try daemon.handleLabelClear(gpa, client),
......@@ -1036,7 +1036,9 @@ pub const Daemon = struct {
10361036 };
10371037 }
10381038
1039- pub fn handleInfo(self: *Daemon, gpa: std.mem.Allocator, client: *Client) !void {
1039+ pub fn handleInfo(self: *Daemon, gpa: std.mem.Allocator, client: *Client, term: *ghostty_vt.Terminal) !void {
1040+ self.setPwd(term);
1041+
10401042 // zeroes() so asBytes() doesn't ship struct padding + unused cmd/cwd
10411043 // tail bytes (daemon stack contents) to clients.
10421044 var info = std.mem.zeroes(ipc.Info);
......@@ -1085,12 +1087,13 @@ pub const Daemon = struct {
10851087 }
10861088
10871089 pub fn handleHistory(
1088- _: *Daemon,
1090+ self: *Daemon,
10891091 gpa: std.mem.Allocator,
10901092 client: *Client,
10911093 term: *ghostty_vt.Terminal,
10921094 payload: []const u8,
10931095 ) !void {
1096+ self.setPwd(term);
10941097 const format: util.HistoryFormat = if (payload.len > 0)
10951098 @enumFromInt(payload[0])
10961099 else
+2, -0
......@@ -28,6 +28,7 @@ osc7_session() {
2828 osc7_session test-cwd-uri "$dir"
2929 wait_for_session test-cwd-uri
3030 wait_for_output test-cwd-uri marker-test-cwd-uri
31+ wait_for_cwd test-cwd-uri "cwd=file://$(hostname)${dir// /%20}"
3132
3233 run "$ZMX" list
3334 [ "$status" -eq 0 ]
......@@ -39,6 +40,7 @@ osc7_session() {
3940 "printf '\033]7;file://some-remote-box/home/me\007marker-remote\n'; sleep 30"
4041 wait_for_session test-cwd-remote
4142 wait_for_output test-cwd-remote marker-remote
43+ wait_for_cwd test-cwd-remote "cwd=file://some-remote-box/home/me"
4244
4345 run "$ZMX" list
4446 [ "$status" -eq 0 ]
+14, -0
......@@ -54,3 +54,17 @@ wait_for_output() {
5454 echo "Timed out waiting for output '$marker' in session '$name'" >&2
5555 return 1
5656 }
57+
58+# Helper: wait for a session's cwd to match expected substring (up to N seconds).
59+wait_for_cwd() {
60+ local name="$1" pattern="$2" timeout="${3:-5}" i=0
61+ while (( i < timeout * 10 )); do
62+ if "$ZMX" list 2>/dev/null | grep -F "name=$name" | grep -qF "$pattern"; then
63+ return 0
64+ fi
65+ sleep 0.1
66+ (( i++ )) || true
67+ done
68+ echo "Timed out waiting for cwd '$pattern' in session '$name'" >&2
69+ return 1
70+}