@native-sdk/cli 0.5.4 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/build/app.zig +50 -1
  2. package/build.zig +588 -32
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +3 -1
  5. package/package.json +9 -9
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/rt/rt.zig +280 -8
  9. package/packages/core/sdk/core.ts +481 -2
  10. package/packages/core/sdk/events.ts +17 -8
  11. package/packages/core/src/checker.ts +305 -2
  12. package/packages/core/src/diagnostics.ts +12 -0
  13. package/packages/core/src/emitter.ts +599 -3
  14. package/packages/core/src/typed_ast.ts +51 -4
  15. package/packages/core/src/types.ts +34 -1
  16. package/skill-data/native-ui/SKILL.md +39 -2
  17. package/skill-data/ts-core/SKILL.md +4 -2
  18. package/src/app_runner/root.zig +32 -10
  19. package/src/automation/layout_fingerprint.zig +160 -0
  20. package/src/automation/protocol.zig +82 -33
  21. package/src/automation/root.zig +1 -0
  22. package/src/automation/server.zig +1 -1
  23. package/src/automation/snapshot.zig +68 -9
  24. package/src/automation/watcher.zig +1 -1
  25. package/src/embed/host.zig +5 -0
  26. package/src/embed/ui_host.zig +13 -0
  27. package/src/platform/linux/gtk_host.c +527 -13
  28. package/src/platform/linux/gtk_host.h +25 -0
  29. package/src/platform/linux/root.zig +280 -7
  30. package/src/platform/macos/appkit_host.h +104 -6
  31. package/src/platform/macos/appkit_host.m +1368 -74
  32. package/src/platform/macos/cef_host.mm +110 -1
  33. package/src/platform/macos/root.zig +287 -7
  34. package/src/platform/null_platform.zig +398 -4
  35. package/src/platform/null_platform_tests.zig +35 -0
  36. package/src/platform/root.zig +9 -0
  37. package/src/platform/types.zig +386 -14
  38. package/src/platform/windows/root.zig +298 -9
  39. package/src/platform/windows/webview2_host.cpp +330 -5
  40. package/src/primitives/app_manifest/validation.zig +18 -0
  41. package/src/primitives/canvas/a11y_audit.zig +33 -11
  42. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  43. package/src/primitives/canvas/drawing.zig +25 -0
  44. package/src/primitives/canvas/equality.zig +8 -0
  45. package/src/primitives/canvas/events.zig +103 -16
  46. package/src/primitives/canvas/frame.zig +125 -1
  47. package/src/primitives/canvas/layout_audit.zig +22 -5
  48. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  49. package/src/primitives/canvas/render_tests.zig +13 -10
  50. package/src/primitives/canvas/root.zig +48 -0
  51. package/src/primitives/canvas/terminal_box.zig +471 -0
  52. package/src/primitives/canvas/terminal_grid.zig +978 -0
  53. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  54. package/src/primitives/canvas/test_support.zig +1 -0
  55. package/src/primitives/canvas/tests.zig +1 -0
  56. package/src/primitives/canvas/text_tests.zig +39 -4
  57. package/src/primitives/canvas/tokens.zig +115 -12
  58. package/src/primitives/canvas/ui.zig +524 -5
  59. package/src/primitives/canvas/ui_markup.zig +195 -2
  60. package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
  61. package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
  62. package/src/primitives/canvas/ui_markup_contract.zig +88 -5
  63. package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
  64. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  65. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  66. package/src/primitives/canvas/ui_markup_tests.zig +149 -0
  67. package/src/primitives/canvas/ui_markup_view.zig +191 -0
  68. package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
  69. package/src/primitives/canvas/ui_schema.zig +97 -17
  70. package/src/primitives/canvas/ui_schema_tests.zig +18 -11
  71. package/src/primitives/canvas/ui_tests.zig +141 -9
  72. package/src/primitives/canvas/widget_access.zig +28 -2
  73. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  74. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  75. package/src/primitives/canvas/widget_layout.zig +59 -11
  76. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  77. package/src/primitives/canvas/widget_render.zig +272 -18
  78. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  79. package/src/primitives/canvas/widget_routing.zig +59 -7
  80. package/src/primitives/canvas/widget_runtime.zig +23 -0
  81. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  82. package/src/primitives/canvas/widget_semantics.zig +119 -11
  83. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  84. package/src/primitives/canvas/widget_tree.zig +17 -0
  85. package/src/primitives/canvas/widgets.zig +132 -0
  86. package/src/root.zig +16 -0
  87. package/src/runtime/api.zig +76 -6
  88. package/src/runtime/automation_commands.zig +20 -1
  89. package/src/runtime/automation_snapshot.zig +25 -1
  90. package/src/runtime/automation_widget_dispatch.zig +73 -8
  91. package/src/runtime/bridge_payload.zig +1 -0
  92. package/src/runtime/canvas_frame.zig +62 -7
  93. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  94. package/src/runtime/canvas_frame_helpers.zig +190 -1
  95. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  96. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  97. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  98. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  99. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  100. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  101. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  102. package/src/runtime/canvas_widget_display.zig +1 -1
  103. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  104. package/src/runtime/canvas_widget_events.zig +268 -26
  105. package/src/runtime/canvas_widget_runtime.zig +213 -29
  106. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  107. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  108. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  109. package/src/runtime/canvas_widget_state.zig +6 -0
  110. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  111. package/src/runtime/core.zig +73 -2
  112. package/src/runtime/effects.zig +6389 -54
  113. package/src/runtime/effects_channel_tests.zig +3519 -0
  114. package/src/runtime/effects_pty_tests.zig +1362 -0
  115. package/src/runtime/effects_tests.zig +14 -9
  116. package/src/runtime/effects_video_tests.zig +3609 -0
  117. package/src/runtime/flow.zig +25 -4
  118. package/src/runtime/gpu_surface_events.zig +475 -15
  119. package/src/runtime/media_surface.zig +116 -11
  120. package/src/runtime/media_surface_tests.zig +61 -0
  121. package/src/runtime/pty.zig +1252 -0
  122. package/src/runtime/pty_windows.zig +1780 -0
  123. package/src/runtime/root.zig +25 -0
  124. package/src/runtime/runtime_event_tests.zig +20 -1
  125. package/src/runtime/session_journal.zig +367 -61
  126. package/src/runtime/session_record.zig +16 -0
  127. package/src/runtime/session_replay.zig +395 -11
  128. package/src/runtime/session_tests.zig +114 -19
  129. package/src/runtime/terminal_session.zig +1569 -0
  130. package/src/runtime/terminal_session_tests.zig +450 -0
  131. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  132. package/src/runtime/terminal_vt_stub.zig +13 -0
  133. package/src/runtime/tests.zig +6 -0
  134. package/src/runtime/ts_core_host.zig +980 -140
  135. package/src/runtime/ts_core_host_tests.zig +1059 -1
  136. package/src/runtime/ts_ui_app.zig +16 -5
  137. package/src/runtime/ui_app.zig +2338 -67
  138. package/src/runtime/ui_app_tests.zig +3171 -744
  139. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  140. package/src/runtime/ui_app_window_tests.zig +268 -0
  141. package/src/runtime/view.zig +190 -2
  142. package/src/runtime/view_widget_scroll.zig +218 -68
  143. package/src/runtime/view_widget_text.zig +11 -2
  144. package/src/runtime/view_widget_tree.zig +111 -3
  145. package/src/runtime/window_storage.zig +45 -2
  146. package/src/runtime/window_view_runtime.zig +34 -2
  147. package/src/runtime/window_views.zig +1 -0
  148. package/src/terminal_session_tests_root.zig +15 -0
  149. package/src/tooling/templates.zig +25 -7
