@native-sdk/cli 0.8.4 → 0.9.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/build/app.zig +1178 -74
- package/build.zig +715 -17
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +10 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +435 -3
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/compiler_typecheck.mjs +116 -15
- package/packages/core/scripts/gen_service_surface.mjs +268 -0
- package/packages/core/scripts/merge_static_archives.mjs +78 -0
- package/packages/core/scripts/npm_static_spike.mjs +64 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +122 -6
- package/packages/core/scripts/run_external_service_compiler.mjs +280 -0
- package/packages/core/scripts/stage_external_core.mjs +9 -1
- package/packages/core/scripts/stage_external_services.mjs +172 -0
- package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
- package/packages/core/scripts/vendor_service_packages.mjs +189 -0
- package/packages/core/sdk/core.d.ts +224 -0
- package/packages/core/sdk/core.ts +694 -22
- package/packages/core/sdk/events.d.ts +89 -0
- package/packages/core/sdk/events.ts +128 -0
- package/packages/core/src/checker.ts +936 -15
- package/packages/core/src/cli.ts +156 -3
- package/packages/core/src/contract.ts +28 -5
- package/packages/core/src/devhost.ts +1876 -16
- package/packages/core/src/devhost_journal.mjs +183 -0
- package/packages/core/src/devhost_resolver.mjs +17 -1
- package/packages/core/src/devhost_service_worker.mjs +90 -0
- package/packages/core/src/diagnostics.ts +179 -22
- package/packages/core/src/frontend.ts +210 -34
- package/packages/core/src/infer.ts +24 -0
- package/packages/core/src/modules.ts +129 -80
- package/packages/core/src/service_contract.ts +597 -0
- package/packages/core/src/sqlite_cli.ts +93 -0
- package/packages/core/src/sqlite_codegen.ts +806 -0
- package/packages/core/src/sqlite_runtime_policy.ts +364 -0
- package/packages/core/src/typed_ast.ts +36 -8
- package/skill-data/automation/SKILL.md +1 -1
- package/skill-data/core/references/project-anatomy.md +1 -1
- package/skill-data/native-ui/SKILL.md +58 -5
- package/skill-data/ts-core/SKILL.md +123 -41
- package/skill-data/ts-services/SKILL.md +126 -0
- package/skill-data/ts-services/references/service-surface.md +604 -0
- package/skill-data/zig/SKILL.md +1 -1
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/no_migrations.zig +3 -0
- package/src/app_runner/no_services.zig +20 -0
- package/src/app_runner/root.zig +133 -4
- package/src/app_runner/ts_core_main.zig +254 -8
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +31 -11
- package/src/embed/app_exports.zig +12 -1
- package/src/embed/c_api.zig +48 -2
- package/src/embed/conversions.zig +4 -5
- package/src/embed/host.zig +109 -1
- package/src/embed/root.zig +8 -0
- package/src/embed/tests.zig +241 -0
- package/src/embed/types.zig +51 -0
- package/src/embed/ui_host.zig +185 -5
- package/src/platform/android/NativeSdkActivity.java +131 -0
- package/src/platform/android/android_host.c +182 -1
- package/src/platform/android/native_sdk_app.h +17 -0
- package/src/platform/ios/native_sdk_app.h +17 -0
- package/src/platform/ios/uikit_host.m +115 -0
- package/src/platform/linux/cef_host.cpp +8 -2
- package/src/platform/linux/gtk_host.c +289 -22
- package/src/platform/linux/gtk_host.h +5 -1
- package/src/platform/linux/root.zig +109 -22
- package/src/platform/macos/appkit_host.h +24 -7
- package/src/platform/macos/appkit_host.m +686 -64
- package/src/platform/macos/cef_host.mm +400 -66
- package/src/platform/macos/root.zig +304 -47
- package/src/platform/null_platform.zig +435 -48
- package/src/platform/null_platform_tests.zig +113 -0
- package/src/platform/root.zig +19 -0
- package/src/platform/types.zig +281 -28
- package/src/platform/windows/root.zig +207 -27
- package/src/platform/windows/webview2_host.cpp +334 -51
- package/src/primitives/app_manifest/comptime_scene.zig +2 -0
- package/src/primitives/app_manifest/root.zig +4 -0
- package/src/primitives/app_manifest/tests.zig +3 -0
- package/src/primitives/app_manifest/types.zig +32 -0
- package/src/primitives/app_manifest/validation.zig +19 -1
- package/src/root.zig +53 -0
- package/src/runtime/api.zig +19 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -20
- package/src/runtime/bridge_permission_tests.zig +58 -3
- package/src/runtime/bridge_responses.zig +4 -2
- package/src/runtime/builtin_bridge.zig +11 -1
- package/src/runtime/canvas_frame.zig +18 -11
- package/src/runtime/canvas_frame_animation_tests.zig +4 -0
- package/src/runtime/clock.zig +13 -1
- package/src/runtime/core.zig +145 -7
- package/src/runtime/credentials_store.zig +115 -0
- package/src/runtime/effects.zig +3701 -231
- package/src/runtime/effects_credentials_tests.zig +332 -0
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_host_tests.zig +208 -1
- package/src/runtime/effects_notification_tests.zig +11 -0
- package/src/runtime/effects_relational_tests.zig +314 -0
- package/src/runtime/effects_store_tests.zig +211 -0
- package/src/runtime/file_access.zig +400 -0
- package/src/runtime/file_effect_crash_helper.zig +28 -0
- package/src/runtime/file_effect_crash_tests.zig +37 -0
- package/src/runtime/flow.zig +35 -10
- package/src/runtime/gpu_surface_events.zig +6 -1
- package/src/runtime/native_command_event_tests.zig +86 -2
- package/src/runtime/persist_store.zig +666 -0
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/record_store.zig +788 -0
- package/src/runtime/relational_store.zig +854 -0
- package/src/runtime/root.zig +54 -0
- package/src/runtime/runtime_event_tests.zig +70 -0
- package/src/runtime/service_host.zig +711 -0
- package/src/runtime/service_pool.zig +1314 -0
- package/src/runtime/session_blobs.zig +4 -1
- package/src/runtime/session_journal.zig +158 -5
- package/src/runtime/session_record.zig +215 -0
- package/src/runtime/session_replay.zig +206 -11
- package/src/runtime/session_tests.zig +81 -0
- package/src/runtime/shell_layout.zig +1 -0
- package/src/runtime/shell_layout_tests.zig +120 -0
- package/src/runtime/sqlite_engine.zig +474 -0
- package/src/runtime/state.zig +16 -0
- package/src/runtime/system_services.zig +170 -38
- package/src/runtime/tests.zig +4 -0
- package/src/runtime/ts_core_host.zig +1067 -95
- package/src/runtime/ts_core_host_tests.zig +325 -11
- package/src/runtime/ts_ui_app.zig +953 -2
- package/src/runtime/ui_app.zig +434 -96
- package/src/runtime/ui_app_tests.zig +287 -11
- package/src/runtime/ui_app_window_tests.zig +61 -7
- package/src/runtime/validation.zig +42 -0
- package/src/runtime/view.zig +9 -0
- package/src/runtime/window_storage.zig +1 -0
- package/src/runtime/window_view_runtime.zig +2 -3
- package/src/runtime/window_views.zig +19 -0
- package/src/tooling/android.zig +21 -16
- package/src/tooling/db.zig +160 -0
- package/src/tooling/ios.zig +7 -1
- package/src/tooling/manifest.zig +214 -2
- package/src/tooling/package.zig +116 -0
- package/src/tooling/raw_manifest.zig +30 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +189 -4
- package/src/tooling/ts_core.zig +366 -17
- package/src/tooling/verbs.zig +7 -0
- package/third_party/sqlite/README.md +13 -0
- package/third_party/sqlite/sqlite3.c +269649 -0
- package/third_party/sqlite/sqlite3.h +14349 -0
- package/tools/corewire/core_abi.zig +14 -2
- package/tools/corewire/emit.zig +98 -29
- package/tools/corewire/emit_facade.zig +442 -27
- package/tools/corewire/emit_profile.zig +6 -2
- package/tools/corewire/emit_service.zig +924 -0
- package/tools/corewire/main.zig +122 -0
- package/tools/corewire/service_contract.zig +250 -0
- package/tools/corewire/sidecar.zig +26 -15
|
@@ -1198,9 +1198,7 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
|
|
|
1198
1198
|
if (self.views[index].pruneCompletedNoopCanvasRenderAnimations(frame_options.timestamp_ns)) {
|
|
1199
1199
|
self.views[index].compactCanvasFrameRenderOverrideNoops();
|
|
1200
1200
|
}
|
|
1201
|
-
|
|
1202
|
-
self.invalidateFor(.state, self.views[index].frame);
|
|
1203
|
-
}
|
|
1201
|
+
const render_animation_active = self.views[index].canvasRenderAnimationsActive(frame_options.timestamp_ns);
|
|
1204
1202
|
// An armed tooltip show delay — and a running anchor-gap
|
|
1205
1203
|
// transit grace — only fire on a presented frame's
|
|
1206
1204
|
// timestamp, so frames must keep coming while either is
|
|
@@ -1213,8 +1211,17 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
|
|
|
1213
1211
|
// requested). Settled shown tooltips and the warm
|
|
1214
1212
|
// window need no pump: both step on journaled input
|
|
1215
1213
|
// timestamps.
|
|
1216
|
-
|
|
1214
|
+
const tooltip_intent_armed = self.views[index].canvasTooltipIntentArmed();
|
|
1215
|
+
if (render_animation_active or tooltip_intent_armed) {
|
|
1217
1216
|
self.invalidateFor(.state, self.views[index].frame);
|
|
1217
|
+
// Invalidation keeps snapshots/diagnostics honest but
|
|
1218
|
+
// does not itself wake an idle retained surface. The
|
|
1219
|
+
// current completion consumed its one-shot request, so
|
|
1220
|
+
// explicitly arm the next one while time-based pixels
|
|
1221
|
+
// still have work. Without this leg animations render
|
|
1222
|
+
// their click endpoints and then park until unrelated
|
|
1223
|
+
// input happens to wake the view.
|
|
1224
|
+
try requestCanvasFrameForView(self, index);
|
|
1218
1225
|
}
|
|
1219
1226
|
} else {
|
|
1220
1227
|
self.views[index].recordCanvasFrame(canvas_frame);
|
|
@@ -1380,15 +1387,15 @@ const CanvasPacketPatchStats = struct {
|
|
|
1380
1387
|
};
|
|
1381
1388
|
|
|
1382
1389
|
/// Stamp `gpu_input_latency` at the RESPONDING present's completion:
|
|
1383
|
-
/// the present call above just returned synchronously, so
|
|
1384
|
-
///
|
|
1385
|
-
///
|
|
1386
|
-
///
|
|
1387
|
-
///
|
|
1388
|
-
///
|
|
1390
|
+
/// the present call above just returned synchronously, so monotonic NOW
|
|
1391
|
+
/// (the domain every host and automation input timestamp uses) is the
|
|
1392
|
+
/// moment the input's pixels reached the swapchain. The paced completion
|
|
1393
|
+
/// event that used to stamp this arrives up to a frame interval later and
|
|
1394
|
+
/// measured the pacing channel, not the glass; it remains the fallback for
|
|
1395
|
+
/// inputs that present nothing.
|
|
1389
1396
|
fn recordCanvasPresentInputLatency(view: anytype) void {
|
|
1390
1397
|
if (view.gpu_pending_input_timestamp_ns == 0) return;
|
|
1391
|
-
view.recordGpuSurfaceInputLatencyForFrame(runtime_clock.
|
|
1398
|
+
view.recordGpuSurfaceInputLatencyForFrame(runtime_clock.monotonicNanoseconds());
|
|
1392
1399
|
}
|
|
1393
1400
|
|
|
1394
1401
|
/// Build the frame's CURRENT keyed command list — every supported render
|
|
@@ -237,6 +237,7 @@ test "runtime schedules canvas render animations without display list rebuild" {
|
|
|
237
237
|
|
|
238
238
|
harness.runtime.invalidated = false;
|
|
239
239
|
harness.runtime.dirty_region_count = 0;
|
|
240
|
+
const frame_requests_before_mid = harness.null_platform.gpu_surface_frame_request_count;
|
|
240
241
|
const mid_frame = try harness.runtime.nextCanvasFrame(1, "canvas", .{
|
|
241
242
|
.frame_index = 2,
|
|
242
243
|
.timestamp_ns = start_ns + 500_000_000,
|
|
@@ -249,9 +250,11 @@ test "runtime schedules canvas render animations without display list rebuild" {
|
|
|
249
250
|
try std.testing.expectEqualDeep(canvas.Affine.translate(5, 0), mid_frame.render_plan.commands[0].transform);
|
|
250
251
|
try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 16, 11), mid_frame.dirty_bounds.?);
|
|
251
252
|
try std.testing.expect(harness.runtime.invalidated);
|
|
253
|
+
try std.testing.expectEqual(frame_requests_before_mid + 1, harness.null_platform.gpu_surface_frame_request_count);
|
|
252
254
|
|
|
253
255
|
harness.runtime.invalidated = false;
|
|
254
256
|
harness.runtime.dirty_region_count = 0;
|
|
257
|
+
const frame_requests_before_final = harness.null_platform.gpu_surface_frame_request_count;
|
|
255
258
|
const final_frame = try harness.runtime.nextCanvasFrame(1, "canvas", .{
|
|
256
259
|
.frame_index = 3,
|
|
257
260
|
.timestamp_ns = start_ns + 1_000_000_000,
|
|
@@ -261,6 +264,7 @@ test "runtime schedules canvas render animations without display list rebuild" {
|
|
|
261
264
|
try std.testing.expectEqualDeep(canvas.Affine.identity(), final_frame.render_plan.commands[0].transform);
|
|
262
265
|
try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 16, 11), final_frame.dirty_bounds.?);
|
|
263
266
|
try std.testing.expect(!harness.runtime.invalidated);
|
|
267
|
+
try std.testing.expectEqual(frame_requests_before_final, harness.null_platform.gpu_surface_frame_request_count);
|
|
264
268
|
try std.testing.expectEqual(@as(usize, 0), (try harness.runtime.canvasRenderAnimations(1, "canvas")).len);
|
|
265
269
|
try std.testing.expectEqual(@as(usize, 0), runtimeViewCanvasFrameRenderOverrides(&harness.runtime.views[0]).len);
|
|
266
270
|
|
package/src/runtime/clock.zig
CHANGED
|
@@ -187,7 +187,11 @@ pub fn timestampToU64(value: i128) u64 {
|
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
pub fn automationInputTimestampNs() u64 {
|
|
190
|
-
|
|
190
|
+
// Automation input participates in the same duration math as native
|
|
191
|
+
// host input and presented-frame timestamps. Keep it in the monotonic
|
|
192
|
+
// domain: wall time can jump, and on Windows/Linux the hosts already
|
|
193
|
+
// stamp GPU events from QPC/CLOCK_MONOTONIC.
|
|
194
|
+
return monotonicNanoseconds();
|
|
191
195
|
}
|
|
192
196
|
|
|
193
197
|
test "the real clocks read plausible, ordered values" {
|
|
@@ -205,6 +209,14 @@ test "the real clocks read plausible, ordered values" {
|
|
|
205
209
|
try std.testing.expect(second >= first);
|
|
206
210
|
}
|
|
207
211
|
|
|
212
|
+
test "automation input timestamps share the monotonic clock domain" {
|
|
213
|
+
const before = monotonicNanoseconds();
|
|
214
|
+
const timestamp = automationInputTimestampNs();
|
|
215
|
+
const after = monotonicNanoseconds();
|
|
216
|
+
try std.testing.expect(timestamp >= before);
|
|
217
|
+
try std.testing.expect(timestamp <= after);
|
|
218
|
+
}
|
|
219
|
+
|
|
208
220
|
test "Clock.system reads the real clocks and Clock{} is the same seam" {
|
|
209
221
|
const clock: Clock = .system;
|
|
210
222
|
try std.testing.expect(clock.wallMs() > 1_577_836_800_000);
|
package/src/runtime/core.zig
CHANGED
|
@@ -40,6 +40,8 @@ const extensions = @import("../extensions/root.zig");
|
|
|
40
40
|
const app_manifest = @import("app_manifest");
|
|
41
41
|
const platform = @import("../platform/root.zig");
|
|
42
42
|
const runtime_effects = @import("effects.zig");
|
|
43
|
+
const runtime_record_store = @import("record_store.zig");
|
|
44
|
+
const runtime_relational_store = @import("relational_store.zig");
|
|
43
45
|
const security = @import("../security/root.zig");
|
|
44
46
|
|
|
45
47
|
const max_async_bridge_responses = runtime_async_bridge.max_async_bridge_responses;
|
|
@@ -99,6 +101,7 @@ const RuntimeMainWebViewState = runtime_state.RuntimeMainWebViewState;
|
|
|
99
101
|
const RuntimeSourceStorage = runtime_state.RuntimeSourceStorage;
|
|
100
102
|
const RuntimeWebView = runtime_state.RuntimeWebView;
|
|
101
103
|
const RuntimeTrayItem = runtime_state.RuntimeTrayItem;
|
|
104
|
+
const RuntimeStatusItem = runtime_state.RuntimeStatusItem;
|
|
102
105
|
const ShellApplyMode = runtime_state.ShellApplyMode;
|
|
103
106
|
const WindowSourcePolicy = runtime_state.WindowSourcePolicy;
|
|
104
107
|
const FocusTraversalDirection = runtime_state.FocusTraversalDirection;
|
|
@@ -203,11 +206,8 @@ pub const Runtime = struct {
|
|
|
203
206
|
view_count: usize = 0,
|
|
204
207
|
webviews: [platform.max_webviews]RuntimeWebView = undefined,
|
|
205
208
|
webview_count: usize = 0,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
tray_created: bool = false,
|
|
209
|
-
tray_title: []const u8 = "",
|
|
210
|
-
tray_title_storage: [platform.max_tray_title_bytes]u8 = undefined,
|
|
209
|
+
status_items: [platform.max_status_items]RuntimeStatusItem = [_]RuntimeStatusItem{.{}} ** platform.max_status_items,
|
|
210
|
+
status_item_count: usize = 0,
|
|
211
211
|
/// Audio playback mirror for the automation snapshot, stamped by
|
|
212
212
|
/// the ui-app layer whenever a dispatch or effect drain may have
|
|
213
213
|
/// moved the effects channel's playback state. Like the tray, the
|
|
@@ -323,7 +323,8 @@ pub const Runtime = struct {
|
|
|
323
323
|
/// list its full per-view item budget — the snapshot never truncates
|
|
324
324
|
/// menus the runtime accepted.
|
|
325
325
|
automation_widget_menu_items: [canvas_limits.max_canvas_widget_context_menu_items_per_view * platform.max_views]automation.snapshot.WidgetContextMenuItem = undefined,
|
|
326
|
-
automation_tray_items: [platform.max_tray_items]automation.snapshot.TrayItem = undefined,
|
|
326
|
+
automation_tray_items: [platform.max_status_items * platform.max_tray_items]automation.snapshot.TrayItem = undefined,
|
|
327
|
+
automation_trays: [platform.max_status_items]automation.snapshot.Tray = undefined,
|
|
327
328
|
/// Handshake for the `provenance` verb: cleared before the query is
|
|
328
329
|
/// evented to the app, set by the app's response publish — so the
|
|
329
330
|
/// dispatcher can answer with a teaching error when no app-side
|
|
@@ -674,6 +675,7 @@ pub const Runtime = struct {
|
|
|
674
675
|
pub const focusWindow = WindowViewMethods.focusWindow;
|
|
675
676
|
pub const closeWindow = WindowViewMethods.closeWindow;
|
|
676
677
|
pub const minimizeWindow = WindowViewMethods.minimizeWindow;
|
|
678
|
+
pub const hideWindow = WindowViewMethods.hideWindow;
|
|
677
679
|
pub const showWindow = WindowViewMethods.showWindow;
|
|
678
680
|
pub const quitApp = WindowViewMethods.quitApp;
|
|
679
681
|
pub const createShellWindow = WindowViewMethods.createShellWindow;
|
|
@@ -772,11 +774,20 @@ pub const Runtime = struct {
|
|
|
772
774
|
pub const setCredential = SystemServiceMethods.setCredential;
|
|
773
775
|
pub const getCredential = SystemServiceMethods.getCredential;
|
|
774
776
|
pub const deleteCredential = SystemServiceMethods.deleteCredential;
|
|
777
|
+
pub const formatLocalTime = SystemServiceMethods.formatLocalTime;
|
|
775
778
|
pub const createTray = SystemServiceMethods.createTray;
|
|
779
|
+
pub const createStatusItem = SystemServiceMethods.createStatusItem;
|
|
780
|
+
pub const updateStatusItemShell = SystemServiceMethods.updateStatusItemShell;
|
|
781
|
+
pub const updateStatusItemMenu = SystemServiceMethods.updateStatusItemMenu;
|
|
782
|
+
pub const updateStatusItemTitle = SystemServiceMethods.updateStatusItemTitle;
|
|
783
|
+
pub const updateStatusItemPresentation = SystemServiceMethods.updateStatusItemPresentation;
|
|
784
|
+
pub const removeStatusItem = SystemServiceMethods.removeStatusItem;
|
|
776
785
|
pub const updateTrayMenu = SystemServiceMethods.updateTrayMenu;
|
|
777
786
|
pub const updateTrayTitle = SystemServiceMethods.updateTrayTitle;
|
|
787
|
+
pub const updateTrayPresentation = SystemServiceMethods.updateTrayPresentation;
|
|
778
788
|
pub const removeTray = SystemServiceMethods.removeTray;
|
|
779
789
|
const trayCommandNameForItem = SystemServiceMethods.trayCommandNameForItem;
|
|
790
|
+
const statusItemCommandNameForItem = SystemServiceMethods.statusItemCommandNameForItem;
|
|
780
791
|
const supportsFeatureFromJson = SystemServiceMethods.supportsFeatureFromJson;
|
|
781
792
|
const readClipboardTextFromJson = SystemServiceMethods.readClipboardTextFromJson;
|
|
782
793
|
const writeClipboardTextFromJson = SystemServiceMethods.writeClipboardTextFromJson;
|
|
@@ -1038,7 +1049,6 @@ pub fn TestHarness() type {
|
|
|
1038
1049
|
trace_records: [64]trace.Record = undefined,
|
|
1039
1050
|
trace_sink: trace.BufferSink = undefined,
|
|
1040
1051
|
runtime: Runtime = undefined,
|
|
1041
|
-
|
|
1042
1052
|
/// The harness embeds the multi-megabyte Runtime, so stack
|
|
1043
1053
|
/// instances overflow test threads; create on the heap.
|
|
1044
1054
|
pub fn create(gpa: std.mem.Allocator, surface: platform.Surface) !*Self {
|
|
@@ -1047,6 +1057,30 @@ pub fn TestHarness() type {
|
|
|
1047
1057
|
return self;
|
|
1048
1058
|
}
|
|
1049
1059
|
|
|
1060
|
+
/// Store-capability counterpart of `create`. The SQLite database is
|
|
1061
|
+
/// private to this harness and is automatically bound to every UiApp
|
|
1062
|
+
/// effect channel installed into its runtime.
|
|
1063
|
+
pub fn createWithRecordStore(gpa: std.mem.Allocator, surface: platform.Surface) !*RecordStoreTestHarness() {
|
|
1064
|
+
return RecordStoreTestHarness().create(gpa, surface);
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
/// Relational-capability counterpart of `create`. `native test`
|
|
1068
|
+
/// receives a private in-memory SQLite database and never touches an
|
|
1069
|
+
/// app-data path.
|
|
1070
|
+
pub fn createWithRelationalStore(gpa: std.mem.Allocator, surface: platform.Surface) !*RelationalStoreTestHarness() {
|
|
1071
|
+
return RelationalStoreTestHarness().create(gpa, surface);
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
/// Credential-capability counterpart of `create`. It enables both
|
|
1075
|
+
/// gates against the NullPlatform's process-local byte store, so
|
|
1076
|
+
/// `native test` never opens a real desktop keychain/keyring.
|
|
1077
|
+
pub fn createWithCredentials(gpa: std.mem.Allocator, surface: platform.Surface) !*Self {
|
|
1078
|
+
const self = try create(gpa, surface);
|
|
1079
|
+
self.runtime.options.credentials_enabled = true;
|
|
1080
|
+
self.runtime.options.security.permissions = &.{security.permission_credentials};
|
|
1081
|
+
return self;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1050
1084
|
pub fn destroy(self: *Self, gpa: std.mem.Allocator) void {
|
|
1051
1085
|
// The harness embeds the runtime's platform: deinit both
|
|
1052
1086
|
// returns the runtime's heap-owned storage (registered font
|
|
@@ -1056,15 +1090,21 @@ pub fn TestHarness() type {
|
|
|
1056
1090
|
// tests) can never wake the freed host — the run loop's exit
|
|
1057
1091
|
// defer for real apps, this line for harness-driven ones.
|
|
1058
1092
|
self.runtime.deinit();
|
|
1093
|
+
self.null_platform.deinit();
|
|
1059
1094
|
gpa.destroy(self);
|
|
1060
1095
|
}
|
|
1061
1096
|
|
|
1062
1097
|
pub fn init(self: *Self, surface: platform.Surface) void {
|
|
1098
|
+
self.initRuntime(surface, null);
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
fn initRuntime(self: *Self, surface: platform.Surface, record_store_binding: ?runtime_effects.RecordStoreBinding) void {
|
|
1063
1102
|
self.null_platform = platform.NullPlatform.init(surface);
|
|
1064
1103
|
self.trace_sink = trace.BufferSink.init(&self.trace_records);
|
|
1065
1104
|
Runtime.initAt(&self.runtime, .{
|
|
1066
1105
|
.platform = self.null_platform.platform(),
|
|
1067
1106
|
.trace_sink = self.trace_sink.sink(),
|
|
1107
|
+
.record_store = record_store_binding,
|
|
1068
1108
|
// On-demand runtime storage (registered font bytes,
|
|
1069
1109
|
// registered image slot buffers, adopted media-surface
|
|
1070
1110
|
// texture buffers) routes through
|
|
@@ -1095,6 +1135,104 @@ pub fn TestHarness() type {
|
|
|
1095
1135
|
};
|
|
1096
1136
|
}
|
|
1097
1137
|
|
|
1138
|
+
/// Capability-opted harness returned by `TestHarness().createWithRecordStore`.
|
|
1139
|
+
/// It is a separate concrete type so ordinary app tests that use
|
|
1140
|
+
/// `TestHarness().create` never analyze or link SQLite merely because Zig's
|
|
1141
|
+
/// test reflection visits the public SDK surface.
|
|
1142
|
+
pub fn RecordStoreTestHarness() type {
|
|
1143
|
+
return struct {
|
|
1144
|
+
const Self = @This();
|
|
1145
|
+
|
|
1146
|
+
null_platform: platform.NullPlatform = platform.NullPlatform.init(.{}),
|
|
1147
|
+
trace_records: [64]trace.Record = undefined,
|
|
1148
|
+
trace_sink: trace.BufferSink = undefined,
|
|
1149
|
+
runtime: Runtime = undefined,
|
|
1150
|
+
record_store: ?runtime_record_store.Store = null,
|
|
1151
|
+
|
|
1152
|
+
pub fn create(gpa: std.mem.Allocator, surface: platform.Surface) !*Self {
|
|
1153
|
+
const self = try gpa.create(Self);
|
|
1154
|
+
errdefer gpa.destroy(self);
|
|
1155
|
+
self.record_store = try runtime_record_store.Store.openMemory(gpa);
|
|
1156
|
+
errdefer if (self.record_store) |*store| store.deinit();
|
|
1157
|
+
self.null_platform = platform.NullPlatform.init(surface);
|
|
1158
|
+
self.trace_sink = trace.BufferSink.init(&self.trace_records);
|
|
1159
|
+
Runtime.initAt(&self.runtime, .{
|
|
1160
|
+
.platform = self.null_platform.platform(),
|
|
1161
|
+
.trace_sink = self.trace_sink.sink(),
|
|
1162
|
+
.record_store = self.record_store.?.binding(),
|
|
1163
|
+
.allocator = if (builtin.is_test) std.testing.allocator else std.heap.page_allocator,
|
|
1164
|
+
.environ = if (builtin.is_test) std.testing.environ else null,
|
|
1165
|
+
});
|
|
1166
|
+
self.runtime.dispatch_error_policy = .propagate;
|
|
1167
|
+
return self;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
pub fn destroy(self: *Self, gpa: std.mem.Allocator) void {
|
|
1171
|
+
self.runtime.deinit();
|
|
1172
|
+
if (self.record_store) |*store| store.deinit();
|
|
1173
|
+
gpa.destroy(self);
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
pub fn start(self: *Self, app: App) anyerror!void {
|
|
1177
|
+
try self.runtime.dispatchPlatformEvent(app, .app_start);
|
|
1178
|
+
try self.runtime.dispatchPlatformEvent(app, .{ .surface_resized = self.null_platform.surface_value });
|
|
1179
|
+
try self.runtime.dispatchPlatformEvent(app, .frame_requested);
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
pub fn stop(self: *Self, app: App) anyerror!void {
|
|
1183
|
+
try self.runtime.dispatchPlatformEvent(app, .app_shutdown);
|
|
1184
|
+
}
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
/// Capability-opted harness returned by
|
|
1189
|
+
/// `TestHarness().createWithRelationalStore`.
|
|
1190
|
+
pub fn RelationalStoreTestHarness() type {
|
|
1191
|
+
return struct {
|
|
1192
|
+
const Self = @This();
|
|
1193
|
+
|
|
1194
|
+
null_platform: platform.NullPlatform = platform.NullPlatform.init(.{}),
|
|
1195
|
+
trace_records: [64]trace.Record = undefined,
|
|
1196
|
+
trace_sink: trace.BufferSink = undefined,
|
|
1197
|
+
runtime: Runtime = undefined,
|
|
1198
|
+
relational_store: ?runtime_relational_store.Database = null,
|
|
1199
|
+
|
|
1200
|
+
pub fn create(gpa: std.mem.Allocator, surface: platform.Surface) !*Self {
|
|
1201
|
+
const self = try gpa.create(Self);
|
|
1202
|
+
errdefer gpa.destroy(self);
|
|
1203
|
+
self.relational_store = try runtime_relational_store.Database.openMemory(gpa);
|
|
1204
|
+
errdefer if (self.relational_store) |*database| database.deinit();
|
|
1205
|
+
self.null_platform = platform.NullPlatform.init(surface);
|
|
1206
|
+
self.trace_sink = trace.BufferSink.init(&self.trace_records);
|
|
1207
|
+
Runtime.initAt(&self.runtime, .{
|
|
1208
|
+
.platform = self.null_platform.platform(),
|
|
1209
|
+
.trace_sink = self.trace_sink.sink(),
|
|
1210
|
+
.relational_store = self.relational_store.?.binding(),
|
|
1211
|
+
.allocator = if (builtin.is_test) std.testing.allocator else std.heap.page_allocator,
|
|
1212
|
+
.environ = if (builtin.is_test) std.testing.environ else null,
|
|
1213
|
+
});
|
|
1214
|
+
self.runtime.dispatch_error_policy = .propagate;
|
|
1215
|
+
return self;
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
pub fn destroy(self: *Self, gpa: std.mem.Allocator) void {
|
|
1219
|
+
self.runtime.deinit();
|
|
1220
|
+
if (self.relational_store) |*database| database.deinit();
|
|
1221
|
+
gpa.destroy(self);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
pub fn start(self: *Self, app: App) anyerror!void {
|
|
1225
|
+
try self.runtime.dispatchPlatformEvent(app, .app_start);
|
|
1226
|
+
try self.runtime.dispatchPlatformEvent(app, .{ .surface_resized = self.null_platform.surface_value });
|
|
1227
|
+
try self.runtime.dispatchPlatformEvent(app, .frame_requested);
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
pub fn stop(self: *Self, app: App) anyerror!void {
|
|
1231
|
+
try self.runtime.dispatchPlatformEvent(app, .app_shutdown);
|
|
1232
|
+
}
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1098
1236
|
const testingWriteViewJson = writeViewJson;
|
|
1099
1237
|
const testingCopyInto = copyInto;
|
|
1100
1238
|
const testingCanvasWidgetSemanticsById = canvasWidgetSemanticsById;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
//! Engine-owned credential-store adapter shared by core effects and the
|
|
2
|
+
//! builtin WebView bridge. PlatformServices remains the one OS vtable; this
|
|
3
|
+
//! module fixes the app-facing bounds, app namespace, and closed outcomes so
|
|
4
|
+
//! neither caller grows its own interpretation of keychain errors.
|
|
5
|
+
|
|
6
|
+
const std = @import("std");
|
|
7
|
+
const platform = @import("../platform/root.zig");
|
|
8
|
+
|
|
9
|
+
pub const max_key_bytes: usize = 256;
|
|
10
|
+
pub const max_secret_bytes: usize = platform.max_credential_secret_bytes;
|
|
11
|
+
|
|
12
|
+
pub const Operation = enum(u8) { set, get, delete };
|
|
13
|
+
|
|
14
|
+
pub const Outcome = enum(u8) {
|
|
15
|
+
ok,
|
|
16
|
+
miss,
|
|
17
|
+
denied,
|
|
18
|
+
locked,
|
|
19
|
+
io_failed,
|
|
20
|
+
over_bound,
|
|
21
|
+
rejected,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
pub const Execution = struct {
|
|
25
|
+
outcome: Outcome,
|
|
26
|
+
len: usize = 0,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/// One app-scoped view over the platform credential vtable. `service` is the
|
|
30
|
+
/// stable app identity (app.zon id); `key` becomes the platform account.
|
|
31
|
+
pub const Binding = struct {
|
|
32
|
+
services: *const platform.PlatformServices,
|
|
33
|
+
service: []const u8,
|
|
34
|
+
permitted: bool,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
pub fn validKey(key: []const u8) bool {
|
|
38
|
+
return key.len > 0 and key.len <= max_key_bytes and
|
|
39
|
+
std.mem.indexOfScalar(u8, key, 0) == null and
|
|
40
|
+
std.unicode.utf8ValidateSlice(key);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
pub fn outcomeName(outcome: Outcome) []const u8 {
|
|
44
|
+
return @tagName(outcome);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
pub fn outcomeFromName(name: []const u8) ?Outcome {
|
|
48
|
+
inline for (std.meta.tags(Outcome)) |outcome| {
|
|
49
|
+
if (std.mem.eql(u8, name, @tagName(outcome))) return outcome;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
pub fn execute(binding: Binding, operation: Operation, key: []const u8, secret: []const u8, output: []u8) Execution {
|
|
55
|
+
if (!binding.permitted) return .{ .outcome = .denied };
|
|
56
|
+
if (!validKey(key) or binding.service.len == 0 or binding.service.len > platform.max_credential_service_bytes or
|
|
57
|
+
std.mem.indexOfScalar(u8, binding.service, 0) != null or
|
|
58
|
+
!std.unicode.utf8ValidateSlice(binding.service))
|
|
59
|
+
{
|
|
60
|
+
return .{ .outcome = .over_bound };
|
|
61
|
+
}
|
|
62
|
+
if (operation == .set and secret.len > max_secret_bytes) return .{ .outcome = .over_bound };
|
|
63
|
+
const credential_key: platform.CredentialKey = .{ .service = binding.service, .account = key };
|
|
64
|
+
return switch (operation) {
|
|
65
|
+
.set => blk: {
|
|
66
|
+
binding.services.setCredential(.{
|
|
67
|
+
.service = binding.service,
|
|
68
|
+
.account = key,
|
|
69
|
+
.secret = secret,
|
|
70
|
+
}) catch |err| break :blk .{ .outcome = classifyError(err) };
|
|
71
|
+
break :blk .{ .outcome = .ok };
|
|
72
|
+
},
|
|
73
|
+
.get => blk: {
|
|
74
|
+
const bytes = binding.services.getCredential(credential_key, output) catch |err| {
|
|
75
|
+
if (err == error.CredentialNotFound) break :blk .{ .outcome = .miss };
|
|
76
|
+
break :blk .{ .outcome = classifyError(err) };
|
|
77
|
+
};
|
|
78
|
+
if (bytes.len > max_secret_bytes or bytes.len > output.len) break :blk .{ .outcome = .over_bound };
|
|
79
|
+
break :blk .{ .outcome = .ok, .len = bytes.len };
|
|
80
|
+
},
|
|
81
|
+
.delete => blk: {
|
|
82
|
+
binding.services.deleteCredential(credential_key) catch |err| {
|
|
83
|
+
if (err == error.CredentialNotFound) break :blk .{ .outcome = .miss };
|
|
84
|
+
break :blk .{ .outcome = classifyError(err) };
|
|
85
|
+
};
|
|
86
|
+
break :blk .{ .outcome = .ok };
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
fn classifyError(err: anyerror) Outcome {
|
|
92
|
+
return switch (err) {
|
|
93
|
+
error.CredentialNotFound => .miss,
|
|
94
|
+
error.UnsupportedService => .locked,
|
|
95
|
+
error.InvalidCredentialOptions,
|
|
96
|
+
error.CredentialFieldTooLarge,
|
|
97
|
+
error.NoSpaceLeft,
|
|
98
|
+
=> .over_bound,
|
|
99
|
+
error.CredentialStoreLocked => .locked,
|
|
100
|
+
error.CredentialStoreFailed => .io_failed,
|
|
101
|
+
error.AccessDenied,
|
|
102
|
+
error.PermissionDenied,
|
|
103
|
+
=> .denied,
|
|
104
|
+
else => .io_failed,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
test "credential adapter validates keys and names closed outcomes" {
|
|
109
|
+
try std.testing.expect(validKey("token"));
|
|
110
|
+
try std.testing.expect(!validKey(""));
|
|
111
|
+
try std.testing.expect(!validKey("token\x00suffix"));
|
|
112
|
+
try std.testing.expect(!validKey(&.{ 0xff, 0xfe }));
|
|
113
|
+
try std.testing.expectEqualStrings("locked", outcomeName(.locked));
|
|
114
|
+
try std.testing.expectEqual(Outcome.denied, outcomeFromName("denied").?);
|
|
115
|
+
}
|