@native-sdk/cli 0.5.3 → 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 (172) hide show
  1. package/build/app.zig +91 -2
  2. package/build.zig +756 -5
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +19 -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 +416 -9
  9. package/packages/core/sdk/core.ts +706 -5
  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 +3187 -264
  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 +42 -4
  17. package/skill-data/ts-core/SKILL.md +13 -3
  18. package/src/app_runner/root.zig +112 -10
  19. package/src/app_runner/ts_core_main.zig +4 -0
  20. package/src/automation/layout_fingerprint.zig +160 -0
  21. package/src/automation/protocol.zig +82 -33
  22. package/src/automation/root.zig +1 -0
  23. package/src/automation/server.zig +1 -1
  24. package/src/automation/snapshot.zig +68 -9
  25. package/src/automation/watcher.zig +1 -1
  26. package/src/embed/host.zig +5 -0
  27. package/src/embed/tests.zig +119 -1
  28. package/src/embed/ui_host.zig +13 -0
  29. package/src/platform/linux/gtk_host.c +639 -16
  30. package/src/platform/linux/gtk_host.h +25 -0
  31. package/src/platform/linux/root.zig +351 -7
  32. package/src/platform/macos/appkit_host.h +152 -8
  33. package/src/platform/macos/appkit_host.m +1816 -100
  34. package/src/platform/macos/cef_host.mm +372 -11
  35. package/src/platform/macos/root.zig +379 -11
  36. package/src/platform/null_platform.zig +696 -9
  37. package/src/platform/null_platform_tests.zig +35 -0
  38. package/src/platform/root.zig +42 -0
  39. package/src/platform/types.zig +524 -18
  40. package/src/platform/windows/root.zig +432 -9
  41. package/src/platform/windows/webview2_host.cpp +482 -45
  42. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  43. package/src/primitives/app_manifest/root.zig +1 -0
  44. package/src/primitives/app_manifest/types.zig +32 -0
  45. package/src/primitives/app_manifest/validation.zig +18 -0
  46. package/src/primitives/canvas/a11y_audit.zig +33 -11
  47. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  48. package/src/primitives/canvas/drawing.zig +25 -0
  49. package/src/primitives/canvas/equality.zig +8 -0
  50. package/src/primitives/canvas/events.zig +103 -16
  51. package/src/primitives/canvas/frame.zig +125 -1
  52. package/src/primitives/canvas/layout_audit.zig +22 -5
  53. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  54. package/src/primitives/canvas/render_tests.zig +13 -10
  55. package/src/primitives/canvas/root.zig +48 -0
  56. package/src/primitives/canvas/terminal_box.zig +471 -0
  57. package/src/primitives/canvas/terminal_grid.zig +978 -0
  58. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  59. package/src/primitives/canvas/test_support.zig +1 -0
  60. package/src/primitives/canvas/tests.zig +2 -0
  61. package/src/primitives/canvas/text_tests.zig +39 -4
  62. package/src/primitives/canvas/tokens.zig +115 -12
  63. package/src/primitives/canvas/ui.zig +535 -12
  64. package/src/primitives/canvas/ui_markup.zig +253 -36
  65. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  66. package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
  67. package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
  68. package/src/primitives/canvas/ui_markup_contract.zig +89 -6
  69. package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
  70. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  71. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  72. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  73. package/src/primitives/canvas/ui_markup_tests.zig +178 -9
  74. package/src/primitives/canvas/ui_markup_view.zig +220 -11
  75. package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
  76. package/src/primitives/canvas/ui_schema.zig +110 -17
  77. package/src/primitives/canvas/ui_schema_tests.zig +18 -10
  78. package/src/primitives/canvas/ui_tests.zig +141 -9
  79. package/src/primitives/canvas/widget_access.zig +28 -2
  80. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  81. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  82. package/src/primitives/canvas/widget_layout.zig +59 -11
  83. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  84. package/src/primitives/canvas/widget_render.zig +272 -18
  85. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  86. package/src/primitives/canvas/widget_routing.zig +59 -7
  87. package/src/primitives/canvas/widget_runtime.zig +23 -0
  88. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  89. package/src/primitives/canvas/widget_semantics.zig +119 -11
  90. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  91. package/src/primitives/canvas/widget_tree.zig +17 -0
  92. package/src/primitives/canvas/widgets.zig +132 -0
  93. package/src/root.zig +23 -0
  94. package/src/runtime/api.zig +76 -5
  95. package/src/runtime/automation_commands.zig +20 -1
  96. package/src/runtime/automation_snapshot.zig +25 -1
  97. package/src/runtime/automation_widget_dispatch.zig +73 -8
  98. package/src/runtime/bridge_payload.zig +8 -0
  99. package/src/runtime/bridge_responses.zig +5 -0
  100. package/src/runtime/builtin_bridge.zig +9 -4
  101. package/src/runtime/canvas_font_tests.zig +439 -2
  102. package/src/runtime/canvas_fonts.zig +61 -6
  103. package/src/runtime/canvas_frame.zig +62 -7
  104. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  105. package/src/runtime/canvas_frame_helpers.zig +190 -1
  106. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  107. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  108. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  109. package/src/runtime/canvas_image_tests.zig +195 -0
  110. package/src/runtime/canvas_images.zig +45 -12
  111. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  112. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  113. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  114. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  115. package/src/runtime/canvas_widget_display.zig +1 -1
  116. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  117. package/src/runtime/canvas_widget_events.zig +240 -24
  118. package/src/runtime/canvas_widget_runtime.zig +213 -29
  119. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  120. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  121. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  122. package/src/runtime/canvas_widget_state.zig +6 -0
  123. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  124. package/src/runtime/core.zig +131 -13
  125. package/src/runtime/effects.zig +8136 -180
  126. package/src/runtime/effects_channel_tests.zig +3519 -0
  127. package/src/runtime/effects_fetch_tests.zig +89 -1
  128. package/src/runtime/effects_file_tests.zig +41 -1
  129. package/src/runtime/effects_image_tests.zig +1304 -0
  130. package/src/runtime/effects_pty_tests.zig +1362 -0
  131. package/src/runtime/effects_tests.zig +167 -9
  132. package/src/runtime/effects_video_tests.zig +3609 -0
  133. package/src/runtime/flow.zig +42 -4
  134. package/src/runtime/gpu_surface_events.zig +473 -13
  135. package/src/runtime/media_surface.zig +116 -11
  136. package/src/runtime/media_surface_tests.zig +61 -0
  137. package/src/runtime/pty.zig +1252 -0
  138. package/src/runtime/pty_windows.zig +1780 -0
  139. package/src/runtime/root.zig +36 -0
  140. package/src/runtime/runtime_event_tests.zig +20 -1
  141. package/src/runtime/session_blobs.zig +689 -0
  142. package/src/runtime/session_journal.zig +432 -62
  143. package/src/runtime/session_record.zig +43 -2
  144. package/src/runtime/session_replay.zig +556 -20
  145. package/src/runtime/session_tests.zig +2087 -1
  146. package/src/runtime/shell_layout.zig +7 -0
  147. package/src/runtime/terminal_session.zig +1569 -0
  148. package/src/runtime/terminal_session_tests.zig +450 -0
  149. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  150. package/src/runtime/terminal_vt_stub.zig +13 -0
  151. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  152. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  153. package/src/runtime/tests.zig +8 -0
  154. package/src/runtime/ts_core_host.zig +1320 -45
  155. package/src/runtime/ts_core_host_tests.zig +1100 -1
  156. package/src/runtime/ts_ui_app.zig +23 -5
  157. package/src/runtime/ui_app.zig +2444 -69
  158. package/src/runtime/ui_app_tests.zig +3171 -744
  159. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  160. package/src/runtime/ui_app_window_tests.zig +736 -0
  161. package/src/runtime/view.zig +190 -2
  162. package/src/runtime/view_widget_scroll.zig +218 -68
  163. package/src/runtime/view_widget_text.zig +11 -2
  164. package/src/runtime/view_widget_tree.zig +111 -3
  165. package/src/runtime/window_command_bridge_tests.zig +117 -0
  166. package/src/runtime/window_storage.zig +77 -2
  167. package/src/runtime/window_view_runtime.zig +34 -2
  168. package/src/runtime/window_views.zig +62 -1
  169. package/src/terminal_session_tests_root.zig +15 -0
  170. package/src/tooling/manifest.zig +75 -0
  171. package/src/tooling/raw_manifest.zig +2 -0
  172. package/src/tooling/templates.zig +244 -8
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
@@ -219,6 +238,14 @@ pub fn build(b: *std.Build) void {
219
238
  markup_cli_mod.addImport("markup_lsp", markup_lsp_mod);
220
239
  const markup_cli_tests = testArtifact(b, markup_cli_mod);
221
240
 
241
+ // The evals harness's Cmd wire-format decoder (copied next to every
242
+ // ts-track case harness at grading time). Its own tests run here —
243
+ // NOT at eval time — because a decoder that lags a
244
+ // cmd_format_version bump panics mid-eval inside case harnesses,
245
+ // where the failure reads as the graded app's, not the tooling's.
246
+ const evals_cmdview_mod = module(b, target, optimize, "evals/harness-lib/cmdview.zig");
247
+ const evals_cmdview_tests = testArtifact(b, evals_cmdview_mod);
248
+
222
249
  // `native version` names the commit the binary was built from, so
223
250
  // binary/framework skew ("your native binary may be stale") is a
224
251
  // one-command check. Falls back to "unknown" outside a git checkout.
@@ -351,6 +378,10 @@ pub fn build(b: *std.Build) void {
351
378
  wasm_native_mod.addImport("app_manifest", module(b, wasm_target, wasm_optimize, "src/primitives/app_manifest/root.zig"));
352
379
  wasm_native_mod.addImport("diagnostics", module(b, wasm_target, wasm_optimize, "src/primitives/diagnostics/root.zig"));
353
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"));
354
385
  const docs_wasm_preview_mod = module(b, wasm_target, wasm_optimize, "tools/docs_wasm_preview.zig");
355
386
  docs_wasm_preview_mod.addImport("native_sdk", wasm_native_mod);
356
387
  docs_wasm_preview_mod.strip = true;
@@ -378,9 +409,41 @@ pub fn build(b: *std.Build) void {
378
409
  // Registry pin printer: emits the ui_schema table counts and
379
410
  // fingerprints in the exact form ui_schema_tests.zig pins, plus the
380
411
  // next free code per table for reserving codes ahead of parallel
381
- // 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"));
382
445
  const print_pins_mod = module(b, host_target, optimize, "tools/print_pins.zig");
383
- 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);
384
447
  const print_pins_exe = b.addExecutable(.{
385
448
  .name = "print-pins",
386
449
  .root_module = print_pins_mod,
@@ -414,6 +477,13 @@ pub fn build(b: *std.Build) void {
414
477
  test_step.dependOn(&b.addRunArtifact(automation_protocol_tests).step);
415
478
  test_step.dependOn(&b.addRunArtifact(tooling_tests).step);
416
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);
417
487
  if (ts_core_e2e_tests) |ts_core_artifacts| {
418
488
  const ts_core_e2e_step = b.step("test-ts-core-e2e", "Run the transpiled-core end-to-end suites (requires node)");
419
489
  const host_e2e_run = b.addRunArtifact(ts_core_artifacts.host);
@@ -424,6 +494,37 @@ pub fn build(b: *std.Build) void {
424
494
  // no build inputs/outputs to hash, so always run it.
425
495
  scaffold_ide_e2e_run.has_side_effects = true;
426
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
+ }
427
528
  ts_core_e2e_step.dependOn(&host_e2e_run.step);
428
529
  ts_core_e2e_step.dependOn(&soundboard_e2e_run.step);
429
530
  ts_core_e2e_step.dependOn(&monitor_e2e_run.step);
@@ -434,10 +535,12 @@ pub fn build(b: *std.Build) void {
434
535
  test_step.dependOn(&monitor_e2e_run.step);
435
536
  test_step.dependOn(&scaffold_ide_e2e_run.step);
436
537
  test_step.dependOn(&ai_chat_e2e_run.step);
538
+ test_step.dependOn(&sidecar_conformance_run.step);
437
539
  }
438
540
  test_step.dependOn(&b.addRunArtifact(markup_lsp_tests).step);
439
541
  test_step.dependOn(&b.addRunArtifact(automation_cli_tests).step);
440
542
  test_step.dependOn(&b.addRunArtifact(markup_cli_tests).step);
543
+ test_step.dependOn(&b.addRunArtifact(evals_cmdview_tests).step);
441
544
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-package-types", "Verify package TypeScript platform feature names", &.{
442
545
  .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "NativeSdkCommandInfo" },
443
546
  .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "list(): Promise<NativeSdkCommandInfo[]>" },
@@ -540,6 +643,12 @@ pub fn build(b: *std.Build) void {
540
643
  .{ .path = "docs/src/app/media-producers/page.mdx", .pattern = "producer: media.MediaSurfaceProducer" },
541
644
  .{ .path = "src/runtime/media_surface_tests.zig", .pattern = "producer: media.MediaSurfaceProducer" },
542
645
  });
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)", &.{
647
+ .{ .path = "src/app_runner/root.zig", .pattern = "native_sdk.platform.installHeadlessImageCodec(build_options.platform, null_platform, &replay_platform.services);" },
648
+ .{ .path = "src/platform/macos/root.zig", .pattern = "pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {\n services.decode_image_fn = decodeImage;\n}" },
649
+ .{ .path = "src/platform/linux/root.zig", .pattern = "pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {\n services.decode_image_fn = decodeImage;\n}" },
650
+ .{ .path = "src/platform/windows/root.zig", .pattern = "pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {\n services.decode_image_fn = decodeImage;\n}" },
651
+ });
543
652
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-js-view-helper-contracts", "Verify injected view helpers support label-first updates", &.{
544
653
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "update:function(options,patch)" },
545
654
  .{ .path = "src/platform/macos/cef_host.mm", .pattern = "update:function(options,patch)" },
