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
1@@ -469,7 +469,7 @@ fn daemonLoop(daemon: *Daemon, gpa: std.mem.Allocator, io: std.Io, server_sock_f
2 .Kill => {
3 break :daemon_loop;
4 },
5- .Info => try daemon.handleInfo(gpa, client),
6+ .Info => try daemon.handleInfo(gpa, client, &term),
7 .LabelGet => try daemon.handleLabelGet(gpa, client),
8 .LabelSet => try daemon.handleLabelSet(gpa, client, msg.payload),
9 .LabelClear => try daemon.handleLabelClear(gpa, client),
10@@ -1036,7 +1036,9 @@ pub const Daemon = struct {
11 };
12 }
13
14- pub fn handleInfo(self: *Daemon, gpa: std.mem.Allocator, client: *Client) !void {
15+ pub fn handleInfo(self: *Daemon, gpa: std.mem.Allocator, client: *Client, term: *ghostty_vt.Terminal) !void {
16+ self.setPwd(term);
17+
18 // zeroes() so asBytes() doesn't ship struct padding + unused cmd/cwd
19 // tail bytes (daemon stack contents) to clients.
20 var info = std.mem.zeroes(ipc.Info);
21@@ -1085,12 +1087,13 @@ pub const Daemon = struct {
22 }
23
24 pub fn handleHistory(
25- _: *Daemon,
26+ self: *Daemon,
27 gpa: std.mem.Allocator,
28 client: *Client,
29 term: *ghostty_vt.Terminal,
30 payload: []const u8,
31 ) !void {
32+ self.setPwd(term);
33 const format: util.HistoryFormat = if (payload.len > 0)
34 @enumFromInt(payload[0])
35 else
+2,
-0
1@@ -28,6 +28,7 @@ osc7_session() {
2 osc7_session test-cwd-uri "$dir"
3 wait_for_session test-cwd-uri
4 wait_for_output test-cwd-uri marker-test-cwd-uri
5+ wait_for_cwd test-cwd-uri "cwd=file://$(hostname)${dir// /%20}"
6
7 run "$ZMX" list
8 [ "$status" -eq 0 ]
9@@ -39,6 +40,7 @@ osc7_session() {
10 "printf '\033]7;file://some-remote-box/home/me\007marker-remote\n'; sleep 30"
11 wait_for_session test-cwd-remote
12 wait_for_output test-cwd-remote marker-remote
13+ wait_for_cwd test-cwd-remote "cwd=file://some-remote-box/home/me"
14
15 run "$ZMX" list
16 [ "$status" -eq 0 ]
+14,
-0
1@@ -54,3 +54,17 @@ wait_for_output() {
2 echo "Timed out waiting for output '$marker' in session '$name'" >&2
3 return 1
4 }
5+
6+# Helper: wait for a session's cwd to match expected substring (up to N seconds).
7+wait_for_cwd() {
8+ local name="$1" pattern="$2" timeout="${3:-5}" i=0
9+ while (( i < timeout * 10 )); do
10+ if "$ZMX" list 2>/dev/null | grep -F "name=$name" | grep -qF "$pattern"; then
11+ return 0
12+ fi
13+ sleep 0.1
14+ (( i++ )) || true
15+ done
16+ echo "Timed out waiting for cwd '$pattern' in session '$name'" >&2
17+ return 1
18+}