@native-sdk/cli 0.5.4 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/build/app.zig +50 -1
  2. package/build.zig +588 -32
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +3 -1
  5. package/package.json +9 -9
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/rt/rt.zig +280 -8
  9. package/packages/core/sdk/core.ts +481 -2
  10. package/packages/core/sdk/events.ts +17 -8
  11. package/packages/core/src/checker.ts +305 -2
  12. package/packages/core/src/diagnostics.ts +12 -0
  13. package/packages/core/src/emitter.ts +599 -3
  14. package/packages/core/src/typed_ast.ts +51 -4
  15. package/packages/core/src/types.ts +34 -1
  16. package/skill-data/native-ui/SKILL.md +39 -2
  17. package/skill-data/ts-core/SKILL.md +4 -2
  18. package/src/app_runner/root.zig +32 -10
  19. package/src/automation/layout_fingerprint.zig +160 -0
  20. package/src/automation/protocol.zig +82 -33
  21. package/src/automation/root.zig +1 -0
  22. package/src/automation/server.zig +1 -1
  23. package/src/automation/snapshot.zig +68 -9
  24. package/src/automation/watcher.zig +1 -1
  25. package/src/embed/host.zig +5 -0
  26. package/src/embed/ui_host.zig +13 -0
  27. package/src/platform/linux/gtk_host.c +527 -13
  28. package/src/platform/linux/gtk_host.h +25 -0
  29. package/src/platform/linux/root.zig +280 -7
  30. package/src/platform/macos/appkit_host.h +104 -6
  31. package/src/platform/macos/appkit_host.m +1368 -74
  32. package/src/platform/macos/cef_host.mm +110 -1
  33. package/src/platform/macos/root.zig +287 -7
  34. package/src/platform/null_platform.zig +398 -4
  35. package/src/platform/null_platform_tests.zig +35 -0
  36. package/src/platform/root.zig +9 -0
  37. package/src/platform/types.zig +386 -14
  38. package/src/platform/windows/root.zig +298 -9
  39. package/src/platform/windows/webview2_host.cpp +330 -5
  40. package/src/primitives/app_manifest/validation.zig +18 -0
  41. package/src/primitives/canvas/a11y_audit.zig +33 -11
  42. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  43. package/src/primitives/canvas/drawing.zig +25 -0
  44. package/src/primitives/canvas/equality.zig +8 -0
  45. package/src/primitives/canvas/events.zig +103 -16
  46. package/src/primitives/canvas/frame.zig +125 -1
  47. package/src/primitives/canvas/layout_audit.zig +22 -5
  48. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  49. package/src/primitives/canvas/render_tests.zig +13 -10
  50. package/src/primitives/canvas/root.zig +48 -0
  51. package/src/primitives/canvas/terminal_box.zig +471 -0
  52. package/src/primitives/canvas/terminal_grid.zig +978 -0
  53. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  54. package/src/primitives/canvas/test_support.zig +1 -0
  55. package/src/primitives/canvas/tests.zig +1 -0
  56. package/src/primitives/canvas/text_tests.zig +39 -4
  57. package/src/primitives/canvas/tokens.zig +115 -12
  58. package/src/primitives/canvas/ui.zig +524 -5
  59. package/src/primitives/canvas/ui_markup.zig +195 -2
  60. package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
  61. package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
  62. package/src/primitives/canvas/ui_markup_contract.zig +88 -5
  63. package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
  64. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  65. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  66. package/src/primitives/canvas/ui_markup_tests.zig +149 -0
  67. package/src/primitives/canvas/ui_markup_view.zig +191 -0
  68. package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
  69. package/src/primitives/canvas/ui_schema.zig +97 -17
  70. package/src/primitives/canvas/ui_schema_tests.zig +18 -11
  71. package/src/primitives/canvas/ui_tests.zig +141 -9
  72. package/src/primitives/canvas/widget_access.zig +28 -2
  73. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  74. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  75. package/src/primitives/canvas/widget_layout.zig +59 -11
  76. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  77. package/src/primitives/canvas/widget_render.zig +272 -18
  78. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  79. package/src/primitives/canvas/widget_routing.zig +59 -7
  80. package/src/primitives/canvas/widget_runtime.zig +23 -0
  81. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  82. package/src/primitives/canvas/widget_semantics.zig +119 -11
  83. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  84. package/src/primitives/canvas/widget_tree.zig +17 -0
  85. package/src/primitives/canvas/widgets.zig +132 -0
  86. package/src/root.zig +16 -0
  87. package/src/runtime/api.zig +76 -6
  88. package/src/runtime/automation_commands.zig +20 -1
  89. package/src/runtime/automation_snapshot.zig +25 -1
  90. package/src/runtime/automation_widget_dispatch.zig +73 -8
  91. package/src/runtime/bridge_payload.zig +1 -0
  92. package/src/runtime/canvas_frame.zig +62 -7
  93. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  94. package/src/runtime/canvas_frame_helpers.zig +190 -1
  95. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  96. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  97. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  98. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  99. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  100. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  101. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  102. package/src/runtime/canvas_widget_display.zig +1 -1
  103. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  104. package/src/runtime/canvas_widget_events.zig +268 -26
  105. package/src/runtime/canvas_widget_runtime.zig +213 -29
  106. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  107. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  108. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  109. package/src/runtime/canvas_widget_state.zig +6 -0
  110. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  111. package/src/runtime/core.zig +73 -2
  112. package/src/runtime/effects.zig +6389 -54
  113. package/src/runtime/effects_channel_tests.zig +3519 -0
  114. package/src/runtime/effects_pty_tests.zig +1362 -0
  115. package/src/runtime/effects_tests.zig +14 -9
  116. package/src/runtime/effects_video_tests.zig +3609 -0
  117. package/src/runtime/flow.zig +25 -4
  118. package/src/runtime/gpu_surface_events.zig +475 -15
  119. package/src/runtime/media_surface.zig +116 -11
  120. package/src/runtime/media_surface_tests.zig +61 -0
  121. package/src/runtime/pty.zig +1252 -0
  122. package/src/runtime/pty_windows.zig +1780 -0
  123. package/src/runtime/root.zig +25 -0
  124. package/src/runtime/runtime_event_tests.zig +20 -1
  125. package/src/runtime/session_journal.zig +367 -61
  126. package/src/runtime/session_record.zig +16 -0
  127. package/src/runtime/session_replay.zig +395 -11
  128. package/src/runtime/session_tests.zig +114 -19
  129. package/src/runtime/terminal_session.zig +1569 -0
  130. package/src/runtime/terminal_session_tests.zig +450 -0
  131. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  132. package/src/runtime/terminal_vt_stub.zig +13 -0
  133. package/src/runtime/tests.zig +6 -0
  134. package/src/runtime/ts_core_host.zig +980 -140
  135. package/src/runtime/ts_core_host_tests.zig +1059 -1
  136. package/src/runtime/ts_ui_app.zig +16 -5
  137. package/src/runtime/ui_app.zig +2338 -67
  138. package/src/runtime/ui_app_tests.zig +3171 -744
  139. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  140. package/src/runtime/ui_app_window_tests.zig +268 -0
  141. package/src/runtime/view.zig +190 -2
  142. package/src/runtime/view_widget_scroll.zig +218 -68
  143. package/src/runtime/view_widget_text.zig +11 -2
  144. package/src/runtime/view_widget_tree.zig +111 -3
  145. package/src/runtime/window_storage.zig +45 -2
  146. package/src/runtime/window_view_runtime.zig +34 -2
  147. package/src/runtime/window_views.zig +1 -0
  148. package/src/terminal_session_tests_root.zig +15 -0
  149. package/src/tooling/templates.zig +25 -7
