@native-sdk/cli 0.5.0 → 0.5.2

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 (60) hide show
  1. package/build/app.zig +198 -13
  2. package/build/ts_run.mjs +58 -19
  3. package/build.zig +42 -0
  4. package/package.json +13 -9
  5. package/packages/core/package-lock.json +4 -3
  6. package/packages/core/package.json +3 -2
  7. package/packages/core/src/typed_ast.ts +11 -1
  8. package/skill-data/native-ui/SKILL.md +2 -2
  9. package/src/platform/types.zig +9 -0
  10. package/src/platform/windows/webview2_host.cpp +24 -0
  11. package/src/primitives/canvas/layout_audit.zig +5 -5
  12. package/src/primitives/canvas/root.zig +6 -0
  13. package/src/primitives/canvas/tokens.zig +185 -7
  14. package/src/primitives/canvas/ui.zig +27 -5
  15. package/src/primitives/canvas/ui_markup.zig +27 -4
  16. package/src/primitives/canvas/ui_markup_compiled.zig +9 -1
  17. package/src/primitives/canvas/ui_markup_compiled_tests.zig +127 -0
  18. package/src/primitives/canvas/ui_markup_tests.zig +47 -0
  19. package/src/primitives/canvas/ui_markup_view.zig +10 -1
  20. package/src/primitives/canvas/ui_markup_view_tests.zig +78 -0
  21. package/src/primitives/canvas/ui_schema.zig +15 -1
  22. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  23. package/src/primitives/canvas/widget_builtin_tests.zig +439 -5
  24. package/src/primitives/canvas/widget_layout.zig +142 -3
  25. package/src/primitives/canvas/widget_layout_tests.zig +82 -0
  26. package/src/primitives/canvas/widget_metrics.zig +16 -8
  27. package/src/primitives/canvas/widget_tree.zig +14 -2
  28. package/src/primitives/canvas/widgets.zig +12 -0
  29. package/src/runtime/automation_widget_dispatch.zig +95 -28
  30. package/src/runtime/canvas_frame.zig +15 -0
  31. package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
  32. package/src/runtime/canvas_widget_context_menu.zig +3 -2
  33. package/src/runtime/canvas_widget_events.zig +1271 -3
  34. package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
  35. package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
  36. package/src/runtime/canvas_widget_state.zig +82 -5
  37. package/src/runtime/core.zig +30 -0
  38. package/src/runtime/effects.zig +1037 -133
  39. package/src/runtime/effects_fetch_tests.zig +42 -0
  40. package/src/runtime/effects_file_tests.zig +220 -0
  41. package/src/runtime/effects_tests.zig +287 -0
  42. package/src/runtime/flow.zig +24 -1
  43. package/src/runtime/gpu_surface_events.zig +44 -5
  44. package/src/runtime/session_journal.zig +25 -13
  45. package/src/runtime/session_record.zig +166 -0
  46. package/src/runtime/session_tests.zig +453 -0
  47. package/src/runtime/ui_app.zig +137 -39
  48. package/src/runtime/ui_app_tests.zig +681 -0
  49. package/src/runtime/ui_app_window_tests.zig +182 -0
  50. package/src/runtime/view.zig +86 -0
  51. package/src/runtime/view_widget_text.zig +18 -1
  52. package/src/runtime/view_widget_tree.zig +339 -20
  53. package/src/runtime/widget_bridge.zig +26 -0
  54. package/src/runtime/window_storage.zig +61 -15
  55. package/src/runtime/window_view_runtime.zig +13 -0
  56. package/src/runtime/window_views.zig +6 -0
  57. package/src/tooling/package.zig +311 -8
  58. package/src/tooling/templates.zig +97 -9
  59. package/src/tooling/ts_core.zig +626 -13
  60. package/src/tooling/verbs.zig +88 -2