@@ -0,0 +1,450 @@
1
+ //! Terminal session store tests: the runtime-owned emulator behind a
2
+ //! bound pty key — snapshot publication through the lookup seam, the
3
+ //! journaled write-back path (key encoding, committed text, query
4
+ //! answers), layout-driven resize, the scrollback source-wins echo, and
5
+ //! the respawn reset. Every input arrives the way the runtime delivers
6
+ //! it (tap events, reconcile calls), so these are the element contract's
7
+ //! tests, not emulator internals'. Skipped wholesale when the
8
+ //! `terminal_vt` seam carries the stub.
9
+
10
+ const std = @import("std");
11
+ const builtin = @import("builtin");
12
+ const canvas = @import("canvas");
13
+ const effects = @import("effects.zig");
14
+ const terminal_session = @import("terminal_session.zig");
15
+
16
+ const testing = std.testing;
17
+ const TerminalSessions = terminal_session.TerminalSessions;
18
+
19
+ const TestGateway = struct {
20
+ gpa: std.mem.Allocator,
21
+ written: std.ArrayList(u8) = .empty,
22
+ resized: ?struct { cols: u16, rows: u16 } = null,
23
+ resize_count: usize = 0,
24
+ accept: bool = true,
25
+
26
+ fn deinit(self: *TestGateway) void {
27
+ self.written.deinit(self.gpa);
28
+ }
29
+
30
+ fn writeFn(context: *anyopaque, key: u64, bytes: []const u8) bool {
31
+ const self: *TestGateway = @ptrCast(@alignCast(context));
32
+ _ = key;
33
+ if (!self.accept) return false;
34
+ self.written.appendSlice(self.gpa, bytes) catch return false;
35
+ return true;
36
+ }
37
+
38
+ fn resizeFn(context: *anyopaque, key: u64, cols: u16, rows: u16) void {
39
+ const self: *TestGateway = @ptrCast(@alignCast(context));
40
+ _ = key;
41
+ self.resized = .{ .cols = cols, .rows = rows };
42
+ self.resize_count += 1;
43
+ }
44
+
45
+ fn gateway(self: *TestGateway) terminal_session.PtyGateway {
46
+ return .{ .context = @ptrCast(self), .write = writeFn, .resize = resizeFn };
47
+ }
48
+ };
49
+
50
+ /// Resolve the published grid the way finalize does: through the
51
+ /// installed lookup, creating the session on first sight of the key.
52
+ fn resolveGrid(store: *TerminalSessions, pty: u64) ?*const canvas.TerminalGrid {
53
+ const lookup = store.lookup() orelse return null;
54
+ return lookup.resolve(lookup.context, pty);
55
+ }
56
+
57
+ fn feedOutput(store: *TerminalSessions, pty: u64, bytes: []const u8) void {
58
+ const event: effects.EffectPtyEvent = .{ .key = pty, .kind = .output, .bytes = bytes };
59
+ store.notePtyEvent(&event);
60
+ }
61
+
62
+ fn feedExit(store: *TerminalSessions, pty: u64) void {
63
+ const event: effects.EffectPtyEvent = .{ .key = pty, .kind = .exit, .code = 0 };
64
+ store.notePtyEvent(&event);
65
+ }
66
+
67
+ fn gridText(grid: *const canvas.TerminalGrid) []const u8 {
68
+ return grid.screen_text;
69
+ }
70
+
71
+ test "binding a pty key publishes a live grid that carries fed output as real cells" {
72
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
73
+ var store = TerminalSessions.init(testing.allocator);
74
+ defer store.deinit();
75
+ store.beginBuild(.{});
76
+
77
+ // First resolve creates the session (binding IS the request); the
78
+ // fresh grid is a running, empty surface.
79
+ const grid = resolveGrid(&store, 7) orelse return error.TestExpectedGrid;
80
+ try testing.expect(grid.running);
81
+
82
+ feedOutput(&store, 7, "hello \x1b[1;31mworld\x1b[0m\r\n$ ");
83
+ const refreshed = resolveGrid(&store, 7) orelse return error.TestExpectedGrid;
84
+ try testing.expect(std.mem.indexOf(u8, gridText(refreshed), "hello world") != null);
85
+ try testing.expect(std.mem.indexOf(u8, gridText(refreshed), "$") != null);
86
+ // The snapshot's rows carry resolved cells: find the 'h' at 0,0.
87
+ try testing.expect(refreshed.rows.len > 0);
88
+ try testing.expectEqual(@as(u21, 'h'), refreshed.rows[0].cells[0].cp);
89
+ try testing.expectEqualStrings("h", refreshed.rows[0].cells[0].cluster);
90
+ // A default (untouched) ANSI-31 red resolves through the theme's
91
+ // destructive token, the palette-honesty story.
92
+ const tokens: canvas.DesignTokens = .{};
93
+ const red_cell = refreshed.rows[0].cells[6];
94
+ try testing.expectEqual(@as(u21, 'w'), red_cell.cp);
95
+ try testing.expectApproxEqAbs(tokens.colors.destructive.r, red_cell.fg.r, 0.2);
96
+ }
97
+
98
+ test "pointer gestures select terminal cells words and lines for clipboard copy" {
99
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
100
+ var store = TerminalSessions.init(testing.allocator);
101
+ defer store.deinit();
102
+ var gw = TestGateway{ .gpa = testing.allocator };
103
+ defer gw.deinit();
104
+ store.setGateway(gw.gateway());
105
+ store.beginBuild(.{});
106
+ _ = store.reconcile(8, 0, 20, 4) orelse return error.TestExpectedState;
107
+ feedOutput(&store, 8, "alpha beta\r\ngamma delta");
108
+ _ = resolveGrid(&store, 8) orelse return error.TestExpectedGrid;
109
+
110
+ // Default tokens resolve to 8x18 cells. A primary drag from the
111
+ // first cell through the fifth selects "alpha".
112
+ _ = store.pointerSelection(8, .{
113
+ .phase = .down,
114
+ .x = 2,
115
+ .y = 5,
116
+ .width = 160,
117
+ .height = 72,
118
+ });
119
+ const drag = store.pointerSelection(8, .{
120
+ .phase = .move,
121
+ .x = 39,
122
+ .y = 5,
123
+ .width = 160,
124
+ .height = 72,
125
+ });
126
+ try testing.expect(drag.changed);
127
+ try testing.expect(drag.selection_active);
128
+ const release = store.pointerSelection(8, .{
129
+ .phase = .up,
130
+ .x = 39,
131
+ .y = 5,
132
+ .width = 160,
133
+ .height = 72,
134
+ });
135
+ try testing.expect(release.selection_active);
136
+ var grid = resolveGrid(&store, 8) orelse return error.TestExpectedGrid;
137
+ try testing.expectEqualStrings("alpha", grid.selection_text);
138
+ try testing.expectEqualDeep(@as(?[2]u16, .{ 0, 4 }), grid.rows[0].selection);
139
+
140
+ // The runtime's journaled click count chooses Ghostty's standard
141
+ // word and line behaviors without a second click clock.
142
+ _ = store.pointerSelection(8, .{
143
+ .phase = .down,
144
+ .x = 60,
145
+ .y = 5,
146
+ .width = 160,
147
+ .height = 72,
148
+ .click_count = 2,
149
+ });
150
+ grid = resolveGrid(&store, 8) orelse return error.TestExpectedGrid;
151
+ try testing.expectEqualStrings("beta", grid.selection_text);
152
+
153
+ _ = store.pointerSelection(8, .{
154
+ .phase = .down,
155
+ .x = 18,
156
+ .y = 5,
157
+ .width = 160,
158
+ .height = 72,
159
+ .click_count = 3,
160
+ });
161
+ grid = resolveGrid(&store, 8) orelse return error.TestExpectedGrid;
162
+ try testing.expectEqualStrings("alpha beta", grid.selection_text);
163
+
164
+ // Input sent to the child dismisses the live selection. Cmd/Ctrl+C
165
+ // is intercepted by the app loop before it reaches this path.
166
+ try testing.expect(store.textInput(8, "x"));
167
+ grid = resolveGrid(&store, 8) orelse return error.TestExpectedGrid;
168
+ try testing.expect(!grid.selection_active);
169
+ try testing.expectEqualStrings("", grid.selection_text);
170
+ }
171
+
172
+ test "committed text and encoded keys reach the pty through the gateway in stdin order" {
173
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
174
+ var store = TerminalSessions.init(testing.allocator);
175
+ defer store.deinit();
176
+ var gw = TestGateway{ .gpa = testing.allocator };
177
+ defer gw.deinit();
178
+ store.setGateway(gw.gateway());
179
+ store.beginBuild(.{});
180
+ _ = resolveGrid(&store, 3) orelse return error.TestExpectedGrid;
181
+
182
+ try testing.expect(store.textInput(3, "ls"));
183
+ try testing.expect(store.keyEvent(3, .{ .phase = .key_down, .key = "enter" }));
184
+ try testing.expectEqualStrings("ls\r", gw.written.items);
185
+
186
+ // Ctrl+C encodes the C0 interrupt byte, never a literal 'c'.
187
+ gw.written.clearRetainingCapacity();
188
+ try testing.expect(store.keyEvent(3, .{
189
+ .phase = .key_down,
190
+ .key = "c",
191
+ .modifiers = .{ .control = true },
192
+ }));
193
+ try testing.expectEqualStrings("\x03", gw.written.items);
194
+
195
+ // A plain printable key_down is consumed silently (its press
196
+ // travels the committed-text channel) — nothing doubles.
197
+ gw.written.clearRetainingCapacity();
198
+ try testing.expect(store.keyEvent(3, .{ .phase = .key_down, .key = "a" }));
199
+ try testing.expectEqualStrings("", gw.written.items);
200
+
201
+ if (comptime builtin.os.tag == .macos) {
202
+ // Natural text navigation follows macOS terminal conventions:
203
+ // Option moves by words and Command moves to line boundaries.
204
+ // These bindings intentionally remain legacy bytes after a TUI
205
+ // enables kitty reporting, and their releases stay consumed.
206
+ feedOutput(&store, 3, "\x1b[>11u");
207
+ try testing.expect(store.keyEvent(3, .{
208
+ .phase = .key_down,
209
+ .key = "arrowleft",
210
+ .modifiers = .{ .alt = true },
211
+ }));
212
+ try testing.expect(store.keyEvent(3, .{
213
+ .phase = .key_up,
214
+ .key = "arrowleft",
215
+ }));
216
+ try testing.expect(store.keyEvent(3, .{
217
+ .phase = .key_down,
218
+ .key = "arrowright",
219
+ .modifiers = .{ .alt = true },
220
+ }));
221
+ try testing.expect(store.keyEvent(3, .{
222
+ .phase = .key_up,
223
+ .key = "arrowright",
224
+ }));
225
+ try testing.expect(store.keyEvent(3, .{
226
+ .phase = .key_down,
227
+ .key = "arrowleft",
228
+ .modifiers = .{ .super = true },
229
+ }));
230
+ try testing.expect(store.keyEvent(3, .{
231
+ .phase = .key_up,
232
+ .key = "arrowleft",
233
+ }));
234
+ try testing.expect(store.keyEvent(3, .{
235
+ .phase = .key_down,
236
+ .key = "arrowright",
237
+ .modifiers = .{ .super = true },
238
+ }));
239
+ try testing.expect(store.keyEvent(3, .{
240
+ .phase = .key_up,
241
+ .key = "arrowright",
242
+ }));
243
+ try testing.expect(store.keyEvent(3, .{
244
+ .phase = .key_down,
245
+ .key = "backspace",
246
+ .modifiers = .{ .super = true },
247
+ }));
248
+ try testing.expect(store.keyEvent(3, .{
249
+ .phase = .key_up,
250
+ .key = "backspace",
251
+ }));
252
+ try testing.expectEqualStrings("\x1bb\x1bf\x01\x05\x15", gw.written.items);
253
+ }
254
+ }
255
+
256
+ test "clipboard paste uses terminal paste encoding and ended sessions refuse it" {
257
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
258
+ var store = TerminalSessions.init(testing.allocator);
259
+ defer store.deinit();
260
+ var gw = TestGateway{ .gpa = testing.allocator };
261
+ defer gw.deinit();
262
+ store.setGateway(gw.gateway());
263
+ store.beginBuild(.{});
264
+ _ = resolveGrid(&store, 3) orelse return error.TestExpectedGrid;
265
+
266
+ // Unbracketed paste follows xterm: LF becomes CR and dangerous
267
+ // control bytes are spaces, never injected verbatim.
268
+ try testing.expect(store.pasteInput(3, "echo one\necho two\x03\x1b"));
269
+ try testing.expectEqualStrings("echo one\recho two ", gw.written.items);
270
+
271
+ // The child enables mode 2004. The next paste is framed against
272
+ // that live emulator mode, with its multiline payload preserved.
273
+ gw.written.clearRetainingCapacity();
274
+ feedOutput(&store, 3, "\x1b[?2004h");
275
+ try testing.expect(store.pasteInput(3, "alpha\nbeta"));
276
+ try testing.expectEqualStrings("\x1b[200~alpha\nbeta\x1b[201~", gw.written.items);
277
+
278
+ // A parked session is no longer an input target. In particular,
279
+ // the clipboard payload does not escape through any fallback.
280
+ gw.written.clearRetainingCapacity();
281
+ feedExit(&store, 3);
282
+ try testing.expect(!store.pasteInput(3, "late"));
283
+ try testing.expectEqualStrings("", gw.written.items);
284
+ }
285
+
286
+ test "a refused write is retained in the ring and drains on the frame flush" {
287
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
288
+ var store = TerminalSessions.init(testing.allocator);
289
+ defer store.deinit();
290
+ var gw = TestGateway{ .gpa = testing.allocator };
291
+ defer gw.deinit();
292
+ store.setGateway(gw.gateway());
293
+ store.beginBuild(.{});
294
+ _ = resolveGrid(&store, 3) orelse return error.TestExpectedGrid;
295
+
296
+ // The pty refuses (a child that stopped reading): the bytes stay
297
+ // queued, not dropped.
298
+ gw.accept = false;
299
+ try testing.expect(store.textInput(3, "queued"));
300
+ try testing.expectEqualStrings("", gw.written.items);
301
+
302
+ // The child resumes reading: the frame flush drains the ring.
303
+ gw.accept = true;
304
+ try testing.expect(store.flushPending());
305
+ try testing.expectEqualStrings("queued", gw.written.items);
306
+ // Nothing pending anymore: the flush is a no-op.
307
+ try testing.expect(!store.flushPending());
308
+ }
309
+
310
+ test "reconcile resizes the emulator, pushes ptyResize, and reports the state once" {
311
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
312
+ var store = TerminalSessions.init(testing.allocator);
313
+ defer store.deinit();
314
+ var gw = TestGateway{ .gpa = testing.allocator };
315
+ defer gw.deinit();
316
+ store.setGateway(gw.gateway());
317
+ store.beginBuild(.{});
318
+
319
+ // The reconcile creates the session too (a layout pass can land
320
+ // before the first paint's resolve).
321
+ const state = store.reconcile(9, 0, 100, 30) orelse return error.TestExpectedState;
322
+ try testing.expectEqual(@as(u16, 100), state.cols);
323
+ try testing.expectEqual(@as(u16, 30), state.rows);
324
+ try testing.expectEqual(@as(u16, 100), gw.resized.?.cols);
325
+ try testing.expectEqual(@as(u16, 30), gw.resized.?.rows);
326
+ // The same layout reconciles to the same state: nothing new to
327
+ // report, no second dispatch.
328
+ try testing.expectEqual(@as(?canvas.TerminalState, null), store.reconcile(9, 0, 100, 30));
329
+ try testing.expectEqual(@as(usize, 1), gw.resize_count);
330
+
331
+ // The emulator grid moved with the pty: the published snapshot's
332
+ // rows match.
333
+ const grid = resolveGrid(&store, 9) orelse return error.TestExpectedGrid;
334
+ try testing.expectEqual(@as(usize, 30), grid.rows.len);
335
+ }
336
+
337
+ test "wheel scrollback windows the viewport and the declared echo follows source-wins" {
338
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
339
+ var store = TerminalSessions.init(testing.allocator);
340
+ defer store.deinit();
341
+ var gw = TestGateway{ .gpa = testing.allocator };
342
+ defer gw.deinit();
343
+ store.setGateway(gw.gateway());
344
+ store.beginBuild(.{});
345
+ _ = store.reconcile(5, 0, 20, 4) orelse return error.TestExpectedState;
346
+ var line: [16]u8 = undefined;
347
+ for (0..30) |index| {
348
+ feedOutput(&store, 5, std.fmt.bufPrint(&line, "line {d}\r\n", .{index}) catch unreachable);
349
+ }
350
+
351
+ // Positive delta reveals history (natural direction); one session
352
+ // cell height per row.
353
+ try testing.expect(store.wheel(5, 18 * 3));
354
+ const scrolled = store.currentState(5) orelse return error.TestExpectedState;
355
+ try testing.expectEqual(@as(u32, 3), scrolled.scrollback);
356
+ try testing.expect(scrolled.history >= scrolled.scrollback);
357
+
358
+ // The app echoes the reported value back: an unchanged declaration
359
+ // never moves the runtime-owned position.
360
+ try testing.expectEqual(@as(?canvas.TerminalState, null), store.reconcile(5, scrolled.scrollback, 20, 4));
361
+ const held = store.currentState(5) orelse return error.TestExpectedState;
362
+ try testing.expectEqual(@as(u32, 3), held.scrollback);
363
+
364
+ // A model-driven change (the declaration MOVED between builds)
365
+ // wins: scroll programmatically back to the live screen.
366
+ const pinned = store.reconcile(5, 0, 20, 4) orelse return error.TestExpectedState;
367
+ try testing.expectEqual(@as(u32, 0), pinned.scrollback);
368
+ }
369
+
370
+ test "typing while scrolled back snaps the viewport to the live screen" {
371
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
372
+ var store = TerminalSessions.init(testing.allocator);
373
+ defer store.deinit();
374
+ var gw = TestGateway{ .gpa = testing.allocator };
375
+ defer gw.deinit();
376
+ store.setGateway(gw.gateway());
377
+ store.beginBuild(.{});
378
+ _ = store.reconcile(5, 0, 20, 4) orelse return error.TestExpectedState;
379
+ var line: [16]u8 = undefined;
380
+ for (0..30) |index| {
381
+ feedOutput(&store, 5, std.fmt.bufPrint(&line, "line {d}\r\n", .{index}) catch unreachable);
382
+ }
383
+ try testing.expect(store.wheel(5, 18 * 4));
384
+ try testing.expect((store.currentState(5) orelse return error.TestExpectedState).scrollback > 0);
385
+ try testing.expect(store.textInput(5, "x"));
386
+ try testing.expectEqual(@as(u32, 0), (store.currentState(5) orelse return error.TestExpectedState).scrollback);
387
+ }
388
+
389
+ test "an exit parks the session and output on the reused key resets to a clean terminal" {
390
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
391
+ var store = TerminalSessions.init(testing.allocator);
392
+ defer store.deinit();
393
+ var gw = TestGateway{ .gpa = testing.allocator };
394
+ defer gw.deinit();
395
+ store.setGateway(gw.gateway());
396
+ store.beginBuild(.{});
397
+ _ = resolveGrid(&store, 2) orelse return error.TestExpectedGrid;
398
+
399
+ feedOutput(&store, 2, "old session content\r\n");
400
+ feedExit(&store, 2);
401
+ const ended = resolveGrid(&store, 2) orelse return error.TestExpectedGrid;
402
+ try testing.expect(!ended.running);
403
+ // An ended session refuses input (the key is free; a respawn owns it).
404
+ try testing.expect(!store.textInput(2, "late"));
405
+ try testing.expect(!store.keyEvent(2, .{ .phase = .key_down, .key = "enter" }));
406
+
407
+ // A new spawn reused the key: its first output resets the emulator
408
+ // before feeding, so the old screen and modes never leak in.
409
+ feedOutput(&store, 2, "fresh prompt $ ");
410
+ const fresh = resolveGrid(&store, 2) orelse return error.TestExpectedGrid;
411
+ try testing.expect(fresh.running);
412
+ try testing.expect(std.mem.indexOf(u8, gridText(fresh), "fresh prompt") != null);
413
+ try testing.expect(std.mem.indexOf(u8, gridText(fresh), "old session") == null);
414
+ }
415
+
416
+ test "emulator query answers write back to the pty through the ring" {
417
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
418
+ var store = TerminalSessions.init(testing.allocator);
419
+ defer store.deinit();
420
+ var gw = TestGateway{ .gpa = testing.allocator };
421
+ defer gw.deinit();
422
+ store.setGateway(gw.gateway());
423
+ store.beginBuild(.{});
424
+ _ = resolveGrid(&store, 4) orelse return error.TestExpectedGrid;
425
+
426
+ // A DSR cursor-position report: the emulator answers and the answer
427
+ // reaches the child (a blocked `read` on the reply never hangs).
428
+ feedOutput(&store, 4, "\x1b[6n");
429
+ try testing.expect(std.mem.indexOf(u8, gw.written.items, "\x1b[") != null);
430
+ try testing.expect(std.mem.indexOf(u8, gw.written.items, "R") != null);
431
+ }
432
+
433
+ test "the wide-cell spacer extends its primary's background in the published snapshot" {
434
+ if (comptime !terminal_session.enabled) return error.SkipZigTest;
435
+ var store = TerminalSessions.init(testing.allocator);
436
+ defer store.deinit();
437
+ store.beginBuild(.{});
438
+ _ = resolveGrid(&store, 6) orelse return error.TestExpectedGrid;
439
+ // Red background behind a double-width glyph (界): the emulator
440
+ // styles only the primary cell, so the snapshot must pre-resolve
441
+ // the spacer's background per the painter's contract.
442
+ feedOutput(&store, 6, "\x1b[41m\xe7\x95\x8c\x1b[0m\r\n");
443
+ const grid = resolveGrid(&store, 6) orelse return error.TestExpectedGrid;
444
+ const row = grid.rows[0];
445
+ try testing.expectEqual(canvas.TerminalWide.wide, row.cells[0].wide);
446
+ try testing.expectEqual(canvas.TerminalWide.spacer, row.cells[1].wide);
447
+ try testing.expect(row.cells[0].bg != null);
448
+ try testing.expect(row.cells[1].bg != null);
449
+ try testing.expectEqual(row.cells[0].bg.?.r, row.cells[1].bg.?.r);
450
+ }
@@ -0,0 +1,15 @@
1
+ //! The `terminal_vt` seam's ENABLED half: re-exports libghostty-vt
2
+ //! (Ghostty's extracted terminal-state core, the `ghostty-vt` Zig
3
+ //! module) for the runtime's terminal-session store. Only an APP build
4
+ //! wires this wrapper, and only when it asks: pin `ghostty` as a lazy
5
+ //! dependency in the app's own `build.zig.zon` and set
6
+ //! `addAppArtifacts(.{ .terminal_sessions = true })`. This package pins
7
+ //! nothing, because a pin here is materialized into every consumer's
8
+ //! package directory even when lazy and unused.
9
+ //!
10
+ //! Everything else (the framework's own builds, scaffolded apps, the
11
+ //! wasm docs preview) gets `terminal_vt_stub.zig` and never traverses
12
+ //! ghostty's graph.
13
+
14
+ pub const enabled = true;
15
+ pub const vt = @import("ghostty-vt");
@@ -0,0 +1,13 @@
1
+ //! The `terminal_vt` seam's DISABLED half: the framework module imports
2
+ //! `terminal_vt` unconditionally, and the build graph wires either this
3
+ //! stub or `terminal_vt_ghostty.zig` (which re-exports the real
4
+ //! `ghostty-vt` module). With the stub in place `<terminal>` elements
5
+ //! render the honest empty surface — no emulator exists — and nothing
6
+ //! in the build traverses ghostty's dependency graph, which is the
7
+ //! load-bearing property for scaffolded and consumer builds (ghostty's
8
+ //! configure step walks lazy dependencies — wuffs, translate_c — whose
9
+ //! build scripts fail in consumer package stores, and its full build
10
+ //! pulls harfbuzz). Code that needs the emulator gates on `enabled` at
11
+ //! comptime and never references `vt` in the disabled branch.
12
+
13
+ pub const enabled = false;
@@ -21,8 +21,14 @@ test {
21
21
  _ = @import("effects_file_tests.zig");
22
22
  _ = @import("effects_clipboard_tests.zig");
23
23
  _ = @import("effects_audio_tests.zig");
24
+ _ = @import("effects_video_tests.zig");
24
25
  _ = @import("effects_image_tests.zig");
26
+ _ = @import("effects_channel_tests.zig");
25
27
  _ = @import("effects_host_tests.zig");
28
+ _ = @import("effects_pty_tests.zig");
29
+ _ = @import("terminal_session_tests.zig");
30
+ _ = @import("pty.zig");
31
+ _ = @import("pty_windows.zig");
26
32
  _ = @import("ts_core_host_tests.zig");
27
33
  _ = @import("clock.zig");
28
34
  _ = @import("frame_profile.zig");