@@ -570,6 +679,46 @@ pub fn build(b: *std.Build) void {
570
679
  .{ .path = "src/platform/linux/gtk_host.c", .pattern = "change != NATIVE_SDK_GST_STATE_CHANGE_ASYNC" },
571
680
  .{ .path = "src/platform/linux/gtk_host.c", .pattern = "#define NATIVE_SDK_GST_STATE_CHANGE_ASYNC 2" },
572
681
  });
682
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-linux-init-close-policy-refusal", "Verify the Linux platform init refuses a .hide main window with the one shared teaching (the pre-created startup window never passes the runtime's create gate, so a silent drop here meant quit-on-close for direct-SDK users)", &.{
683
+ // The gate itself is unit-tested cross-host (it is extern-free);
684
+ // this pins its WIRING into initWithOptions, which only a Linux
685
+ // link can execute.
686
+ .{ .path = "src/platform/linux/root.zig", .pattern = "try refuseUnsupportedMainWindowClosePolicy(window_options);" },
687
+ // One message, all seams: the platform-init refusal and the
688
+ // generated runner's comptime refusal teach with the same text.
689
+ .{ .path = "src/platform/linux/root.zig", .pattern = "close_policy \\\"hide\\\" is not supported on linux: the GTK host has no status item (tray), so nothing could bring the hidden window back - declare \\\"quit\\\" (the default), or scope the .hide declaration to macos/windows builds" },
690
+ .{ .path = "src/app_runner/root.zig", .pattern = "close_policy \\\"hide\\\" is not supported on linux: the GTK host has no status item (tray), so nothing could bring the hidden window back - declare \\\"quit\\\" (the default), or scope the .hide declaration to macos/windows builds" },
691
+ .{ .path = "src/tooling/templates.zig", .pattern = "close_policy \\\\\\\"hide\\\\\\\" is not supported on linux" },
692
+ });
693
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-macos-close-clears-policy-hidden", "Verify every macOS close exit leaves the policy-hidden set before its open=false emit (both hosts derive the frame event's hidden flag from set membership, and the Dock reopen re-shows every member — a close exit that skips the cleanup emits {open=false, hidden=true} and lets the reopen resurrect an app-closed window)", &.{
694
+ // AppKit: every close routes through NSWindow close/performClose,
695
+ // so the delegate's windowWillClose is the one cleanup site.
696
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[self.host.policyHiddenWindows removeObject:@(self.windowId)];\n [self.host emitWindowFrameForWindowId:self.windowId open:NO];" },
697
+ // CEF: the delegate cleanup covers the [window close] fallback,
698
+ // and the app-driven close of a browser-bearing window exits
699
+ // through orderOut WITHOUT reaching windowWillClose — that
700
+ // branch must do the set cleanup itself, before its emit.
701
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "[self.host.policyHiddenWindows removeObject:@(self.windowId)];\n [self.host emitWindowFrameForWindowId:self.windowId open:NO];" },
702
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "[self.policyHiddenWindows removeObject:@(windowId)];\n [window orderOut:nil];\n [self emitWindowFrameForWindowId:windowId open:NO];" },
703
+ });
704
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-macos-cef-window-verbs-synchronous", "Verify the CEF host's show and minimize verbs run synchronously on the main thread, the close verb's discipline (a dispatch_async show returns success while the window is still in policyHiddenWindows — the runtime's post-success focus flip then emits {focused:true, hidden:true} until the queued block lands — and a show-then-close in one dispatch re-orders: the queued show lands AFTER the synchronous close and puts a retained ordered-out closed window back on the glass)", &.{
705
+ // The show verb: direct on main, dispatch_sync hop otherwise,
706
+ // with the window lookup INSIDE the block so a window closed
707
+ // before an off-main hop lands is a no-op, not a resurrection.
708
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "if ([NSThread isMainThread]) {\n showBlock();\n } else {\n dispatch_sync(dispatch_get_main_queue(), showBlock);\n }" },
709
+ // The minimize twin (a queued miniaturize captured past a
710
+ // synchronous close genies an app-closed window into the Dock).
711
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "if ([NSThread isMainThread]) {\n miniaturizeBlock();\n } else {\n dispatch_sync(dispatch_get_main_queue(), miniaturizeBlock);\n }" },
712
+ // The C shims return success only after the synchronous verb —
713
+ // no dispatch_async between the lookup and the method call.
714
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "if (!object.windows[@(window_id)]) return 0;\n [object miniaturizeWindowWithId:window_id];\n return 1;" },
715
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "[object showWindowWithId:window_id];\n return 1;" },
716
+ // The AppKit host's twins are already synchronous direct calls
717
+ // (its runtime callbacks arrive on the main thread); these pins
718
+ // hold that symmetry.
719
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[object showWindowWithId:window_id];\n return 1;" },
720
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[object miniaturizeWindowWithId:window_id];\n return 1;" },
721
+ });
573
722
  // The embedded-WebView layer must stay real AND declare-to-use: the