@@ -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
@@ -3185,6 +3645,227 @@ test "ui app delivers chrome overlay geometry before install and on change" {
3185
3645
  try std.testing.expect(try retainedTextExists(&harness.runtime, "leading 0"));
3186
3646
  }
3187
3647
 
3648
+ // ---------------------------------- window-control clearance fixtures
3649
+
3650
+ const CaptionModel = struct {
3651
+ /// The trailing chrome reservation the CONTRACT app consumes (the
3652
+ /// soundboard pattern: a spacer sized to `insets.right`); the naive
3653
+ /// app leaves it unwired at 0, exactly like an app that never
3654
+ /// subscribed to the chrome channel.
3655
+ trailing: f32 = 0,
3656
+ };
3657
+
3658
+ const CaptionMsg = union(enum) {
3659
+ chrome: zero_platform.WindowChrome,
3660
+ };
3661
+
3662
+ const CaptionApp = ui_app_model.UiApp(CaptionModel, CaptionMsg);
3663
+
3664
+ fn captionUpdate(model: *CaptionModel, msg: CaptionMsg) void {
3665
+ switch (msg) {
3666
+ .chrome => |chrome| model.trailing = chrome.insets.right,
3667
+ }
3668
+ }
3669
+
3670
+ /// A hidden-titlebar header that never consumed the chrome channel:
3671
+ /// title leading, status text trailing — the system-monitor shape whose
3672
+ /// status line rendered UNDER the Windows caption buttons.
3673
+ fn captionNaiveView(ui: *CaptionApp.Ui, model: *const CaptionModel) CaptionApp.Ui.Node {
3674
+ _ = model;
3675
+ return ui.column(.{}, .{
3676
+ ui.row(.{ .window_drag = true, .height = 40 }, .{
3677
+ ui.text(.{}, "Monitor"),
3678
+ ui.el(.stack, .{ .grow = 1 }, .{}),
3679
+ ui.text(.{}, "sampling"),
3680
+ }),
3681
+ ui.text(.{}, "body"),
3682
+ });
3683
+ }
3684
+
3685
+ /// The documented contract shape (the soundboard pattern): the header
3686
+ /// ends with a spacer sized to `insets.right`, so its own content
3687
+ /// already clears the caption cluster and the runtime reservation must
3688
+ /// stay out of the way.
3689
+ fn captionContractView(ui: *CaptionApp.Ui, model: *const CaptionModel) CaptionApp.Ui.Node {
3690
+ return ui.column(.{}, .{
3691
+ ui.row(.{ .window_drag = true, .height = 40 }, .{
3692
+ ui.text(.{}, "Monitor"),
3693
+ ui.el(.stack, .{ .grow = 1 }, .{}),
3694
+ ui.text(.{}, "sampling"),
3695
+ ui.el(.stack, .{ .width = model.trailing }, .{}),
3696
+ }),
3697
+ ui.text(.{}, "body"),
3698
+ });
3699
+ }
3700
+
3701
+ /// The centered-title pattern: ONE grow text spanning the header row.
3702
+ /// Its FRAME runs under the caption cluster, but the centered glyphs
3703
+ /// sit well clear of it — nothing here needs (or may pay for) the
3704
+ /// clearance retry.
3705
+ fn captionCenteredView(ui: *CaptionApp.Ui, model: *const CaptionModel) CaptionApp.Ui.Node {
3706
+ _ = model;
3707
+ return ui.column(.{}, .{
3708
+ ui.row(.{ .window_drag = true, .height = 40 }, .{
3709
+ ui.text(.{ .grow = 1, .text_alignment = .center }, "Monitor"),
3710
+ }),
3711
+ ui.text(.{}, "body"),
3712
+ });
3713
+ }
3714
+
3715
+ fn captionChromeMap(chrome: zero_platform.WindowChrome) ?CaptionMsg {
3716
+ return .{ .chrome = chrome };
3717
+ }
3718
+
3719
+ fn captionTextFrame(runtime: *core.Runtime, text: []const u8) !geometry.RectF {
3720
+ const layout = try runtime.canvasWidgetLayout(1, canvas_label);
3721
+ for (layout.nodes) |node| {
3722
+ if (node.widget.kind == .text and std.mem.eql(u8, node.widget.text, text)) return node.frame;
3723
+ }
3724
+ return error.TestUnexpectedResult;
3725
+ }
3726
+
3727
+ test "drag header trailing content stays clear of the Windows caption cluster" {
3728
+ // Windows-shaped hidden-titlebar chrome on a 400pt window: the DWM
3729
+ // caption cluster overlays the trailing 138pt of the top band, and
3730
+ // the platform reports it through the same chrome channel macOS
3731
+ // reports the traffic lights on. The app never consumed the
3732
+ // channel, so its right-aligned header status would lay out flush
3733
+ // to the window edge — UNDER the min/max/close buttons. The runtime
3734
+ // detects the collision after layout and re-lays the drag header
3735
+ // with the cluster reserved, so the status text ends at the
3736
+ // cluster's leading edge instead.
3737
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
3738
+ defer harness.destroy(std.testing.allocator);
3739
+ harness.null_platform.gpu_surfaces = true;
3740
+ harness.null_platform.window_chrome = .{
3741
+ .insets = .{ .top = 32, .right = 138 },
3742
+ .buttons = geometry.RectF.init(262, 0, 138, 32),
3743
+ };
3744
+
3745
+ const app_state = try std.testing.allocator.create(CaptionApp);
3746
+ defer std.testing.allocator.destroy(app_state);
3747
+ app_state.* = CaptionApp.init(std.heap.page_allocator, .{}, .{
3748
+ .name = "ui-app-caption-naive",
3749
+ .scene = counter_scene,
3750
+ .canvas_label = canvas_label,
3751
+ .update = captionUpdate,
3752
+ .view = captionNaiveView,
3753
+ });
3754
+ defer app_state.deinit();
3755
+ const app = app_state.app();
3756
+ try harness.start(app);
3757
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
3758
+ .label = canvas_label,
3759
+ .size = geometry.SizeF.init(400, 300),
3760
+ .scale_factor = 1,
3761
+ .frame_index = 1,
3762
+ .timestamp_ns = 1_000_000,
3763
+ .nonblank = true,
3764
+ } });
3765
+ try std.testing.expect(app_state.installed);
3766
+
3767
+ // The trailing status text ends at (or before) the cluster's
3768
+ // leading edge; without the reservation it ended at the window's
3769
+ // right edge, inside the cluster.
3770
+ const status = try captionTextFrame(&harness.runtime, "sampling");
3771
+ try std.testing.expect(status.maxX() <= 262 + 0.01);
3772
+ // The leading title and the body below the band are untouched.
3773
+ const title = try captionTextFrame(&harness.runtime, "Monitor");
3774
+ try std.testing.expectEqual(@as(f32, 0), title.x);
3775
+ }
3776
+
3777
+ test "drag header that already pads the caption cluster keeps its layout" {
3778
+ // The contract app (the soundboard shape): its header ends with a
3779
+ // spacer consuming `insets.right`, so nothing collides and the
3780
+ // runtime reservation must NOT fire — a double reservation would
3781
+ // shove the status text a full cluster-width further left.
3782
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
3783
+ defer harness.destroy(std.testing.allocator);
3784
+ harness.null_platform.gpu_surfaces = true;
3785
+ harness.null_platform.window_chrome = .{
3786
+ .insets = .{ .top = 32, .right = 138 },
3787
+ .buttons = geometry.RectF.init(262, 0, 138, 32),
3788
+ };
3789
+
3790
+ const app_state = try std.testing.allocator.create(CaptionApp);
3791
+ defer std.testing.allocator.destroy(app_state);
3792
+ app_state.* = CaptionApp.init(std.heap.page_allocator, .{}, .{
3793
+ .name = "ui-app-caption-contract",
3794
+ .scene = counter_scene,
3795
+ .canvas_label = canvas_label,
3796
+ .update = captionUpdate,
3797
+ .view = captionContractView,
3798
+ .on_chrome = captionChromeMap,
3799
+ });
3800
+ defer app_state.deinit();
3801
+ const app = app_state.app();
3802
+ try harness.start(app);
3803
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
3804
+ .label = canvas_label,
3805
+ .size = geometry.SizeF.init(400, 300),
3806
+ .scale_factor = 1,
3807
+ .frame_index = 1,
3808
+ .timestamp_ns = 1_000_000,
3809
+ .nonblank = true,
3810
+ } });
3811
+ try std.testing.expect(app_state.installed);
3812
+ try std.testing.expectEqual(@as(f32, 138), app_state.model.trailing);
3813
+
3814
+ // The app's own spacer puts the status text at the cluster's edge;
3815
+ // the runtime must not reserve on top of it (a double reservation
3816
+ // would land it near 262 - 138 = 124).
3817
+ const status = try captionTextFrame(&harness.runtime, "sampling");
3818
+ try std.testing.expect(@abs(status.maxX() - 262) < 0.5);
3819
+ }
3820
+
3821
+ test "drag header centered title never pays the clearance retry" {
3822
+ // The false positive the painted-bounds scan removes: a grow text
3823
+ // spanning the header row with centered glyphs. Its FRAME runs
3824
+ // under the caption cluster, but nothing inked does — a frame-based
3825
+ // scan paid the one retry here, and the remedy's trimmed content
3826
+ // box then visibly shifted the centered title left. The scan judges
3827
+ // aligned painted bounds, so no retry fires and the layout is
3828
+ // byte-identical to an unstamped build: the title's grow frame
3829
+ // still spans the full row, cluster and all.
3830
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
3831
+ defer harness.destroy(std.testing.allocator);
3832
+ harness.null_platform.gpu_surfaces = true;
3833
+ harness.null_platform.window_chrome = .{
3834
+ .insets = .{ .top = 32, .right = 138 },
3835
+ .buttons = geometry.RectF.init(262, 0, 138, 32),
3836
+ };
3837
+
3838
+ const app_state = try std.testing.allocator.create(CaptionApp);
3839
+ defer std.testing.allocator.destroy(app_state);
3840
+ app_state.* = CaptionApp.init(std.heap.page_allocator, .{}, .{
3841
+ .name = "ui-app-caption-centered",
3842
+ .scene = counter_scene,
3843
+ .canvas_label = canvas_label,
3844
+ .update = captionUpdate,
3845
+ .view = captionCenteredView,
3846
+ });
3847
+ defer app_state.deinit();
3848
+ const app = app_state.app();
3849
+ try harness.start(app);
3850
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
3851
+ .label = canvas_label,
3852
+ .size = geometry.SizeF.init(400, 300),
3853
+ .scale_factor = 1,
3854
+ .frame_index = 1,
3855
+ .timestamp_ns = 1_000_000,
3856
+ .nonblank = true,
3857
+ } });
3858
+ try std.testing.expect(app_state.installed);
3859
+
3860
+ // No reservation fired: the title's frame still spans the whole
3861
+ // row. A paid retry would have trimmed the drag row's content box
3862
+ // at the cluster's leading edge (262) and re-centered the glyphs
3863
+ // inside the trimmed frame — the visible title shift.
3864
+ const title = try captionTextFrame(&harness.runtime, "Monitor");
3865
+ try std.testing.expectEqual(@as(f32, 0), title.x);
3866
+ try std.testing.expectEqual(@as(f32, 400), title.maxX());
3867
+ }
3868
+
3188
3869
  // -------------------------------------- windowed virtual list fixture
3189
3870
 
3190
3871
  const VirtualFeedModel = struct {