@native-sdk/cli 0.5.1 → 0.5.3

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 (98) hide show
  1. package/build.zig +41 -0
  2. package/package.json +9 -9
  3. package/packages/core/package-lock.json +2 -2
  4. package/packages/core/package.json +1 -1
  5. package/packages/core/sdk/events.ts +39 -2
  6. package/packages/core/src/checker.ts +1 -1
  7. package/packages/core/src/emitter.ts +39 -3
  8. package/packages/core/src/infer.ts +53 -7
  9. package/skill-data/automation/SKILL.md +7 -4
  10. package/skill-data/core/references/app-model-runtime.md +3 -0
  11. package/skill-data/native-ui/SKILL.md +3 -2
  12. package/src/app_runner/root.zig +25 -0
  13. package/src/automation/protocol.zig +20 -1
  14. package/src/embed/host.zig +27 -0
  15. package/src/embed/tests.zig +69 -0
  16. package/src/embed/ui_host.zig +4 -0
  17. package/src/platform/macos/appkit_host.h +11 -0
  18. package/src/platform/macos/appkit_host.m +130 -0
  19. package/src/platform/macos/root.zig +34 -0
  20. package/src/platform/null_platform_tests.zig +39 -0
  21. package/src/platform/root.zig +3 -0
  22. package/src/platform/types.zig +118 -4
  23. package/src/primitives/canvas/chart.zig +7 -7
  24. package/src/primitives/canvas/chart_tests.zig +66 -0
  25. package/src/primitives/canvas/commands.zig +48 -0
  26. package/src/primitives/canvas/events.zig +161 -0
  27. package/src/primitives/canvas/font_ttf.zig +155 -8
  28. package/src/primitives/canvas/font_ttf_tests.zig +686 -0
  29. package/src/primitives/canvas/reference.zig +67 -8
  30. package/src/primitives/canvas/render_fingerprints.zig +8 -0
  31. package/src/primitives/canvas/root.zig +26 -0
  32. package/src/primitives/canvas/tokens.zig +170 -7
  33. package/src/primitives/canvas/ui.zig +62 -7
  34. package/src/primitives/canvas/ui_markup.zig +51 -4
  35. package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
  36. package/src/primitives/canvas/ui_markup_compiled.zig +49 -4
  37. package/src/primitives/canvas/ui_markup_compiled_tests.zig +160 -0
  38. package/src/primitives/canvas/ui_markup_contract.zig +9 -0
  39. package/src/primitives/canvas/ui_markup_contract_tests.zig +24 -0
  40. package/src/primitives/canvas/ui_markup_tests.zig +73 -0
  41. package/src/primitives/canvas/ui_markup_view.zig +63 -5
  42. package/src/primitives/canvas/ui_markup_view_tests.zig +151 -2
  43. package/src/primitives/canvas/ui_schema.zig +31 -1
  44. package/src/primitives/canvas/ui_schema_tests.zig +11 -11
  45. package/src/primitives/canvas/ui_tests.zig +31 -0
  46. package/src/primitives/canvas/vector.zig +258 -141
  47. package/src/primitives/canvas/widget_access.zig +1 -1
  48. package/src/primitives/canvas/widget_builtin_tests.zig +259 -0
  49. package/src/primitives/canvas/widget_layout.zig +13 -5
  50. package/src/primitives/canvas/widget_layout_tests.zig +82 -0
  51. package/src/primitives/canvas/widget_render.zig +78 -40
  52. package/src/primitives/canvas/widget_render_controls.zig +15 -4
  53. package/src/primitives/canvas/widget_semantics.zig +6 -1
  54. package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
  55. package/src/primitives/canvas/widget_text_input.zig +118 -10
  56. package/src/primitives/canvas/widget_tree.zig +14 -2
  57. package/src/primitives/canvas/widgets.zig +28 -0
  58. package/src/root.zig +5 -0
  59. package/src/runtime/api.zig +13 -0
  60. package/src/runtime/automation_commands.zig +33 -0
  61. package/src/runtime/automation_widget_dispatch.zig +159 -28
  62. package/src/runtime/canvas_font_tests.zig +272 -3
  63. package/src/runtime/canvas_fonts.zig +60 -20
  64. package/src/runtime/canvas_frame.zig +15 -0
  65. package/src/runtime/canvas_frame_helpers.zig +15 -0
  66. package/src/runtime/canvas_image_tests.zig +26 -0
  67. package/src/runtime/canvas_images.zig +33 -7
  68. package/src/runtime/canvas_limits.zig +44 -8
  69. package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
  70. package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
  71. package/src/runtime/canvas_widget_context_menu.zig +3 -2
  72. package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
  73. package/src/runtime/canvas_widget_events.zig +1295 -7
  74. package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
  75. package/src/runtime/canvas_widget_runtime.zig +24 -7
  76. package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
  77. package/src/runtime/canvas_widget_state.zig +88 -6
  78. package/src/runtime/canvas_widget_text_tests.zig +277 -0
  79. package/src/runtime/core.zig +112 -6
  80. package/src/runtime/flow.zig +51 -1
  81. package/src/runtime/gpu_surface_events.zig +51 -5
  82. package/src/runtime/media_surface.zig +726 -0
  83. package/src/runtime/media_surface_tests.zig +1476 -0
  84. package/src/runtime/root.zig +9 -0
  85. package/src/runtime/session_journal.zig +52 -13
  86. package/src/runtime/session_record.zig +166 -0
  87. package/src/runtime/session_tests.zig +575 -0
  88. package/src/runtime/tests.zig +1 -0
  89. package/src/runtime/ts_ui_app.zig +56 -0
  90. package/src/runtime/ui_app.zig +64 -1
  91. package/src/runtime/ui_app_tests.zig +794 -0
  92. package/src/runtime/view.zig +86 -0
  93. package/src/runtime/view_widget_text.zig +18 -1
  94. package/src/runtime/view_widget_tree.zig +339 -20
  95. package/src/runtime/widget_bridge.zig +26 -0
  96. package/src/runtime/window_storage.zig +61 -15
  97. package/src/runtime/window_view_runtime.zig +13 -0
  98. package/src/runtime/window_views.zig +6 -0