574
723
  // standard build graph puts the vendored WebView2 SDK header on the
575
724
  // include path exactly when app.zon declares web use (`if
@@ -693,6 +842,59 @@ pub fn build(b: *std.Build) void {
693
842
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)scheduleFrameEventEmission" },
694
843
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)emitScheduledFrameEvent" },
695
844
  });
845
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-quit-stop-queued", "Verify the quit verb's stop is queued to the next loop turn on every synchronous-emit host (a synchronous emitShutdown nests the shutdown dispatch inside the requesting command's dispatch, seals the session journal before the command commits, and replay diverges)", &.{
846
+ // macOS (AppKit and CEF hosts): the main-queue hop, with the
847
+ // pre-run-loop inline fallback the failed-START precedent needs.
848
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (!NSApp.running) {" },
849
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "if (!NSApp.running) {" },
850
+ // Linux: the idle hop — the same seam the wake and
851
+ // frame-request paths ride.
852
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "static gboolean native_sdk_stop_idle(gpointer data)" },
853
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "g_idle_add(native_sdk_stop_idle, host);" },
854
+ // Windows was queued from the start: stop posts, the loop
855
+ // exits, and the shutdown emits after the loop at top level.
856
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "void native_sdk_windows_stop(Host *host) {" },
857
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "PostQuitMessage(0);" },
858
+ // The runtime ordering the queue protects: the recorder seals
859
+ // on the shutdown dispatch's exit, and the modeled host's
860
+ // queued seam keeps the runtime suites honest about it.
861
+ .{ .path = "src/runtime/flow.zig", .pattern = "if (event_value == .app_shutdown) recorder.finish();" },
862
+ .{ .path = "src/platform/null_platform.zig", .pattern = "pub fn takeQueuedQuit" },
863
+ });
864
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-quit-pre-run-pending", "Verify a PRE-RUN quit verb on the macOS hosts parks as a pending flag drained at top level, never the inline emit (an inline pre-run emit nests the shutdown inside the boot dispatch that requested it — the recorder seals the journal before that dispatch commits, the same bug the running-path queue fixes)", &.{
865
+ // The quit verb's own landing point: pre-run it PARKS — the
866
+ // inline emitShutdown+stop stays exclusive to
867
+ // native_sdk_appkit_stop, the host-side failure request the
868
+ // failed-START precedent rides (runWithCallback's didShutdown
869
+ // check).
870
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "void native_sdk_appkit_request_stop(native_sdk_appkit_host_t *host) {" },
871
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "object.pendingPreRunStop = YES;" },
872
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "void native_sdk_appkit_request_stop(native_sdk_appkit_host_t *host) {" },
873
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "object.pendingPreRunStop = YES;" },
874
+ // The drains: after the START dispatch (at the didShutdown
875
+ // decision point) and after the remaining pre-run dispatches
876
+ // (appearance/resize/window-frame, and AppKit's synchronous
877
+ // first canvas frame) — emitShutdown + stop at TOP LEVEL, once.
878
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (BOOL)drainPendingPreRunStop {\n if (!self.pendingPreRunStop) return NO;\n self.pendingPreRunStop = NO;\n if (self.didShutdown) return NO;\n [self emitShutdown];\n [self stop];\n return YES;\n}" },
879
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[self drainPendingPreRunStop];\n // A failed START handler requests shutdown synchronously" },
880
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if ([self drainPendingPreRunStop]) return;" },
881
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "- (BOOL)drainPendingPreRunStop {\n if (!self.pendingPreRunStop) return NO;\n self.pendingPreRunStop = NO;\n if (self.didShutdown) return NO;\n [self emitShutdown];\n [self stop];\n return YES;\n}" },
882
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "[self drainPendingPreRunStop];\n // A failed START handler requests shutdown synchronously" },
883
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "if ([self drainPendingPreRunStop]) {\n shutdownCefIfNeeded();\n return;\n }" },
884
+ // The Zig split: the quit verb rides request_stop; the failed
885
+ // emit keeps the byte-for-byte host-side stop.
886
+ .{ .path = "src/platform/macos/root.zig", .pattern = "native_sdk_appkit_request_stop(self.host);" },
887
+ .{ .path = "src/platform/macos/root.zig", .pattern = "if (self.self) |mac| native_sdk_appkit_stop(mac.host);" },
888
+ });
889
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-gtk-stop-idle-tracked", "Verify the GTK quit-stop idle source is tracked on the host, coalesced while pending, skipped after shutdown, and removed at destroy (an untracked second g_idle_add leaves a source holding a freed host after the loop quits)", &.{
890
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "guint stop_idle_source;" },
891
+ // The idle retires its own tracking before it emits.
892
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "host->stop_idle_source = 0;\n if (!host->did_shutdown) {" },
893
+ // Coalesce + post-shutdown skip, then the tracked add.
894
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "if (host->did_shutdown || host->stop_idle_source) return;\n host->stop_idle_source = g_idle_add(native_sdk_stop_idle, host);" },
895
+ // Destroy removes a still-pending stop turn.
896
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "if (host->stop_idle_source) {\n g_source_remove(host->stop_idle_source);\n host->stop_idle_source = 0;\n }" },
897
+ });
696
898
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-gpu-occluded-frame-heartbeat", "Verify occluded windows throttle frame completions to a heartbeat and restore full cadence on reveal", &.{
697
899
  // macOS: occluded surfaces pace logical completions on the ~1 Hz
698
900
  // heartbeat (never stopping — on_frame-driven models stay gently
@@ -709,13 +911,20 @@ pub fn build(b: *std.Build) void {
709
911
  // sustain a spin.
710
912
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "scheduleFrameEventEmissionForPresentCompletion:YES" },
711
913
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)noteGpuSurfaceInputActivity" },
712
- // Windows: the same throttle keyed on the one reliable Win32
713
- // occlusion signal (minimize); restore re-arms the pending
714
- // one-shot timer at the frame-grid delay, and the input /
914
+ // Windows: the same throttle keyed on the two reliable
915
+ // occlusion facts — minimize (IsIconic) and the close_policy
916
+ // .hide hide (policy_hidden: a hidden menu-bar app must not
917
+ // spin its frame loop or its spectrum emissions full-rate for
918
+ // days). Restore re-arms the pending one-shot timer at the
919
+ // frame-grid delay through WM_SIZE, re-show through the show
920
+ // verb (SW_SHOW dispatches no WM_SIZE), and the input /
715
921
  // first-present exemptions ride one prompt-frame flag.
