@native-sdk/cli 0.5.4 → 0.6.0

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 +534 -3
  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 +1283 -66
  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 +70 -1
  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 +240 -24
  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 +473 -13
  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 +109 -15
  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 +2333 -63
  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
@@ -511,23 +511,25 @@ test "rebuild dirty bounds derive from the patch edit script, not the window" {
511
511
  try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, baseline.mode);
512
512
  try std.testing.expect(harness.runtime.views[0].canvas_packet_baseline_valid);
513
513
 
514
- // Rebuild with ONE color change: dirty is that command's rect, the
515
- // present is a one-upsert patch, and the wire scissor matches.
514
+ // Rebuild with ONE color change: dirty is that command's rect plus
515
+ // the one-device-pixel AA bleed allowance, the present is a
516
+ // one-upsert patch, and the wire scissor matches.
516
517
  rects[13].fill_rect.fill = .{ .color = canvas.Color.rgb8(37, 99, 235) };
517
518
  _ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &rects });
518
519
  const toggled = try presentFrame(harness, &buffers, 61);
519
520
  try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, toggled.mode);
520
- try std.testing.expectEqualDeep(buildGrid.rectAt(13), toggled.frame.dirty_bounds.?);
521
+ try std.testing.expectEqualDeep(buildGrid.rectAt(13).inflate(geometry.InsetsF.all(1)), toggled.frame.dirty_bounds.?);
521
522
  try std.testing.expectEqual(platform.GpuPresentPacketMode.patch, harness.runtime.views[0].gpu_present_packet_mode);
522
523
  try std.testing.expectEqual(@as(usize, 1), harness.runtime.views[0].gpu_present_patch_upsert_count);
523
524
 
524
- // Rebuild that MOVES a command: dirty covers old and new extents.
525
+ // Rebuild that MOVES a command: dirty covers old and new extents
526
+ // (plus the bleed).
525
527
  const moved_from = buildGrid.rectAt(20);
526
528
  const moved_to = geometry.RectF.init(moved_from.x + 60, moved_from.y + 30, 30, 18);
527
529
  rects[20].fill_rect.rect = moved_to;
528
530
  _ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &rects });
529
531
  const moved = try presentFrame(harness, &buffers, 62);
530
- try std.testing.expectEqualDeep(geometry.RectF.unionWith(moved_from, moved_to), moved.frame.dirty_bounds.?);
532
+ try std.testing.expectEqualDeep(geometry.RectF.unionWith(moved_from, moved_to).inflate(geometry.InsetsF.all(1)), moved.frame.dirty_bounds.?);
531
533
 
532
534
  // Identical rebuild (revision bumps, content does not): the edit
533
535
  // script is empty, so nothing presents at all.
@@ -585,17 +587,166 @@ test "rebuild dirty bounds derive from the edit script on small command lists to
585
587
  try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, baseline.mode);
586
588
  try std.testing.expect(harness.runtime.views[0].canvas_packet_baseline_valid);
587
589
 
588
- // Rebuild with ONE color change: dirty is that command's rect, not
589
- // the window, and the present is a one-upsert patch.
590
+ // Rebuild with ONE color change: dirty is that command's rect plus
591
+ // the AA bleed, not the window, and the present is a one-upsert
592
+ // patch.
590
593
  rects[7].fill_rect.fill = .{ .color = canvas.Color.rgb8(37, 99, 235) };
591
594
  _ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &rects });
592
595
  const toggled = try presentFrame(harness, &buffers, 71);
593
596
  try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, toggled.mode);
594
- try std.testing.expectEqualDeep(buildRow.rectAt(7), toggled.frame.dirty_bounds.?);
597
+ try std.testing.expectEqualDeep(buildRow.rectAt(7).inflate(geometry.InsetsF.all(1)), toggled.frame.dirty_bounds.?);
595
598
  try std.testing.expectEqual(platform.GpuPresentPacketMode.patch, harness.runtime.views[0].gpu_present_packet_mode);