package/build.zig CHANGED
@@ -138,6 +138,7 @@ pub fn build(b: *std.Build) void {
138
138
  desktop_mod.addImport("platform_info", platform_info_mod);
139
139
  desktop_mod.addImport("json", json_mod);
140
140
  desktop_mod.addImport("canvas", canvas_mod);
141
+ desktop_mod.addImport("terminal_vt", terminalVtModule(b, target, optimize));
141
142
  const desktop_tests = testArtifact(b, desktop_mod);
142
143
  const desktop_test_shards = desktopTestShardArtifacts(b, desktop_mod);
143
144
 
@@ -195,6 +196,24 @@ pub fn build(b: *std.Build) void {
195
196
  eject_components_mod.addImport("native_sdk", desktop_mod);
196
197
  const eject_components_tests = testArtifact(b, eject_components_mod);
197
198
 
199
+ // corewire, the contract-sidecar shim generator (tools/corewire):
200
+ // std-only unit suites, one test root per source file (tests live
201
+ // in the file they cover, and imported files' tests do not run
202
+ // under an importer's root). The conformance suite — both lanes per
203
+ // ts-core fixture, compared by layout fingerprint and
204
+ // model-contract artifact — rides the ts-core e2e block, since it
205
+ // needs node and the transpiler toolchain.
206
+ const corewire_sidecar_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/sidecar.zig"));
207
+ const corewire_emit_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/emit.zig"));
208
+ const corewire_facade_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/emit_facade.zig"));
209
+ const corewire_profile_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/emit_profile.zig"));
210
+ const corewire_extract_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/extract.zig"));
211
+ const corewire_shim_rt_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/shim_rt.zig"));
212
+ // The paired-core root generator (tests/compiled-core): its emitted
213
+ // surface rules are pinned here so the env-gated batteries cannot
214
+ // drift silently between supplied-archive runs.
215
+ const gen_paired_tests = testArtifact(b, module(b, target, optimize, "tests/compiled-core/gen_paired.zig"));
216
+
198
217
  // Transpiled-core end-to-end suite: tests/ts-core/fixture.ts is
199
218
  // emitted by the repo's own transpiler AT BUILD TIME (never a
200
219
  // committed Zig snapshot) and driven through the real runtime via
@@ -359,6 +378,10 @@ pub fn build(b: *std.Build) void {
359
378
  wasm_native_mod.addImport("app_manifest", module(b, wasm_target, wasm_optimize, "src/primitives/app_manifest/root.zig"));
360
379
  wasm_native_mod.addImport("diagnostics", module(b, wasm_target, wasm_optimize, "src/primitives/diagnostics/root.zig"));
361
380
  wasm_native_mod.addImport("platform_info", module(b, wasm_target, wasm_optimize, "src/primitives/platform_info/root.zig"));
381
+ // The docs preview never runs an emulator: the stub keeps the wasm
382
+ // module free of the ghostty graph (and of pty transports it could
383
+ // not use anyway).
384
+ wasm_native_mod.addImport("terminal_vt", module(b, wasm_target, wasm_optimize, "src/runtime/terminal_vt_stub.zig"));
362
385
  const docs_wasm_preview_mod = module(b, wasm_target, wasm_optimize, "tools/docs_wasm_preview.zig");
363
386
  docs_wasm_preview_mod.addImport("native_sdk", wasm_native_mod);
364
387
  docs_wasm_preview_mod.strip = true;
@@ -386,9 +409,41 @@ pub fn build(b: *std.Build) void {
386
409
  // Registry pin printer: emits the ui_schema table counts and
387
410
  // fingerprints in the exact form ui_schema_tests.zig pins, plus the
388
411
  // next free code per table for reserving codes ahead of parallel
389
- // work. `zig build print-pins` after registry additions.
412
+ // work, plus this build's layout fingerprints (session journal
413
+ // format, automation protocol). `zig build print-pins` after
414
+ // registry additions. The journal fingerprint lives in the full
415
+ // framework module, and the tool runs on the build HOST by
416
+ // construction (addRunArtifact), so it builds against a host clone
417
+ // of the framework module — cross-compiled `-Dtarget` builds keep a
418
+ // runnable print-pins, and the fingerprints are layout identities
419
+ // (type shapes, never target-sized values), identical either way.
420
+ const pins_json_mod = module(b, host_target, optimize, "src/primitives/json/root.zig");
421
+ const pins_canvas_mod = module(b, host_target, optimize, "src/primitives/canvas/root.zig");
422
+ pins_canvas_mod.addImport("geometry", host_geometry_mod);
423
+ pins_canvas_mod.addImport("json", pins_json_mod);
424
+ if (host_target.result.os.tag == .macos) {
425
+ // Same CoreText linkage the target canvas module carries (see
426
+ // canvas_mod above): the shaping path calls it on macOS hosts.
427
+ pins_canvas_mod.linkFramework("CoreFoundation", .{});
428
+ pins_canvas_mod.linkFramework("CoreGraphics", .{});
429
+ pins_canvas_mod.linkFramework("CoreText", .{});
430
+ pins_canvas_mod.linkSystemLibrary("c", .{});
431
+ }
432
+ const pins_native_mod = module(b, host_target, optimize, "src/root.zig");
433
+ pins_native_mod.addImport("geometry", host_geometry_mod);
434
+ pins_native_mod.addImport("app_dirs", host_app_dirs_mod);
435
+ pins_native_mod.addImport("assets", host_assets_mod);
436
+ pins_native_mod.addImport("trace", host_trace_mod);
437
+ pins_native_mod.addImport("app_manifest", host_app_manifest_mod);
438
+ pins_native_mod.addImport("diagnostics", host_diagnostics_mod);
439
+ pins_native_mod.addImport("platform_info", host_platform_info_mod);
440
+ pins_native_mod.addImport("json", pins_json_mod);
441
+ pins_native_mod.addImport("canvas", pins_canvas_mod);
442
+ // The pin printer reflects registry tables and layout fingerprints —
443
+ // type shapes, never emulator state — so the stub keeps it light.
444
+ pins_native_mod.addImport("terminal_vt", module(b, host_target, optimize, "src/runtime/terminal_vt_stub.zig"));
390
445
  const print_pins_mod = module(b, host_target, optimize, "tools/print_pins.zig");
391
- print_pins_mod.addImport("ui_schema", module(b, host_target, optimize, "src/primitives/canvas/ui_schema.zig"));
446
+ print_pins_mod.addImport("native_sdk", pins_native_mod);
392
447
  const print_pins_exe = b.addExecutable(.{
393
448
  .name = "print-pins",
394
449
  .root_module = print_pins_mod,
@@ -422,6 +477,13 @@ pub fn build(b: *std.Build) void {
422
477
  test_step.dependOn(&b.addRunArtifact(automation_protocol_tests).step);
423
478
  test_step.dependOn(&b.addRunArtifact(tooling_tests).step);
424
479
  test_step.dependOn(&b.addRunArtifact(eject_components_tests).step);
480
+ test_step.dependOn(&b.addRunArtifact(corewire_sidecar_tests).step);
481
+ test_step.dependOn(&b.addRunArtifact(corewire_emit_tests).step);
482
+ test_step.dependOn(&b.addRunArtifact(corewire_facade_tests).step);
483
+ test_step.dependOn(&b.addRunArtifact(corewire_profile_tests).step);
484
+ test_step.dependOn(&b.addRunArtifact(corewire_extract_tests).step);
485
+ test_step.dependOn(&b.addRunArtifact(corewire_shim_rt_tests).step);
486
+ test_step.dependOn(&b.addRunArtifact(gen_paired_tests).step);
425
487
  if (ts_core_e2e_tests) |ts_core_artifacts| {
426
488
  const ts_core_e2e_step = b.step("test-ts-core-e2e", "Run the transpiled-core end-to-end suites (requires node)");
427
489
  const host_e2e_run = b.addRunArtifact(ts_core_artifacts.host);
@@ -432,6 +494,37 @@ pub fn build(b: *std.Build) void {
432
494
  // no build inputs/outputs to hash, so always run it.
433
495
  scaffold_ide_e2e_run.has_side_effects = true;
434
496
  const ai_chat_e2e_run = b.addRunArtifact(ts_core_artifacts.ai_chat);
497
+ const sidecar_conformance_run = b.addRunArtifact(ts_core_artifacts.sidecar_conformance);
498
+ const sidecar_conformance_step = b.step("sidecar-conformance", "Prove corewire-generated mirrors fingerprint-identical to transpiler output (requires node)");
499
+ sidecar_conformance_step.dependOn(&sidecar_conformance_run.step);
500
+ // Skipped unless the caller supplies a compiled-core archive:
501
+ // the repo builds none, so the step gates on the env var and
502
+ // `zig build test` stays green without it.
503
+ const parity_step = b.step("test-external-core-parity", "Run the compiled-core behavior-parity suite (requires node and NATIVE_SDK_EXTERNAL_CORE_ARCHIVE=<link input[" ++ [_]u8{std.fs.path.delimiter} ++ "link input...]>; skipped when unset)");
504
+ if (ts_core_artifacts.external_core_parity) |parity_tests| {
505
+ const parity_run = b.addRunArtifact(parity_tests);
506
+ parity_step.dependOn(&parity_run.step);
507
+ test_step.dependOn(&parity_run.step);
508
+ }
509
+ // The full-corpus twin: each fixture app's e2e battery over a
510
+ // paired core, gated per fixture on its archive/sidecar env
511
+ // pair; with none supplied the step is a clean no-op and
512
+ // `zig build test` is untouched.
513
+ const compiled_parity_step = b.step("test-compiled-core-parity", "Run each fixture app's e2e battery over a paired core — transpiled lane vs a caller-supplied compiled-core archive (requires node and NATIVE_SDK_EXTERNAL_CORE_ARCHIVE_<FIXTURE> + NATIVE_SDK_EXTERNAL_CORE_SIDECAR_<FIXTURE>; fixtures without both are skipped)");
514
+ for (ts_core_artifacts.compiled_core_parity) |battery| {
515
+ const battery_run = b.addRunArtifact(battery.tests);
516
+ compiled_parity_step.dependOn(&battery_run.step);
517
+ test_step.dependOn(&battery_run.step);
518
+ }
519
+ // The corpus contract artifacts an external core toolchain
520
+ // consumes: per fixture, the extracted contract sidecar and its
521
+ // TypeScript facade projection under zig-out/core-contracts.
522
+ const contracts_step = b.step("stage-core-contracts", "Install each ts-core fixture's contract sidecar and TypeScript facade projection under zig-out/core-contracts (requires node)");
523
+ for (ts_core_artifacts.core_contracts) |contract| {
524
+ const dir: std.Build.InstallDir = .{ .custom = b.fmt("core-contracts/{s}", .{contract.name}) };
525
+ contracts_step.dependOn(&b.addInstallFileWithDir(contract.sidecar, dir, "core.contract.json").step);
526
+ contracts_step.dependOn(&b.addInstallFileWithDir(contract.facade, dir, "core_facade.ts").step);
527
+ }
435
528
  ts_core_e2e_step.dependOn(&host_e2e_run.step);
436
529
  ts_core_e2e_step.dependOn(&soundboard_e2e_run.step);
437
530
  ts_core_e2e_step.dependOn(&monitor_e2e_run.step);
@@ -442,6 +535,7 @@ pub fn build(b: *std.Build) void {
442
535
  test_step.dependOn(&monitor_e2e_run.step);
443
536
  test_step.dependOn(&scaffold_ide_e2e_run.step);
444
537
  test_step.dependOn(&ai_chat_e2e_run.step);
538
+ test_step.dependOn(&sidecar_conformance_run.step);
445
539
  }
446
540
  test_step.dependOn(&b.addRunArtifact(markup_lsp_tests).step);
447
541
  test_step.dependOn(&b.addRunArtifact(automation_cli_tests).step);
@@ -550,7 +644,7 @@ pub fn build(b: *std.Build) void {
550
644
  .{ .path = "src/runtime/media_surface_tests.zig", .pattern = "producer: media.MediaSurfaceProducer" },
551
645
  });
552
646
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-session-replay-image-codec", "Verify the replay runner installs the host image codec headlessly (the desktop arms cannot link in unit tests; the null-fallback arm is covered in session_tests.zig)", &.{
553
- .{ .path = "src/app_runner/root.zig", .pattern = "native_sdk.platform.installHeadlessImageCodec(build_options.platform, &null_platform, &replay_platform.services);" },
647
+ .{ .path = "src/app_runner/root.zig", .pattern = "native_sdk.platform.installHeadlessImageCodec(build_options.platform, null_platform, &replay_platform.services);" },
554
648
  .{ .path = "src/platform/macos/root.zig", .pattern = "pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {\n services.decode_image_fn = decodeImage;\n}" },
555
649
  .{ .path = "src/platform/linux/root.zig", .pattern = "pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {\n services.decode_image_fn = decodeImage;\n}" },
556
650
  .{ .path = "src/platform/windows/root.zig", .pattern = "pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {\n services.decode_image_fn = decodeImage;\n}" },
@@ -1025,6 +1119,13 @@ pub fn build(b: *std.Build) void {
1025
1119
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NATIVE_SDK_APPKIT_GPU_INPUT_POINTER_CANCEL" },
1026
1120
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "_surfaceCursor = cursor ?: [NSCursor arrowCursor]" },
1027
1121
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSCursor pointingHandCursor" },
1122
+ // A full-bounds canvas cursor rect geometrically overlaps a
1123
+ // higher-layer webview even though hit testing does not. The
1124
+ // workbench needs both halves: subtract the overlay from the
1125
+ // cursor rects and refuse a direct canvas cursor set there.
1126
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSMutableArray<NSValue *> *visibleCursorRects" },
1127
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "surfaceView.coveredMouseRects = coveredRects" },
1128
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (!covered && NSPointInRect(mousePoint, self.bounds)) [_surfaceCursor set]" },
1028
1129
  });
1029
1130
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-widget-accessibility-actions", "Verify AppKit GPU widget accessibility actions route to the runtime", &.{
1030
1131
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "accessibilityPerformPress" },
@@ -1097,6 +1198,11 @@ pub fn build(b: *std.Build) void {
1097
1198
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)selectAll:(id)sender" },
1098
1199
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "@selector(selectAll:)" },
1099
1200
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitSyntheticKeyDownWithKey:@\"a\" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand)" },
1201
+ // Modified horizontal navigation must bypass AppKit's selector
1202
+ // rewrite: the shared editor consumes the raw modifiers, and a
1203
+ // terminal translates them to its shell/protocol bindings.
1204
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkTextNavigationNeedsRawKeyEvent(event)" },
1205
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSEventModifierFlagCommand | NSEventModifierFlagOption" },
1100
1206
  });