716
922
  .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "kGpuOccludedHeartbeatNs = 1000000000ull" },
717
923
  .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "gpuSurfaceOccludedPacingActive" },
924
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "owner->second.policy_hidden) return true;" },
718
925
  .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "IsIconic(root)" },
926
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "!IsIconic(entry.second.hwnd) && !entry.second.policy_hidden" },
927
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "Re-show returns full frame cadence without dropping a beat" },
719
928
  .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "gpu_prompt_frame_pending" },
720
929
  .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "native_sdk_windows_note_gpu_surface_input" },
721
930
  // The runtime side of the measurement honesty: occluded logical
@@ -809,6 +1018,100 @@ pub fn build(b: *std.Build) void {
809
1018
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkItalicSansFont(base)" },
810
1019
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkItalicSansFont(NativeSdkWeightedSansFont(@[ @\"Geist-Bold\", @\"Geist Bold\" ], base, NSFontWeightBold, YES, size))" },
811
1020
  });
1021
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-registered-font-cache-eviction", "Verify the AppKit host invalidates BOTH per-process registered-font caches at registration (the caches are per-process while font-id permanence is per-runtime, so a new runtime re-registering an id must never resolve the previous runtime's face or its measured widths): the NSFont size cache by prefix eviction and the measured-width NSCache by a process-global registration token in its key", &.{
1022
+ // No SDK test tier links appkit_host.m (only managed app builds
1023
+ // compile it), so the eviction wiring is pinned textually like
1024
+ // the other AppKit host contracts: the shared accessor both the
1025
+ // resolve and registration paths use, the prefix eviction inside
1026
+ // register_font, and the honest lifetime comment.
1027
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSMutableDictionary<NSString *, NSFont *> *NativeSdkRegisteredFontSizeCache(void)" },
1028
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSString *stalePrefix = [NSString stringWithFormat:@\"%llu/\", (unsigned long long)font_id];" },
1029
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if ([cachedKey hasPrefix:stalePrefix]) [sizeCache removeObjectForKey:cachedKey];" },
1030
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "an id is only permanent within" },
1031
+ // The width-cache half: NSCache cannot enumerate keys, so the
1032
+ // measured-width cache is invalidated by a registration token
1033
+ // drawn from one process-global monotonic counter (tokens never
1034
+ // repeat, which is what lets unregister DELETE an id's record
1035
+ // instead of retaining a bumped one per retired id) — the token
1036
+ // table, the fresh stamp inside register_font, and the
1037
+ // token-carrying key inside measure_text.
1038
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSMutableDictionary<NSNumber *, NSNumber *> *NativeSdkRegisteredFontTokens(void)" },
1039
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "unsigned long long token = ++NativeSdkRegisteredFontTokenCounter;" },
1040
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkRegisteredFontTokens()[@(font_id)] = @(token);" },
1041
+ // The stamp is also the registration's OWNERSHIP token: register
1042
+ // reports it to the caller (`*out_token`), the runtime stores it
1043
+ // beside the captured unregister owner, and unregister removes
1044
+ // the id's state only while the id's current registration still
1045
+ // carries it — an older runtime's deinit must never tear down a
1046
+ // newer runtime's live face under a shared id (ids are
1047
+ // per-runtime, host font state is per-process, last wins).
1048
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "*out_token = token;" },
1049
+ // The token and the registered face reach measure_text from ONE
1050
+ // critical section (the snapshot helper): separate acquisitions
1051
+ // let a registration land between the token read and the face
1052
+ // resolution, pairing token 0 with the new registered face and
1053
+ // caching registered widths under the reusable token-0 key —
1054
+ // stale registered widths served after teardown. The snapshot
1055
+ // signature and its measure_text call site are pinned so the
1056
+ // two-acquisition shape cannot quietly return.
1057
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSFont *NativeSdkRegisteredFontSnapshot(unsigned long long value, CGFloat size, unsigned long long *out_token)" },
1058
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSFont *registered = NativeSdkRegisteredFontSnapshot((unsigned long long)font_id, clamped, &token);" },
1059
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSFont *font = registered ?: NativeSdkBuiltInFontForFontId(font_id, clamped);" },
1060
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[NSString stringWithFormat:@\"%llu/%llu/%.3f/%@\", (unsigned long long)font_id, token, (double)clamped, value]" },
1061
+ // The width-cache WRITE is token-rechecked. Shaping runs outside
1062
+ // the guard, so an unregister can land inside the shaping window:
1063
+ // it clears the whole width cache (its only possible eviction),
1064
+ // and an unconditional post-shape write would then repopulate the
1065
+ // cleared cache with a retired-token entry — unreachable for
1066
+ // serving (tokens never repeat) but resident until memory
1067
+ // pressure, breaking the zero-retained-state teardown the clear
1068
+ // exists to guarantee. measure_text therefore re-enters the
1069
+ // descriptor guard after shaping and writes only while the id's
1070
+ // current token still equals the snapshotted one; token 0
1071
+ // (built-in resolution — never registered, so never cleared)
1072
+ // caches without the recheck. Both branches are pinned so the
1073
+ // unconditional-write shape cannot quietly return.
1074
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (token == 0) {" },
1075
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSNumber *currentToken = NativeSdkRegisteredFontTokens()[@(font_id)];" },
1076
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (currentToken && currentToken.unsignedLongLongValue == token) {" },
1077
+ // The teardown half: Runtime.deinit returns the host-side
1078
+ // registration through the unregister owner each font entry
1079
+ // captured at registration time (never live `options.platform`,
1080
+ // which is publicly mutable), and the ObjC removal drops the
1081
+ // descriptor, the size-cache entries, AND the token record —
1082
+ // zero retained state per retired id. Pinned like the
1083
+ // registration half (appkit_host.m has no SDK test tier); the
1084
+ // capture and the deinit call site are pinned too so the seam
1085
+ // can never silently lose its one caller or regress to the live
1086
+ // read, and the embed cycle and platform-swap tests assert both
1087
+ // behaviorally against null platform recorders.
1088
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "int native_sdk_appkit_unregister_font(uint64_t font_id, uint64_t token) {" },
1089
+ // The token-match guard itself: reverting removal to id-keyed
1090
+ // (deleting whatever the id currently holds, whoever registered
1091
+ // it) must fail here — the embed suite's survives-teardown test
1092
+ // pins the same guard behaviorally against the null platform's
1093
+ // host-font mirror.
1094
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (!current || current.unsignedLongLongValue != token) return 1;" },
1095
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[NativeSdkRegisteredFontTokens() removeObjectForKey:@(font_id)];" },
1096
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[table removeObjectForKey:@(font_id)];" },
1097
+ // Teardown must also CLEAR the measured-width NSCache: a
1098
+ // retiring token's entries can never be served again (tokens
1099
+ // never repeat) but they stay resident until memory pressure,
1100
+ // and NSCache cannot enumerate keys, so the whole-cache clear on
1101
+ // the token-matched path is the only release. Pinned textually
1102
+ // because no behavioral tier can observe it — only managed app
1103
+ // builds compile appkit_host.m, so no SDK test can watch the
1104
+ // ObjC cache empty. The shared accessor and its measure_text
1105
+ // call site are pinned with the clear so the cache cannot
1106
+ // quietly retreat to a function-local static the unregister
1107
+ // path has no way to reach.
1108
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSCache<NSString *, NSNumber *> *NativeSdkMeasuredWidthCache(void)" },
1109
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[NativeSdkMeasuredWidthCache() removeAllObjects];" },
1110
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSCache<NSString *, NSNumber *> *widthCache = NativeSdkMeasuredWidthCache();" },
1111
+ .{ .path = "src/runtime/canvas_fonts.zig", .pattern = ".host_unregister_fn = services.unregister_gpu_surface_font_fn," },
1112
+ .{ .path = "src/runtime/canvas_fonts.zig", .pattern = ".host_registration_token = host_token," },
1113
+ .{ .path = "src/runtime/core.zig", .pattern = "host_unregister_fn(entry.host_unregister_context, entry.id, entry.host_registration_token) catch {};" },
1114
+ });
812
1115
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-widget-cursor-bridge", "Verify AppKit GPU widgets apply retained cursor intent", &.{
813
1116
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "native_sdk_appkit_set_view_cursor" },
814
1117
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "resetCursorRects" },
@@ -888,6 +1191,11 @@ pub fn build(b: *std.Build) void {
888
1191
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)selectAll:(id)sender" },
889
1192
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "@selector(selectAll:)" },
890
1193
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitSyntheticKeyDownWithKey:@\"a\" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand)" },
1194
+ // Modified horizontal navigation must bypass AppKit's selector
1195
+ // rewrite: the shared editor consumes the raw modifiers, and a
1196
+ // terminal translates them to its shell/protocol bindings.
1197
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkTextNavigationNeedsRawKeyEvent(event)" },
1198
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSEventModifierFlagCommand | NSEventModifierFlagOption" },
891
1199
  });
