@native-sdk/cli 0.0.0 → 0.4.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.
- package/LICENSE +176 -0
- package/README.md +50 -1
- package/app.zon +30 -0
- package/assets/icon.icns +0 -0
- package/assets/icon.ico +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +15 -0
- package/assets/native-sdk.entitlements +10 -0
- package/assets/native-sdk.manifest +12 -0
- package/bin/native.js +156 -0
- package/build/app.zig +716 -0
- package/build.zig +2593 -0
- package/build.zig.zon +24 -0
- package/native-sdk.d.ts +615 -0
- package/package.json +45 -8
- package/skill-data/automation/SKILL.md +248 -0
- package/skill-data/core/SKILL.md +249 -0
- package/skill-data/core/references/app-model-runtime.md +141 -0
- package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
- package/skill-data/core/references/frontend-assets.md +124 -0
- package/skill-data/core/references/project-anatomy.md +108 -0
- package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
- package/skill-data/native-ui/SKILL.md +1080 -0
- package/skills/native-sdk/SKILL.md +33 -0
- package/src/app_runner/root.zig +740 -0
- package/src/assets/root.zig +20 -0
- package/src/automation/protocol.zig +285 -0
- package/src/automation/root.zig +13 -0
- package/src/automation/server.zig +506 -0
- package/src/automation/snapshot.zig +1202 -0
- package/src/automation/watcher.zig +165 -0
- package/src/bridge/root.zig +507 -0
- package/src/debug/root.zig +246 -0
- package/src/embed/app_exports.zig +11 -0
- package/src/embed/c_api.zig +793 -0
- package/src/embed/c_exports.zig +10 -0
- package/src/embed/chrome.zig +168 -0
- package/src/embed/conversions.zig +359 -0
- package/src/embed/host.zig +960 -0
- package/src/embed/root.zig +81 -0
- package/src/embed/tests.zig +2552 -0
- package/src/embed/types.zig +382 -0
- package/src/embed/ui_host.zig +289 -0
- package/src/extensions/root.zig +197 -0
- package/src/frontend/root.zig +48 -0
- package/src/js/root.zig +65 -0
- package/src/platform/android/NativeSdkActivity.java +1370 -0
- package/src/platform/android/android_host.c +696 -0
- package/src/platform/android/files.zig +9 -0
- package/src/platform/android/native_sdk_app.h +237 -0
- package/src/platform/ios/files.zig +8 -0
- package/src/platform/ios/native_sdk_app.h +289 -0
- package/src/platform/ios/uikit_host.m +2739 -0
- package/src/platform/linux/cef_host.cpp +599 -0
- package/src/platform/linux/gtk_host.c +5362 -0
- package/src/platform/linux/gtk_host.h +265 -0
- package/src/platform/linux/root.zig +1519 -0
- package/src/platform/macos/appkit_host.h +604 -0
- package/src/platform/macos/appkit_host.m +10392 -0
- package/src/platform/macos/automation_host.h +14 -0
- package/src/platform/macos/automation_host.m +12 -0
- package/src/platform/macos/cef_host.mm +3028 -0
- package/src/platform/macos/root.zig +2260 -0
- package/src/platform/null_platform.zig +2232 -0
- package/src/platform/null_platform_tests.zig +670 -0
- package/src/platform/policy_values.zig +14 -0
- package/src/platform/root.zig +181 -0
- package/src/platform/types.zig +2681 -0
- package/src/platform/windows/cef_host.cpp +3 -0
- package/src/platform/windows/root.zig +1521 -0
- package/src/platform/windows/webview2_host.cpp +6230 -0
- package/src/primitives/app_dirs/root.zig +440 -0
- package/src/primitives/app_manifest/root.zig +109 -0
- package/src/primitives/app_manifest/tests.zig +758 -0
- package/src/primitives/app_manifest/types.zig +587 -0
- package/src/primitives/app_manifest/validation.zig +828 -0
- package/src/primitives/assets/root.zig +520 -0
- package/src/primitives/canvas/a11y_audit.zig +390 -0
- package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
- package/src/primitives/canvas/app_icon.zig +1590 -0
- package/src/primitives/canvas/chart.zig +392 -0
- package/src/primitives/canvas/chart_tests.zig +751 -0
- package/src/primitives/canvas/commands.zig +446 -0
- package/src/primitives/canvas/drawing.zig +309 -0
- package/src/primitives/canvas/equality.zig +316 -0
- package/src/primitives/canvas/events.zig +696 -0
- package/src/primitives/canvas/font_coverage.zig +118 -0
- package/src/primitives/canvas/font_ttf.zig +510 -0
- package/src/primitives/canvas/font_ttf_tests.zig +280 -0
- package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
- package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
- package/src/primitives/canvas/frame.zig +679 -0
- package/src/primitives/canvas/frame_metrics.zig +462 -0
- package/src/primitives/canvas/gpu.zig +639 -0
- package/src/primitives/canvas/hash.zig +112 -0
- package/src/primitives/canvas/icons/alert.svg +1 -0
- package/src/primitives/canvas/icons/archive.svg +1 -0
- package/src/primitives/canvas/icons/arrow-down.svg +1 -0
- package/src/primitives/canvas/icons/arrow-right.svg +1 -0
- package/src/primitives/canvas/icons/arrow-up.svg +1 -0
- package/src/primitives/canvas/icons/check-circle.svg +1 -0
- package/src/primitives/canvas/icons/check.svg +1 -0
- package/src/primitives/canvas/icons/chevron-down.svg +1 -0
- package/src/primitives/canvas/icons/chevron-left.svg +1 -0
- package/src/primitives/canvas/icons/chevron-right.svg +1 -0
- package/src/primitives/canvas/icons/chevron-up.svg +1 -0
- package/src/primitives/canvas/icons/circle-dot.svg +1 -0
- package/src/primitives/canvas/icons/clock.svg +1 -0
- package/src/primitives/canvas/icons/copy.svg +1 -0
- package/src/primitives/canvas/icons/download.svg +1 -0
- package/src/primitives/canvas/icons/edit.svg +1 -0
- package/src/primitives/canvas/icons/ellipsis.svg +1 -0
- package/src/primitives/canvas/icons/external-link.svg +1 -0
- package/src/primitives/canvas/icons/eye.svg +1 -0
- package/src/primitives/canvas/icons/file-text.svg +1 -0
- package/src/primitives/canvas/icons/folder-open.svg +1 -0
- package/src/primitives/canvas/icons/folder.svg +1 -0
- package/src/primitives/canvas/icons/git-branch.svg +1 -0
- package/src/primitives/canvas/icons/git-merge.svg +1 -0
- package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
- package/src/primitives/canvas/icons/info.svg +1 -0
- package/src/primitives/canvas/icons/menu.svg +1 -0
- package/src/primitives/canvas/icons/missing.svg +1 -0
- package/src/primitives/canvas/icons/moon.svg +1 -0
- package/src/primitives/canvas/icons/music.svg +1 -0
- package/src/primitives/canvas/icons/panel-left.svg +1 -0
- package/src/primitives/canvas/icons/panel-right.svg +1 -0
- package/src/primitives/canvas/icons/pause.svg +1 -0
- package/src/primitives/canvas/icons/play.svg +1 -0
- package/src/primitives/canvas/icons/plus.svg +1 -0
- package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
- package/src/primitives/canvas/icons/repeat.svg +1 -0
- package/src/primitives/canvas/icons/save.svg +1 -0
- package/src/primitives/canvas/icons/search.svg +1 -0
- package/src/primitives/canvas/icons/send.svg +1 -0
- package/src/primitives/canvas/icons/settings.svg +1 -0
- package/src/primitives/canvas/icons/shuffle.svg +1 -0
- package/src/primitives/canvas/icons/skip-back.svg +1 -0
- package/src/primitives/canvas/icons/skip-forward.svg +1 -0
- package/src/primitives/canvas/icons/sun.svg +1 -0
- package/src/primitives/canvas/icons/terminal.svg +1 -0
- package/src/primitives/canvas/icons/trash.svg +1 -0
- package/src/primitives/canvas/icons/volume.svg +1 -0
- package/src/primitives/canvas/icons/wrench.svg +1 -0
- package/src/primitives/canvas/icons/x-circle.svg +1 -0
- package/src/primitives/canvas/icons/x.svg +1 -0
- package/src/primitives/canvas/icons.zig +249 -0
- package/src/primitives/canvas/layout_audit.zig +744 -0
- package/src/primitives/canvas/layout_audit_tests.zig +426 -0
- package/src/primitives/canvas/markdown.zig +1031 -0
- package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
- package/src/primitives/canvas/markdown_tests.zig +538 -0
- package/src/primitives/canvas/plan_key_index.zig +120 -0
- package/src/primitives/canvas/png.zig +355 -0
- package/src/primitives/canvas/reference.zig +1457 -0
- package/src/primitives/canvas/reference_blur.zig +104 -0
- package/src/primitives/canvas/reference_memo.zig +322 -0
- package/src/primitives/canvas/reference_paths.zig +184 -0
- package/src/primitives/canvas/reference_tests.zig +1650 -0
- package/src/primitives/canvas/render.zig +747 -0
- package/src/primitives/canvas/render_effects.zig +255 -0
- package/src/primitives/canvas/render_fingerprints.zig +256 -0
- package/src/primitives/canvas/render_generic_resources.zig +376 -0
- package/src/primitives/canvas/render_images.zig +247 -0
- package/src/primitives/canvas/render_layers.zig +260 -0
- package/src/primitives/canvas/render_paths.zig +347 -0
- package/src/primitives/canvas/render_resources.zig +51 -0
- package/src/primitives/canvas/render_tests.zig +3186 -0
- package/src/primitives/canvas/root.zig +744 -0
- package/src/primitives/canvas/serialization.zig +1528 -0
- package/src/primitives/canvas/svg_icon.zig +636 -0
- package/src/primitives/canvas/svg_icon_tests.zig +312 -0
- package/src/primitives/canvas/test_support.zig +422 -0
- package/src/primitives/canvas/testdata/markdown_document.md +83 -0
- package/src/primitives/canvas/tests.zig +30 -0
- package/src/primitives/canvas/text.zig +82 -0
- package/src/primitives/canvas/text_atlas.zig +408 -0
- package/src/primitives/canvas/text_batch_tests.zig +431 -0
- package/src/primitives/canvas/text_interaction.zig +615 -0
- package/src/primitives/canvas/text_layout.zig +1069 -0
- package/src/primitives/canvas/text_layout_cache.zig +281 -0
- package/src/primitives/canvas/text_layout_hash.zig +113 -0
- package/src/primitives/canvas/text_layout_types.zig +128 -0
- package/src/primitives/canvas/text_measure_cache.zig +279 -0
- package/src/primitives/canvas/text_metrics.zig +309 -0
- package/src/primitives/canvas/text_metrics_tests.zig +262 -0
- package/src/primitives/canvas/text_span_tests.zig +608 -0
- package/src/primitives/canvas/text_spans.zig +1010 -0
- package/src/primitives/canvas/text_tests.zig +1949 -0
- package/src/primitives/canvas/themes/geist.zig +470 -0
- package/src/primitives/canvas/tokens.zig +1522 -0
- package/src/primitives/canvas/ui.zig +2686 -0
- package/src/primitives/canvas/ui_markup.zig +3791 -0
- package/src/primitives/canvas/ui_markup_binary.zig +522 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
- package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
- package/src/primitives/canvas/ui_markup_edit.zig +416 -0
- package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
- package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
- package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
- package/src/primitives/canvas/ui_markup_view.zig +2352 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
- package/src/primitives/canvas/ui_provenance.zig +96 -0
- package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
- package/src/primitives/canvas/ui_schema.zig +825 -0
- package/src/primitives/canvas/ui_schema_tests.zig +128 -0
- package/src/primitives/canvas/ui_tests.zig +1432 -0
- package/src/primitives/canvas/vector.zig +919 -0
- package/src/primitives/canvas/vector_tests.zig +547 -0
- package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
- package/src/primitives/canvas/virtual_extents.zig +540 -0
- package/src/primitives/canvas/widget_access.zig +208 -0
- package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
- package/src/primitives/canvas/widget_invalidation.zig +748 -0
- package/src/primitives/canvas/widget_layout.zig +2055 -0
- package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
- package/src/primitives/canvas/widget_metrics.zig +228 -0
- package/src/primitives/canvas/widget_render.zig +2534 -0
- package/src/primitives/canvas/widget_render_controls.zig +1563 -0
- package/src/primitives/canvas/widget_render_scroll.zig +136 -0
- package/src/primitives/canvas/widget_render_style.zig +626 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
- package/src/primitives/canvas/widget_routing.zig +475 -0
- package/src/primitives/canvas/widget_runtime.zig +307 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
- package/src/primitives/canvas/widget_semantics.zig +480 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
- package/src/primitives/canvas/widget_tests.zig +8 -0
- package/src/primitives/canvas/widget_text_input.zig +351 -0
- package/src/primitives/canvas/widget_text_select.zig +147 -0
- package/src/primitives/canvas/widget_tree.zig +232 -0
- package/src/primitives/canvas/widgets.zig +1319 -0
- package/src/primitives/diagnostics/root.zig +445 -0
- package/src/primitives/geometry/root.zig +889 -0
- package/src/primitives/json/root.zig +272 -0
- package/src/primitives/platform_info/root.zig +450 -0
- package/src/primitives/trace/root.zig +569 -0
- package/src/root.zig +165 -0
- package/src/runtime/api.zig +431 -0
- package/src/runtime/async_bridge.zig +49 -0
- package/src/runtime/automation_commands.zig +686 -0
- package/src/runtime/automation_liveness_tests.zig +140 -0
- package/src/runtime/automation_snapshot.zig +246 -0
- package/src/runtime/automation_widget_dispatch.zig +617 -0
- package/src/runtime/bridge_dispatch_tests.zig +202 -0
- package/src/runtime/bridge_payload.zig +194 -0
- package/src/runtime/bridge_permission_tests.zig +551 -0
- package/src/runtime/bridge_responses.zig +414 -0
- package/src/runtime/builtin_bridge.zig +554 -0
- package/src/runtime/canvas_budget_edge_tests.zig +415 -0
- package/src/runtime/canvas_font_tests.zig +410 -0
- package/src/runtime/canvas_fonts.zig +229 -0
- package/src/runtime/canvas_frame.zig +1734 -0
- package/src/runtime/canvas_frame_animation_tests.zig +609 -0
- package/src/runtime/canvas_frame_cache_tests.zig +333 -0
- package/src/runtime/canvas_frame_helpers.zig +414 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
- package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
- package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
- package/src/runtime/canvas_frame_retained_tests.zig +753 -0
- package/src/runtime/canvas_frame_tests.zig +9 -0
- package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
- package/src/runtime/canvas_image_tests.zig +362 -0
- package/src/runtime/canvas_images.zig +224 -0
- package/src/runtime/canvas_limits.zig +317 -0
- package/src/runtime/canvas_screenshot_tests.zig +289 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
- package/src/runtime/canvas_widget_chart_tests.zig +249 -0
- package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
- package/src/runtime/canvas_widget_context_menu.zig +318 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
- package/src/runtime/canvas_widget_control_tests.zig +2164 -0
- package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
- package/src/runtime/canvas_widget_display.zig +677 -0
- package/src/runtime/canvas_widget_event_tests.zig +1779 -0
- package/src/runtime/canvas_widget_events.zig +1098 -0
- package/src/runtime/canvas_widget_floating_tests.zig +695 -0
- package/src/runtime/canvas_widget_layout_tests.zig +26 -0
- package/src/runtime/canvas_widget_runtime.zig +1335 -0
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
- package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
- package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
- package/src/runtime/canvas_widget_state.zig +798 -0
- package/src/runtime/canvas_widget_text_tests.zig +2104 -0
- package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
- package/src/runtime/clock.zig +231 -0
- package/src/runtime/core.zig +927 -0
- package/src/runtime/effects.zig +4197 -0
- package/src/runtime/effects_audio_tests.zig +690 -0
- package/src/runtime/effects_clipboard_tests.zig +317 -0
- package/src/runtime/effects_fetch_tests.zig +1031 -0
- package/src/runtime/effects_file_tests.zig +407 -0
- package/src/runtime/effects_tests.zig +1251 -0
- package/src/runtime/flow.zig +1175 -0
- package/src/runtime/frame_profile.zig +221 -0
- package/src/runtime/gpu_surface_events.zig +639 -0
- package/src/runtime/launch_timing.zig +59 -0
- package/src/runtime/markdown_app_tests.zig +224 -0
- package/src/runtime/native_command_event_tests.zig +431 -0
- package/src/runtime/platform_bridge_tests.zig +8 -0
- package/src/runtime/platform_config_tests.zig +392 -0
- package/src/runtime/root.zig +150 -0
- package/src/runtime/runtime_event_tests.zig +1079 -0
- package/src/runtime/session_journal.zig +1522 -0
- package/src/runtime/session_record.zig +332 -0
- package/src/runtime/session_replay.zig +274 -0
- package/src/runtime/session_state.zig +30 -0
- package/src/runtime/session_tests.zig +399 -0
- package/src/runtime/shell_layout.zig +472 -0
- package/src/runtime/shell_layout_tests.zig +1246 -0
- package/src/runtime/shell_view_tests.zig +604 -0
- package/src/runtime/state.zig +110 -0
- package/src/runtime/system_services.zig +392 -0
- package/src/runtime/test_support.zig +79 -0
- package/src/runtime/tests.zig +30 -0
- package/src/runtime/ui_app.zig +3290 -0
- package/src/runtime/ui_app_huge_model_tests.zig +351 -0
- package/src/runtime/ui_app_provenance.zig +370 -0
- package/src/runtime/ui_app_tests.zig +3254 -0
- package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
- package/src/runtime/ui_app_window_tests.zig +442 -0
- package/src/runtime/validation.zig +206 -0
- package/src/runtime/view.zig +908 -0
- package/src/runtime/view_canvas.zig +850 -0
- package/src/runtime/view_widget_control.zig +433 -0
- package/src/runtime/view_widget_scroll.zig +360 -0
- package/src/runtime/view_widget_text.zig +275 -0
- package/src/runtime/view_widget_tree.zig +843 -0
- package/src/runtime/webview_view_bridge_tests.zig +664 -0
- package/src/runtime/widget_bridge.zig +231 -0
- package/src/runtime/window_command_bridge_tests.zig +403 -0
- package/src/runtime/window_storage.zig +255 -0
- package/src/runtime/window_view_runtime.zig +727 -0
- package/src/runtime/window_views.zig +334 -0
- package/src/security/root.zig +118 -0
- package/src/tooling/android.zig +1172 -0
- package/src/tooling/assets.zig +128 -0
- package/src/tooling/buildgraph.zig +379 -0
- package/src/tooling/cef.zig +671 -0
- package/src/tooling/codesign.zig +172 -0
- package/src/tooling/components/identity_tests.zig +185 -0
- package/src/tooling/components/stepper.zig +113 -0
- package/src/tooling/components/timeline.native +27 -0
- package/src/tooling/components/timeline_item.zig +131 -0
- package/src/tooling/default_icon.icns +0 -0
- package/src/tooling/default_icon.png +0 -0
- package/src/tooling/dev.zig +172 -0
- package/src/tooling/doctor.zig +349 -0
- package/src/tooling/eject_components.zig +170 -0
- package/src/tooling/embedlib.zig +290 -0
- package/src/tooling/ios.zig +528 -0
- package/src/tooling/manifest.zig +1939 -0
- package/src/tooling/package.zig +2388 -0
- package/src/tooling/process_tree.zig +114 -0
- package/src/tooling/raw_manifest.zig +193 -0
- package/src/tooling/root.zig +22 -0
- package/src/tooling/templates.zig +3191 -0
- package/src/tooling/toolchain.zig +371 -0
- package/src/tooling/verbs.zig +204 -0
- package/src/tooling/web_engine.zig +135 -0
- package/src/tooling/xcodeproj.zig +462 -0
- package/src/window_state/root.zig +507 -0
- package/index.js +0 -2
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
//! Session recorder: streams a live session into the journal format.
|
|
2
|
+
//!
|
|
3
|
+
//! Wired through `Runtime.Options.session_recorder`, the dispatch choke
|
|
4
|
+
//! point stages every platform event on entry and commits it on exit, so
|
|
5
|
+
//! effect results drained DURING an event's dispatch land in the stream
|
|
6
|
+
//! BEFORE the event record — the ordering replay depends on (feed the
|
|
7
|
+
//! stub executor, then dispatch). Nested dispatches (automation commands
|
|
8
|
+
//! inside `frame_requested`) commit innermost-first for the same reason.
|
|
9
|
+
//!
|
|
10
|
+
//! Recording must never take the app down: any failure — a sink write
|
|
11
|
+
//! error, an over-budget event, a journal past its size budget — flips
|
|
12
|
+
//! the recorder into a failed state that says so loudly on stderr ONCE
|
|
13
|
+
//! and drops everything after. A failed recording has no end record, so
|
|
14
|
+
//! replay refuses it as truncated instead of silently replaying a
|
|
15
|
+
//! prefix.
|
|
16
|
+
//!
|
|
17
|
+
//! The struct embeds multi-megabyte staging buffers — construct it on
|
|
18
|
+
//! the heap (the Runtime precedent).
|
|
19
|
+
|
|
20
|
+
const std = @import("std");
|
|
21
|
+
const platform = @import("../platform/root.zig");
|
|
22
|
+
const runtime_clock = @import("clock.zig");
|
|
23
|
+
const runtime_effects = @import("effects.zig");
|
|
24
|
+
const journal = @import("session_journal.zig");
|
|
25
|
+
|
|
26
|
+
pub const Header = journal.Header;
|
|
27
|
+
|
|
28
|
+
/// Where journal bytes go. The app runner backs this with a file opened
|
|
29
|
+
/// at launch; tests back it with a growable buffer.
|
|
30
|
+
pub const RecorderSink = struct {
|
|
31
|
+
context: *anyopaque,
|
|
32
|
+
write_fn: *const fn (context: *anyopaque, bytes: []const u8) anyerror!void,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
pub const SessionRecorder = struct {
|
|
36
|
+
sink: RecorderSink,
|
|
37
|
+
began: bool = false,
|
|
38
|
+
finished: bool = false,
|
|
39
|
+
failed: bool = false,
|
|
40
|
+
bytes_written: u64 = 0,
|
|
41
|
+
event_count: u64 = 0,
|
|
42
|
+
effect_count: u64 = 0,
|
|
43
|
+
checkpoint_count: u64 = 0,
|
|
44
|
+
screenshot_count: u64 = 0,
|
|
45
|
+
/// Frame index of the last recorded checkpoint, so exactly one
|
|
46
|
+
/// checkpoint follows each published frame.
|
|
47
|
+
last_checkpoint_frame: u64 = 0,
|
|
48
|
+
depth: usize = 0,
|
|
49
|
+
staged_lens: [journal.max_session_event_depth]usize = [_]usize{0} ** journal.max_session_event_depth,
|
|
50
|
+
staged: [journal.max_session_event_depth][journal.max_session_event_bytes]u8 = undefined,
|
|
51
|
+
/// Encode scratch for effect payloads (up to a whole file read).
|
|
52
|
+
effect_buffer: [journal.max_session_record_bytes]u8 = undefined,
|
|
53
|
+
small_buffer: [1024]u8 = undefined,
|
|
54
|
+
|
|
55
|
+
pub fn init(sink: RecorderSink) SessionRecorder {
|
|
56
|
+
return .{ .sink = sink };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// Write the preamble and session header. Must run before the first
|
|
60
|
+
/// dispatched event.
|
|
61
|
+
pub fn begin(self: *SessionRecorder, header: Header) void {
|
|
62
|
+
if (self.began or self.failed) return;
|
|
63
|
+
self.began = true;
|
|
64
|
+
var preamble_buffer: [journal.preamble_len]u8 = undefined;
|
|
65
|
+
self.write(journal.writePreamble(&preamble_buffer));
|
|
66
|
+
const payload = journal.encodeHeader(header, &self.small_buffer) catch {
|
|
67
|
+
return self.fail("session header does not fit its record budget");
|
|
68
|
+
};
|
|
69
|
+
self.writeRecord(.header, payload);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/// Serialize `event` into the staging stack. Effect results drained
|
|
73
|
+
/// during its dispatch write directly to the stream; `commitEvent`
|
|
74
|
+
/// then appends the event record after them.
|
|
75
|
+
pub fn stageEvent(self: *SessionRecorder, event: platform.Event) void {
|
|
76
|
+
if (!self.began or self.failed or self.finished) return;
|
|
77
|
+
if (self.depth >= journal.max_session_event_depth) {
|
|
78
|
+
return self.fail("dispatch nesting exceeded max_session_event_depth - this is a runtime bug, not a session shape");
|
|
79
|
+
}
|
|
80
|
+
const encoded = journal.encodeEvent(event, &self.staged[self.depth]) catch {
|
|
81
|
+
return self.fail("a platform event exceeded max_session_event_bytes");
|
|
82
|
+
};
|
|
83
|
+
self.staged_lens[self.depth] = encoded.len;
|
|
84
|
+
self.depth += 1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/// Append the innermost staged event record. Call exactly once per
|
|
88
|
+
/// successful `stageEvent`, on dispatch exit.
|
|
89
|
+
pub fn commitEvent(self: *SessionRecorder) void {
|
|
90
|
+
if (!self.began or self.failed or self.finished) return;
|
|
91
|
+
if (self.depth == 0) return;
|
|
92
|
+
self.depth -= 1;
|
|
93
|
+
self.writeRecord(.event, self.staged[self.depth][0..self.staged_lens[self.depth]]);
|
|
94
|
+
if (!self.failed) self.event_count += 1;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// True when dispatch just returned to the top level and the frame
|
|
98
|
+
/// index moved — the once-per-published-frame checkpoint gate.
|
|
99
|
+
pub fn wantsCheckpoint(self: *const SessionRecorder, frame_index: u64) bool {
|
|
100
|
+
return self.began and !self.failed and !self.finished and
|
|
101
|
+
self.depth == 0 and frame_index != self.last_checkpoint_frame;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
pub fn recordCheckpoint(self: *SessionRecorder, frame_index: u64, fingerprint: u64) void {
|
|
105
|
+
if (!self.began or self.failed or self.finished) return;
|
|
106
|
+
self.last_checkpoint_frame = frame_index;
|
|
107
|
+
const payload = journal.encodeCheckpoint(.{
|
|
108
|
+
.event_ordinal = self.event_count,
|
|
109
|
+
.frame_index = frame_index,
|
|
110
|
+
.fingerprint = fingerprint,
|
|
111
|
+
}, &self.small_buffer) catch return self.fail("checkpoint record over budget");
|
|
112
|
+
self.writeRecord(.checkpoint, payload);
|
|
113
|
+
if (!self.failed) self.checkpoint_count += 1;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/// Mark the session with a pixel checkpoint (an automation
|
|
117
|
+
/// `screenshot` during recording): replay re-renders the same view
|
|
118
|
+
/// at the same scale through the deterministic reference renderer
|
|
119
|
+
/// and compares hashes.
|
|
120
|
+
pub fn recordScreenshot(self: *SessionRecorder, view_label: []const u8, scale: f32, png_hash: u64, png_len: u64) void {
|
|
121
|
+
if (!self.began or self.failed or self.finished) return;
|
|
122
|
+
const payload = journal.encodeScreenshot(.{
|
|
123
|
+
.event_ordinal = self.event_count,
|
|
124
|
+
.view_label = view_label,
|
|
125
|
+
.scale = scale,
|
|
126
|
+
.png_hash = png_hash,
|
|
127
|
+
.png_len = png_len,
|
|
128
|
+
}, &self.small_buffer) catch return self.fail("screenshot record over budget");
|
|
129
|
+
self.writeRecord(.screenshot, payload);
|
|
130
|
+
if (!self.failed) self.screenshot_count += 1;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/// Record one drained effect result (the `Effects.bindJournal`
|
|
134
|
+
/// callback target).
|
|
135
|
+
pub fn recordEffect(self: *SessionRecorder, record: runtime_effects.EffectResultRecord) void {
|
|
136
|
+
if (!self.began or self.failed or self.finished) return;
|
|
137
|
+
const payload = journal.encodeEffect(record, &self.effect_buffer) catch {
|
|
138
|
+
return self.fail("an effect result exceeded max_session_record_bytes");
|
|
139
|
+
};
|
|
140
|
+
self.writeRecord(.effect, payload);
|
|
141
|
+
if (!self.failed) self.effect_count += 1;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/// The type-erased binding `Effects.bindJournal` takes.
|
|
145
|
+
pub fn effectJournal(self: *SessionRecorder) runtime_effects.EffectJournal {
|
|
146
|
+
return .{ .context = self, .record_fn = recordEffectErased };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
fn recordEffectErased(context: *anyopaque, record: runtime_effects.EffectResultRecord) void {
|
|
150
|
+
const self: *SessionRecorder = @ptrCast(@alignCast(context));
|
|
151
|
+
self.recordEffect(record);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/// Write the end record, sealing the journal. A failed recording
|
|
155
|
+
/// seals nothing: without the end record, replay refuses the file
|
|
156
|
+
/// as truncated rather than silently replaying a prefix.
|
|
157
|
+
pub fn finish(self: *SessionRecorder) void {
|
|
158
|
+
if (!self.began or self.failed or self.finished) return;
|
|
159
|
+
self.finished = true;
|
|
160
|
+
const payload = journal.encodeEnd(.{
|
|
161
|
+
.event_count = self.event_count,
|
|
162
|
+
.effect_count = self.effect_count,
|
|
163
|
+
.checkpoint_count = self.checkpoint_count,
|
|
164
|
+
.screenshot_count = self.screenshot_count,
|
|
165
|
+
}, &self.small_buffer) catch return self.fail("end record over budget");
|
|
166
|
+
self.writeRecord(.end, payload);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
fn writeRecord(self: *SessionRecorder, kind: journal.RecordKind, payload: []const u8) void {
|
|
170
|
+
if (self.failed) return;
|
|
171
|
+
if (payload.len > journal.max_session_record_bytes) {
|
|
172
|
+
return self.fail("a record exceeded max_session_record_bytes");
|
|
173
|
+
}
|
|
174
|
+
const total = self.bytes_written + 5 + payload.len;
|
|
175
|
+
if (total > journal.max_session_journal_bytes) {
|
|
176
|
+
return self.fail("the journal exceeded max_session_journal_bytes - recording stopped");
|
|
177
|
+
}
|
|
178
|
+
var record_header: [5]u8 = undefined;
|
|
179
|
+
record_header[0] = @intFromEnum(kind);
|
|
180
|
+
std.mem.writeInt(u32, record_header[1..5], @intCast(payload.len), .little);
|
|
181
|
+
self.write(&record_header);
|
|
182
|
+
self.write(payload);
|
|
183
|
+
if (!self.failed) self.bytes_written = total;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
fn write(self: *SessionRecorder, bytes: []const u8) void {
|
|
187
|
+
if (self.failed) return;
|
|
188
|
+
self.sink.write_fn(self.sink.context, bytes) catch |err| {
|
|
189
|
+
self.fail(@errorName(err));
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/// Flip into the failed state, loudly, once. Recording failures
|
|
194
|
+
/// degrade — the app keeps running; only the journal dies.
|
|
195
|
+
fn fail(self: *SessionRecorder, reason: []const u8) void {
|
|
196
|
+
if (self.failed) return;
|
|
197
|
+
self.failed = true;
|
|
198
|
+
// No stderr on freestanding targets (the docs' wasm preview
|
|
199
|
+
// host): analyzing the print would drag `std.Io.Threaded` in.
|
|
200
|
+
if (comptime @import("builtin").os.tag != .freestanding) {
|
|
201
|
+
std.debug.print("session recording failed and stopped: {s} (the partial journal has no end record; replay will refuse it)\n", .{reason});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/// A convenience header for the app runner: identity plus the recording
|
|
207
|
+
/// wall-clock stamp.
|
|
208
|
+
pub fn headerNow(platform_name: []const u8, app_name: []const u8, window_width: f32, window_height: f32) Header {
|
|
209
|
+
return .{
|
|
210
|
+
.platform_name = platform_name,
|
|
211
|
+
.app_name = app_name,
|
|
212
|
+
.recorded_at_wall_ms = runtime_clock.nowMs(),
|
|
213
|
+
.window_width = window_width,
|
|
214
|
+
.window_height = window_height,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// -------------------------------------------------------------- tests
|
|
219
|
+
|
|
220
|
+
const testing = std.testing;
|
|
221
|
+
|
|
222
|
+
const BufferSink = struct {
|
|
223
|
+
buffer: [1 << 16]u8 = undefined,
|
|
224
|
+
len: usize = 0,
|
|
225
|
+
fail_after: ?usize = null,
|
|
226
|
+
|
|
227
|
+
fn sink(self: *BufferSink) RecorderSink {
|
|
228
|
+
return .{ .context = self, .write_fn = write };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
fn write(context: *anyopaque, chunk: []const u8) anyerror!void {
|
|
232
|
+
const self: *BufferSink = @ptrCast(@alignCast(context));
|
|
233
|
+
if (self.fail_after) |limit| {
|
|
234
|
+
if (self.len + chunk.len > limit) return error.NoSpaceLeft;
|
|
235
|
+
}
|
|
236
|
+
@memcpy(self.buffer[self.len .. self.len + chunk.len], chunk);
|
|
237
|
+
self.len += chunk.len;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
fn bytes(self: *const BufferSink) []const u8 {
|
|
241
|
+
return self.buffer[0..self.len];
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
test "recorder orders effect results before their consuming event" {
|
|
246
|
+
var buffer_sink = BufferSink{};
|
|
247
|
+
const recorder = try testing.allocator.create(SessionRecorder);
|
|
248
|
+
defer testing.allocator.destroy(recorder);
|
|
249
|
+
recorder.* = SessionRecorder.init(buffer_sink.sink());
|
|
250
|
+
|
|
251
|
+
recorder.begin(.{ .platform_name = "test", .app_name = "demo" });
|
|
252
|
+
recorder.stageEvent(.app_start);
|
|
253
|
+
recorder.commitEvent();
|
|
254
|
+
recorder.stageEvent(.wake);
|
|
255
|
+
// Drained during the wake dispatch:
|
|
256
|
+
recorder.recordEffect(.{ .kind = .line, .key = 1, .payload = "hello" });
|
|
257
|
+
recorder.commitEvent();
|
|
258
|
+
recorder.recordCheckpoint(1, 0xabc);
|
|
259
|
+
recorder.finish();
|
|
260
|
+
try testing.expect(!recorder.failed);
|
|
261
|
+
|
|
262
|
+
var reader = try journal.Reader.init(buffer_sink.bytes());
|
|
263
|
+
_ = (try reader.next()).?; // header
|
|
264
|
+
try testing.expect((try reader.next()).?.event == .app_start);
|
|
265
|
+
const effect = (try reader.next()).?;
|
|
266
|
+
try testing.expectEqualStrings("hello", effect.effect.payload);
|
|
267
|
+
const event = (try reader.next()).?;
|
|
268
|
+
try testing.expect(event.event == .wake);
|
|
269
|
+
const checkpoint = (try reader.next()).?;
|
|
270
|
+
try testing.expectEqual(@as(u64, 0xabc), checkpoint.checkpoint.fingerprint);
|
|
271
|
+
try testing.expectEqual(@as(u64, 2), checkpoint.checkpoint.event_ordinal);
|
|
272
|
+
const end = (try reader.next()).?;
|
|
273
|
+
try testing.expectEqual(@as(u64, 2), end.end.event_count);
|
|
274
|
+
try testing.expectEqual(@as(u64, 1), end.end.effect_count);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
test "recorder commits nested events innermost-first" {
|
|
278
|
+
var buffer_sink = BufferSink{};
|
|
279
|
+
const recorder = try testing.allocator.create(SessionRecorder);
|
|
280
|
+
defer testing.allocator.destroy(recorder);
|
|
281
|
+
recorder.* = SessionRecorder.init(buffer_sink.sink());
|
|
282
|
+
recorder.begin(.{ .platform_name = "test", .app_name = "demo" });
|
|
283
|
+
recorder.stageEvent(.frame_requested);
|
|
284
|
+
recorder.stageEvent(.{ .menu_command = .{ .name = "app.about", .window_id = 1 } });
|
|
285
|
+
recorder.commitEvent();
|
|
286
|
+
recorder.commitEvent();
|
|
287
|
+
recorder.finish();
|
|
288
|
+
|
|
289
|
+
var reader = try journal.Reader.init(buffer_sink.bytes());
|
|
290
|
+
_ = (try reader.next()).?;
|
|
291
|
+
const inner = (try reader.next()).?;
|
|
292
|
+
try testing.expectEqualStrings("app.about", inner.event.menu_command.name);
|
|
293
|
+
const outer = (try reader.next()).?;
|
|
294
|
+
try testing.expect(outer.event == .frame_requested);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
test "recorder fails loudly once and seals nothing after a sink error" {
|
|
298
|
+
var buffer_sink = BufferSink{ .fail_after = 32 };
|
|
299
|
+
const recorder = try testing.allocator.create(SessionRecorder);
|
|
300
|
+
defer testing.allocator.destroy(recorder);
|
|
301
|
+
recorder.* = SessionRecorder.init(buffer_sink.sink());
|
|
302
|
+
recorder.begin(.{ .platform_name = "test", .app_name = "demo" });
|
|
303
|
+
var index: usize = 0;
|
|
304
|
+
while (index < 8) : (index += 1) {
|
|
305
|
+
recorder.stageEvent(.frame_requested);
|
|
306
|
+
recorder.commitEvent();
|
|
307
|
+
}
|
|
308
|
+
try testing.expect(recorder.failed);
|
|
309
|
+
recorder.finish();
|
|
310
|
+
// Whatever landed before the failure has no end record: replay
|
|
311
|
+
// refuses the file as truncated.
|
|
312
|
+
if (journal.Reader.init(buffer_sink.bytes())) |reader_value| {
|
|
313
|
+
var reader = reader_value;
|
|
314
|
+
const failed = while (true) {
|
|
315
|
+
const record = reader.next() catch break true;
|
|
316
|
+
if (record == null) break false;
|
|
317
|
+
};
|
|
318
|
+
try testing.expect(failed);
|
|
319
|
+
} else |_| {}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
test "checkpoint gate fires once per frame index" {
|
|
323
|
+
var buffer_sink = BufferSink{};
|
|
324
|
+
const recorder = try testing.allocator.create(SessionRecorder);
|
|
325
|
+
defer testing.allocator.destroy(recorder);
|
|
326
|
+
recorder.* = SessionRecorder.init(buffer_sink.sink());
|
|
327
|
+
recorder.begin(.{ .platform_name = "test", .app_name = "demo" });
|
|
328
|
+
try testing.expect(recorder.wantsCheckpoint(1));
|
|
329
|
+
recorder.recordCheckpoint(1, 5);
|
|
330
|
+
try testing.expect(!recorder.wantsCheckpoint(1));
|
|
331
|
+
try testing.expect(recorder.wantsCheckpoint(2));
|
|
332
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
//! Session replay: drive a recorded journal back through the dispatch
|
|
2
|
+
//! choke point, deterministically, and verify equivalence.
|
|
3
|
+
//!
|
|
4
|
+
//! The journal is the world: the app's effects channel is armed into
|
|
5
|
+
//! replay mode FIRST (fake executor — `fx.spawn`/`fx.fetch`/file/
|
|
6
|
+
//! clipboard requests park in their slots; no process, network, file, or
|
|
7
|
+
//! pasteboard is ever touched), then records replay in file order —
|
|
8
|
+
//! effect results feed the parked requests, events dispatch through
|
|
9
|
+
//! `Runtime.dispatchPlatformEvent` exactly as the platform once did, and
|
|
10
|
+
//! checkpoints compare the live state fingerprint (and screenshot pixel
|
|
11
|
+
//! hashes) against what the recording saw.
|
|
12
|
+
//!
|
|
13
|
+
//! Replay hosts on the null platform: window creates, presents, and
|
|
14
|
+
//! timers are inert there, and every input that matters arrives from the
|
|
15
|
+
//! journal (timer fires and effect wakes are platform events, so they
|
|
16
|
+
//! ride the event stream like everything else).
|
|
17
|
+
//!
|
|
18
|
+
//! THE INIT CONTRACT (see session_journal.zig): replay re-runs the app's
|
|
19
|
+
//! own model init and `init_fx` rather than restoring a serialized
|
|
20
|
+
//! model, so both must be deterministic. A violation shows up here as
|
|
21
|
+
//! the first mismatching checkpoint.
|
|
22
|
+
//!
|
|
23
|
+
//! Divergence is loud and specific: a fed effect result whose key has no
|
|
24
|
+
//! parked request (`ReplayEffectDivergence`) means update spawned
|
|
25
|
+
//! different effects than the recording — usually nondeterminism outside
|
|
26
|
+
//! the effect boundary; a fingerprint mismatch names the event ordinal
|
|
27
|
+
//! and frame where state first differed.
|
|
28
|
+
|
|
29
|
+
const std = @import("std");
|
|
30
|
+
const canvas = @import("canvas");
|
|
31
|
+
const automation_protocol = @import("../automation/protocol.zig");
|
|
32
|
+
const core = @import("core.zig");
|
|
33
|
+
const journal = @import("session_journal.zig");
|
|
34
|
+
|
|
35
|
+
pub const ReplayError = error{
|
|
36
|
+
/// The journal was recorded on a different platform; v1 replay is
|
|
37
|
+
/// same-platform only (font metrics and scale behavior differ).
|
|
38
|
+
ReplayPlatformMismatch,
|
|
39
|
+
/// The journal's automation protocol version differs from this
|
|
40
|
+
/// build's — the recording binary and this one are skewed.
|
|
41
|
+
ReplayProtocolMismatch,
|
|
42
|
+
/// A journaled effect result found no parked request with its key:
|
|
43
|
+
/// the replayed updates issued different effects than the recorded
|
|
44
|
+
/// ones did.
|
|
45
|
+
ReplayEffectDivergence,
|
|
46
|
+
/// The app registered no replay hook (`App.replay_fn`), but the
|
|
47
|
+
/// journal carries effect results that need one.
|
|
48
|
+
ReplayUnsupportedApp,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/// Bounded mismatch detail (first N are kept; the count keeps counting).
|
|
52
|
+
pub const max_replay_mismatches: usize = 16;
|
|
53
|
+
|
|
54
|
+
pub const ReplayMismatchKind = enum { fingerprint, screenshot };
|
|
55
|
+
|
|
56
|
+
pub const ReplayMismatch = struct {
|
|
57
|
+
kind: ReplayMismatchKind,
|
|
58
|
+
event_ordinal: u64,
|
|
59
|
+
frame_index: u64 = 0,
|
|
60
|
+
expected: u64,
|
|
61
|
+
actual: u64,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
pub const ReplayOptions = struct {
|
|
65
|
+
/// Compare fingerprint checkpoints and screenshot marks. Off, replay
|
|
66
|
+
/// only proves the journal drives cleanly end to end.
|
|
67
|
+
verify: bool = true,
|
|
68
|
+
/// Refuse a journal recorded on another platform (the v1 bar).
|
|
69
|
+
/// Tests recording under the null platform disable this.
|
|
70
|
+
require_same_platform: bool = true,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
pub const ReplayReport = struct {
|
|
74
|
+
protocol_version: u32 = 0,
|
|
75
|
+
events_replayed: u64 = 0,
|
|
76
|
+
effects_fed: u64 = 0,
|
|
77
|
+
effects_skipped: u64 = 0,
|
|
78
|
+
checkpoints_verified: u64 = 0,
|
|
79
|
+
screenshots_verified: u64 = 0,
|
|
80
|
+
mismatch_count: u64 = 0,
|
|
81
|
+
mismatches: [max_replay_mismatches]ReplayMismatch = undefined,
|
|
82
|
+
|
|
83
|
+
pub fn ok(self: *const ReplayReport) bool {
|
|
84
|
+
return self.mismatch_count == 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fn recordMismatch(self: *ReplayReport, mismatch: ReplayMismatch) void {
|
|
88
|
+
if (self.mismatch_count < max_replay_mismatches) {
|
|
89
|
+
self.mismatches[self.mismatch_count] = mismatch;
|
|
90
|
+
}
|
|
91
|
+
self.mismatch_count += 1;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/// The platform name this build records into headers and replay
|
|
96
|
+
/// compares against — the OS, not the hosting platform value (replay
|
|
97
|
+
/// hosts on the null platform on purpose).
|
|
98
|
+
pub fn currentPlatformName() []const u8 {
|
|
99
|
+
const builtin = @import("builtin");
|
|
100
|
+
return switch (builtin.os.tag) {
|
|
101
|
+
.macos => "macos",
|
|
102
|
+
.linux => "linux",
|
|
103
|
+
.windows => "windows",
|
|
104
|
+
.ios => "ios",
|
|
105
|
+
else => "other",
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/// Replay `journal_bytes` into `runtime`/`app`. The runtime must be
|
|
110
|
+
/// freshly initialized (no events dispatched yet) over the null
|
|
111
|
+
/// platform, with no automation server (live automation commands would
|
|
112
|
+
/// interleave with the journal). The journal bytes must outlive the
|
|
113
|
+
/// call — decoded event payloads reference them.
|
|
114
|
+
pub fn replaySession(
|
|
115
|
+
runtime: *core.Runtime,
|
|
116
|
+
app: core.App,
|
|
117
|
+
journal_bytes: []const u8,
|
|
118
|
+
options: ReplayOptions,
|
|
119
|
+
) anyerror!ReplayReport {
|
|
120
|
+
var reader = try journal.Reader.init(journal_bytes);
|
|
121
|
+
var report: ReplayReport = .{};
|
|
122
|
+
var armed = false;
|
|
123
|
+
|
|
124
|
+
while (try reader.next()) |record| {
|
|
125
|
+
switch (record) {
|
|
126
|
+
.header => |header| {
|
|
127
|
+
report.protocol_version = header.protocol_version;
|
|
128
|
+
if (header.protocol_version != automation_protocol.version) {
|
|
129
|
+
std.debug.print(
|
|
130
|
+
"replay refused: the journal was recorded at automation protocol v{d} but this build speaks v{d} - re-record with this build\n",
|
|
131
|
+
.{ header.protocol_version, automation_protocol.version },
|
|
132
|
+
);
|
|
133
|
+
return error.ReplayProtocolMismatch;
|
|
134
|
+
}
|
|
135
|
+
if (options.require_same_platform and !std.mem.eql(u8, header.platform_name, currentPlatformName())) {
|
|
136
|
+
std.debug.print(
|
|
137
|
+
"replay refused: the journal was recorded on \"{s}\" but this host is \"{s}\" - v1 replay is same-platform only (font metrics and scale behavior differ across platforms)\n",
|
|
138
|
+
.{ header.platform_name, currentPlatformName() },
|
|
139
|
+
);
|
|
140
|
+
return error.ReplayPlatformMismatch;
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
.event => |event| {
|
|
144
|
+
if (!armed) {
|
|
145
|
+
armed = true;
|
|
146
|
+
app.replayControl(.arm) catch {
|
|
147
|
+
// Apps without the hook still replay when the
|
|
148
|
+
// journal carries no effect results; a feed
|
|
149
|
+
// below fails loudly instead.
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
try runtime.dispatchPlatformEvent(app, event);
|
|
153
|
+
report.events_replayed += 1;
|
|
154
|
+
},
|
|
155
|
+
.effect => |effect| {
|
|
156
|
+
if (effectRegeneratesUnderReplay(effect)) {
|
|
157
|
+
report.effects_skipped += 1;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
app.replayControl(.{ .feed = effect }) catch |err| switch (err) {
|
|
161
|
+
error.EffectNotFound => {
|
|
162
|
+
std.debug.print(
|
|
163
|
+
"replay diverged after event {d}: journaled {s} result for effect key {d} has no matching pending request - the replayed updates issued different effects than the recording (nondeterminism outside the effect boundary?)\n",
|
|
164
|
+
.{ report.events_replayed, @tagName(effect.kind), effect.key },
|
|
165
|
+
);
|
|
166
|
+
return error.ReplayEffectDivergence;
|
|
167
|
+
},
|
|
168
|
+
error.ReplayUnsupported => {
|
|
169
|
+
std.debug.print(
|
|
170
|
+
"replay refused: the journal carries effect results but this app registered no replay hook (App.replay_fn - UiApp wires it automatically)\n",
|
|
171
|
+
.{},
|
|
172
|
+
);
|
|
173
|
+
return error.ReplayUnsupportedApp;
|
|
174
|
+
},
|
|
175
|
+
else => return err,
|
|
176
|
+
};
|
|
177
|
+
report.effects_fed += 1;
|
|
178
|
+
},
|
|
179
|
+
.checkpoint => |checkpoint| {
|
|
180
|
+
if (!options.verify) continue;
|
|
181
|
+
const actual = runtime.sessionStateFingerprint();
|
|
182
|
+
report.checkpoints_verified += 1;
|
|
183
|
+
if (actual != checkpoint.fingerprint) {
|
|
184
|
+
report.recordMismatch(.{
|
|
185
|
+
.kind = .fingerprint,
|
|
186
|
+
.event_ordinal = checkpoint.event_ordinal,
|
|
187
|
+
.frame_index = checkpoint.frame_index,
|
|
188
|
+
.expected = checkpoint.fingerprint,
|
|
189
|
+
.actual = actual,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
.screenshot => |mark| {
|
|
194
|
+
if (!options.verify) continue;
|
|
195
|
+
report.screenshots_verified += 1;
|
|
196
|
+
const actual = renderScreenshotHash(runtime, mark.view_label, mark.scale) catch 0;
|
|
197
|
+
if (actual != mark.png_hash) {
|
|
198
|
+
report.recordMismatch(.{
|
|
199
|
+
.kind = .screenshot,
|
|
200
|
+
.event_ordinal = mark.event_ordinal,
|
|
201
|
+
.expected = mark.png_hash,
|
|
202
|
+
.actual = actual,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
.end => {},
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return report;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/// Journaled results that regenerate deterministically from the
|
|
213
|
+
/// replayed updates themselves — feeding them would double-deliver:
|
|
214
|
+
/// rejections (the same over-capacity/duplicate-key validation refuses
|
|
215
|
+
/// again, loop-side) and fx-timer Msgs (real fires replay through the
|
|
216
|
+
/// journaled platform `.timer` events; rejections regenerate).
|
|
217
|
+
fn effectRegeneratesUnderReplay(record: journal.EffectResultRecord) bool {
|
|
218
|
+
return switch (record.kind) {
|
|
219
|
+
.timer => true,
|
|
220
|
+
.exit => record.exit_reason == .rejected,
|
|
221
|
+
.response => record.fetch_outcome == .rejected,
|
|
222
|
+
.file => record.file_outcome == .rejected,
|
|
223
|
+
.clipboard => record.clipboard_outcome == .rejected,
|
|
224
|
+
// Audio rejections are loop-side validation (path bounds) that
|
|
225
|
+
// refuses again; everything else — loaded acknowledgments,
|
|
226
|
+
// position ticks, completions, platform failures — is an
|
|
227
|
+
// external input and must be fed.
|
|
228
|
+
.audio => record.audio_kind == .rejected,
|
|
229
|
+
.line, .clock => false,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/// Re-render a journaled screenshot mark through the same deterministic
|
|
234
|
+
/// reference renderer the automation `screenshot` verb used at record
|
|
235
|
+
/// time, and hash the PNG.
|
|
236
|
+
fn renderScreenshotHash(runtime: *core.Runtime, view_label: []const u8, scale: f32) anyerror!u64 {
|
|
237
|
+
const window_id = blk: {
|
|
238
|
+
for (runtime.views[0..runtime.view_count]) |*view| {
|
|
239
|
+
if (view.open and view.kind == .gpu_surface and std.mem.eql(u8, view.label, view_label)) {
|
|
240
|
+
break :blk view.window_id;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return error.ViewNotFound;
|
|
244
|
+
};
|
|
245
|
+
const allocator = std.heap.page_allocator;
|
|
246
|
+
const pixel_size = try runtime.canvasScreenshotPixelSize(window_id, view_label, scale);
|
|
247
|
+
const pixels = try allocator.alloc(u8, pixel_size.byte_len);
|
|
248
|
+
defer allocator.free(pixels);
|
|
249
|
+
const scratch = try allocator.alloc(u8, pixel_size.byte_len);
|
|
250
|
+
defer allocator.free(scratch);
|
|
251
|
+
const screenshot = try runtime.renderCanvasScreenshot(window_id, view_label, scale, pixels, scratch);
|
|
252
|
+
var writer = try std.Io.Writer.Allocating.initCapacity(
|
|
253
|
+
allocator,
|
|
254
|
+
try canvas.png.encodedRgba8ByteLen(screenshot.width, screenshot.height),
|
|
255
|
+
);
|
|
256
|
+
defer writer.deinit();
|
|
257
|
+
try canvas.png.writeRgba8(&writer.writer, screenshot.width, screenshot.height, screenshot.rgba8);
|
|
258
|
+
dumpReplayScreenshot(view_label, writer.written());
|
|
259
|
+
return std.hash.Wyhash.hash(0, writer.written());
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/// Debug aid: `NATIVE_SDK_SESSION_REPLAY_DUMP=<dir>` writes each
|
|
263
|
+
/// replay-rendered screenshot PNG so a mismatching pixel mark can be
|
|
264
|
+
/// diffed against the recording's artifact.
|
|
265
|
+
fn dumpReplayScreenshot(view_label: []const u8, png_bytes: []const u8) void {
|
|
266
|
+
const builtin = @import("builtin");
|
|
267
|
+
if (!builtin.link_libc) return;
|
|
268
|
+
const dir = std.c.getenv("NATIVE_SDK_SESSION_REPLAY_DUMP") orelse return;
|
|
269
|
+
var path_buffer: [1024]u8 = undefined;
|
|
270
|
+
const path = std.fmt.bufPrintSentinel(&path_buffer, "{s}/replay-screenshot-{s}.png", .{ std.mem.span(dir), view_label }, 0) catch return;
|
|
271
|
+
const file = std.c.fopen(path, "wb") orelse return;
|
|
272
|
+
defer _ = std.c.fclose(file);
|
|
273
|
+
_ = std.c.fwrite(png_bytes.ptr, 1, png_bytes.len, file);
|
|
274
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//! Session state fingerprinting: the record/replay verification hash.
|
|
2
|
+
//!
|
|
3
|
+
//! The fingerprint is the Wyhash of the runtime's ACCESSIBILITY snapshot
|
|
4
|
+
//! text — every window, view, and widget's semantic state (roles, names,
|
|
5
|
+
//! text values, control values, scroll offsets, bounds, focus/hover/
|
|
6
|
+
//! pressed flags) — deliberately NOT the full automation snapshot, whose
|
|
7
|
+
//! header carries wall-clock uptime, pids, and per-present GPU telemetry
|
|
8
|
+
//! that legitimately differ between a live run and its replay. Anything
|
|
9
|
+
//! that changes what the a11y tree says the app IS changes the hash;
|
|
10
|
+
//! anything that only says how fast the host drew does not.
|
|
11
|
+
|
|
12
|
+
const std = @import("std");
|
|
13
|
+
const automation = @import("../automation/root.zig");
|
|
14
|
+
|
|
15
|
+
pub fn RuntimeSessionState(comptime Runtime: type) type {
|
|
16
|
+
return struct {
|
|
17
|
+
/// Hash of the current semantic state. A formatting failure
|
|
18
|
+
/// cannot happen with a draining hash writer, but the seam stays
|
|
19
|
+
/// honest: 0 means "no fingerprint", and replay treats a 0-0
|
|
20
|
+
/// comparison as a match of unknowns, never silently as proof.
|
|
21
|
+
pub fn sessionStateFingerprint(self: *Runtime) u64 {
|
|
22
|
+
const input = self.automationSnapshot("session");
|
|
23
|
+
var buffer: [512]u8 = undefined;
|
|
24
|
+
var hashing = std.Io.Writer.Hashing(std.hash.Wyhash).initHasher(std.hash.Wyhash.init(0), &buffer);
|
|
25
|
+
automation.snapshot.writeA11yText(input, &hashing.writer) catch return 0;
|
|
26
|
+
hashing.writer.flush() catch return 0;
|
|
27
|
+
return hashing.hasher.final();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|