596
599
  try std.testing.expectEqual(@as(usize, 1), harness.runtime.views[0].gpu_present_patch_upsert_count);
597
600
  }
598
601
 
602
+ fn reflowPillCommand(id: canvas.ObjectId, rect: geometry.RectF) canvas.CanvasCommand {
603
+ return .{ .fill_rounded_rect = .{
604
+ .id = id,
605
+ .rect = rect,
606
+ .radius = canvas.Radius.all(rect.height * 0.5),
607
+ .fill = .{ .color = canvas.Color.rgb8(148, 163, 184) },
608
+ } };
609
+ }
610
+
611
+ fn expectDirtyCovers(dirty: geometry.RectF, painted: geometry.RectF) !void {
612
+ // The damage region must cover the painted extent of the rect plus
613
+ // the one-device-pixel AA bleed hosts can ink past its bounds.
614
+ const required = painted.normalized().inflate(geometry.InsetsF.all(1));
615
+ const epsilon: f32 = 1e-4;
616
+ try std.testing.expect(dirty.minX() <= required.minX() + epsilon);
617
+ try std.testing.expect(dirty.minY() <= required.minY() + epsilon);
618
+ try std.testing.expect(dirty.maxX() >= required.maxX() - epsilon);
619
+ try std.testing.expect(dirty.maxY() >= required.maxY() - epsilon);
620
+ }
621
+
622
+ fn expectDirtyRectsCover(rects: []const geometry.RectF, painted: geometry.RectF) !void {
623
+ // Refined dirty rect lists are what retained hosts CLEAR: at least
624
+ // one rect must cover the painted extent plus its AA bleed, or the
625
+ // vacated fringe survives the repaint.
626
+ const required = painted.normalized().inflate(geometry.InsetsF.all(1));
627
+ const epsilon: f32 = 1e-4;
628
+ for (rects) |rect| {
629
+ if (rect.minX() <= required.minX() + epsilon and
630
+ rect.minY() <= required.minY() + epsilon and
631
+ rect.maxX() >= required.maxX() - epsilon and
632
+ rect.maxY() >= required.maxY() - epsilon) return;
633
+ }
634
+ return error.DirtyRectsMissPaintedExtent;
635
+ }
636
+
637
+ test "reflow damage covers vacated pixels plus the anti-aliasing bleed" {
638
+ // The list-detail regression shape: a selection change reflows a
639
+ // row of rounded pills at fractional coordinates — pills get
640
+ // removed, shrunk, moved, and replaced under new keys. Each
641
+ // incremental present's damage must cover the OLD painted extent
642
+ // (bounds plus the one-device-pixel AA bleed host rasterizers ink
643
+ // past them) as well as the new one; anything less leaves stale
644
+ // fringes at the old pills' edges.
645
+ var app_state: PatchHarnessApp = .{};
646
+ const harness = try createPatchHarness(&app_state);
647
+ defer harness.destroy(std.testing.allocator);
648
+ var buffers = try PresentBuffers.init(std.testing.allocator);
649
+ defer buffers.deinit(std.testing.allocator);
650
+
651
+ const anchor = canvas.CanvasCommand{ .fill_rect = .{
652
+ .id = 100,
653
+ .rect = geometry.RectF.init(4, 4, 24, 12),
654
+ .fill = .{ .color = canvas.Color.rgb8(51, 65, 85) },
655
+ } };
656
+ const pill_wide = geometry.RectF.init(30.4, 60.6, 120.2, 24.8);
657
+ const pill_second = geometry.RectF.init(160.9, 60.6, 80.3, 24.8);
658
+ const pill_shrunk = geometry.RectF.init(30.4, 60.6, 70.1, 20.3);
659
+ const pill_moved = geometry.RectF.init(90.7, 130.2, 70.1, 20.3);
660
+ const pill_replacement = geometry.RectF.init(42.5, 132.9, 96.6, 22.4);
661
+ const pillAt = reflowPillCommand;
662
+
663
+ // Baseline: two pills; the first present is necessarily full.
664
+ _ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &.{ anchor, pillAt(201, pill_wide), pillAt(202, pill_second) } });
665
+ const baseline = try presentFrame(harness, &buffers, 80);
666
+ try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, baseline.mode);
667
+ try std.testing.expect(harness.runtime.views[0].canvas_packet_baseline_valid);
668
+
669
+ // Removed: the second pill's arm turns off. Damage must cover the
670
+ // vacated pill plus its bleed.
671
+ _ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &.{ anchor, pillAt(201, pill_wide) } });
672
+ const removed = try presentFrame(harness, &buffers, 81);
673
+ try std.testing.expect(!removed.frame.full_repaint);
674
+ try expectDirtyCovers(removed.frame.dirty_bounds.?, pill_second);
675
+
676
+ // Shrunk: the surviving pill narrows and shortens. Damage must
677
+ // cover the OLD, larger extent.
678
+ _ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &.{ anchor, pillAt(201, pill_shrunk) } });
679
+ const shrunk = try presentFrame(harness, &buffers, 82);
680
+ try std.testing.expect(!shrunk.frame.full_repaint);
681
+ try expectDirtyCovers(shrunk.frame.dirty_bounds.?, pill_wide);
682
+ try expectDirtyCovers(shrunk.frame.dirty_bounds.?, pill_shrunk);
683
+
684
+ // Moved: same pill, new position. Damage covers both poses.
685
+ _ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &.{ anchor, pillAt(201, pill_moved) } });
686
+ const moved = try presentFrame(harness, &buffers, 83);
687
+ try std.testing.expect(!moved.frame.full_repaint);
688
+ try expectDirtyCovers(moved.frame.dirty_bounds.?, pill_shrunk);
689
+ try expectDirtyCovers(moved.frame.dirty_bounds.?, pill_moved);
690
+
691
+ // Keyed replacement: the subtree swaps — the old pill's key
692
+ // vanishes, a new key mounts elsewhere. Damage covers the evicted
693
+ // extent and the mounted one, and the refined rect list (what a
694
+ // retained host actually clears) covers each with its bleed.
695
+ _ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &.{ anchor, pillAt(301, pill_replacement), pillAt(302, geometry.RectF.init(200.2, 20.7, 60.4, 18.6)) } });
696
+ const replaced = try presentFrame(harness, &buffers, 84);
697
+ try std.testing.expect(!replaced.frame.full_repaint);
698
+ try expectDirtyCovers(replaced.frame.dirty_bounds.?, pill_moved);
699
+ try expectDirtyCovers(replaced.frame.dirty_bounds.?, pill_replacement);
700
+ if (replaced.frame.dirtyRects().len > 0) {
701
+ try expectDirtyRectsCover(replaced.frame.dirtyRects(), pill_moved);
702
+ try expectDirtyRectsCover(replaced.frame.dirtyRects(), pill_replacement);
703
+ }
704
+ }
705
+
706
+ test "a coarser presentation scale widens reflow damage to its device pixel" {
707
+ // Frames plan at the surface scale, but a present may override the
708
+ // EFFECTIVE scale downward (`packet_scale`/`pixel_scale`). The AA
709
+ // bleed allowance was folded in at plan scale, so the present must
710
+ // widen the damage to the coarser scale's device pixel — half a
711
+ // point of allowance where the host's raster apron spans a full
712
+ // point reopens the stale fringe.
713
+ var app_state: PatchHarnessApp = .{};
714
+ const harness = try createPatchHarness(&app_state);
715
+ defer harness.destroy(std.testing.allocator);
716
+ var buffers = try PresentBuffers.init(std.testing.allocator);
717
+ defer buffers.deinit(std.testing.allocator);
718
+
719
+ const anchor = canvas.CanvasCommand{ .fill_rect = .{
720
+ .id = 100,
721
+ .rect = geometry.RectF.init(4, 4, 24, 12),
722
+ .fill = .{ .color = canvas.Color.rgb8(51, 65, 85) },
723
+ } };
724
+ const pill = geometry.RectF.init(30.4, 60.6, 120.2, 24.8);
725
+ const presentAtScaleOne = struct {
726
+ fn present(h: anytype, b: *PresentBuffers, frame_index: u64) !CanvasPresentationResult {
727
+ return h.runtime.presentNextCanvasFrame(1, "canvas", .{
728
+ .frame_index = frame_index,
729
+ .timestamp_ns = frame_index * 16_000,
730
+ .surface_size = geometry.SizeF.init(patch_surface_width, patch_surface_height),
731
+ .scale = 2,
732
+ }, canvasFrameScratchStorage(&h.runtime), b.gpu_commands, b.packet_buffer, b.pixels, b.scratch, canvas.Color.rgb8(15, 23, 42), 1);
733
+ }
734
+ }.present;
735
+
736
+ _ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &.{ anchor, reflowPillCommand(401, pill) } });
737
+ const baseline = try presentAtScaleOne(harness, &buffers, 90);
738
+ try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, baseline.mode);
739
+
740
+ // Removed pill: the damage must carry a FULL point of allowance —
741
+ // one device pixel at the presented scale (1), not the plan
742
+ // scale's (2) half point.
743
+ _ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &.{anchor} });
744
+ const removed = try presentAtScaleOne(harness, &buffers, 91);
745
+ try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, removed.mode);
746
+ try std.testing.expect(!removed.frame.full_repaint);
747
+ try expectDirtyCovers(removed.frame.dirty_bounds.?, pill);
748
+ }
749
+
599
750
  test "a host that refuses patches gets a full resync in the same frame" {
600
751
  var app_state: PatchHarnessApp = .{};
601
752
  const harness = try createPatchHarness(&app_state);
@@ -1066,8 +1217,8 @@ test "pixel presents adopt a dirty-refinement baseline only for opted-in hosts a
1066
1217
  .scale = 1,
1067
1218
  }, canvasFrameScratchStorage(&harness.runtime), buffers.pixels, buffers.scratch, canvas.Color.rgb8(15, 23, 42));