892
1200
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-appearance-bridge", "Verify AppKit reports system light and dark appearance changes", &.{
893
1201
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "effectiveAppearance" },
@@ -916,9 +1224,19 @@ pub fn build(b: *std.Build) void {
916
1224
  for (desktop_test_shard_specs, desktop_test_shards) |spec, shard_tests| {
917
1225
  addTestStep(b, b.fmt("test-desktop-{s}", .{spec.name}), spec.description, shard_tests);
918
1226
  }
1227
+ // The font-registry suite as its own step so CI lanes on real
1228
+ // Windows hardware can run it natively: the whole font pipeline
1229
+ // (TrueType parsing, glyph rasterization, the reference renderer)
1230
+ // is platform-neutral Zig, and this suite's Chinese-receipt test
1231
+ // registers a committed CJK face through the app-fonts seam and
1232
+ // proves the rendered string is real glyphs, not tofu — running it
1233
+ // on a Windows runner makes that a Windows-native receipt. The same
1234
+ // tests also run inside `zig build test` via the canvas-frame shard.
1235
+ addTestStep(b, "test-canvas-fonts", "Run the runtime font-registry tests (includes the registered-CJK Chinese receipt)", filteredTestArtifact(b, desktop_mod, "canvas-fonts-tests", &.{"runtime.canvas_font_tests.test"}));
919
1236
  addTestStep(b, "test-automation-protocol", "Run automation protocol tests", automation_protocol_tests);
920
1237
  addTestStep(b, "test-automation-cli", "Run native automate CLI tests", automation_cli_tests);
921
1238
  addTestStep(b, "test-markup-cli", "Run native markup CLI tests", markup_cli_tests);
1239
+ addTestStep(b, "test-evals-cmdview", "Run the evals harness Cmd wire decoder tests", evals_cmdview_tests);
922
1240
  addTestStep(b, "test-tooling", "Run Native SDK tooling tests", tooling_tests);
923
1241
  addTestStep(b, "test-eject-components", "Run ejected-component widget-identity tests", eject_components_tests);
924
1242
 
@@ -1040,6 +1358,7 @@ pub fn build(b: *std.Build) void {
1040
1358
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-kanban", "Run ui builder kanban example tests", "examples/kanban", .managed);
1041
1359
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-habits", "Run markup habits example tests", "examples/habits", .managed);
1042
1360
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard", "Run soundboard example tests", "examples/soundboard", .managed);
1361
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-video-player", "Run video player example tests", "examples/video-player", .managed);
1043
1362
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard-ts", "Run soundboard-ts example tests", "examples/soundboard-ts", .managed);
1044
1363
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-deck", "Run deck example tests", "examples/deck", .managed);
1045
1364
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-markdown-viewer", "Run markdown viewer example tests", "examples/markdown-viewer", .managed);
@@ -1047,8 +1366,12 @@ pub fn build(b: *std.Build) void {
1047
1366
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-notes", "Run notes example tests", "examples/notes", .managed);
1048
1367
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-split-collapse", "Run split collapse example tests", "examples/split-collapse", .managed);
1049
1368
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-system-monitor", "Run system monitor example tests", "examples/system-monitor", .managed);
1369
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-terminal", "Run terminal example tests", "examples/terminal", .owned);
1370
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-workbench", "Run workbench example tests", "examples/workbench", .owned);
1050
1371
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-system-monitor-ts", "Run system-monitor-ts example tests", "examples/system-monitor-ts", .managed);
1051
1372
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-effects-probe", "Run effects probe example tests", "examples/effects-probe", .managed);
1373
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-channel-monitor", "Run channel monitor example tests", "examples/channel-monitor", .managed);
1374
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-menu-bar", "Run menu-bar lifecycle example tests", "examples/menu-bar", .managed);
1052
1375
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-feed", "Run feed example tests", "examples/feed", .managed);
1053
1376
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-canvas-preview", "Run canvas preview example tests", "examples/canvas-preview", .managed);
1054
1377
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-capabilities", "Run capabilities example tests", "examples/capabilities", .owned);
@@ -2548,6 +2871,19 @@ fn module(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin
2548
2871
  });
2549
2872
  }
2550
2873
 
2874
+ /// The framework module's `terminal_vt` import for THIS repository's own
2875
+ /// builds: always the stub. The emulator (libghostty-vt) is pinned by
2876
+ /// the APPS that want live `<terminal>` sessions, never by this package
2877
+ /// — a pin in `build.zig.zon` is materialized into every consumer's
2878
+ /// package directory even when lazy and unused, and ghostty's own graph
2879
+ /// walks translate_c/wuffs and pulls harfbuzz, which is exactly what a
2880
+ /// scaffolded app must never carry. `AppOptions.terminal_sessions`
2881
+ /// resolves the app's own pin (see build/app.zig), and the terminal
2882
+ /// examples own the enabled path's test coverage.
2883
+ fn terminalVtModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Module {
2884
+ return module(b, target, optimize, "src/runtime/terminal_vt_stub.zig");
2885
+ }
2886
+
2551
2887
  /// The short commit hash of the framework checkout the CLI is built
2552
2888
  /// from, for `native version` staleness checks. "unknown" when
2553
2889
  /// git is unavailable (e.g. building from a package tarball).
@@ -2581,8 +2917,71 @@ const TsCoreE2eArtifacts = struct {
2581
2917
  /// paths, and builds keep working with node_modules deleted.
2582
2918
  scaffold_ide: *std.Build.Step.Compile,
2583
2919
  ai_chat: *std.Build.Step.Compile,
2920
+ /// Sidecar-shim conformance (tests/sidecar): every fixture built
2921
+ /// through BOTH lanes — the transpiler and corewire's generated
2922
+ /// mirror — and compared by layout fingerprint and model-contract
2923
+ /// artifact.
2924
+ sidecar_conformance: *std.Build.Step.Compile,
2925
+ /// Behavior parity against a REAL compiled core: built only when
2926
+ /// NATIVE_SDK_EXTERNAL_CORE_ARCHIVE names the archive(s) to link
2927
+ /// (path-delimiter-separated link inputs exporting the markup
2928
+ /// fixture's attested symbol set); null — the suite is skipped —
2929
+ /// otherwise.
2930
+ external_core_parity: ?*std.Build.Step.Compile,
2931
+ /// The full-corpus compiled-core batteries: each entry is one
2932
+ /// fixture app's OWN e2e suite compiled over a paired core — the
2933
+ /// transpiled lane plus a generated mirror dispatching into a
2934
+ /// caller-supplied compiled-core archive, byte-compared at every
2935
+ /// seam. Built per fixture only when its archive/sidecar env pair
2936
+ /// (NATIVE_SDK_EXTERNAL_CORE_ARCHIVE_<FIXTURE> and
2937
+ /// NATIVE_SDK_EXTERNAL_CORE_SIDECAR_<FIXTURE>) is supplied; empty
2938
+ /// — every battery skipped — otherwise.
2939
+ compiled_core_parity: []const CompiledCoreParity,
2940
+ /// Per-fixture contract artifacts for an external core toolchain:
2941
+ /// the extracted contract sidecar and its TypeScript facade
2942
+ /// projection, installed by the stage-core-contracts step.
2943
+ core_contracts: []const CoreContract,
2944
+ };
2945
+
2946
+ const CompiledCoreParity = struct {
2947
+ name: []const u8,
2948
+ tests: *std.Build.Step.Compile,
2949
+ };
2950
+
2951
+ const CoreContract = struct {
2952
+ name: []const u8,
2953
+ sidecar: std.Build.LazyPath,
2954
+ facade: std.Build.LazyPath,
2584
2955
  };
2585
2956
 
2957
+ /// One fixture's compiled-core supply: the archive link input(s) and
2958
+ /// the archive's own emitted contract sidecar. Both come as a pair —
2959
+ /// a real archive's build_id can only match its co-emitted sidecar, so
2960
+ /// one without the other is a misconfiguration, refused with a
2961
+ /// teaching rather than skipped into silence.
2962
+ const CompiledCoreSupply = struct {
2963
+ archives: []const u8,
2964
+ sidecar: std.Build.LazyPath,
2965
+ };
2966
+
2967
+ fn compiledCoreEnv(b: *std.Build, comptime suffix: []const u8) ?CompiledCoreSupply {
2968
+ const archive_var = "NATIVE_SDK_EXTERNAL_CORE_ARCHIVE_" ++ suffix;
2969
+ const sidecar_var = "NATIVE_SDK_EXTERNAL_CORE_SIDECAR_" ++ suffix;
2970
+ const archives = b.graph.environ_map.get(archive_var);
2971
+ const sidecar = b.graph.environ_map.get(sidecar_var);
2972
+ if (archives == null and sidecar == null) return null;
2973
+ if (archives == null or sidecar == null) {
2974
+ std.debug.panic(
2975
+ "{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",
2976
+ .{ archive_var, sidecar_var },
2977
+ );
2978
+ }
2979
+ return .{
2980
+ .archives = b.dupe(archives.?),
2981
+ .sidecar = .{ .cwd_relative = b.dupe(sidecar.?) },
2982
+ };
2983
+ }
2984
+
2586
2985
  fn tsCoreE2eArtifact(
2587
2986
  b: *std.Build,
2588
2987
  target: std.Build.ResolvedTarget,
@@ -2663,15 +3062,367 @@ fn tsCoreE2eArtifact(
2663
3062
  ai_chat_mod.addImport("native_sdk", desktop_mod);
2664
3063
  ai_chat_mod.addImport("ts_ai_chat_core", ai_chat_core_mod);
2665
3064
 
3065
+ // Sidecar-shim conformance: pair every fixture's transpiled module
3066
+ // with a corewire-generated mirror. The markup fixture's sidecar is
3067
+ // the committed hand-written one (independent ground truth for the
3068
+ // schema); the rest are extracted from the transpiled modules at
3069
+ // build time, so corpus fixtures cannot go stale against their
3070
+ // sidecars.
3071
+ const corewire_mod = b.createModule(.{
3072
+ .root_source_file = b.path("tools/corewire/main.zig"),
3073
+ .target = target,
3074
+ .optimize = optimize,
3075
+ });
3076
+ const corewire_exe = b.addExecutable(.{
3077
+ .name = "corewire",
3078
+ .root_module = corewire_mod,
3079
+ .use_llvm = @import("build/app.zig").useLlvmWorkaround(target),
3080
+ });
3081
+ const extract_mod = module(b, target, optimize, "tools/corewire/extract.zig");
3082
+
3083
+ const conformance_mod = module(b, target, optimize, "tests/sidecar/conformance_tests.zig");
3084
+ conformance_mod.addImport("native_sdk", desktop_mod);
3085
+ // The canonical value encoder the facade parity axis compares
3086
+ // against (the same module the generated shims stage).
3087
+ conformance_mod.addImport("corewire_rt", module(b, target, optimize, "tools/corewire/shim_rt.zig"));
3088
+ conformance_mod.addImport("ts_markup_core", markup_fixture_mod);
3089
+ conformance_mod.addImport("shim_markup_core", sidecarShimModule(b, target, optimize, corewire_exe, b.path("tests/sidecar/markup_fixture.contract.json")));
3090
+ conformance_mod.addImport("facade_markup_core", facadeCoreModule(b, target, optimize, node, corewire_exe, b.path("tests/sidecar/markup_fixture.contract.json")));
3091
+ // The integer-class fixture: a hand-written sidecar attesting mixed
3092
+ // i64/u64 slot classes, so the suite drives boundary and full-range
3093
+ // integer values through a generated mirror's decode paths and
3094
+ // holds the compiled facade's integer encoders to the same bytes.
3095
+ conformance_mod.addImport("shim_integer_core", sidecarShimModule(b, target, optimize, corewire_exe, b.path("tests/sidecar/integer_fixture.contract.json")));
3096
+ conformance_mod.addImport("facade_integer_core", facadeCoreModule(b, target, optimize, node, corewire_exe, b.path("tests/sidecar/integer_fixture.contract.json")));
3097
+ const conformance_fixtures = [_]struct {
3098
+ ts_import: []const u8,
3099
+ shim_import: []const u8,
3100
+ facade_import: []const u8,
3101
+ contract_name: []const u8,
3102
+ core_mod: *std.Build.Module,
3103
+ entry: []const u8,
3104
+ }{
3105
+ .{ .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" },
3106
+ .{ .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" },
3107
+ .{ .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" },
3108
+ .{ .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" },
3109
+ };
3110
+ // The corpus contract artifacts an external core toolchain consumes
3111
+ // (stage-core-contracts): the extracted sidecar plus its facade
3112
+ // projection, per fixture.
3113
+ var core_contracts: std.ArrayList(CoreContract) = .empty;
3114
+ {
3115
+ const markup_sidecar = sidecarExtractJson(b, target, optimize, extract_mod, markup_fixture_mod, "tests/ts-core/markup_fixture.ts");
3116
+ core_contracts.append(b.allocator, .{
3117
+ .name = "markup-fixture",
3118
+ .sidecar = markup_sidecar,
3119
+ .facade = facadeTsFile(b, corewire_exe, markup_sidecar),
3120
+ }) catch @panic("OOM");
3121
+ }
3122
+ for (conformance_fixtures) |fixture| {
3123
+ const sidecar_json = sidecarExtractJson(b, target, optimize, extract_mod, fixture.core_mod, fixture.entry);
3124
+ conformance_mod.addImport(fixture.ts_import, fixture.core_mod);
3125
+ conformance_mod.addImport(fixture.shim_import, sidecarShimModule(b, target, optimize, corewire_exe, sidecar_json));
3126
+ conformance_mod.addImport(fixture.facade_import, facadeCoreModule(b, target, optimize, node, corewire_exe, sidecar_json));
3127
+ core_contracts.append(b.allocator, .{
3128
+ .name = fixture.contract_name,
3129
+ .sidecar = sidecar_json,
3130
+ .facade = facadeTsFile(b, corewire_exe, sidecar_json),
3131
+ }) catch @panic("OOM");
3132
+ }
3133
+
3134
+ // Compiled-core behavior parity (tests/sidecar/
3135
+ // external_core_parity_tests.zig): the executable half of the
3136
+ // conformance story, gated on a caller-supplied compiled-core
3137
+ // archive because the repo builds none itself. The env var carries
3138
+ // one or more link inputs (path-delimiter-separated) that together
3139
+ // export the markup fixture's attested symbol set; the binary pairs
3140
+ // a FRESH generated mirror with them (the conformance binary's
3141
+ // mirror links the stub core's exports — one process cannot carry
3142
+ // both symbol sets). A real archive's sidecar carries the compile's
3143
+ // own build_id, which the mirror's boot fence checks against the
3144
+ // identity getters — so the caller supplies the archive's OWN
3145
+ // emitted sidecar through NATIVE_SDK_EXTERNAL_CORE_SIDECAR (the
3146
+ // committed fixture sidecar stays the default for stub-shaped
3147
+ // callers that restate its identity).
3148
+ const external_core_parity: ?*std.Build.Step.Compile = if (b.graph.environ_map.get("NATIVE_SDK_EXTERNAL_CORE_ARCHIVE")) |archives| blk: {
3149
+ const parity_mod = module(b, target, optimize, "tests/sidecar/external_core_parity_tests.zig");
3150
+ parity_mod.link_libc = true;
3151
+ parity_mod.addImport("corewire_rt", module(b, target, optimize, "tools/corewire/shim_rt.zig"));
3152
+ parity_mod.addImport("core_abi", module(b, target, optimize, "tools/corewire/core_abi.zig"));
3153
+ parity_mod.addImport("ts_core", markup_fixture_mod);
3154
+ const parity_sidecar: std.Build.LazyPath = if (b.graph.environ_map.get("NATIVE_SDK_EXTERNAL_CORE_SIDECAR")) |sidecar|
3155
+ .{ .cwd_relative = b.dupe(sidecar) }
3156
+ else
3157
+ b.path("tests/sidecar/markup_fixture.contract.json");
3158
+ parity_mod.addImport("shim_core", sidecarShimModule(b, target, optimize, corewire_exe, parity_sidecar));
3159
+ var inputs = std.mem.tokenizeScalar(u8, archives, std.fs.path.delimiter);
3160
+ while (inputs.next()) |input| {
3161
+ parity_mod.addObjectFile(.{ .cwd_relative = b.dupe(input) });
3162
+ }
3163
+ const parity_tests = filteredTestArtifact(b, parity_mod, "external-core-parity-tests", &.{});
3164
+ // Run the checker over the supplied sidecar explicitly (the
3165
+ // shim generation above validates too, but the checker tier —
3166
+ // both projections, integer_slots structural rules included —
3167
+ // is the surface an external compile is verified against).
3168
+ const check_sidecar = b.addRunArtifact(corewire_exe);
3169
+ check_sidecar.addArg("--sidecar");
3170
+ check_sidecar.addFileArg(parity_sidecar);
3171
+ check_sidecar.addArg("--check");
3172
+ parity_tests.step.dependOn(&check_sidecar.step);
3173
+ break :blk parity_tests;
3174
+ } else null;
3175
+
3176
+ // The full-corpus compiled-core batteries: each supplied fixture's
3177
+ // OWN e2e test root recompiled over a paired core (the transpiled
3178
+ // lane plus a fresh generated mirror linked against the caller's
3179
+ // archive), so every behavioral assertion the fixture app carries
3180
+ // runs through the compiled core with byte parity checked at every
3181
+ // seam (commands, snapshots, subscriptions, channels, helpers).
3182
+ // Env-gated per fixture like the markup parity suite: unset means
3183
+ // the battery is never built and `zig build test` stays green.
3184
+ var compiled_core_parity: std.ArrayList(CompiledCoreParity) = .empty;
3185
+ const compiled_core_fixtures = [_]struct {
3186
+ name: []const u8,
3187
+ supply: ?CompiledCoreSupply,
3188
+ ts_mod: *std.Build.Module,
3189
+ root: std.Build.LazyPath,
3190
+ core_import: []const u8,
3191
+ /// The host suite's second lane (the markup fixture) rides the
3192
+ /// same binary, transpiler-only: one archive per process is the
3193
+ /// compiled-core contract.
3194
+ second_import: ?[]const u8 = null,
3195
+ second_mod: ?*std.Build.Module = null,
3196
+ }{
3197
+ .{ .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 },
3198
+ // The markup battery is the mirror image of the host one: the
3199
+ // markup fixture's core pairs, and the host fixture rides along
3200
+ // transpiler-only as the second lane.
3201
+ .{ .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 },
3202
+ .{ .name = "soundboard", .supply = compiledCoreEnv(b, "SOUNDBOARD"), .ts_mod = soundboard_core_mod, .root = soundboard_root, .core_import = "ts_soundboard_core" },
3203
+ .{ .name = "system-monitor", .supply = compiledCoreEnv(b, "SYSTEM_MONITOR"), .ts_mod = monitor_core_mod, .root = monitor_root, .core_import = "ts_system_monitor_core" },
3204
+ .{ .name = "ai-chat", .supply = compiledCoreEnv(b, "AI_CHAT"), .ts_mod = ai_chat_core_mod, .root = ai_chat_root, .core_import = "ts_ai_chat_core" },
3205
+ };
3206
+ for (compiled_core_fixtures) |entry| {
3207
+ const supply = entry.supply orelse continue;
3208
+ const paired_mod = pairedCoreModule(b, target, optimize, corewire_exe, entry.ts_mod, supply);
3209
+ const battery_mod = b.createModule(.{
3210
+ .root_source_file = entry.root,
3211
+ .target = target,
3212
+ .optimize = optimize,
3213
+ });
3214
+ battery_mod.addImport("native_sdk", desktop_mod);
3215
+ battery_mod.addImport(entry.core_import, paired_mod);
3216
+ if (entry.second_import) |second| battery_mod.addImport(second, entry.second_mod.?);
3217
+ const battery = filteredTestArtifact(b, battery_mod, b.fmt("compiled-core-{s}-tests", .{entry.name}), &.{});
3218
+ // Run the checker tier over the supplied sidecar explicitly —
3219
+ // the same surface an external compile is verified against in
3220
+ // the markup parity suite.
3221
+ const check_sidecar = b.addRunArtifact(corewire_exe);
3222
+ check_sidecar.addArg("--sidecar");
3223
+ check_sidecar.addFileArg(supply.sidecar);
3224
+ check_sidecar.addArg("--check");
3225
+ battery.step.dependOn(&check_sidecar.step);
3226
+ compiled_core_parity.append(b.allocator, .{ .name = b.dupe(entry.name), .tests = battery }) catch @panic("OOM");
3227
+ }
3228
+
2666
3229
  return .{
2667
3230
  .host = filteredTestArtifact(b, e2e_mod, "ts-core-e2e-tests", &.{}),
2668
3231
  .soundboard = filteredTestArtifact(b, soundboard_mod, "ts-soundboard-e2e-tests", &.{}),
2669
3232
  .system_monitor = filteredTestArtifact(b, monitor_mod, "ts-system-monitor-e2e-tests", &.{}),
2670
3233
  .scaffold_ide = filteredTestArtifact(b, scaffold_ide_mod, "ts-scaffold-ide-e2e-tests", &.{}),
2671
3234
  .ai_chat = filteredTestArtifact(b, ai_chat_mod, "ts-ai-chat-e2e-tests", &.{}),
3235
+ .sidecar_conformance = filteredTestArtifact(b, conformance_mod, "sidecar-conformance-tests", &.{}),
3236
+ .external_core_parity = external_core_parity,
3237
+ .compiled_core_parity = compiled_core_parity.toOwnedSlice(b.allocator) catch @panic("OOM"),
3238
+ .core_contracts = core_contracts.toOwnedSlice(b.allocator) catch @panic("OOM"),
2672
3239
  };
2673
3240
  }
2674
3241
 
3242
+ /// One fixture's paired-core module (tests/compiled-core): generate
3243
+ /// the lockstep root from the transpiled module's own export surface,
3244
+ /// stage it beside the pairing library and the mirror-value converter,
3245
+ /// bind the transpiled lane and a mirror generated from the supplied
3246
+ /// contract sidecar, and link the caller's compiled-core archive(s).
3247
+ fn pairedCoreModule(
3248
+ b: *std.Build,
3249
+ target: std.Build.ResolvedTarget,
3250
+ optimize: std.builtin.OptimizeMode,
3251
+ corewire_exe: *std.Build.Step.Compile,
3252
+ ts_mod: *std.Build.Module,
3253
+ supply: CompiledCoreSupply,
3254
+ ) *std.Build.Module {
3255
+ const gen_root = b.addWriteFiles().add("gen_paired_main.zig",
3256
+ \\//! Generated by the build: emit a fixture's paired-core root
3257
+ \\//! from its transpiled module (tests/compiled-core/gen_paired.zig).
3258
+ \\const std = @import("std");
3259
+ \\const gen = @import("gen_paired");
3260
+ \\const core = @import("ts_core");
3261
+ \\pub fn main(init: std.process.Init) !void {
3262
+ \\ try gen.emitMain(core, init);
3263
+ \\}
3264
+ \\
3265
+ );
3266
+ const gen_mod = b.createModule(.{
3267
+ .root_source_file = gen_root,
3268
+ .target = target,
3269
+ .optimize = optimize,
3270
+ });
3271
+ gen_mod.addImport("gen_paired", module(b, target, optimize, "tests/compiled-core/gen_paired.zig"));
3272
+ gen_mod.addImport("ts_core", ts_mod);
3273
+ const gen_exe = b.addExecutable(.{
3274
+ .name = "gen-paired",
3275
+ .root_module = gen_mod,
3276
+ .use_llvm = @import("build/app.zig").useLlvmWorkaround(target),
3277
+ });
3278
+ const gen_run = b.addRunArtifact(gen_exe);
3279
+ const paired_src = gen_run.addOutputFileArg("paired.zig");
3280
+
3281
+ const staged = b.addWriteFiles();
3282
+ const paired_root = staged.addCopyFile(paired_src, "paired.zig");
3283
+ _ = staged.addCopyFile(b.path("tests/compiled-core/paired_core.zig"), "paired_core.zig");
3284
+ _ = staged.addCopyFile(b.path("tests/sidecar/mirror_value.zig"), "mirror_value.zig");
3285
+ const mod = b.createModule(.{
3286
+ .root_source_file = paired_root,
3287
+ .target = target,
3288
+ .optimize = optimize,
3289
+ });
3290
+ mod.link_libc = true;
3291
+ mod.addImport("ts_lane", ts_mod);
3292
+ mod.addImport("shim_lane", sidecarShimModule(b, target, optimize, corewire_exe, supply.sidecar));
3293
+ mod.addImport("corewire_rt", module(b, target, optimize, "tools/corewire/shim_rt.zig"));
3294
+ mod.addImport("core_abi", module(b, target, optimize, "tools/corewire/core_abi.zig"));
3295
+ var inputs = std.mem.tokenizeScalar(u8, supply.archives, std.fs.path.delimiter);
3296
+ while (inputs.next()) |input| {
3297
+ mod.addObjectFile(.{ .cwd_relative = b.dupe(input) });
3298
+ }
3299
+ return mod;
3300
+ }
3301
+
3302
+ /// A sidecar's TypeScript facade projection alone (core_facade.ts) —
3303
+ /// the contract module an external core toolchain compiles.
3304
+ fn facadeTsFile(
3305
+ b: *std.Build,
3306
+ corewire_exe: *std.Build.Step.Compile,
3307
+ sidecar_json: std.Build.LazyPath,
3308
+ ) std.Build.LazyPath {
3309
+ const generate = b.addRunArtifact(corewire_exe);
3310
+ generate.addArg("--sidecar");
3311
+ generate.addFileArg(sidecar_json);
3312
+ generate.addArg("--facade");
3313
+ return generate.addOutputFileArg("core_facade.ts");
3314
+ }
3315
+
3316
+ /// One fixture's generated-mirror module: run corewire over the
3317
+ /// sidecar, stage the emitted core_shim.zig as core.zig beside its two
3318
+ /// staged runtime files (shim_rt.zig, core_abi.zig) — the same staging
3319
+ /// shape the transpiler lane gives its emitted core and rt.zig.
3320
+ fn sidecarShimModule(
3321
+ b: *std.Build,
3322
+ target: std.Build.ResolvedTarget,
3323
+ optimize: std.builtin.OptimizeMode,
3324
+ corewire_exe: *std.Build.Step.Compile,
3325
+ sidecar_json: std.Build.LazyPath,
3326
+ ) *std.Build.Module {
3327
+ const generate = b.addRunArtifact(corewire_exe);
3328
+ generate.addArg("--sidecar");
3329
+ generate.addFileArg(sidecar_json);
3330
+ generate.addArg("--out");
3331
+ const generated = generate.addOutputFileArg("core_shim.zig");
3332
+ const staged = b.addWriteFiles();
3333
+ const shim_root = staged.addCopyFile(generated, "core.zig");
3334
+ _ = staged.addCopyFile(b.path("tools/corewire/shim_rt.zig"), "shim_rt.zig");
3335
+ _ = staged.addCopyFile(b.path("tools/corewire/core_abi.zig"), "core_abi.zig");
3336
+ return b.createModule(.{
3337
+ .root_source_file = shim_root,
3338
+ .target = target,
3339
+ .optimize = optimize,
3340
+ });
3341
+ }
3342
+
3343
+ /// One fixture's compiled-facade module: run corewire over the sidecar
3344
+ /// for its TypeScript projection (core_facade.ts), then compile that
3345
+ /// projection through the shipped transpiler — the checker/emitter tier
3346
+ /// is the compile, so this step IS the subset-acceptance proof — and
3347
+ /// stage the emitted Zig beside its rt kernel like any fixture core.
3348
+ fn facadeCoreModule(
3349
+ b: *std.Build,
3350
+ target: std.Build.ResolvedTarget,
3351
+ optimize: std.builtin.OptimizeMode,
3352
+ node: []const u8,
3353
+ corewire_exe: *std.Build.Step.Compile,
3354
+ sidecar_json: std.Build.LazyPath,
3355
+ ) *std.Build.Module {
3356
+ const generate = b.addRunArtifact(corewire_exe);
3357
+ generate.addArg("--sidecar");
3358
+ generate.addFileArg(sidecar_json);
3359
+ generate.addArg("--facade");
3360
+ const facade_ts = generate.addOutputFileArg("core_facade.ts");
3361
+ const staged_ts = b.addWriteFiles();
3362
+ const facade_entry = staged_ts.addCopyFile(facade_ts, "core.ts");
3363
+
3364
+ const transpile = b.addSystemCommand(&.{node});
3365
+ transpile.addFileArg(b.path("packages/core/src/cli.ts"));
3366
+ transpile.addFileArg(facade_entry);
3367
+ transpile.addArg("-o");
3368
+ const emitted_core = transpile.addOutputFileArg("core.zig");
3369
+ tsCoreAddDirInputs(b, transpile, "packages/core/sdk");
3370
+ const transpiler_sources = [_][]const u8{
3371
+ "checker.ts", "cli.ts", "diagnostics.ts", "emitter.ts", "infer.ts", "modules.ts", "transpile.ts", "typed_ast.ts", "types.ts",
3372
+ };
3373
+ for (transpiler_sources) |source| {
3374
+ transpile.addFileInput(b.path(b.fmt("packages/core/src/{s}", .{source})));
3375
+ }
3376
+
3377
+ const staged = b.addWriteFiles();
3378
+ const core_root = staged.addCopyFile(emitted_core, "core.zig");
3379
+ _ = staged.addCopyFile(b.path("packages/core/rt/rt.zig"), "rt.zig");
3380
+ return b.createModule(.{
3381
+ .root_source_file = core_root,
3382
+ .target = target,
3383
+ .optimize = optimize,
3384
+ });
3385
+ }
3386
+
3387
+ /// Extract a fixture's contract sidecar from its transpiled module
3388
+ /// (tools/corewire/extract.zig) — a generated one-line main per
3389
+ /// fixture, so corpus sidecars regenerate whenever the fixture or the
3390
+ /// transpiler changes.
3391
+ fn sidecarExtractJson(
3392
+ b: *std.Build,
3393
+ target: std.Build.ResolvedTarget,
3394
+ optimize: std.builtin.OptimizeMode,
3395
+ extract_mod: *std.Build.Module,
3396
+ core_mod: *std.Build.Module,
3397
+ entry: []const u8,
3398
+ ) std.Build.LazyPath {
3399
+ const root = b.addWriteFiles().add("extract_main.zig", b.fmt(
3400
+ \\//! Generated by the build: extract the contract sidecar from a
3401
+ \\//! transpiled fixture core (see tools/corewire/extract.zig).
3402
+ \\const std = @import("std");
3403
+ \\const extract = @import("extract");
3404
+ \\const core = @import("ts_core");
3405
+ \\pub fn main(init: std.process.Init) !void {{
3406
+ \\ try extract.emitMain(core, "{s}", init);
3407
+ \\}}
3408
+ \\
3409
+ , .{entry}));
3410
+ const mod = b.createModule(.{
3411
+ .root_source_file = root,
3412
+ .target = target,
3413
+ .optimize = optimize,
3414
+ });
3415
+ mod.addImport("extract", extract_mod);
3416
+ mod.addImport("ts_core", core_mod);
3417
+ const exe = b.addExecutable(.{
3418
+ .name = "sidecar-extract",
3419
+ .root_module = mod,
3420
+ .use_llvm = @import("build/app.zig").useLlvmWorkaround(target),
3421
+ });
3422
+ const run = b.addRunArtifact(exe);
3423
+ return run.addOutputFileArg("core.contract.json");
3424
+ }
3425
+
2675
3426
  /// Transpile one TS fixture core at build time and pair the emitted
2676
3427
  /// Zig with its rt kernel in one generated module.
2677
3428
  fn tsCoreFixtureModule(