@@ -1986,6 +1986,466 @@ test "automation set_text routes through the input path so the elm mirror stays
1986
1986
  }
1987
1987
  }
1988
1988
 
1989
+ // -------------------------------------------- edit-derivation choke point
1990
+
1991
+ const search_mirror_canvas_label = "search-mirror-canvas";
1992
+
1993
+ const SearchMirrorModel = struct {
1994
+ query: canvas.TextBuffer(64) = .{},
1995
+ edit_count: u32 = 0,
1996
+ };
1997
+
1998
+ const SearchMirrorMsg = union(enum) {
1999
+ query_edit: canvas.TextInputEvent,
2000
+ };
2001
+
2002
+ const SearchMirrorApp = ui_app_model.UiApp(SearchMirrorModel, SearchMirrorMsg);
2003
+
2004
+ fn searchMirrorUpdate(model: *SearchMirrorModel, msg: SearchMirrorMsg) void {
2005
+ switch (msg) {
2006
+ .query_edit => |edit| {
2007
+ model.query.apply(edit);
2008
+ model.edit_count += 1;
2009
+ },
2010
+ }
2011
+ }
2012
+
2013
+ fn searchMirrorView(ui: *SearchMirrorApp.Ui, model: *const SearchMirrorModel) SearchMirrorApp.Ui.Node {
2014
+ return ui.column(.{ .gap = 8, .padding = 12 }, .{
2015
+ ui.el(.search_field, .{
2016
+ .text = model.query.text(),
2017
+ .placeholder = "Search",
2018
+ .on_input = SearchMirrorApp.Ui.inputMsg(.query_edit),
2019
+ }, .{}),
2020
+ ui.text(.{}, if (model.query.len == 0) "Unfiltered" else "Filtered"),
2021
+ });
2022
+ }
2023
+
2024
+ const search_mirror_views = [_]app_manifest.ShellView{
2025
+ .{ .label = search_mirror_canvas_label, .kind = .gpu_surface, .fill = true, .gpu_backend = .metal },
2026
+ };
2027
+ const search_mirror_windows = [_]app_manifest.ShellWindow{.{
2028
+ .label = "main",
2029
+ .title = "SearchMirror",
2030
+ .width = 400,
2031
+ .height = 300,
2032
+ .views = &search_mirror_views,
2033
+ }};
2034
+ const search_mirror_scene: app_manifest.ShellConfig = .{ .windows = &search_mirror_windows };
2035
+
2036
+ fn startSearchMirror(harness: *core.TestHarness(), app_state: *SearchMirrorApp) !void {
2037
+ app_state.* = SearchMirrorApp.init(std.heap.page_allocator, .{}, .{
2038
+ .name = "ui-app-search-mirror",
2039
+ .scene = search_mirror_scene,
2040
+ .canvas_label = search_mirror_canvas_label,
2041
+ .update = searchMirrorUpdate,
2042
+ .view = searchMirrorView,
2043
+ });
2044
+ const app = app_state.app();
2045
+ try harness.start(app);
2046
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
2047
+ .label = search_mirror_canvas_label,
2048
+ .size = geometry.SizeF.init(400, 300),
2049
+ .scale_factor = 1,
2050
+ .frame_index = 1,
2051
+ .timestamp_ns = 1_000_000,
2052
+ .nonblank = true,
2053
+ } });
2054
+ try std.testing.expect(app_state.installed);
2055
+ }
2056
+
2057
+ fn searchMirrorHasText(app_state: *const SearchMirrorApp, text: []const u8) bool {
2058
+ const tree = app_state.tree orelse return false;
2059
+ return widgetTreeHasText(tree.root, text);
2060
+ }
2061
+
2062
+ fn widgetTreeHasText(widget: canvas.Widget, text: []const u8) bool {
2063
+ if (widget.kind == .text and std.mem.eql(u8, widget.text, text)) return true;
2064
+ for (widget.children) |child| {
2065
+ if (widgetTreeHasText(child, text)) return true;
2066
+ }
2067
+ return false;
2068
+ }
2069
+
2070
+ test "Escape's search-field clear reaches the model through the edit-derivation seam" {
2071
+ // The post-launch live-GUI bug: Escape made the runtime editor clear
2072
+ // the field VISUALLY while the model's `on_input` mirror never heard
2073
+ // anything — the list stayed filtered against a query the screen no
2074
+ // longer showed, and the next keystroke dispatched against the stale
2075
+ // term. The keyboard derivation now stamps the edit it applies onto
2076
+ // the dispatched event, so every formerly runtime-only edit (the
2077
+ // Escape clear, the composition cancel, the single-line ArrowUp/Down
2078
+ // caret jumps) reaches the model exactly as applied.
2079
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
2080
+ defer harness.destroy(std.testing.allocator);
2081
+ harness.null_platform.gpu_surfaces = true;
2082
+
2083
+ const app_state = try std.testing.allocator.create(SearchMirrorApp);
2084
+ defer std.testing.allocator.destroy(app_state);
2085
+ try startSearchMirror(harness, app_state);
2086
+ defer app_state.deinit();
2087
+ const app = app_state.app();
2088
+
2089
+ const field_id = findWidgetIdByKind(app_state.tree.?.root, .search_field).?;
2090
+ const field_frame = (try harness.runtime.canvasWidgetLayout(1, search_mirror_canvas_label)).findById(field_id).?.frame;
2091
+
2092
+ // Click into the (empty) field to focus it and type through the
2093
+ // platform text channel.
2094
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2095
+ .window_id = 1,
2096
+ .label = search_mirror_canvas_label,
2097
+ .kind = .pointer_down,
2098
+ .x = field_frame.x + field_frame.width * 0.5,
2099
+ .y = field_frame.y + field_frame.height * 0.5,
2100
+ } });
2101
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2102
+ .window_id = 1,
2103
+ .label = search_mirror_canvas_label,
2104
+ .kind = .text_input,
2105
+ .text = "glass",
2106
+ } });
2107
+ try std.testing.expectEqualStrings("glass", app_state.model.query.text());
2108
+ try std.testing.expect(searchMirrorHasText(app_state, "Filtered"));
2109
+
2110
+ // ArrowUp jumps the caret to the start in a single-line field — a
2111
+ // runtime-only derivation before the stamp; the model's selection
2112
+ // mirror must follow so its next splice lands where the editor's
2113
+ // does.
2114
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2115
+ .window_id = 1,
2116
+ .label = search_mirror_canvas_label,
2117
+ .kind = .key_down,
2118
+ .key = "arrowup",
2119
+ } });
2120
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(0), app_state.model.query.selection);
2121
+
2122
+ // THE pin: Escape clears the field AND the model hears it.
2123
+ const edits_before_escape = app_state.model.edit_count;
2124
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2125
+ .window_id = 1,
2126
+ .label = search_mirror_canvas_label,
2127
+ .kind = .key_down,
2128
+ .key = "escape",
2129
+ } });
2130
+ try std.testing.expect(app_state.model.edit_count > edits_before_escape);
2131
+ try std.testing.expectEqualStrings("", app_state.model.query.text());
2132
+ try std.testing.expect(searchMirrorHasText(app_state, "Unfiltered"));
2133
+
2134
+ // The visual state agrees with the model: the retained editor and
2135
+ // the automation snapshot both show the cleared field.
2136
+ const cleared_layout = try harness.runtime.canvasWidgetLayout(1, search_mirror_canvas_label);
2137
+ try std.testing.expectEqualStrings("", cleared_layout.findById(field_id).?.widget.text);
2138
+ const snapshot = harness.runtime.automationSnapshot("SearchMirror");
2139
+ for (snapshot.widgets) |widget| {
2140
+ if (widget.id == field_id) try std.testing.expectEqualStrings("", widget.text_value);
2141
+ }
2142
+
2143
+ // Escape during composition cancels the composition FIRST — and the
2144
+ // model hears that too (the second formerly runtime-only arm).
2145
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2146
+ .window_id = 1,
2147
+ .label = search_mirror_canvas_label,
2148
+ .kind = .ime_set_composition,
2149
+ .text = "ne",
2150
+ } });
2151
+ try std.testing.expectEqualStrings("ne", app_state.model.query.text());
2152
+ try std.testing.expect(app_state.model.query.composition != null);
2153
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2154
+ .window_id = 1,
2155
+ .label = search_mirror_canvas_label,
2156
+ .kind = .key_down,
2157
+ .key = "escape",
2158
+ } });
2159
+ try std.testing.expectEqualStrings("", app_state.model.query.text());
2160
+ try std.testing.expect(app_state.model.query.composition == null);
2161
+ const canceled_layout = try harness.runtime.canvasWidgetLayout(1, search_mirror_canvas_label);
2162
+ try std.testing.expectEqualStrings("", canceled_layout.findById(field_id).?.widget.text);
2163
+ }
2164
+
2165
+ test "automation composition and selection verbs keep the model mirror consistent" {
2166
+ // The automation/accessibility text verbs (`widget-action ...
2167
+ // set_composition/commit_composition/cancel_composition`) used to
2168
+ // write the runtime editor directly — on-screen composition the
2169
+ // model never heard, the `set_text` bug's composition twin. They
2170
+ // now ride the SAME ime input events a real IME session produces
2171
+ // (journaled, stamped, dispatched); `set_selection` synthesizes the
2172
+ // stamped keyboard event the clipboard edits use.
2173
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
2174
+ defer harness.destroy(std.testing.allocator);
2175
+ harness.null_platform.gpu_surfaces = true;
2176
+
2177
+ const app_state = try std.testing.allocator.create(SearchMirrorApp);
2178
+ defer std.testing.allocator.destroy(app_state);
2179
+ try startSearchMirror(harness, app_state);
2180
+ defer app_state.deinit();
2181
+ const app = app_state.app();
2182
+
2183
+ const field_id = findWidgetIdByKind(app_state.tree.?.root, .search_field).?;
2184
+
2185
+ // Compose marked text: the editor shows it AND the model hears it.
2186
+ try core.testing.dispatchAutomationWidgetAction(&harness.runtime, app, .{
2187
+ .view_label = search_mirror_canvas_label,
2188
+ .id = field_id,
2189
+ .action = .set_composition,
2190
+ .value = "ing",
2191
+ });
2192
+ try std.testing.expectEqualStrings("ing", app_state.model.query.text());
2193
+ try std.testing.expectEqualDeep(@as(?canvas.TextRange, canvas.TextRange.init(0, 3)), app_state.model.query.composition);
2194
+ const composing_layout = try harness.runtime.canvasWidgetLayout(1, search_mirror_canvas_label);
2195
+ try std.testing.expectEqualStrings("ing", composing_layout.findById(field_id).?.widget.text);
2196
+
2197
+ // Commit: composition resolves to plain text in both.
2198
+ try core.testing.dispatchAutomationWidgetAction(&harness.runtime, app, .{
2199
+ .view_label = search_mirror_canvas_label,
2200
+ .id = field_id,
2201
+ .action = .commit_composition,
2202
+ });
2203
+ try std.testing.expectEqualStrings("ing", app_state.model.query.text());
2204
+ try std.testing.expect(app_state.model.query.composition == null);
2205
+
2206
+ // Select a range: the model's selection mirror follows.
2207
+ try core.testing.dispatchAutomationWidgetAction(&harness.runtime, app, .{
2208
+ .view_label = search_mirror_canvas_label,
2209
+ .id = field_id,
2210
+ .action = .set_selection,
2211
+ .value = "0 3",
2212
+ });
2213
+ try std.testing.expectEqualDeep(canvas.TextSelection{ .anchor = 0, .focus = 3 }, app_state.model.query.selection);
2214
+
2215
+ // Cancel a fresh composition: the marked run vanishes from both.
2216
+ try core.testing.dispatchAutomationWidgetAction(&harness.runtime, app, .{
2217
+ .view_label = search_mirror_canvas_label,
2218
+ .id = field_id,
2219
+ .action = .set_composition,
2220
+ .value = "aro",
2221
+ });
2222
+ try std.testing.expectEqualStrings("aro", app_state.model.query.text());
2223
+ try core.testing.dispatchAutomationWidgetAction(&harness.runtime, app, .{
2224
+ .view_label = search_mirror_canvas_label,
2225
+ .id = field_id,
2226
+ .action = .cancel_composition,
2227
+ });
2228
+ try std.testing.expectEqualStrings("", app_state.model.query.text());
2229
+ try std.testing.expect(app_state.model.query.composition == null);
2230
+ const canceled_layout = try harness.runtime.canvasWidgetLayout(1, search_mirror_canvas_label);
2231
+ try std.testing.expectEqualStrings("", canceled_layout.findById(field_id).?.widget.text);
2232
+ }
2233
+
2234
+ // --------------------------------- combobox open-arrow (mirror invariant)
2235
+
2236
+ const combo_mirror_canvas_label = "combo-mirror-canvas";
2237
+
2238
+ const ComboMirrorModel = struct {
2239
+ query: canvas.TextBuffer(64) = .{},
2240
+ note: canvas.TextBuffer(64) = .{},
2241
+ open: bool = false,
2242
+ opens: u32 = 0,
2243
+ query_edits: u32 = 0,
2244
+ };
2245
+
2246
+ const ComboMirrorMsg = union(enum) {
2247
+ open_picker,
2248
+ close_picker,
2249
+ query_edit: canvas.TextInputEvent,
2250
+ note_edit: canvas.TextInputEvent,
2251
+ };
2252
+
2253
+ const ComboMirrorApp = ui_app_model.UiApp(ComboMirrorModel, ComboMirrorMsg);
2254
+
2255
+ fn comboMirrorUpdate(model: *ComboMirrorModel, msg: ComboMirrorMsg) void {
2256
+ switch (msg) {
2257
+ .open_picker => {
2258
+ model.open = true;
2259
+ model.opens += 1;
2260
+ },
2261
+ .close_picker => model.open = false,
2262
+ .query_edit => |edit| {
2263
+ model.query.apply(edit);
2264
+ model.query_edits += 1;
2265
+ },
2266
+ .note_edit => |edit| model.note.apply(edit),
2267
+ }
2268
+ }
2269
+
2270
+ fn comboMirrorView(ui: *ComboMirrorApp.Ui, model: *const ComboMirrorModel) ComboMirrorApp.Ui.Node {
2271
+ const trigger = ui.el(.combobox, .{
2272
+ .text = model.query.text(),
2273
+ .placeholder = "Filter",
2274
+ .width = 200,
2275
+ .expanded = model.open,
2276
+ .on_press = .open_picker,
2277
+ .on_input = ComboMirrorApp.Ui.inputMsg(.query_edit),
2278
+ }, .{});
2279
+ const picker = if (model.open) ui.stack(.{ .height = 28 }, .{
2280
+ trigger,
2281
+ ui.el(.dropdown_menu, .{
2282
+ .anchor = .below,
2283
+ .anchor_alignment = .stretch,
2284
+ .width = 200,
2285
+ .height = 60,
2286
+ .on_dismiss = .close_picker,
2287
+ }, .{
2288
+ ui.el(.menu_item, .{ .key = .{ .int = 0 }, .text = "glass bead", .height = 26, .on_press = .close_picker }, .{}),
2289
+ ui.el(.menu_item, .{ .key = .{ .int = 1 }, .text = "glass jar", .height = 26, .on_press = .close_picker }, .{}),
2290
+ }),
2291
+ }) else ui.stack(.{ .height = 28 }, .{trigger});
2292
+ return ui.column(.{ .gap = 8, .padding = 12 }, .{
2293
+ picker,
2294
+ ui.el(.text_field, .{
2295
+ .text = model.note.text(),
2296
+ .placeholder = "Note",
2297
+ .width = 200,
2298
+ .on_input = ComboMirrorApp.Ui.inputMsg(.note_edit),
2299
+ }, .{}),
2300
+ });
2301
+ }
2302
+
2303
+ const combo_mirror_views = [_]app_manifest.ShellView{
2304
+ .{ .label = combo_mirror_canvas_label, .kind = .gpu_surface, .fill = true, .gpu_backend = .metal },
2305
+ };
2306
+ const combo_mirror_windows = [_]app_manifest.ShellWindow{.{
2307
+ .label = "main",
2308
+ .title = "ComboMirror",
2309
+ .width = 400,
2310
+ .height = 300,
2311
+ .views = &combo_mirror_views,
2312
+ }};
2313
+ const combo_mirror_scene: app_manifest.ShellConfig = .{ .windows = &combo_mirror_windows };
2314
+
2315
+ fn comboMirrorKey(harness: *core.TestHarness(), app: core.App, key: []const u8) !void {
2316
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2317
+ .window_id = 1,
2318
+ .label = combo_mirror_canvas_label,
2319
+ .kind = .key_down,
2320
+ .key = key,
2321
+ } });
2322
+ }
2323
+
2324
+ fn comboMirrorRetainedSelection(harness: *core.TestHarness(), id: canvas.ObjectId) !?canvas.TextSelection {
2325
+ const layout = try harness.runtime.canvasWidgetLayout(1, combo_mirror_canvas_label);
2326
+ return layout.findById(id).?.widget.text_selection;
2327
+ }
2328
+
2329
+ test "a closed combobox's open arrows move neither the retained caret nor the model mirror" {
2330
+ // The split-brain escapee: a CLOSED combobox maps ArrowUp/Down to
2331
+ // BOTH its open press (`widgetKeyboardControlIntent`'s menu-open
2332
+ // keys) and — through the single-line caret derivation — a stamped
2333
+ // caret jump. The app dispatch resolves the press FIRST, so the
2334
+ // runtime editor moved its caret while the model's mirror heard
2335
+ // nothing, and the next insert landed at two different offsets.
2336
+ // Opening wins (the platform convention): the derivation yields no
2337
+ // edit, and BOTH sides agree the arrow moved no caret.
2338
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
2339
+ defer harness.destroy(std.testing.allocator);
2340
+ harness.null_platform.gpu_surfaces = true;
2341
+
2342
+ const app_state = try std.testing.allocator.create(ComboMirrorApp);
2343
+ defer std.testing.allocator.destroy(app_state);
2344
+ app_state.* = ComboMirrorApp.init(std.heap.page_allocator, .{}, .{
2345
+ .name = "ui-app-combo-mirror",
2346
+ .scene = combo_mirror_scene,
2347
+ .canvas_label = combo_mirror_canvas_label,
2348
+ .update = comboMirrorUpdate,
2349
+ .view = comboMirrorView,
2350
+ });
2351
+ defer app_state.deinit();
2352
+ const app = app_state.app();
2353
+ try harness.start(app);
2354
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
2355
+ .label = combo_mirror_canvas_label,
2356
+ .size = geometry.SizeF.init(400, 300),
2357
+ .scale_factor = 1,
2358
+ .frame_index = 1,
2359
+ .timestamp_ns = 1_000_000,
2360
+ .nonblank = true,
2361
+ } });
2362
+ try std.testing.expect(app_state.installed);
2363
+
2364
+ const combo_id = findWidgetIdByKind(app_state.tree.?.root, .combobox).?;
2365
+
2366
+ // Focus WITHOUT pressing (a click on a combobox IS its open press),
2367
+ // type, and walk the caret off the end so a divergence would show.
2368
+ try core.testing.dispatchAutomationWidgetAction(&harness.runtime, app, .{
2369
+ .view_label = combo_mirror_canvas_label,
2370
+ .id = combo_id,
2371
+ .action = .focus,
2372
+ });
2373
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2374
+ .window_id = 1,
2375
+ .label = combo_mirror_canvas_label,
2376
+ .kind = .text_input,
2377
+ .text = "glass",
2378
+ } });
2379
+ try comboMirrorKey(harness, app, "arrowleft");
2380
+ try comboMirrorKey(harness, app, "arrowleft");
2381
+ try std.testing.expectEqualStrings("glass", app_state.model.query.text());
2382
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(3), app_state.model.query.selection);
2383
+
2384
+ // THE pin: ArrowDown on the closed trigger opens the picker and
2385
+ // both carets stay at 3 — no query edit is heard or applied.
2386
+ const edits_before_open = app_state.model.query_edits;
2387
+ try comboMirrorKey(harness, app, "arrowdown");
2388
+ try std.testing.expect(app_state.model.open);
2389
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.opens);
2390
+ try std.testing.expectEqual(edits_before_open, app_state.model.query_edits);
2391
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(3), app_state.model.query.selection);
2392
+ try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed(3)), try comboMirrorRetainedSelection(harness, combo_id));
2393
+
2394
+ // The OPEN-picker truth, pinned as-is: the next arrow walks the
2395
+ // keyboard INTO the mounted menu (the focus step consumes it before
2396
+ // routing reaches the trigger), so it is no caret edit either.
2397
+ const first_item_id = findWidgetIdByText(app_state.tree.?, .menu_item, "glass bead").?;
2398
+ try comboMirrorKey(harness, app, "arrowdown");
2399
+ try std.testing.expectEqual(first_item_id, harness.runtime.views[0].canvas_widget_focused_id);
2400
+ try std.testing.expectEqual(edits_before_open, app_state.model.query_edits);
2401
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(3), app_state.model.query.selection);
2402
+ try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed(3)), try comboMirrorRetainedSelection(harness, combo_id));
2403
+
2404
+ // Escape is consumed by the DISMISSAL pass while the menu floats:
2405
+ // the picker closes through `on_dismiss` and the combobox's
2406
+ // Escape-clear never runs — the query survives.
2407
+ try comboMirrorKey(harness, app, "escape");
2408
+ try std.testing.expect(!app_state.model.open);
2409
+ try std.testing.expectEqualStrings("glass", app_state.model.query.text());
2410
+ try std.testing.expectEqual(combo_id, harness.runtime.views[0].canvas_widget_focused_id);
2411
+
2412
+ // ArrowUp on the closed trigger is the same open key: opens, and
2413
+ // both carets stay put again.
2414
+ try comboMirrorKey(harness, app, "arrowup");
2415
+ try std.testing.expect(app_state.model.open);
2416
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.opens);
2417
+ try std.testing.expectEqual(edits_before_open, app_state.model.query_edits);
2418
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(3), app_state.model.query.selection);
2419
+ try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed(3)), try comboMirrorRetainedSelection(harness, combo_id));
2420
+ try comboMirrorKey(harness, app, "escape");
2421
+ try std.testing.expect(!app_state.model.open);
2422
+
2423
+ // The suppression is combobox-only: a plain text field keeps the
2424
+ // single-line ArrowUp/Down caret jumps, and the model mirror hears
2425
+ // them through the stamped edit (the #129 seam, unregressed).
2426
+ const note_id = findWidgetIdByKind(app_state.tree.?.root, .text_field).?;
2427
+ const note_frame = (try harness.runtime.canvasWidgetLayout(1, combo_mirror_canvas_label)).findById(note_id).?.frame;
2428
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2429
+ .window_id = 1,
2430
+ .label = combo_mirror_canvas_label,
2431
+ .kind = .pointer_down,
2432
+ .x = note_frame.x + note_frame.width * 0.5,
2433
+ .y = note_frame.y + note_frame.height * 0.5,
2434
+ } });
2435
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2436
+ .window_id = 1,
2437
+ .label = combo_mirror_canvas_label,
2438
+ .kind = .text_input,
2439
+ .text = "abc",
2440
+ } });
2441
+ try comboMirrorKey(harness, app, "arrowup");
2442
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(0), app_state.model.note.selection);
2443
+ try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed(0)), try comboMirrorRetainedSelection(harness, note_id));
2444
+ try comboMirrorKey(harness, app, "arrowdown");
2445
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(3), app_state.model.note.selection);
2446
+ try std.testing.expectEqualDeep(@as(?canvas.TextSelection, canvas.TextSelection.collapsed(3)), try comboMirrorRetainedSelection(harness, note_id));
2447
+ }
2448
+
1989
2449
  // ------------------------------------------------- autofocus (notes flow)