1068
1219
  try std.testing.expect(!toggled.full_repaint);
1069
- try std.testing.expectEqualDeep(buildGrid.rectAt(13), toggled.dirty_bounds.?);
1070
- try std.testing.expectEqualDeep(buildGrid.rectAt(13), harness.null_platform.gpu_surface_present_dirty_bounds.?);
1220
+ try std.testing.expectEqualDeep(buildGrid.rectAt(13).inflate(geometry.InsetsF.all(1)), toggled.dirty_bounds.?);
1221
+ try std.testing.expectEqualDeep(buildGrid.rectAt(13).inflate(geometry.InsetsF.all(1)), harness.null_platform.gpu_surface_present_dirty_bounds.?);
1071
1222
 
1072
1223
  // A packet present against the pixel-adopted mirror resyncs FULL —
1073
1224
  // the patch gate refuses it even though the baseline is valid.
@@ -308,7 +308,9 @@ test "runtime canvas frame plan computes incremental dirty from previous display
308
308
  try std.testing.expectEqual(@as(usize, 1), frame.changes.len);
309
309
  try std.testing.expectEqual(canvas.DiffKind.changed, frame.changes[0].kind);
310
310
  try std.testing.expectEqual(@as(?canvas.ObjectId, 1), frame.changes[0].id);