1101
1207
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-appearance-bridge", "Verify AppKit reports system light and dark appearance changes", &.{
1102
1208
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "effectiveAppearance" },
@@ -1237,10 +1343,10 @@ pub fn build(b: *std.Build) void {
1237
1343
  linux_web_layer_audit_step.dependOn(&audit_webview_elf.step);
1238
1344
 
1239
1345
  const frontend_examples_step = b.step("test-examples-frontends", "Run frontend example tests");
1240
- addExampleTestStep(b, host_cli_exe, frontend_examples_step, "test-example-next", "Run Next example tests", "examples/next", .owned);
1241
- addExampleTestStep(b, host_cli_exe, frontend_examples_step, "test-example-react", "Run React example tests", "examples/react", .owned);
1242
- addExampleTestStep(b, host_cli_exe, frontend_examples_step, "test-example-svelte", "Run Svelte example tests", "examples/svelte", .owned);
1243
- addExampleTestStep(b, host_cli_exe, frontend_examples_step, "test-example-vue", "Run Vue example tests", "examples/vue", .owned);
1346
+ _ = addExampleTestStep(b, host_cli_exe, frontend_examples_step, "test-example-next", "Run Next example tests", "examples/next", .owned);
1347
+ _ = addExampleTestStep(b, host_cli_exe, frontend_examples_step, "test-example-react", "Run React example tests", "examples/react", .owned);
1348
+ _ = addExampleTestStep(b, host_cli_exe, frontend_examples_step, "test-example-svelte", "Run Svelte example tests", "examples/svelte", .owned);
1349
+ _ = addExampleTestStep(b, host_cli_exe, frontend_examples_step, "test-example-vue", "Run Vue example tests", "examples/vue", .owned);
1244
1350
  addFileContainsCheckStep(b, file_contains_checker, frontend_examples_step, "test-example-frontend-positioning", "Verify frontend example native shell positioning", &.{
1245
1351
  .{ .path = "examples/next/README.md", .pattern = "opens the native app shell with WebView content." },
1246
1352
  .{ .path = "examples/react/README.md", .pattern = "opens the native app shell with WebView content." },
@@ -1249,30 +1355,51 @@ pub fn build(b: *std.Build) void {
1249
1355
  });
1250
1356
 
1251
1357
  const native_examples_step = b.step("test-examples-native", "Run native-first example tests");
1252
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-command-app", "Run command app example tests", "examples/command-app", .owned);
1253
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-native-shell", "Run native shell example tests", "examples/native-shell", .owned);
1254
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-native-panels", "Run native panels example tests", "examples/native-panels", .owned);
1255
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-gpu-surface", "Run GPU surface example tests", "examples/gpu-surface", .managed);
1256
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-gpu-dashboard", "Run GPU dashboard example tests", "examples/gpu-dashboard", .managed);
1257
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-gpu-components", "Run GPU components example tests", "examples/gpu-components", .managed);
1258
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-ui-inbox", "Run ui builder inbox example tests", "examples/ui-inbox", .owned);
1259
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-kanban", "Run ui builder kanban example tests", "examples/kanban", .managed);
1260
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-habits", "Run markup habits example tests", "examples/habits", .managed);
1261
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard", "Run soundboard example tests", "examples/soundboard", .managed);
1262
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard-ts", "Run soundboard-ts example tests", "examples/soundboard-ts", .managed);
1263
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-deck", "Run deck example tests", "examples/deck", .managed);
1264
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-markdown-viewer", "Run markdown viewer example tests", "examples/markdown-viewer", .managed);
1265
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-calculator", "Run calculator example tests", "examples/calculator", .managed);
1266
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-notes", "Run notes example tests", "examples/notes", .managed);
1267
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-split-collapse", "Run split collapse example tests", "examples/split-collapse", .managed);
1268
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-system-monitor", "Run system monitor example tests", "examples/system-monitor", .managed);
1269
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-system-monitor-ts", "Run system-monitor-ts example tests", "examples/system-monitor-ts", .managed);
1270
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-effects-probe", "Run effects probe example tests", "examples/effects-probe", .managed);
1271
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-menu-bar", "Run menu-bar lifecycle example tests", "examples/menu-bar", .managed);
1272
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-feed", "Run feed example tests", "examples/feed", .managed);
1273
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-canvas-preview", "Run canvas preview example tests", "examples/canvas-preview", .managed);
1274
- addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-capabilities", "Run capabilities example tests", "examples/capabilities", .owned);
1275
- addFileContainsCheckStep(b, file_contains_checker, native_examples_step, "test-example-capabilities-events", "Verify capabilities example event bridge names", &.{
1358
+ const native_example_shard_steps = [_]*std.Build.Step{
1359
+ b.step("test-examples-native-shard-1", "Run the first native-first example test shard"),
1360
+ b.step("test-examples-native-shard-2", "Run the second native-first example test shard"),
1361
+ b.step("test-examples-native-shard-3", "Run the third native-first example test shard"),
1362
+ b.step("test-examples-native-shard-4", "Run the fourth native-first example test shard"),
1363
+ };
1364
+ const native_example_steps = [_]*std.Build.Step{
1365
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-command-app", "Run command app example tests", "examples/command-app", .owned),
1366
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-native-shell", "Run native shell example tests", "examples/native-shell", .owned),
1367
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-native-panels", "Run native panels example tests", "examples/native-panels", .owned),
1368
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-gpu-surface", "Run GPU surface example tests", "examples/gpu-surface", .managed),
1369
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-gpu-dashboard", "Run GPU dashboard example tests", "examples/gpu-dashboard", .managed),
1370
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-gpu-components", "Run GPU components example tests", "examples/gpu-components", .managed),
1371
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-ui-inbox", "Run ui builder inbox example tests", "examples/ui-inbox", .owned),
1372
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-kanban", "Run ui builder kanban example tests", "examples/kanban", .managed),
1373
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-habits", "Run markup habits example tests", "examples/habits", .managed),
1374
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard", "Run soundboard example tests", "examples/soundboard", .managed),
1375
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-video-player", "Run video player example tests", "examples/video-player", .managed),
1376
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard-ts", "Run soundboard-ts example tests", "examples/soundboard-ts", .managed),
1377
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-deck", "Run deck example tests", "examples/deck", .managed),
1378
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-markdown-viewer", "Run markdown viewer example tests", "examples/markdown-viewer", .managed),
1379
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-calculator", "Run calculator example tests", "examples/calculator", .managed),
1380
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-notes", "Run notes example tests", "examples/notes", .managed),
1381
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-split-collapse", "Run split collapse example tests", "examples/split-collapse", .managed),
1382
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-system-monitor", "Run system monitor example tests", "examples/system-monitor", .managed),
1383
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-terminal", "Run terminal example tests", "examples/terminal", .owned),
1384
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-workbench", "Run workbench example tests", "examples/workbench", .owned),
1385
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-system-monitor-ts", "Run system-monitor-ts example tests", "examples/system-monitor-ts", .managed),
1386
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-effects-probe", "Run effects probe example tests", "examples/effects-probe", .managed),
1387
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-channel-monitor", "Run channel monitor example tests", "examples/channel-monitor", .managed),
1388
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-menu-bar", "Run menu-bar lifecycle example tests", "examples/menu-bar", .managed),
1389
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-feed", "Run feed example tests", "examples/feed", .managed),
1390
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-canvas-preview", "Run canvas preview example tests", "examples/canvas-preview", .managed),
1391
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-capabilities", "Run capabilities example tests", "examples/capabilities", .owned),
1392
+ };
1393
+ for (native_example_shard_steps) |shard_step| {
1394
+ native_examples_step.dependOn(shard_step);
1395
+ }
1396
+ for (native_example_steps, 0..) |example_step, index| {
1397
+ native_example_shard_steps[index % native_example_shard_steps.len].dependOn(example_step);
1398
+ }
1399
+ // Keep this companion check in the same shard as capabilities. The
1400
+ // aggregate step depends on every shard, so `test-examples-native`
1401
+ // retains exactly the same coverage as before.
1402
+ addFileContainsCheckStep(b, file_contains_checker, native_example_shard_steps[2], "test-example-capabilities-events", "Verify capabilities example event bridge names", &.{
1276
1403
  .{ .path = "examples/capabilities/src/main.zig", .pattern = "native-sdk:drop:files" },
1277
1404
  });
1278
1405
 
@@ -2768,6 +2895,19 @@ fn module(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin
2768
2895
  });
2769
2896
  }
2770
2897
 
2898
+ /// The framework module's `terminal_vt` import for THIS repository's own
2899
+ /// builds: always the stub. The emulator (libghostty-vt) is pinned by
2900
+ /// the APPS that want live `<terminal>` sessions, never by this package
2901
+ /// — a pin in `build.zig.zon` is materialized into every consumer's
2902
+ /// package directory even when lazy and unused, and ghostty's own graph
2903
+ /// walks translate_c/wuffs and pulls harfbuzz, which is exactly what a
2904
+ /// scaffolded app must never carry. `AppOptions.terminal_sessions`
2905
+ /// resolves the app's own pin (see build/app.zig), and the terminal
2906
+ /// examples own the enabled path's test coverage.
2907
+ fn terminalVtModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Module {
2908
+ return module(b, target, optimize, "src/runtime/terminal_vt_stub.zig");
2909
+ }
2910
+
2771
2911
  /// The short commit hash of the framework checkout the CLI is built
2772
2912
  /// from, for `native version` staleness checks. "unknown" when
2773
2913
  /// git is unavailable (e.g. building from a package tarball).
@@ -2801,8 +2941,71 @@ const TsCoreE2eArtifacts = struct {
2801
2941
  /// paths, and builds keep working with node_modules deleted.
2802
2942
  scaffold_ide: *std.Build.Step.Compile,
2803
2943
  ai_chat: *std.Build.Step.Compile,
2944
+ /// Sidecar-shim conformance (tests/sidecar): every fixture built
2945
+ /// through BOTH lanes — the transpiler and corewire's generated
2946
+ /// mirror — and compared by layout fingerprint and model-contract
2947
+ /// artifact.
2948
+ sidecar_conformance: *std.Build.Step.Compile,
2949
+ /// Behavior parity against a REAL compiled core: built only when
2950
+ /// NATIVE_SDK_EXTERNAL_CORE_ARCHIVE names the archive(s) to link
2951
+ /// (path-delimiter-separated link inputs exporting the markup
2952
+ /// fixture's attested symbol set); null — the suite is skipped —
2953
+ /// otherwise.
2954
+ external_core_parity: ?*std.Build.Step.Compile,
2955
+ /// The full-corpus compiled-core batteries: each entry is one
2956
+ /// fixture app's OWN e2e suite compiled over a paired core — the
2957
+ /// transpiled lane plus a generated mirror dispatching into a
2958
+ /// caller-supplied compiled-core archive, byte-compared at every
2959
+ /// seam. Built per fixture only when its archive/sidecar env pair
2960
+ /// (NATIVE_SDK_EXTERNAL_CORE_ARCHIVE_<FIXTURE> and
2961
+ /// NATIVE_SDK_EXTERNAL_CORE_SIDECAR_<FIXTURE>) is supplied; empty
2962
+ /// — every battery skipped — otherwise.
2963
+ compiled_core_parity: []const CompiledCoreParity,
2964
+ /// Per-fixture contract artifacts for an external core toolchain:
2965
+ /// the extracted contract sidecar and its TypeScript facade
2966
+ /// projection, installed by the stage-core-contracts step.
2967
+ core_contracts: []const CoreContract,
2968
+ };
2969
+
2970
+ const CompiledCoreParity = struct {
2971
+ name: []const u8,
2972
+ tests: *std.Build.Step.Compile,
2804
2973
  };
2805
2974
 
2975
+ const CoreContract = struct {
2976
+ name: []const u8,
2977
+ sidecar: std.Build.LazyPath,
2978
+ facade: std.Build.LazyPath,
2979
+ };
2980
+
2981
+ /// One fixture's compiled-core supply: the archive link input(s) and
2982
+ /// the archive's own emitted contract sidecar. Both come as a pair —
2983
+ /// a real archive's build_id can only match its co-emitted sidecar, so
2984
+ /// one without the other is a misconfiguration, refused with a
2985
+ /// teaching rather than skipped into silence.
2986
+ const CompiledCoreSupply = struct {
2987
+ archives: []const u8,
2988
+ sidecar: std.Build.LazyPath,
2989
+ };
2990
+
2991
+ fn compiledCoreEnv(b: *std.Build, comptime suffix: []const u8) ?CompiledCoreSupply {
2992
+ const archive_var = "NATIVE_SDK_EXTERNAL_CORE_ARCHIVE_" ++ suffix;
2993
+ const sidecar_var = "NATIVE_SDK_EXTERNAL_CORE_SIDECAR_" ++ suffix;
2994
+ const archives = b.graph.environ_map.get(archive_var);
2995
+ const sidecar = b.graph.environ_map.get(sidecar_var);
2996
+ if (archives == null and sidecar == null) return null;
2997
+ if (archives == null or sidecar == null) {
2998
+ std.debug.panic(
2999
+ "{s} and {s} come as a pair: a compiled-core fixture needs both its archive link input(s) and the archive's own emitted contract sidecar",
3000
+ .{ archive_var, sidecar_var },
3001
+ );
3002
+ }
3003
+ return .{
3004
+ .archives = b.dupe(archives.?),
3005
+ .sidecar = .{ .cwd_relative = b.dupe(sidecar.?) },
3006
+ };
3007
+ }
3008
+
2806
3009
  fn tsCoreE2eArtifact(
2807
3010
  b: *std.Build,
2808
3011
  target: std.Build.ResolvedTarget,
@@ -2883,13 +3086,365 @@ fn tsCoreE2eArtifact(
2883
3086
  ai_chat_mod.addImport("native_sdk", desktop_mod);
2884
3087
  ai_chat_mod.addImport("ts_ai_chat_core", ai_chat_core_mod);
2885
3088
 
3089
+ // Sidecar-shim conformance: pair every fixture's transpiled module
3090
+ // with a corewire-generated mirror. The markup fixture's sidecar is
3091
+ // the committed hand-written one (independent ground truth for the
3092
+ // schema); the rest are extracted from the transpiled modules at
3093
+ // build time, so corpus fixtures cannot go stale against their
3094
+ // sidecars.
3095
+ const corewire_mod = b.createModule(.{
3096
+ .root_source_file = b.path("tools/corewire/main.zig"),
3097
+ .target = target,
3098
+ .optimize = optimize,
3099
+ });
3100
+ const corewire_exe = b.addExecutable(.{
3101
+ .name = "corewire",
3102
+ .root_module = corewire_mod,
3103
+ .use_llvm = @import("build/app.zig").useLlvmWorkaround(target),
3104
+ });
3105
+ const extract_mod = module(b, target, optimize, "tools/corewire/extract.zig");
3106
+
3107
+ const conformance_mod = module(b, target, optimize, "tests/sidecar/conformance_tests.zig");
3108
+ conformance_mod.addImport("native_sdk", desktop_mod);
3109
+ // The canonical value encoder the facade parity axis compares
3110
+ // against (the same module the generated shims stage).
3111
+ conformance_mod.addImport("corewire_rt", module(b, target, optimize, "tools/corewire/shim_rt.zig"));
3112
+ conformance_mod.addImport("ts_markup_core", markup_fixture_mod);
3113
+ conformance_mod.addImport("shim_markup_core", sidecarShimModule(b, target, optimize, corewire_exe, b.path("tests/sidecar/markup_fixture.contract.json")));
3114
+ conformance_mod.addImport("facade_markup_core", facadeCoreModule(b, target, optimize, node, corewire_exe, b.path("tests/sidecar/markup_fixture.contract.json")));
3115
+ // The integer-class fixture: a hand-written sidecar attesting mixed
3116
+ // i64/u64 slot classes, so the suite drives boundary and full-range
3117
+ // integer values through a generated mirror's decode paths and
3118
+ // holds the compiled facade's integer encoders to the same bytes.
3119
+ conformance_mod.addImport("shim_integer_core", sidecarShimModule(b, target, optimize, corewire_exe, b.path("tests/sidecar/integer_fixture.contract.json")));
3120
+ conformance_mod.addImport("facade_integer_core", facadeCoreModule(b, target, optimize, node, corewire_exe, b.path("tests/sidecar/integer_fixture.contract.json")));
3121
+ const conformance_fixtures = [_]struct {
3122
+ ts_import: []const u8,
3123
+ shim_import: []const u8,
3124
+ facade_import: []const u8,
3125
+ contract_name: []const u8,
3126
+ core_mod: *std.Build.Module,
3127
+ entry: []const u8,
3128
+ }{
3129
+ .{ .ts_import = "ts_host_core", .shim_import = "shim_host_core", .facade_import = "facade_host_core", .contract_name = "host-fixture", .core_mod = fixture_mod, .entry = "tests/ts-core/fixture.ts" },
3130
+ .{ .ts_import = "ts_soundboard_core", .shim_import = "shim_soundboard_core", .facade_import = "facade_soundboard_core", .contract_name = "soundboard", .core_mod = soundboard_core_mod, .entry = "examples/soundboard-ts/src/core.ts" },
3131
+ .{ .ts_import = "ts_monitor_core", .shim_import = "shim_monitor_core", .facade_import = "facade_monitor_core", .contract_name = "system-monitor", .core_mod = monitor_core_mod, .entry = "examples/system-monitor-ts/src/core.ts" },
3132
+ .{ .ts_import = "ts_ai_chat_core", .shim_import = "shim_ai_chat_core", .facade_import = "facade_ai_chat_core", .contract_name = "ai-chat", .core_mod = ai_chat_core_mod, .entry = "examples/ai-chat-ts/src/core.ts" },
3133
+ };
3134
+ // The corpus contract artifacts an external core toolchain consumes
3135
+ // (stage-core-contracts): the extracted sidecar plus its facade
3136
+ // projection, per fixture.
3137
+ var core_contracts: std.ArrayList(CoreContract) = .empty;
3138
+ {
3139
+ const markup_sidecar = sidecarExtractJson(b, target, optimize, extract_mod, markup_fixture_mod, "tests/ts-core/markup_fixture.ts");
3140
+ core_contracts.append(b.allocator, .{
3141
+ .name = "markup-fixture",
3142
+ .sidecar = markup_sidecar,
3143
+ .facade = facadeTsFile(b, corewire_exe, markup_sidecar),
3144
+ }) catch @panic("OOM");
3145
+ }
3146
+ for (conformance_fixtures) |fixture| {
3147
+ const sidecar_json = sidecarExtractJson(b, target, optimize, extract_mod, fixture.core_mod, fixture.entry);
3148
+ conformance_mod.addImport(fixture.ts_import, fixture.core_mod);
3149
+ conformance_mod.addImport(fixture.shim_import, sidecarShimModule(b, target, optimize, corewire_exe, sidecar_json));
3150
+ conformance_mod.addImport(fixture.facade_import, facadeCoreModule(b, target, optimize, node, corewire_exe, sidecar_json));
3151
+ core_contracts.append(b.allocator, .{
3152
+ .name = fixture.contract_name,
3153
+ .sidecar = sidecar_json,
3154
+ .facade = facadeTsFile(b, corewire_exe, sidecar_json),
3155
+ }) catch @panic("OOM");
3156
+ }
3157
+
3158
+ // Compiled-core behavior parity (tests/sidecar/
3159
+ // external_core_parity_tests.zig): the executable half of the
3160
+ // conformance story, gated on a caller-supplied compiled-core
3161
+ // archive because the repo builds none itself. The env var carries
3162
+ // one or more link inputs (path-delimiter-separated) that together
3163
+ // export the markup fixture's attested symbol set; the binary pairs
3164
+ // a FRESH generated mirror with them (the conformance binary's
3165
+ // mirror links the stub core's exports — one process cannot carry
3166
+ // both symbol sets). A real archive's sidecar carries the compile's
3167
+ // own build_id, which the mirror's boot fence checks against the
3168
+ // identity getters — so the caller supplies the archive's OWN
3169
+ // emitted sidecar through NATIVE_SDK_EXTERNAL_CORE_SIDECAR (the
3170
+ // committed fixture sidecar stays the default for stub-shaped
3171
+ // callers that restate its identity).
3172
+ const external_core_parity: ?*std.Build.Step.Compile = if (b.graph.environ_map.get("NATIVE_SDK_EXTERNAL_CORE_ARCHIVE")) |archives| blk: {
3173
+ const parity_mod = module(b, target, optimize, "tests/sidecar/external_core_parity_tests.zig");
3174
+ parity_mod.link_libc = true;
3175
+ parity_mod.addImport("corewire_rt", module(b, target, optimize, "tools/corewire/shim_rt.zig"));
3176
+ parity_mod.addImport("core_abi", module(b, target, optimize, "tools/corewire/core_abi.zig"));
3177
+ parity_mod.addImport("ts_core", markup_fixture_mod);
3178
+ const parity_sidecar: std.Build.LazyPath = if (b.graph.environ_map.get("NATIVE_SDK_EXTERNAL_CORE_SIDECAR")) |sidecar|
3179
+ .{ .cwd_relative = b.dupe(sidecar) }
3180
+ else
3181
+ b.path("tests/sidecar/markup_fixture.contract.json");
3182
+ parity_mod.addImport("shim_core", sidecarShimModule(b, target, optimize, corewire_exe, parity_sidecar));
3183
+ var inputs = std.mem.tokenizeScalar(u8, archives, std.fs.path.delimiter);
3184
+ while (inputs.next()) |input| {
3185
+ parity_mod.addObjectFile(.{ .cwd_relative = b.dupe(input) });
3186
+ }
3187
+ const parity_tests = filteredTestArtifact(b, parity_mod, "external-core-parity-tests", &.{});
3188
+ // Run the checker over the supplied sidecar explicitly (the
3189
+ // shim generation above validates too, but the checker tier —
3190
+ // both projections, integer_slots structural rules included —
3191
+ // is the surface an external compile is verified against).
3192
+ const check_sidecar = b.addRunArtifact(corewire_exe);
3193
+ check_sidecar.addArg("--sidecar");
3194
+ check_sidecar.addFileArg(parity_sidecar);
3195
+ check_sidecar.addArg("--check");
3196
+ parity_tests.step.dependOn(&check_sidecar.step);
3197
+ break :blk parity_tests;
3198
+ } else null;
3199
+
3200
+ // The full-corpus compiled-core batteries: each supplied fixture's
3201
+ // OWN e2e test root recompiled over a paired core (the transpiled
3202
+ // lane plus a fresh generated mirror linked against the caller's
3203
+ // archive), so every behavioral assertion the fixture app carries
3204
+ // runs through the compiled core with byte parity checked at every
3205
+ // seam (commands, snapshots, subscriptions, channels, helpers).
3206
+ // Env-gated per fixture like the markup parity suite: unset means
3207
+ // the battery is never built and `zig build test` stays green.
3208
+ var compiled_core_parity: std.ArrayList(CompiledCoreParity) = .empty;
3209
+ const compiled_core_fixtures = [_]struct {
3210
+ name: []const u8,
3211
+ supply: ?CompiledCoreSupply,
3212
+ ts_mod: *std.Build.Module,
3213
+ root: std.Build.LazyPath,
3214
+ core_import: []const u8,
3215
+ /// The host suite's second lane (the markup fixture) rides the
3216
+ /// same binary, transpiler-only: one archive per process is the
3217
+ /// compiled-core contract.
3218
+ second_import: ?[]const u8 = null,
3219
+ second_mod: ?*std.Build.Module = null,
3220
+ }{
3221
+ .{ .name = "host", .supply = compiledCoreEnv(b, "HOST"), .ts_mod = fixture_mod, .root = b.path("tests/ts-core/host_e2e_tests.zig"), .core_import = "ts_core_fixture", .second_import = "ts_markup_fixture", .second_mod = markup_fixture_mod },
3222
+ // The markup battery is the mirror image of the host one: the
3223
+ // markup fixture's core pairs, and the host fixture rides along
3224
+ // transpiler-only as the second lane.
3225
+ .{ .name = "markup", .supply = compiledCoreEnv(b, "MARKUP"), .ts_mod = markup_fixture_mod, .root = b.path("tests/ts-core/markup_e2e_tests.zig"), .core_import = "ts_markup_fixture", .second_import = "ts_core_fixture", .second_mod = fixture_mod },
3226
+ .{ .name = "soundboard", .supply = compiledCoreEnv(b, "SOUNDBOARD"), .ts_mod = soundboard_core_mod, .root = soundboard_root, .core_import = "ts_soundboard_core" },
3227
+ .{ .name = "system-monitor", .supply = compiledCoreEnv(b, "SYSTEM_MONITOR"), .ts_mod = monitor_core_mod, .root = monitor_root, .core_import = "ts_system_monitor_core" },
3228
+ .{ .name = "ai-chat", .supply = compiledCoreEnv(b, "AI_CHAT"), .ts_mod = ai_chat_core_mod, .root = ai_chat_root, .core_import = "ts_ai_chat_core" },
3229
+ };
3230
+ for (compiled_core_fixtures) |entry| {
3231
+ const supply = entry.supply orelse continue;
3232
+ const paired_mod = pairedCoreModule(b, target, optimize, corewire_exe, entry.ts_mod, supply);
3233
+ const battery_mod = b.createModule(.{
3234
+ .root_source_file = entry.root,
3235
+ .target = target,
3236
+ .optimize = optimize,
3237
+ });
3238
+ battery_mod.addImport("native_sdk", desktop_mod);
3239
+ battery_mod.addImport(entry.core_import, paired_mod);
3240
+ if (entry.second_import) |second| battery_mod.addImport(second, entry.second_mod.?);
3241
+ const battery = filteredTestArtifact(b, battery_mod, b.fmt("compiled-core-{s}-tests", .{entry.name}), &.{});
3242
+ // Run the checker tier over the supplied sidecar explicitly —
3243
+ // the same surface an external compile is verified against in
3244
+ // the markup parity suite.
3245
+ const check_sidecar = b.addRunArtifact(corewire_exe);
3246
+ check_sidecar.addArg("--sidecar");
3247
+ check_sidecar.addFileArg(supply.sidecar);
3248
+ check_sidecar.addArg("--check");
3249
+ battery.step.dependOn(&check_sidecar.step);
3250
+ compiled_core_parity.append(b.allocator, .{ .name = b.dupe(entry.name), .tests = battery }) catch @panic("OOM");
3251
+ }
3252
+
2886
3253
  return .{
2887
3254
  .host = filteredTestArtifact(b, e2e_mod, "ts-core-e2e-tests", &.{}),
2888
3255
  .soundboard = filteredTestArtifact(b, soundboard_mod, "ts-soundboard-e2e-tests", &.{}),
2889
3256
  .system_monitor = filteredTestArtifact(b, monitor_mod, "ts-system-monitor-e2e-tests", &.{}),
2890
3257
  .scaffold_ide = filteredTestArtifact(b, scaffold_ide_mod, "ts-scaffold-ide-e2e-tests", &.{}),
2891
3258
  .ai_chat = filteredTestArtifact(b, ai_chat_mod, "ts-ai-chat-e2e-tests", &.{}),
3259
+ .sidecar_conformance = filteredTestArtifact(b, conformance_mod, "sidecar-conformance-tests", &.{}),
3260
+ .external_core_parity = external_core_parity,
3261
+ .compiled_core_parity = compiled_core_parity.toOwnedSlice(b.allocator) catch @panic("OOM"),
3262
+ .core_contracts = core_contracts.toOwnedSlice(b.allocator) catch @panic("OOM"),
3263
+ };
3264
+ }
3265
+
3266
+ /// One fixture's paired-core module (tests/compiled-core): generate
3267
+ /// the lockstep root from the transpiled module's own export surface,
3268
+ /// stage it beside the pairing library and the mirror-value converter,
3269
+ /// bind the transpiled lane and a mirror generated from the supplied
3270
+ /// contract sidecar, and link the caller's compiled-core archive(s).
3271
+ fn pairedCoreModule(
3272
+ b: *std.Build,
3273
+ target: std.Build.ResolvedTarget,
3274
+ optimize: std.builtin.OptimizeMode,
3275
+ corewire_exe: *std.Build.Step.Compile,
3276
+ ts_mod: *std.Build.Module,
3277
+ supply: CompiledCoreSupply,
3278
+ ) *std.Build.Module {
3279
+ const gen_root = b.addWriteFiles().add("gen_paired_main.zig",
3280
+ \\//! Generated by the build: emit a fixture's paired-core root
3281
+ \\//! from its transpiled module (tests/compiled-core/gen_paired.zig).
3282
+ \\const std = @import("std");
3283
+ \\const gen = @import("gen_paired");
3284
+ \\const core = @import("ts_core");
3285
+ \\pub fn main(init: std.process.Init) !void {
3286
+ \\ try gen.emitMain(core, init);
3287
+ \\}
3288
+ \\
3289
+ );
3290
+ const gen_mod = b.createModule(.{
3291
+ .root_source_file = gen_root,
3292
+ .target = target,
3293
+ .optimize = optimize,
3294
+ });
3295
+ gen_mod.addImport("gen_paired", module(b, target, optimize, "tests/compiled-core/gen_paired.zig"));
3296
+ gen_mod.addImport("ts_core", ts_mod);
3297
+ const gen_exe = b.addExecutable(.{
3298
+ .name = "gen-paired",
3299
+ .root_module = gen_mod,
3300
+ .use_llvm = @import("build/app.zig").useLlvmWorkaround(target),
3301
+ });
3302
+ const gen_run = b.addRunArtifact(gen_exe);
3303
+ const paired_src = gen_run.addOutputFileArg("paired.zig");
3304
+
3305
+ const staged = b.addWriteFiles();
3306
+ const paired_root = staged.addCopyFile(paired_src, "paired.zig");
3307
+ _ = staged.addCopyFile(b.path("tests/compiled-core/paired_core.zig"), "paired_core.zig");
3308
+ _ = staged.addCopyFile(b.path("tests/sidecar/mirror_value.zig"), "mirror_value.zig");
3309
+ const mod = b.createModule(.{
3310
+ .root_source_file = paired_root,
3311
+ .target = target,
3312
+ .optimize = optimize,
3313
+ });
3314
+ mod.link_libc = true;
3315
+ mod.addImport("ts_lane", ts_mod);
3316
+ mod.addImport("shim_lane", sidecarShimModule(b, target, optimize, corewire_exe, supply.sidecar));
3317
+ mod.addImport("corewire_rt", module(b, target, optimize, "tools/corewire/shim_rt.zig"));
3318
+ mod.addImport("core_abi", module(b, target, optimize, "tools/corewire/core_abi.zig"));
3319
+ var inputs = std.mem.tokenizeScalar(u8, supply.archives, std.fs.path.delimiter);
3320
+ while (inputs.next()) |input| {
3321
+ mod.addObjectFile(.{ .cwd_relative = b.dupe(input) });
3322
+ }
3323
+ return mod;
3324
+ }
3325
+
3326
+ /// A sidecar's TypeScript facade projection alone (core_facade.ts) —
3327
+ /// the contract module an external core toolchain compiles.
3328
+ fn facadeTsFile(
3329
+ b: *std.Build,
3330
+ corewire_exe: *std.Build.Step.Compile,
3331
+ sidecar_json: std.Build.LazyPath,
3332
+ ) std.Build.LazyPath {
3333
+ const generate = b.addRunArtifact(corewire_exe);
3334
+ generate.addArg("--sidecar");
3335
+ generate.addFileArg(sidecar_json);
3336
+ generate.addArg("--facade");
3337
+ return generate.addOutputFileArg("core_facade.ts");
3338
+ }
3339
+
3340
+ /// One fixture's generated-mirror module: run corewire over the
3341
+ /// sidecar, stage the emitted core_shim.zig as core.zig beside its two
3342
+ /// staged runtime files (shim_rt.zig, core_abi.zig) — the same staging
3343
+ /// shape the transpiler lane gives its emitted core and rt.zig.
3344
+ fn sidecarShimModule(
3345
+ b: *std.Build,
3346
+ target: std.Build.ResolvedTarget,
3347
+ optimize: std.builtin.OptimizeMode,
3348
+ corewire_exe: *std.Build.Step.Compile,
3349
+ sidecar_json: std.Build.LazyPath,
3350
+ ) *std.Build.Module {
3351
+ const generate = b.addRunArtifact(corewire_exe);
3352
+ generate.addArg("--sidecar");
3353
+ generate.addFileArg(sidecar_json);
3354
+ generate.addArg("--out");
3355
+ const generated = generate.addOutputFileArg("core_shim.zig");
3356
+ const staged = b.addWriteFiles();
3357
+ const shim_root = staged.addCopyFile(generated, "core.zig");
3358
+ _ = staged.addCopyFile(b.path("tools/corewire/shim_rt.zig"), "shim_rt.zig");
3359
+ _ = staged.addCopyFile(b.path("tools/corewire/core_abi.zig"), "core_abi.zig");
3360
+ return b.createModule(.{
3361
+ .root_source_file = shim_root,
3362
+ .target = target,
3363
+ .optimize = optimize,
3364
+ });
3365
+ }
3366
+
3367
+ /// One fixture's compiled-facade module: run corewire over the sidecar
3368
+ /// for its TypeScript projection (core_facade.ts), then compile that
3369
+ /// projection through the shipped transpiler — the checker/emitter tier
3370
+ /// is the compile, so this step IS the subset-acceptance proof — and
3371
+ /// stage the emitted Zig beside its rt kernel like any fixture core.
3372
+ fn facadeCoreModule(
3373
+ b: *std.Build,
3374
+ target: std.Build.ResolvedTarget,
3375
+ optimize: std.builtin.OptimizeMode,
3376
+ node: []const u8,
3377
+ corewire_exe: *std.Build.Step.Compile,
3378
+ sidecar_json: std.Build.LazyPath,
3379
+ ) *std.Build.Module {
3380
+ const generate = b.addRunArtifact(corewire_exe);
3381
+ generate.addArg("--sidecar");
3382
+ generate.addFileArg(sidecar_json);
3383
+ generate.addArg("--facade");
3384
+ const facade_ts = generate.addOutputFileArg("core_facade.ts");
3385
+ const staged_ts = b.addWriteFiles();
3386
+ const facade_entry = staged_ts.addCopyFile(facade_ts, "core.ts");
3387
+
3388
+ const transpile = b.addSystemCommand(&.{node});
3389
+ transpile.addFileArg(b.path("packages/core/src/cli.ts"));
3390
+ transpile.addFileArg(facade_entry);
3391
+ transpile.addArg("-o");
3392
+ const emitted_core = transpile.addOutputFileArg("core.zig");
3393
+ tsCoreAddDirInputs(b, transpile, "packages/core/sdk");
3394
+ const transpiler_sources = [_][]const u8{
3395
+ "checker.ts", "cli.ts", "diagnostics.ts", "emitter.ts", "infer.ts", "modules.ts", "transpile.ts", "typed_ast.ts", "types.ts",
2892
3396
  };
3397
+ for (transpiler_sources) |source| {
3398
+ transpile.addFileInput(b.path(b.fmt("packages/core/src/{s}", .{source})));
3399
+ }
3400
+
3401
+ const staged = b.addWriteFiles();
3402
+ const core_root = staged.addCopyFile(emitted_core, "core.zig");
3403
+ _ = staged.addCopyFile(b.path("packages/core/rt/rt.zig"), "rt.zig");
3404
+ return b.createModule(.{
3405
+ .root_source_file = core_root,
3406
+ .target = target,
3407
+ .optimize = optimize,
3408
+ });
3409
+ }
3410
+
3411
+ /// Extract a fixture's contract sidecar from its transpiled module
3412
+ /// (tools/corewire/extract.zig) — a generated one-line main per
3413
+ /// fixture, so corpus sidecars regenerate whenever the fixture or the
3414
+ /// transpiler changes.
3415
+ fn sidecarExtractJson(
3416
+ b: *std.Build,
3417
+ target: std.Build.ResolvedTarget,
3418
+ optimize: std.builtin.OptimizeMode,
3419
+ extract_mod: *std.Build.Module,
3420
+ core_mod: *std.Build.Module,
3421
+ entry: []const u8,
3422
+ ) std.Build.LazyPath {
3423
+ const root = b.addWriteFiles().add("extract_main.zig", b.fmt(
3424
+ \\//! Generated by the build: extract the contract sidecar from a
3425
+ \\//! transpiled fixture core (see tools/corewire/extract.zig).
3426
+ \\const std = @import("std");
3427
+ \\const extract = @import("extract");
3428
+ \\const core = @import("ts_core");
3429
+ \\pub fn main(init: std.process.Init) !void {{
3430
+ \\ try extract.emitMain(core, "{s}", init);
3431
+ \\}}
3432
+ \\
3433
+ , .{entry}));
3434
+ const mod = b.createModule(.{
3435
+ .root_source_file = root,
3436
+ .target = target,
3437
+ .optimize = optimize,
3438
+ });
3439
+ mod.addImport("extract", extract_mod);
3440
+ mod.addImport("ts_core", core_mod);
3441
+ const exe = b.addExecutable(.{
3442
+ .name = "sidecar-extract",
3443
+ .root_module = mod,
3444
+ .use_llvm = @import("build/app.zig").useLlvmWorkaround(target),
3445
+ });
3446
+ const run = b.addRunArtifact(exe);
3447
+ return run.addOutputFileArg("core.contract.json");
2893
3448
  }
2894
3449
 
2895
3450
  /// Transpile one TS fixture core at build time and pair the emitted
@@ -3145,7 +3700,7 @@ fn addTestStep(b: *std.Build, name: []const u8, description: []const u8, artifac
3145
3700
  /// driven through plain in-dir `zig build`.
3146
3701
  const ExampleBuildShape = enum { managed, owned };
3147
3702
 
3148
- fn addExampleTestStep(b: *std.Build, cli_exe: *std.Build.Step.Compile, group: *std.Build.Step, name: []const u8, description: []const u8, example_path: []const u8, shape: ExampleBuildShape) void {
3703
+ fn addExampleTestStep(b: *std.Build, cli_exe: *std.Build.Step.Compile, group: *std.Build.Step, name: []const u8, description: []const u8, example_path: []const u8, shape: ExampleBuildShape) *std.Build.Step {
3149
3704
  const run = switch (shape) {
3150
3705
  .owned => b.addSystemCommand(&.{ "zig", "build", "test", "-Dplatform=null" }),
3151
3706
  .managed => managedExampleRun(b, cli_exe, &.{ "test", "-Dplatform=null" }),
@@ -3173,6 +3728,7 @@ fn addExampleTestStep(b: *std.Build, cli_exe: *std.Build.Step.Compile, group: *s
3173
3728
  const step = b.step(name, description);
3174
3729
  step.dependOn(&run.step);
3175
3730
  group.dependOn(&run.step);
3731
+ return step;
3176
3732
  }
3177
3733
 
3178
3734
  /// Run a `native` CLI verb (argv tail) against a managed example. The CLI