1990
2450
 
1991
2451
  const autofocus_canvas_label = "autofocus-canvas"; // shell scene label below
@@ -3582,3 +4042,337 @@ test "windowed virtual list scrolls, re-windows, budgets to the viewport, and fi
3582
4042
  try std.testing.expectEqual(@as(usize, 600), first_index + mounted);
3583
4043
  try std.testing.expect(mounted >= 25);
3584
4044
  }
4045
+
4046
+ // ------------------------------------------------------- pinch channel
4047
+
4048
+ const ZoomModel = struct {
4049
+ /// Cumulative gesture scale: the running product of `1 + delta`
4050
+ /// across change events — the semantics the channel documents.
4051
+ scale: f32 = 1,
4052
+ begins: u32 = 0,
4053
+ ends: u32 = 0,
4054
+ anchor_x: f32 = 0,
4055
+ anchor_y: f32 = 0,
4056
+ /// Source-identity mirrors: the window and view the last pinch
4057
+ /// event named (x/y are view-local, so a coordinate without its
4058
+ /// view is not a position — multi-window apps tell pinches apart
4059
+ /// by these).
4060
+ window_id: u64 = 0,
4061
+ label: []const u8 = "",
4062
+ };
4063
+
4064
+ const ZoomMsg = union(enum) {
4065
+ pinch: zero_platform.PinchEvent,
4066
+ };
4067
+
4068
+ const ZoomApp = ui_app_model.UiApp(ZoomModel, ZoomMsg);
4069
+
4070
+ fn zoomUpdate(model: *ZoomModel, msg: ZoomMsg) void {
4071
+ switch (msg) {
4072
+ .pinch => |pinch| {
4073
+ model.window_id = pinch.window_id;
4074
+ model.label = pinch.label;
4075
+ switch (pinch.phase) {
4076
+ .begin => {
4077
+ model.begins += 1;
4078
+ model.anchor_x = pinch.x;
4079
+ model.anchor_y = pinch.y;
4080
+ },
4081
+ .change => model.scale *= (1 + pinch.scale),
4082
+ .end => model.ends += 1,
4083
+ }
4084
+ },
4085
+ }
4086
+ }
4087
+
4088
+ fn zoomView(ui: *ZoomApp.Ui, model: *const ZoomModel) ZoomApp.Ui.Node {
4089
+ return ui.column(.{ .gap = 8, .padding = 12 }, .{
4090
+ ui.text(.{}, ui.fmt("Zoom {d:.2}", .{model.scale})),
4091
+ });
4092
+ }
4093
+
4094
+ fn zoomPinch(pinch: zero_platform.PinchEvent) ?ZoomMsg {
4095
+ return .{ .pinch = pinch };
4096
+ }
4097
+
4098
+ test "trackpad pinch reaches the app through on_pinch with product-of-deltas scale" {
4099
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
4100
+ defer harness.destroy(std.testing.allocator);
4101
+ harness.null_platform.gpu_surfaces = true;
4102
+
4103
+ const app_state = try std.testing.allocator.create(ZoomApp);
4104
+ defer std.testing.allocator.destroy(app_state);
4105
+ app_state.* = ZoomApp.init(std.heap.page_allocator, .{}, .{
4106
+ .name = "ui-app-zoom",
4107
+ .scene = counter_scene,
4108
+ .canvas_label = canvas_label,
4109
+ .update = zoomUpdate,
4110
+ .view = zoomView,
4111
+ .on_pinch = zoomPinch,
4112
+ });
4113
+ defer app_state.deinit();
4114
+ const app = app_state.app();
4115
+ try harness.start(app);
4116
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
4117
+ .label = canvas_label,
4118
+ .size = geometry.SizeF.init(400, 300),
4119
+ .scale_factor = 2,
4120
+ .frame_index = 1,
4121
+ .timestamp_ns = 1_000_000,
4122
+ .nonblank = true,
4123
+ } });
4124
+ try std.testing.expect(app_state.installed);
4125
+
4126
+ // begin -> change -> change -> change -> end, the host's phase
4127
+ // stream: the model hears every phase, the pointer anchor rides
4128
+ // x/y, and the cumulative scale is the PRODUCT of (1 + delta) —
4129
+ // two +25% steps land on 1.5625, never the 1.45 a sum-of-deltas
4130
+ // would produce (deltas are raw NSEvent.magnification, the
4131
+ // multiplicative per-event delta per the engine convention; see
4132
+ // the doctrine note in appkit_host.m).
4133
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4134
+ .window_id = 1,
4135
+ .label = canvas_label,
4136
+ .kind = .pinch_begin,
4137
+ .x = 120,
4138
+ .y = 80,
4139
+ } });
4140
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.begins);
4141
+ try std.testing.expectEqual(@as(f32, 120), app_state.model.anchor_x);
4142
+ try std.testing.expectEqual(@as(f32, 80), app_state.model.anchor_y);
4143
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4144
+ .window_id = 1,
4145
+ .label = canvas_label,
4146
+ .kind = .pinch_change,
4147
+ .x = 120,
4148
+ .y = 80,
4149
+ .scale = 0.25,
4150
+ } });
4151
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4152
+ .window_id = 1,
4153
+ .label = canvas_label,
4154
+ .kind = .pinch_change,
4155
+ .x = 120,
4156
+ .y = 80,
4157
+ .scale = 0.25,
4158
+ } });
4159
+ try std.testing.expectEqual(@as(f32, 1.5625), app_state.model.scale);
4160
+ try std.testing.expectEqual(@as(u32, 0), app_state.model.ends);
4161
+ // A terminal-delta Ended: AppKit's Ended/Cancelled event still
4162
+ // carries the magnification since the previous event, so the host
4163
+ // forwards it as one last change BEFORE the end marker — the
4164
+ // product folds it in (1.5625 * 1.25 = 1.953125, binary-exact).
4165
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4166
+ .window_id = 1,
4167
+ .label = canvas_label,
4168
+ .kind = .pinch_change,
4169
+ .x = 120,
4170
+ .y = 80,
4171
+ .scale = 0.25,
4172
+ } });
4173
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4174
+ .window_id = 1,
4175
+ .label = canvas_label,
4176
+ .kind = .pinch_end,
4177
+ .x = 120,
4178
+ .y = 80,
4179
+ } });
4180
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.ends);
4181
+ try std.testing.expectEqual(@as(f32, 1.953125), app_state.model.scale);
4182
+ // The dispatched Msgs rebuilt the view from the model.
4183
+ try std.testing.expect(try retainedTextExists(&harness.runtime, "Zoom 1.95"));
4184
+
4185
+ // A zero-delta Ended is just the end marker: begin then end moves
4186
+ // no scale.
4187
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4188
+ .window_id = 1,
4189
+ .label = canvas_label,
4190
+ .kind = .pinch_begin,
4191
+ .x = 120,
4192
+ .y = 80,
4193
+ } });
4194
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4195
+ .window_id = 1,
4196
+ .label = canvas_label,
4197
+ .kind = .pinch_end,
4198
+ .x = 120,
4199
+ .y = 80,
4200
+ } });
4201
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.begins);
4202
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.ends);
4203
+ try std.testing.expectEqual(@as(f32, 1.953125), app_state.model.scale);
4204
+
4205
+ // Non-pinch raw input never leaks into the channel: a scroll leaves
4206
+ // the model untouched.
4207
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4208
+ .window_id = 1,
4209
+ .label = canvas_label,
4210
+ .kind = .scroll,
4211
+ .delta_y = 24,
4212
+ } });
4213
+ try std.testing.expectEqual(@as(f32, 1.953125), app_state.model.scale);
4214
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.begins);
4215
+
4216
+ // The automation verb drives the same real events: one full gesture
4217
+ // whose change carries scale - 1, anchor defaulting to the view
4218
+ // center, so tests and users can pinch without a trackpad.
4219
+ app_state.model = .{};
4220
+ var command_buffer: [96]u8 = undefined;
4221
+ const pinch_default = try std.fmt.bufPrint(&command_buffer, "widget-pinch {s} 1.5", .{canvas_label});
4222
+ try harness.runtime.dispatchAutomationCommand(app, pinch_default);
4223
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.begins);
4224
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.ends);
4225
+ try std.testing.expectEqual(@as(f32, 1.5), app_state.model.scale);
4226
+ try std.testing.expectEqual(@as(f32, 200), app_state.model.anchor_x);
4227
+ try std.testing.expectEqual(@as(f32, 150), app_state.model.anchor_y);
4228
+
4229
+ // An explicit anchor point rides through; the cumulative scale keeps
4230
+ // compounding across gestures exactly as deltas compound within one.
4231
+ const pinch_at = try std.fmt.bufPrint(&command_buffer, "widget-pinch {s} 0.5 40 60", .{canvas_label});
4232
+ try harness.runtime.dispatchAutomationCommand(app, pinch_at);
4233
+ try std.testing.expectEqual(@as(f32, 0.75), app_state.model.scale);
4234
+ try std.testing.expectEqual(@as(f32, 40), app_state.model.anchor_x);
4235
+ try std.testing.expectEqual(@as(f32, 60), app_state.model.anchor_y);
4236
+
4237
+ // A malformed scale is loud driver misuse, not a dispatched gesture
4238
+ // (the product of 1 + delta can never reach a non-positive scale).
4239
+ const pinch_bad = try std.fmt.bufPrint(&command_buffer, "widget-pinch {s} 0", .{canvas_label});
4240
+ try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchAutomationCommand(app, pinch_bad));
4241
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.begins);
4242
+
4243
+ // The f32 wire can betray the parser's `scale > 0` guard: a tiny
4244
+ // positive scale rounds `scale - 1` to exactly -1 — factor 0 on the
4245
+ // wire — so the dispatch refuses it with the wire-minimum teaching
4246
+ // instead of emitting a zoom through zero scale. Nothing dispatches:
4247
+ // no begin, no journaled partial gesture.
4248
+ const pinch_tiny = try std.fmt.bufPrint(&command_buffer, "widget-pinch {s} 1e-20", .{canvas_label});
4249
+ try std.testing.expectError(error.PinchScaleBelowWireMinimum, harness.runtime.dispatchAutomationCommand(app, pinch_tiny));
4250
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.begins);
4251
+ try std.testing.expectEqual(@as(f32, 0.75), app_state.model.scale);
4252
+
4253
+ // The smallest accepted scale — the first f32 above 2^-25 — round-
4254
+ // trips with a positive factor: its delta rounds to -1 + 2^-24, so
4255
+ // the factor is exactly 2^-24 and the model's product stays > 0
4256
+ // (0.75 * 2^-24 = 0x1.8p-25, binary-exact).
4257
+ const pinch_min = try std.fmt.bufPrint(&command_buffer, "widget-pinch {s} 2.9802326e-8", .{canvas_label});
4258
+ try harness.runtime.dispatchAutomationCommand(app, pinch_min);
4259
+ try std.testing.expectEqual(@as(u32, 3), app_state.model.begins);
4260
+ try std.testing.expectEqual(@as(u32, 3), app_state.model.ends);
4261
+ try std.testing.expect(app_state.model.scale > 0);
4262
+ try std.testing.expectEqual(@as(f32, 0x1.8p-25), app_state.model.scale);
4263
+ }
4264
+
4265
+ const zoom_pair_main_views = [_]app_manifest.ShellView{
4266
+ .{ .label = "zoom-main-canvas", .kind = .gpu_surface, .fill = true, .gpu_backend = .metal },
4267
+ };
4268
+ const zoom_pair_inspector_views = [_]app_manifest.ShellView{
4269
+ .{ .label = "zoom-inspector-canvas", .kind = .gpu_surface, .fill = true, .gpu_backend = .metal },
4270
+ };
4271
+ const zoom_pair_windows = [_]app_manifest.ShellWindow{ .{
4272
+ .label = "main",
4273
+ .title = "Zoom",
4274
+ .width = 400,
4275
+ .height = 300,
4276
+ .views = &zoom_pair_main_views,
4277
+ }, .{
4278
+ .label = "inspector",
4279
+ .title = "Zoom Inspector",
4280
+ .width = 300,
4281
+ .height = 300,
4282
+ .views = &zoom_pair_inspector_views,
4283
+ } };
4284
+ const zoom_pair_scene: app_manifest.ShellConfig = .{ .windows = &zoom_pair_windows };
4285
+
4286
+ test "pinch identity distinguishes windows and views in the Msg" {
4287
+ // Two windows, two gpu-surface views: the pinch channel forwards
4288
+ // the source identity (window_id + view label) the journaled
4289
+ // platform event already carries, so a multi-window app hears WHICH
4290
+ // view a gesture zoomed — x/y are view-local, and a coordinate
4291
+ // without its view is not a position.
4292
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
4293
+ defer harness.destroy(std.testing.allocator);
4294
+ harness.null_platform.gpu_surfaces = true;
4295
+
4296
+ const app_state = try std.testing.allocator.create(ZoomApp);
4297
+ defer std.testing.allocator.destroy(app_state);
4298
+ app_state.* = ZoomApp.init(std.heap.page_allocator, .{}, .{
4299
+ .name = "ui-app-zoom-pair",
4300
+ .scene = zoom_pair_scene,
4301
+ .canvas_label = "zoom-main-canvas",
4302
+ .update = zoomUpdate,
4303
+ .view = zoomView,
4304
+ .on_pinch = zoomPinch,
4305
+ });
4306
+ defer app_state.deinit();
4307
+ const app = app_state.app();
4308
+ try harness.start(app);
4309
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
4310
+ .label = "zoom-main-canvas",
4311
+ .size = geometry.SizeF.init(400, 300),
4312
+ .scale_factor = 2,
4313
+ .frame_index = 1,
4314
+ .timestamp_ns = 1_000_000,
4315
+ .nonblank = true,
4316
+ } });
4317
+ try std.testing.expect(app_state.installed);
4318
+
4319
+ // A gesture on the main window's canvas names its source on every
4320
+ // phase.
4321
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4322
+ .window_id = 1,
4323
+ .label = "zoom-main-canvas",
4324
+ .kind = .pinch_begin,
4325
+ .x = 100,
4326
+ .y = 50,
4327
+ } });
4328
+ try std.testing.expectEqual(@as(u64, 1), app_state.model.window_id);
4329
+ try std.testing.expectEqualStrings("zoom-main-canvas", app_state.model.label);
4330
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4331
+ .window_id = 1,
4332
+ .label = "zoom-main-canvas",
4333
+ .kind = .pinch_change,
4334
+ .x = 100,
4335
+ .y = 50,
4336
+ .scale = 0.25,
4337
+ } });
4338
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4339
+ .window_id = 1,
4340
+ .label = "zoom-main-canvas",
4341
+ .kind = .pinch_end,
4342
+ .x = 100,
4343
+ .y = 50,
4344
+ } });
4345
+ try std.testing.expectEqual(@as(f32, 1.25), app_state.model.scale);
4346
+
4347
+ // A gesture on the second window's view is distinguishable: same
4348
+ // channel, different identity in the Msg.
4349
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4350
+ .window_id = 2,
4351
+ .label = "zoom-inspector-canvas",
4352
+ .kind = .pinch_begin,
4353
+ .x = 10,
4354
+ .y = 20,
4355
+ } });
4356
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4357
+ .window_id = 2,
4358
+ .label = "zoom-inspector-canvas",
4359
+ .kind = .pinch_change,
4360
+ .x = 10,
4361
+ .y = 20,
4362
+ .scale = -0.5,
4363
+ } });
4364
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4365
+ .window_id = 2,
4366
+ .label = "zoom-inspector-canvas",
4367
+ .kind = .pinch_end,
4368
+ .x = 10,
4369
+ .y = 20,
4370
+ } });
4371
+ try std.testing.expectEqual(@as(u64, 2), app_state.model.window_id);
4372
+ try std.testing.expectEqualStrings("zoom-inspector-canvas", app_state.model.label);
4373
+ // Both gestures compounded the one model's zoom (1.25 * 0.5,
4374
+ // binary-exact) and every phase was heard.
4375
+ try std.testing.expectEqual(@as(f32, 0.625), app_state.model.scale);
4376
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.begins);
4377
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.ends);
4378
+ }