311
- try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 60, 40), frame.dirty_bounds.?);
311
+ // Old extent (0,0,40,40) union new (20,0,40,40), inflated by the
312
+ // one-device-pixel AA bleed and clipped to the surface.
313
+ try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 61, 41), frame.dirty_bounds.?);
312
314
  }
313
315
 
314
316
  test "runtime next canvas frame tracks presented state and resource cache" {
@@ -396,7 +398,8 @@ test "runtime next canvas frame tracks presented state and resource cache" {
396
398
  try std.testing.expect(moved_frame.requiresRender());
397
399
  try std.testing.expectEqual(@as(usize, 1), moved_frame.changes.len);
398
400
  try std.testing.expectEqual(canvas.DiffKind.changed, moved_frame.changes[0].kind);
399
- try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 60, 40), moved_frame.dirty_bounds.?);
401
+ // Both extents' union, inflated by the AA bleed and surface-clipped.
402
+ try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 61, 41), moved_frame.dirty_bounds.?);
400
403
  try std.testing.expectEqual(@as(usize, 1), moved_frame.resource_cache_plan.retainCount());
401
404
  try std.testing.expectEqual(@as(u64, 2), harness.runtime.views[0].presented_canvas_revision);
402
405
  }
@@ -940,7 +940,7 @@ test "runtime publishes canvas widget accessibility snapshots to platform" {
940
940
  } });
941
941
  try std.testing.expect(runtime.dispatchErrors().len > errors_before_invalid);
942
942
  try std.testing.expectEqualStrings("InvalidCommand", runtime.dispatchErrors()[runtime.dispatchErrors().len - 1].error_name);
943
- try std.testing.expectEqualStrings("widget_accessibility_action", runtime.dispatchErrors()[runtime.dispatchErrors().len - 1].event);
943
+ try std.testing.expectEqualStrings("widget_accessibility_action", runtime.dispatchErrors()[runtime.dispatchErrors().len - 1].event());
944
944
  try std.testing.expectEqualStrings("Search", platform_state.nodes[3].text_value);
945
945
 
946
946
  try runtime.dispatchPlatformEvent(app_state.app(), .{ .widget_accessibility_action = .{
@@ -168,6 +168,46 @@ test "keyboard-only selection (shift+arrows) feeds copy" {
168
168
  try std.testing.expectEqualStrings("ry", try harness.runtime.readClipboard(&clipboard_buffer));
169
169
  }
170
170
 
171
+ test "a focused terminal copies its emulator selection" {
172
+ var app_state: ClipboardTestApp = .{};
173
+ const app = app_state.app();
174
+ const harness = try createClipboardHarness(app);
175
+ defer harness.destroy(std.testing.allocator);
176
+
177
+ var grid = canvas.TerminalGrid{
178
+ .background = canvas.Color.rgba(0, 0, 0, 1),
179
+ .foreground = canvas.Color.rgba(1, 1, 1, 1),
180
+ .cursor_color = canvas.Color.rgba(1, 1, 1, 1),
181
+ .selection_color = canvas.Color.rgba(0, 0.5, 1, 1),
182
+ .screen_text = "alpha beta",
183
+ .selection_text = "beta",
184
+ .selection_active = true,
185
+ };
186
+ const terminal = canvas.Widget{
187
+ .id = 2,
188
+ .kind = .terminal,
189
+ .frame = geometry.RectF.init(12, 16, 200, 80),
190
+ .terminal = .{ .pty = 7, .grid = &grid },
191
+ };
192
+ var nodes: [2]canvas.WidgetLayoutNode = undefined;
193
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{terminal} }, geometry.RectF.init(0, 0, 320, 200), &nodes);
194
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
195
+
196
+ try harness.runtime.dispatchPlatformEvent(app, pointerInput(.pointer_down, 40, 40));
197
+ try harness.runtime.dispatchPlatformEvent(app, keyInput("c", cmd));
198
+
199
+ var clipboard_buffer: [64]u8 = undefined;
200
+ try std.testing.expectEqualStrings("beta", try harness.runtime.readClipboard(&clipboard_buffer));
201
+
202
+ // An active whitespace-only selection owns Copy too: its trimmed
203
+ // text is empty, so it clears rather than falling through to some
204
+ // unrelated selection in the view.
205
+ grid.selection_text = "";
206
+ try harness.runtime.writeClipboard("stale");
207
+ try harness.runtime.dispatchPlatformEvent(app, keyInput("c", cmd));
208
+ try std.testing.expectEqualStrings("", try harness.runtime.readClipboard(&clipboard_buffer));
209
+ }
210
+
171
211
  test "a multi-line paste into a single-line field strips line breaks; a textarea keeps them" {
172
212
  var app_state: ClipboardTestApp = .{};
173
213
  const app = app_state.app();