@native-sdk/cli 0.9.0 → 0.9.2
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 +357 -33
- package/build.zig +234 -11
- package/native-sdk.d.ts +8 -0
- package/package.json +10 -10
- package/packages/core/compile-surface/core.ts +70 -1
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/merge_static_archives.mjs +78 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +52 -7
- package/packages/core/scripts/run_external_service_compiler.mjs +53 -13
- package/packages/core/scripts/stage_external_services.mjs +1 -1
- package/packages/core/sdk/core.d.ts +75 -0
- package/packages/core/sdk/core.ts +170 -13
- package/packages/core/sdk/events.d.ts +53 -0
- package/packages/core/sdk/events.ts +78 -7
- package/packages/core/src/checker.ts +470 -2
- package/packages/core/src/cli.ts +13 -0
- package/packages/core/src/contract.ts +3 -1
- package/packages/core/src/devhost.ts +30 -1
- package/packages/core/src/devhost_journal.mjs +10 -8
- package/packages/core/src/diagnostics.ts +99 -8
- package/packages/core/src/frontend.ts +6 -0
- package/packages/core/src/infer.ts +24 -0
- package/skill-data/automation/SKILL.md +1 -1
- package/skill-data/native-ui/SKILL.md +18 -12
- package/skill-data/ts-core/SKILL.md +54 -21
- package/skill-data/ts-services/SKILL.md +4 -4
- package/skill-data/ts-services/references/service-surface.md +2 -1
- package/skill-data/zig/SKILL.md +1 -1
- package/src/app_runner/root.zig +122 -6
- package/src/app_runner/ts_core_main.zig +9 -4
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/app_runner/window_placement.zig +63 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +8 -6
- package/src/embed/app_exports.zig +3 -1
- package/src/embed/conversions.zig +1 -0
- package/src/embed/host.zig +10 -3
- package/src/embed/root.zig +2 -0
- package/src/embed/tests.zig +41 -1
- package/src/embed/types.zig +2 -0
- package/src/embed/ui_host.zig +94 -4
- package/src/platform/android/NativeSdkActivity.java +49 -4
- package/src/platform/android/android_host.c +3 -3
- package/src/platform/android/native_sdk_app.h +1 -1
- package/src/platform/ios/apple_image_fit.h +38 -0
- package/src/platform/ios/files.zig +1 -0
- package/src/platform/ios/native_sdk_app.h +1 -1
- package/src/platform/ios/uikit_host.m +28 -5
- package/src/platform/linux/cef_host.cpp +17 -3
- package/src/platform/linux/gtk_host.c +243 -15
- package/src/platform/linux/gtk_host.h +5 -4
- package/src/platform/linux/root.zig +91 -11
- package/src/platform/macos/appkit_host.h +18 -11
- package/src/platform/macos/appkit_host.m +402 -128
- package/src/platform/macos/cef_host.mm +342 -122
- package/src/platform/macos/image_fit_test.m +44 -0
- package/src/platform/macos/root.zig +231 -39
- package/src/platform/null_platform.zig +251 -54
- package/src/platform/null_platform_tests.zig +97 -4
- package/src/platform/root.zig +12 -0
- package/src/platform/types.zig +174 -35
- package/src/platform/windows/root.zig +42 -13
- package/src/platform/windows/webview2_host.cpp +72 -11
- package/src/primitives/app_manifest/root.zig +3 -0
- package/src/primitives/app_manifest/tests.zig +24 -0
- package/src/primitives/app_manifest/types.zig +13 -0
- package/src/primitives/app_manifest/validation.zig +24 -0
- package/src/primitives/canvas/a11y_audit.zig +9 -7
- package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
- package/src/primitives/canvas/events.zig +50 -0
- package/src/primitives/canvas/layout_audit.zig +6 -6
- package/src/primitives/canvas/markdown.zig +4 -0
- package/src/primitives/canvas/markdown_tests.zig +1 -0
- package/src/primitives/canvas/png.zig +138 -0
- package/src/primitives/canvas/root.zig +13 -2
- package/src/primitives/canvas/text_span_tests.zig +5 -3
- package/src/primitives/canvas/text_spans.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +20 -0
- package/src/primitives/canvas/ui.zig +55 -2
- package/src/primitives/canvas/ui_markup.zig +40 -13
- package/src/primitives/canvas/ui_markup_binary.zig +8 -6
- package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
- package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +52 -0
- package/src/primitives/canvas/ui_markup_tests.zig +11 -2
- package/src/primitives/canvas/ui_markup_view.zig +8 -2
- package/src/primitives/canvas/ui_markup_view_tests.zig +49 -4
- package/src/primitives/canvas/ui_schema.zig +17 -13
- package/src/primitives/canvas/ui_tests.zig +47 -0
- package/src/primitives/canvas/widget_access.zig +3 -3
- package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +580 -32
- package/src/primitives/canvas/widget_invalidation.zig +33 -6
- package/src/primitives/canvas/widget_layout.zig +333 -126
- package/src/primitives/canvas/widget_layout_tests.zig +169 -0
- package/src/primitives/canvas/widget_metrics.zig +7 -8
- package/src/primitives/canvas/widget_render.zig +76 -44
- package/src/primitives/canvas/widget_render_controls.zig +110 -32
- package/src/primitives/canvas/widget_render_style.zig +58 -18
- package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
- package/src/primitives/canvas/widget_routing.zig +40 -34
- package/src/primitives/canvas/widget_runtime.zig +11 -2
- package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
- package/src/primitives/canvas/widget_semantics.zig +8 -3
- package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
- package/src/primitives/canvas/widget_tree.zig +99 -5
- package/src/primitives/canvas/widgets.zig +20 -7
- package/src/root.zig +10 -0
- package/src/runtime/api.zig +14 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -24
- package/src/runtime/automation_widget_dispatch.zig +48 -6
- package/src/runtime/bridge_permission_tests.zig +35 -1
- package/src/runtime/bridge_responses.zig +1 -1
- package/src/runtime/builtin_bridge.zig +16 -3
- package/src/runtime/canvas_frame_packet_tests.zig +22 -13
- package/src/runtime/canvas_image_tests.zig +146 -2
- package/src/runtime/canvas_images.zig +35 -16
- package/src/runtime/canvas_limits.zig +13 -3
- package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
- package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
- package/src/runtime/canvas_widget_control_tests.zig +31 -1
- package/src/runtime/canvas_widget_events.zig +151 -26
- package/src/runtime/canvas_widget_floating_tests.zig +48 -0
- package/src/runtime/canvas_widget_runtime.zig +322 -102
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
- package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
- package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
- package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
- package/src/runtime/canvas_widget_state.zig +33 -7
- package/src/runtime/core.zig +28 -6
- package/src/runtime/effects.zig +1337 -49
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_image_tests.zig +91 -0
- package/src/runtime/effects_notification_tests.zig +11 -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 +21 -9
- package/src/runtime/gpu_surface_events.zig +25 -2
- package/src/runtime/native_command_event_tests.zig +44 -2
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/root.zig +7 -0
- package/src/runtime/session_blobs.zig +4 -1
- package/src/runtime/session_journal.zig +56 -5
- package/src/runtime/session_record.zig +38 -0
- package/src/runtime/session_replay.zig +110 -15
- package/src/runtime/session_tests.zig +192 -4
- package/src/runtime/shell_layout_tests.zig +12 -0
- package/src/runtime/state.zig +10 -0
- package/src/runtime/system_services.zig +129 -36
- package/src/runtime/ts_core_host.zig +281 -11
- package/src/runtime/ts_core_host_tests.zig +142 -1
- package/src/runtime/ts_ui_app.zig +461 -8
- package/src/runtime/ui_app.zig +330 -112
- package/src/runtime/ui_app_tests.zig +251 -25
- package/src/runtime/ui_app_window_tests.zig +74 -8
- package/src/runtime/validation.zig +20 -0
- package/src/runtime/view.zig +3 -0
- package/src/runtime/view_widget_control.zig +18 -0
- package/src/runtime/view_widget_scroll.zig +112 -18
- package/src/runtime/view_widget_tree.zig +110 -13
- package/src/runtime/widget_bridge.zig +2 -0
- package/src/runtime/window_command_bridge_tests.zig +86 -0
- package/src/runtime/window_storage.zig +16 -1
- package/src/runtime/window_views.zig +1 -0
- package/src/tooling/ios.zig +3 -0
- package/src/tooling/manifest.zig +90 -2
- package/src/tooling/package.zig +67 -2
- package/src/tooling/raw_manifest.zig +10 -0
- package/src/tooling/templates.zig +156 -18
- package/src/tooling/ts_core.zig +83 -0
- package/src/tooling/web_engine.zig +1 -1
- package/tools/corewire/emit.zig +3 -3
- package/tools/corewire/emit_facade.zig +65 -5
- package/tools/corewire/emit_profile.zig +2 -2
- package/tools/corewire/emit_service.zig +2 -2
- package/tools/corewire/service_contract.zig +4 -4
- package/tools/corewire/sidecar.zig +4 -4
|
@@ -294,6 +294,97 @@ test "fake executor records the whole load request shape and feeds bytes through
|
|
|
294
294
|
try std.testing.expectEqual(@as(usize, 1), h.app_state.effects.pendingImageLoadCount());
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
+
test "photo-scale feed decodes to fit and reports registered geometry" {
|
|
298
|
+
var h = try Harness.create();
|
|
299
|
+
defer h.destroy();
|
|
300
|
+
h.app_state.effects.executor = .fake;
|
|
301
|
+
test_path = "assets/photo.png";
|
|
302
|
+
try h.app_state.dispatch(&h.harness.runtime, 1, .start);
|
|
303
|
+
|
|
304
|
+
const width: usize = 640;
|
|
305
|
+
const height: usize = 480;
|
|
306
|
+
const pixels = try std.testing.allocator.alloc(u8, width * height * 4);
|
|
307
|
+
defer std.testing.allocator.free(pixels);
|
|
308
|
+
var index: usize = 0;
|
|
309
|
+
while (index < pixels.len) : (index += 4) pixels[index..][0..4].* = .{ 24, 88, 176, 255 };
|
|
310
|
+
const encoded_len = try canvas.png.encodedRgba8ByteLen(width, height);
|
|
311
|
+
const encoded_buffer = try std.testing.allocator.alloc(u8, encoded_len);
|
|
312
|
+
defer std.testing.allocator.free(encoded_buffer);
|
|
313
|
+
var writer = std.Io.Writer.fixed(encoded_buffer);
|
|
314
|
+
try canvas.png.writeRgba8(&writer, width, height, pixels);
|
|
315
|
+
|
|
316
|
+
try h.app_state.effects.feedImageBytes(image_id, writer.buffered());
|
|
317
|
+
try h.drainWakes();
|
|
318
|
+
const result = h.app_state.model.last.?;
|
|
319
|
+
try std.testing.expectEqual(effects_mod.EffectImageOutcome.loaded, result.outcome);
|
|
320
|
+
try std.testing.expectEqual(@as(usize, 591), result.width);
|
|
321
|
+
try std.testing.expectEqual(@as(usize, 443), result.height);
|
|
322
|
+
try std.testing.expect(result.width * result.height * 4 <= h.harness.runtime.max_image_pixel_bytes);
|
|
323
|
+
try std.testing.expectApproxEqAbs(@as(f64, 4.0 / 3.0), @as(f64, @floatFromInt(result.width)) / @as(f64, @floatFromInt(result.height)), 0.01);
|
|
324
|
+
const registered = h.harness.runtime.registeredCanvasImage(image_id).?;
|
|
325
|
+
try std.testing.expectEqual(result.width, registered.width);
|
|
326
|
+
try std.testing.expectEqual(result.height, registered.height);
|
|
327
|
+
try std.testing.expectEqualSlices(u8, &[_]u8{ 24, 88, 176, 255 }, h.harness.runtime.registeredCanvasImages()[0].pixels[0..4]);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
test "raised image budget loads a 1080p source without downscaling" {
|
|
331
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
332
|
+
defer harness.destroy(std.testing.allocator);
|
|
333
|
+
harness.null_platform.gpu_surfaces = true;
|
|
334
|
+
harness.null_platform.image_decode = true;
|
|
335
|
+
core.Runtime.initAt(&harness.runtime, .{
|
|
336
|
+
.platform = harness.null_platform.platform(),
|
|
337
|
+
.trace_sink = harness.trace_sink.sink(),
|
|
338
|
+
.max_image_pixel_bytes = canvas_limits.max_registered_canvas_image_pixel_bytes_ceiling,
|
|
339
|
+
.environ = std.testing.environ,
|
|
340
|
+
});
|
|
341
|
+
harness.runtime.dispatch_error_policy = .propagate;
|
|
342
|
+
|
|
343
|
+
const app_state = try std.testing.allocator.create(ImageApp);
|
|
344
|
+
defer std.testing.allocator.destroy(app_state);
|
|
345
|
+
app_state.* = ImageApp.init(std.heap.page_allocator, .{}, .{
|
|
346
|
+
.name = "effects-image-raised-budget",
|
|
347
|
+
.scene = image_scene,
|
|
348
|
+
.canvas_label = canvas_label,
|
|
349
|
+
.update_fx = imageUpdate,
|
|
350
|
+
.view = imageView,
|
|
351
|
+
});
|
|
352
|
+
defer app_state.deinit();
|
|
353
|
+
app_state.effects.executor = .fake;
|
|
354
|
+
const app = app_state.app();
|
|
355
|
+
try harness.start(app);
|
|
356
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
357
|
+
.label = canvas_label,
|
|
358
|
+
.size = geometry.SizeF.init(400, 300),
|
|
359
|
+
.scale_factor = 1,
|
|
360
|
+
.frame_index = 1,
|
|
361
|
+
.timestamp_ns = 1_000_000,
|
|
362
|
+
.nonblank = true,
|
|
363
|
+
} });
|
|
364
|
+
|
|
365
|
+
test_path = "assets/wallpaper.png";
|
|
366
|
+
try app_state.dispatch(&harness.runtime, 1, .start);
|
|
367
|
+
const width: usize = 1920;
|
|
368
|
+
const height: usize = 1080;
|
|
369
|
+
const pixels = try std.testing.allocator.alloc(u8, width * height * 4);
|
|
370
|
+
defer std.testing.allocator.free(pixels);
|
|
371
|
+
@memset(pixels, 0x6D);
|
|
372
|
+
const encoded_len = try canvas.png.encodedRgba8ByteLen(width, height);
|
|
373
|
+
try std.testing.expect(encoded_len <= effects_mod.max_effect_image_source_bytes);
|
|
374
|
+
const encoded = try std.testing.allocator.alloc(u8, encoded_len);
|
|
375
|
+
defer std.testing.allocator.free(encoded);
|
|
376
|
+
var writer = std.Io.Writer.fixed(encoded);
|
|
377
|
+
try canvas.png.writeRgba8(&writer, width, height, pixels);
|
|
378
|
+
try app_state.effects.feedImageBytes(image_id, writer.buffered());
|
|
379
|
+
try harness.runtime.dispatchPlatformEvent(app, .wake);
|
|
380
|
+
|
|
381
|
+
const result = app_state.model.last.?;
|
|
382
|
+
try std.testing.expectEqual(effects_mod.EffectImageOutcome.loaded, result.outcome);
|
|
383
|
+
try std.testing.expectEqual(width, result.width);
|
|
384
|
+
try std.testing.expectEqual(height, result.height);
|
|
385
|
+
try std.testing.expectEqual(width, harness.runtime.registeredCanvasImage(image_id).?.width);
|
|
386
|
+
}
|
|
387
|
+
|
|
297
388
|
test "undecodable and oversized feeds fail with the registry's own classes" {
|
|
298
389
|
var h = try Harness.create();
|
|
299
390
|
defer h.destroy();
|
|
@@ -18,15 +18,21 @@ test "notification effect delivers validated fields to the platform service" {
|
|
|
18
18
|
fx.bindServices(&host.services);
|
|
19
19
|
|
|
20
20
|
fx.showNotification(.{
|
|
21
|
+
.id = "build-status",
|
|
21
22
|
.title = "Build finished",
|
|
22
23
|
.subtitle = "native-sdk",
|
|
23
24
|
.body = "All checks passed.",
|
|
25
|
+
.action_label = "Open",
|
|
26
|
+
.action_command = "build.open",
|
|
24
27
|
});
|
|
25
28
|
|
|
26
29
|
try std.testing.expectEqual(@as(usize, 1), null_platform.notificationCount());
|
|
27
30
|
try std.testing.expectEqualStrings("Build finished", null_platform.lastNotificationTitle());
|
|
28
31
|
try std.testing.expectEqualStrings("native-sdk", null_platform.lastNotificationSubtitle());
|
|
29
32
|
try std.testing.expectEqualStrings("All checks passed.", null_platform.lastNotificationBody());
|
|
33
|
+
try std.testing.expectEqualStrings("build-status", null_platform.lastNotificationId());
|
|
34
|
+
try std.testing.expectEqualStrings("Open", null_platform.lastNotificationActionLabel());
|
|
35
|
+
try std.testing.expectEqualStrings("build.open", null_platform.lastNotificationActionCommand());
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
test "notification effect rejects malformed and over-bound requests" {
|
|
@@ -37,9 +43,14 @@ test "notification effect rejects malformed and over-bound requests" {
|
|
|
37
43
|
fx.bindServices(&host.services);
|
|
38
44
|
|
|
39
45
|
const long_title = [_]u8{'x'} ** (platform.max_notification_title_bytes + 1);
|
|
46
|
+
const long_id = [_]u8{'x'} ** (platform.max_notification_id_bytes + 1);
|
|
40
47
|
fx.showNotification(.{ .title = "" });
|
|
41
48
|
fx.showNotification(.{ .title = "bad\x00title" });
|
|
42
49
|
fx.showNotification(.{ .title = &long_title });
|
|
50
|
+
fx.showNotification(.{ .id = &long_id, .title = "Bad id" });
|
|
51
|
+
fx.showNotification(.{ .title = "Missing command", .action_label = "Open" });
|
|
52
|
+
fx.showNotification(.{ .title = "Missing label", .action_command = "build.open" });
|
|
53
|
+
fx.showNotification(.{ .title = "Invalid command", .action_label = "Open", .action_command = "../open" });
|
|
43
54
|
|
|
44
55
|
try std.testing.expectEqual(@as(usize, 0), null_platform.notificationCount());
|
|
45
56
|
}
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
//! Runtime policy for raw file effects.
|
|
2
|
+
//!
|
|
3
|
+
//! A manifest `filesystem` grant allows any process-visible path. Without
|
|
4
|
+
//! that grant, raw file effects are confined to the six directories the
|
|
5
|
+
//! app-dir resolver owns for this app. The check canonicalizes the existing
|
|
6
|
+
//! target, or the deepest existing parent for a target that will be created,
|
|
7
|
+
//! before comparing roots. Consequently an in-root symlink that points out
|
|
8
|
+
//! is not an app-directory exemption.
|
|
9
|
+
|
|
10
|
+
const std = @import("std");
|
|
11
|
+
|
|
12
|
+
pub const max_roots: usize = 6;
|
|
13
|
+
|
|
14
|
+
pub const Binding = struct {
|
|
15
|
+
roots: []const []const u8 = &.{},
|
|
16
|
+
permitted: bool = false,
|
|
17
|
+
/// The migration seam. Shipping runners set this true; embedders may use
|
|
18
|
+
/// false for one warning release while still exercising normalization.
|
|
19
|
+
enforce: bool = true,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
pub const Decision = enum { allow, warn, reject };
|
|
23
|
+
|
|
24
|
+
pub const Resolved = struct {
|
|
25
|
+
path: []u8,
|
|
26
|
+
decision: Decision,
|
|
27
|
+
/// For an app-directory exemption, the already-open parent directory
|
|
28
|
+
/// capability the worker must use instead of reopening `path`. `basename`
|
|
29
|
+
/// points into `path`. Holding this handle across the worker handoff closes
|
|
30
|
+
/// the canonicalize-then-open race: every parent was opened first and its
|
|
31
|
+
/// handle-identity path verified inside the selected root.
|
|
32
|
+
parent: ?std.Io.Dir = null,
|
|
33
|
+
basename: []const u8 = "",
|
|
34
|
+
/// A read/stat/delete whose parent does not exist is authorized but absent. The
|
|
35
|
+
/// caller returns the operation's ordinary not-found shape without ever
|
|
36
|
+
/// reopening the unresolved pathname.
|
|
37
|
+
missing: bool = false,
|
|
38
|
+
|
|
39
|
+
pub fn deinit(self: *Resolved, allocator: std.mem.Allocator, io: std.Io) void {
|
|
40
|
+
if (self.parent) |parent| parent.close(io);
|
|
41
|
+
allocator.free(self.path);
|
|
42
|
+
self.* = undefined;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
pub const ResolveOptions = struct {
|
|
47
|
+
create_parents: bool = false,
|
|
48
|
+
/// Authorize the fully resolved target, but hand the caller the resolved
|
|
49
|
+
/// parent plus the request's original final component. Deletion uses this
|
|
50
|
+
/// so removing a symlink unlinks that directory entry rather than the file
|
|
51
|
+
/// it names. Both paths must be inside an app root when no filesystem
|
|
52
|
+
/// permission is present.
|
|
53
|
+
preserve_final_component: bool = false,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/// Normalize first, then decide authority over that exact spelling. Most
|
|
57
|
+
/// callers perform I/O against the resolved target. Operations that preserve
|
|
58
|
+
/// the final component authorize both that target and the resolved directory
|
|
59
|
+
/// entry they hand to the worker.
|
|
60
|
+
pub fn resolve(
|
|
61
|
+
allocator: std.mem.Allocator,
|
|
62
|
+
io: std.Io,
|
|
63
|
+
binding: Binding,
|
|
64
|
+
requested_path: []const u8,
|
|
65
|
+
) !Resolved {
|
|
66
|
+
return resolveForOperation(allocator, io, binding, requested_path, .{});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
pub fn resolveForOperation(
|
|
70
|
+
allocator: std.mem.Allocator,
|
|
71
|
+
io: std.Io,
|
|
72
|
+
binding: Binding,
|
|
73
|
+
requested_path: []const u8,
|
|
74
|
+
options: ResolveOptions,
|
|
75
|
+
) !Resolved {
|
|
76
|
+
if (requested_path.len == 0 or std.mem.indexOfScalar(u8, requested_path, 0) != null) return error.InvalidPath;
|
|
77
|
+
const canonical_target = try canonicalizeTarget(allocator, io, requested_path);
|
|
78
|
+
if (!options.preserve_final_component) {
|
|
79
|
+
return resolveCanonicalOperation(allocator, io, binding, canonical_target, canonical_target, options);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
defer allocator.free(canonical_target);
|
|
83
|
+
const operation_path = try canonicalizeFinalEntry(allocator, io, requested_path);
|
|
84
|
+
return resolveCanonicalOperation(allocator, io, binding, canonical_target, operation_path, options);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fn resolveCanonicalOperation(
|
|
88
|
+
allocator: std.mem.Allocator,
|
|
89
|
+
io: std.Io,
|
|
90
|
+
binding: Binding,
|
|
91
|
+
canonical_target: []const u8,
|
|
92
|
+
operation_path: []u8,
|
|
93
|
+
options: ResolveOptions,
|
|
94
|
+
) Resolved {
|
|
95
|
+
if (binding.permitted) return .{ .path = operation_path, .decision = .allow };
|
|
96
|
+
if (options.preserve_final_component and
|
|
97
|
+
!canonicalIsInsideAnyRoot(allocator, io, binding.roots, canonical_target))
|
|
98
|
+
{
|
|
99
|
+
return .{ .path = operation_path, .decision = if (binding.enforce) .reject else .warn };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
for (binding.roots) |root| {
|
|
103
|
+
if (root.len == 0) continue;
|
|
104
|
+
const canonical_root = canonicalizeTarget(allocator, io, root) catch continue;
|
|
105
|
+
defer allocator.free(canonical_root);
|
|
106
|
+
var root_dir = openCanonicalDir(io, canonical_root, options.create_parents) catch {
|
|
107
|
+
// A missing root can only authorize an absent read/stat/delete. Compare
|
|
108
|
+
// canonical lexical spellings, then return the closed absence
|
|
109
|
+
// result; writes created the root above and never take this path.
|
|
110
|
+
if (!options.create_parents and pathIsWithin(canonical_root, operation_path)) {
|
|
111
|
+
return .{ .path = operation_path, .decision = .allow, .missing = true };
|
|
112
|
+
}
|
|
113
|
+
continue;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
var root_real_storage: [std.Io.Dir.max_path_bytes]u8 = undefined;
|
|
117
|
+
const root_real_len = root_dir.realPath(io, &root_real_storage) catch {
|
|
118
|
+
root_dir.close(io);
|
|
119
|
+
continue;
|
|
120
|
+
};
|
|
121
|
+
const root_real = root_real_storage[0..root_real_len];
|
|
122
|
+
if (!pathIsWithin(root_real, operation_path)) {
|
|
123
|
+
root_dir.close(io);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const relative = relativeToRoot(root_real, operation_path) orelse {
|
|
128
|
+
root_dir.close(io);
|
|
129
|
+
continue;
|
|
130
|
+
};
|
|
131
|
+
const basename = std.fs.path.basename(relative);
|
|
132
|
+
if (basename.len == 0 or std.mem.eql(u8, basename, ".") or std.mem.eql(u8, basename, "..")) {
|
|
133
|
+
root_dir.close(io);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const parent_path = std.fs.path.dirname(relative) orelse "";
|
|
137
|
+
const parent = openVerifiedParent(io, root_dir, root_real, parent_path, options.create_parents) catch |err| switch (err) {
|
|
138
|
+
error.FileNotFound => return .{ .path = operation_path, .decision = .allow, .missing = true },
|
|
139
|
+
else => continue,
|
|
140
|
+
};
|
|
141
|
+
const basename_offset = @intFromPtr(basename.ptr) - @intFromPtr(relative.ptr) +
|
|
142
|
+
(@intFromPtr(relative.ptr) - @intFromPtr(operation_path.ptr));
|
|
143
|
+
return .{
|
|
144
|
+
.path = operation_path,
|
|
145
|
+
.decision = .allow,
|
|
146
|
+
.parent = parent,
|
|
147
|
+
.basename = operation_path[basename_offset .. basename_offset + basename.len],
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return .{ .path = operation_path, .decision = if (binding.enforce) .reject else .warn };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/// Resolve every parent component but preserve the request's final directory
|
|
155
|
+
/// entry. Unlike `canonicalizeTarget`, this deliberately does not follow a
|
|
156
|
+
/// final symlink.
|
|
157
|
+
fn canonicalizeFinalEntry(allocator: std.mem.Allocator, io: std.Io, requested_path: []const u8) ![]u8 {
|
|
158
|
+
const basename = std.fs.path.basename(requested_path);
|
|
159
|
+
if (basename.len == 0 or
|
|
160
|
+
std.mem.eql(u8, basename, ".") or
|
|
161
|
+
std.mem.eql(u8, basename, "..") or
|
|
162
|
+
std.mem.indexOfAny(u8, basename, if (@import("builtin").os.tag == .windows) "/\\" else "/") != null)
|
|
163
|
+
{
|
|
164
|
+
return error.InvalidPath;
|
|
165
|
+
}
|
|
166
|
+
const parent_path = std.fs.path.dirname(requested_path) orelse ".";
|
|
167
|
+
const canonical_parent = try canonicalizeTarget(allocator, io, parent_path);
|
|
168
|
+
defer allocator.free(canonical_parent);
|
|
169
|
+
return std.fs.path.resolve(allocator, &.{ canonical_parent, basename });
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
fn openCanonicalDir(io: std.Io, canonical_path: []const u8, create: bool) !std.Io.Dir {
|
|
173
|
+
var components = std.fs.path.componentIterator(canonical_path);
|
|
174
|
+
const root = components.root() orelse return error.BadPathName;
|
|
175
|
+
var current = try std.Io.Dir.openDirAbsolute(io, root, .{ .follow_symlinks = false });
|
|
176
|
+
errdefer current.close(io);
|
|
177
|
+
while (components.next()) |component| {
|
|
178
|
+
const next = current.openDir(io, component.name, .{ .follow_symlinks = false }) catch |err| switch (err) {
|
|
179
|
+
error.FileNotFound => if (create) create_component: {
|
|
180
|
+
current.createDir(io, component.name, .default_dir) catch |create_err| switch (create_err) {
|
|
181
|
+
error.PathAlreadyExists => {},
|
|
182
|
+
else => return create_err,
|
|
183
|
+
};
|
|
184
|
+
break :create_component try current.openDir(io, component.name, .{ .follow_symlinks = false });
|
|
185
|
+
} else return error.FileNotFound,
|
|
186
|
+
else => return err,
|
|
187
|
+
};
|
|
188
|
+
current.close(io);
|
|
189
|
+
current = next;
|
|
190
|
+
}
|
|
191
|
+
return current;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
pub fn decide(
|
|
195
|
+
allocator: std.mem.Allocator,
|
|
196
|
+
io: std.Io,
|
|
197
|
+
binding: Binding,
|
|
198
|
+
requested_path: []const u8,
|
|
199
|
+
) Decision {
|
|
200
|
+
const resolved = resolve(allocator, io, binding, requested_path) catch return .reject;
|
|
201
|
+
var owned = resolved;
|
|
202
|
+
defer owned.deinit(allocator, io);
|
|
203
|
+
return resolved.decision;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
fn relativeToRoot(root: []const u8, target: []const u8) ?[]const u8 {
|
|
207
|
+
if (!pathIsWithin(root, target) or pathsEqual(root, target)) return null;
|
|
208
|
+
var at = root.len;
|
|
209
|
+
while (at < target.len and isSeparator(target[at])) at += 1;
|
|
210
|
+
return target[at..];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
fn openVerifiedParent(
|
|
214
|
+
io: std.Io,
|
|
215
|
+
root_dir: std.Io.Dir,
|
|
216
|
+
canonical_root: []const u8,
|
|
217
|
+
parent_path: []const u8,
|
|
218
|
+
create_parents: bool,
|
|
219
|
+
) !std.Io.Dir {
|
|
220
|
+
var current = root_dir;
|
|
221
|
+
errdefer current.close(io);
|
|
222
|
+
var components = std.fs.path.componentIterator(parent_path);
|
|
223
|
+
while (components.next()) |component| {
|
|
224
|
+
var next = current.openDir(io, component.name, .{ .follow_symlinks = true }) catch |err| switch (err) {
|
|
225
|
+
error.FileNotFound => if (create_parents) create: {
|
|
226
|
+
current.createDir(io, component.name, .default_dir) catch |create_err| switch (create_err) {
|
|
227
|
+
error.PathAlreadyExists => {},
|
|
228
|
+
else => return create_err,
|
|
229
|
+
};
|
|
230
|
+
// A component we created must still be a directory, not a
|
|
231
|
+
// symlink substituted between create and open.
|
|
232
|
+
break :create try current.openDir(io, component.name, .{ .follow_symlinks = false });
|
|
233
|
+
} else return error.FileNotFound,
|
|
234
|
+
else => return err,
|
|
235
|
+
};
|
|
236
|
+
var next_real_storage: [std.Io.Dir.max_path_bytes]u8 = undefined;
|
|
237
|
+
const next_real_len = next.realPath(io, &next_real_storage) catch |err| {
|
|
238
|
+
next.close(io);
|
|
239
|
+
return err;
|
|
240
|
+
};
|
|
241
|
+
if (!pathIsWithin(canonical_root, next_real_storage[0..next_real_len])) {
|
|
242
|
+
next.close(io);
|
|
243
|
+
return error.AccessDenied;
|
|
244
|
+
}
|
|
245
|
+
current.close(io);
|
|
246
|
+
current = next;
|
|
247
|
+
}
|
|
248
|
+
return current;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/// Canonicalize the target when it exists. For a new target, walk upward to
|
|
252
|
+
/// the deepest existing parent, canonicalize that parent (resolving every
|
|
253
|
+
/// symlink in the chain), then append the missing lexical suffix. Root paths
|
|
254
|
+
/// are canonicalized independently so aliases such as macOS `/tmp` and
|
|
255
|
+
/// `/private/tmp` compare correctly.
|
|
256
|
+
pub fn isInsideAnyRoot(
|
|
257
|
+
allocator: std.mem.Allocator,
|
|
258
|
+
io: std.Io,
|
|
259
|
+
roots: []const []const u8,
|
|
260
|
+
requested_path: []const u8,
|
|
261
|
+
) bool {
|
|
262
|
+
if (requested_path.len == 0 or roots.len == 0 or std.mem.indexOfScalar(u8, requested_path, 0) != null) return false;
|
|
263
|
+
const canonical_target = canonicalizeTarget(allocator, io, requested_path) catch return false;
|
|
264
|
+
defer allocator.free(canonical_target);
|
|
265
|
+
return canonicalIsInsideAnyRoot(allocator, io, roots, canonical_target);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
fn canonicalIsInsideAnyRoot(allocator: std.mem.Allocator, io: std.Io, roots: []const []const u8, canonical_target: []const u8) bool {
|
|
269
|
+
for (roots) |root| {
|
|
270
|
+
if (root.len == 0) continue;
|
|
271
|
+
const canonical_root = canonicalizeTarget(allocator, io, root) catch continue;
|
|
272
|
+
defer allocator.free(canonical_root);
|
|
273
|
+
if (pathIsWithin(canonical_root, canonical_target)) return true;
|
|
274
|
+
}
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
fn canonicalizeTarget(allocator: std.mem.Allocator, io: std.Io, path: []const u8) ![]u8 {
|
|
279
|
+
const cwd = std.Io.Dir.cwd();
|
|
280
|
+
if (cwd.realPathFileAlloc(io, path, allocator)) |resolved| {
|
|
281
|
+
defer allocator.free(resolved);
|
|
282
|
+
return allocator.dupe(u8, resolved);
|
|
283
|
+
} else |_| {}
|
|
284
|
+
|
|
285
|
+
// Preserve every missing component while searching for an existing
|
|
286
|
+
// ancestor. `std.fs.path.resolve` then normalizes `.`/`..` in the joined
|
|
287
|
+
// result, after the existing prefix has been resolved through symlinks.
|
|
288
|
+
var ancestor = path;
|
|
289
|
+
var suffix: std.ArrayList([]const u8) = .empty;
|
|
290
|
+
defer suffix.deinit(allocator);
|
|
291
|
+
while (true) {
|
|
292
|
+
const parent = std.fs.path.dirname(ancestor) orelse break;
|
|
293
|
+
const base = std.fs.path.basename(ancestor);
|
|
294
|
+
try suffix.append(allocator, base);
|
|
295
|
+
if (cwd.realPathFileAlloc(io, parent, allocator)) |resolved_parent| {
|
|
296
|
+
defer allocator.free(resolved_parent);
|
|
297
|
+
var parts: std.ArrayList([]const u8) = .empty;
|
|
298
|
+
defer parts.deinit(allocator);
|
|
299
|
+
try parts.append(allocator, resolved_parent);
|
|
300
|
+
var index = suffix.items.len;
|
|
301
|
+
while (index > 0) {
|
|
302
|
+
index -= 1;
|
|
303
|
+
try parts.append(allocator, suffix.items[index]);
|
|
304
|
+
}
|
|
305
|
+
return std.fs.path.resolve(allocator, parts.items);
|
|
306
|
+
} else |_| {}
|
|
307
|
+
if (std.mem.eql(u8, parent, ancestor)) break;
|
|
308
|
+
ancestor = parent;
|
|
309
|
+
}
|
|
310
|
+
// A completely missing relative tail still has one existing parent: cwd.
|
|
311
|
+
// Resolve it explicitly and append every requested component lexically.
|
|
312
|
+
if (!std.fs.path.isAbsolute(path)) {
|
|
313
|
+
const cwd_resolved = try cwd.realPathFileAlloc(io, ".", allocator);
|
|
314
|
+
defer allocator.free(cwd_resolved);
|
|
315
|
+
return std.fs.path.resolve(allocator, &.{ cwd_resolved, path });
|
|
316
|
+
}
|
|
317
|
+
return error.FileNotFound;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
fn pathIsWithin(root: []const u8, target: []const u8) bool {
|
|
321
|
+
if (pathsEqual(root, target)) return true;
|
|
322
|
+
if (root.len == 0 or target.len <= root.len) return false;
|
|
323
|
+
if (!pathPrefixEqual(root, target[0..root.len])) return false;
|
|
324
|
+
return isSeparator(target[root.len]) or isSeparator(root[root.len - 1]);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
fn pathsEqual(a: []const u8, b: []const u8) bool {
|
|
328
|
+
if (a.len != b.len) return false;
|
|
329
|
+
return pathPrefixEqual(a, b);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
fn pathPrefixEqual(a: []const u8, b: []const u8) bool {
|
|
333
|
+
if (@import("builtin").os.tag != .windows) return std.mem.eql(u8, a, b);
|
|
334
|
+
return std.ascii.eqlIgnoreCase(a, b);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
fn isSeparator(byte: u8) bool {
|
|
338
|
+
return byte == '/' or (@import("builtin").os.tag == .windows and byte == '\\');
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
test "canonical containment rejects lexical escapes and symlinks that point out" {
|
|
342
|
+
var tmp = std.testing.tmpDir(.{});
|
|
343
|
+
defer tmp.cleanup();
|
|
344
|
+
try tmp.dir.createDirPath(std.testing.io, "app/data");
|
|
345
|
+
try tmp.dir.createDirPath(std.testing.io, "outside");
|
|
346
|
+
|
|
347
|
+
var root_buffer: [256]u8 = undefined;
|
|
348
|
+
var inside_buffer: [256]u8 = undefined;
|
|
349
|
+
var escape_buffer: [256]u8 = undefined;
|
|
350
|
+
const root = try std.fmt.bufPrint(&root_buffer, ".zig-cache/tmp/{s}/app/data", .{tmp.sub_path[0..]});
|
|
351
|
+
const inside = try std.fmt.bufPrint(&inside_buffer, "{s}/nested/new.bin", .{root});
|
|
352
|
+
const escaped = try std.fmt.bufPrint(&escape_buffer, "{s}/../../outside/new.bin", .{root});
|
|
353
|
+
try std.testing.expect(isInsideAnyRoot(std.testing.allocator, std.testing.io, &.{root}, inside));
|
|
354
|
+
try std.testing.expect(!isInsideAnyRoot(std.testing.allocator, std.testing.io, &.{root}, escaped));
|
|
355
|
+
|
|
356
|
+
if (@import("builtin").os.tag != .windows) {
|
|
357
|
+
try tmp.dir.symLink(std.testing.io, "../../outside", "app/data/link", .{ .is_directory = true });
|
|
358
|
+
var symlink_buffer: [256]u8 = undefined;
|
|
359
|
+
const through_symlink = try std.fmt.bufPrint(&symlink_buffer, "{s}/link/new.bin", .{root});
|
|
360
|
+
try std.testing.expect(!isInsideAnyRoot(std.testing.allocator, std.testing.io, &.{root}, through_symlink));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
test "an authorized request retains the opened parent capability" {
|
|
365
|
+
var tmp = std.testing.tmpDir(.{});
|
|
366
|
+
defer tmp.cleanup();
|
|
367
|
+
try tmp.dir.createDirPath(std.testing.io, "app/data/nested");
|
|
368
|
+
var root_buffer: [256]u8 = undefined;
|
|
369
|
+
var target_buffer: [256]u8 = undefined;
|
|
370
|
+
const root = try std.fmt.bufPrint(&root_buffer, ".zig-cache/tmp/{s}/app/data", .{tmp.sub_path[0..]});
|
|
371
|
+
const target = try std.fmt.bufPrint(&target_buffer, "{s}/nested/file.bin", .{root});
|
|
372
|
+
var resolved = try resolveForOperation(std.testing.allocator, std.testing.io, .{ .roots = &.{root} }, target, .{ .create_parents = true });
|
|
373
|
+
defer resolved.deinit(std.testing.allocator, std.testing.io);
|
|
374
|
+
try std.testing.expectEqual(Decision.allow, resolved.decision);
|
|
375
|
+
try std.testing.expect(resolved.parent != null);
|
|
376
|
+
try std.testing.expectEqualStrings("file.bin", resolved.basename);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
test "a retained parent capability ignores a later pathname symlink swap" {
|
|
380
|
+
if (@import("builtin").os.tag == .windows) return error.SkipZigTest;
|
|
381
|
+
var tmp = std.testing.tmpDir(.{});
|
|
382
|
+
defer tmp.cleanup();
|
|
383
|
+
try tmp.dir.createDirPath(std.testing.io, "app/data/nested");
|
|
384
|
+
try tmp.dir.createDirPath(std.testing.io, "outside");
|
|
385
|
+
var root_buffer: [256]u8 = undefined;
|
|
386
|
+
var target_buffer: [256]u8 = undefined;
|
|
387
|
+
const root = try std.fmt.bufPrint(&root_buffer, ".zig-cache/tmp/{s}/app/data", .{tmp.sub_path[0..]});
|
|
388
|
+
const target = try std.fmt.bufPrint(&target_buffer, "{s}/nested/file.bin", .{root});
|
|
389
|
+
var resolved = try resolveForOperation(std.testing.allocator, std.testing.io, .{ .roots = &.{root} }, target, .{ .create_parents = true });
|
|
390
|
+
defer resolved.deinit(std.testing.allocator, std.testing.io);
|
|
391
|
+
|
|
392
|
+
try tmp.dir.rename("app/data/nested", tmp.dir, "app/data/retained", std.testing.io);
|
|
393
|
+
try tmp.dir.symLink(std.testing.io, "../../outside", "app/data/nested", .{ .is_directory = true });
|
|
394
|
+
try resolved.parent.?.writeFile(std.testing.io, .{ .sub_path = resolved.basename, .data = "safe" });
|
|
395
|
+
|
|
396
|
+
const retained = try tmp.dir.readFileAlloc(std.testing.io, "app/data/retained/file.bin", std.testing.allocator, .limited(16));
|
|
397
|
+
defer std.testing.allocator.free(retained);
|
|
398
|
+
try std.testing.expectEqualStrings("safe", retained);
|
|
399
|
+
try std.testing.expectError(error.FileNotFound, tmp.dir.openFile(std.testing.io, "outside/file.bin", .{}));
|
|
400
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const native_sdk = @import("native_sdk");
|
|
3
|
+
|
|
4
|
+
const Msg = union(enum) { file: native_sdk.EffectFileResult };
|
|
5
|
+
const Fx = native_sdk.Effects(Msg);
|
|
6
|
+
|
|
7
|
+
fn waitResult(fx: *Fx, io: std.Io) !native_sdk.EffectFileResult {
|
|
8
|
+
while (true) {
|
|
9
|
+
if (fx.takeMsg()) |msg| return msg.file;
|
|
10
|
+
try std.Io.sleep(io, std.Io.Duration.fromMilliseconds(1), .awake);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
pub fn main(init: std.process.Init) !void {
|
|
15
|
+
const args = try init.minimal.args.toSlice(init.arena.allocator());
|
|
16
|
+
if (args.len != 3) return error.InvalidArguments;
|
|
17
|
+
const destination = args[1];
|
|
18
|
+
const ready = args[2];
|
|
19
|
+
var fx = Fx.init(init.gpa);
|
|
20
|
+
// Deliberately no deinit: the parent kills this process to model a hard
|
|
21
|
+
// crash after the temporary contains bytes but before atomic replace.
|
|
22
|
+
fx.writeFileStream(.{ .key = 1, .path = destination, .on_result = Fx.fileMsg(.file) });
|
|
23
|
+
if ((try waitResult(&fx, init.io)).outcome != .ok) return error.OpenFailed;
|
|
24
|
+
fx.writeFileChunk(.{ .key = 1, .bytes = "partial replacement that must never become visible", .on_result = Fx.fileMsg(.file) });
|
|
25
|
+
if ((try waitResult(&fx, init.io)).outcome != .ok) return error.ChunkFailed;
|
|
26
|
+
try std.Io.Dir.cwd().writeFile(init.io, .{ .sub_path = ready, .data = "ready" });
|
|
27
|
+
while (true) try std.Io.sleep(init.io, std.Io.Duration.fromSeconds(60), .awake);
|
|
28
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const crash_options = @import("file_crash_options");
|
|
3
|
+
|
|
4
|
+
test "hard process death before streamed close leaves the installed file untouched" {
|
|
5
|
+
const io = std.testing.io;
|
|
6
|
+
var tmp = std.testing.tmpDir(.{});
|
|
7
|
+
defer tmp.cleanup();
|
|
8
|
+
try tmp.dir.writeFile(io, .{ .sub_path = "export.bin", .data = "previous complete generation" });
|
|
9
|
+
|
|
10
|
+
var destination_storage: [std.Io.Dir.max_path_bytes]u8 = undefined;
|
|
11
|
+
var ready_storage: [std.Io.Dir.max_path_bytes]u8 = undefined;
|
|
12
|
+
const destination = try std.fmt.bufPrint(&destination_storage, ".zig-cache/tmp/{s}/export.bin", .{tmp.sub_path[0..]});
|
|
13
|
+
const ready = try std.fmt.bufPrint(&ready_storage, ".zig-cache/tmp/{s}/ready", .{tmp.sub_path[0..]});
|
|
14
|
+
var child = try std.process.spawn(io, .{
|
|
15
|
+
.argv = &.{ crash_options.helper_executable, destination, ready },
|
|
16
|
+
.stdin = .ignore,
|
|
17
|
+
.stdout = .ignore,
|
|
18
|
+
.stderr = .inherit,
|
|
19
|
+
});
|
|
20
|
+
defer child.kill(io);
|
|
21
|
+
|
|
22
|
+
var waited_ms: usize = 0;
|
|
23
|
+
while (waited_ms < 20_000) : (waited_ms += 10) {
|
|
24
|
+
if (tmp.dir.openFile(io, "ready", .{})) |file_value| {
|
|
25
|
+
var file = file_value;
|
|
26
|
+
file.close(io);
|
|
27
|
+
break;
|
|
28
|
+
} else |_| {}
|
|
29
|
+
try std.Io.sleep(io, std.Io.Duration.fromMilliseconds(10), .awake);
|
|
30
|
+
}
|
|
31
|
+
if (waited_ms == 20_000) return error.TestTimedOut;
|
|
32
|
+
child.kill(io);
|
|
33
|
+
|
|
34
|
+
const visible = try tmp.dir.readFileAlloc(io, "export.bin", std.testing.allocator, .limited(128));
|
|
35
|
+
defer std.testing.allocator.free(visible);
|
|
36
|
+
try std.testing.expectEqualStrings("previous complete generation", visible);
|
|
37
|
+
}
|
package/src/runtime/flow.zig
CHANGED
|
@@ -45,7 +45,7 @@ const parseAutomationWidgetKey = automation_commands.parseAutomationWidgetKey;
|
|
|
45
45
|
const parseAutomationWidgetPinch = automation_commands.parseAutomationWidgetPinch;
|
|
46
46
|
const parseAutomationWidgetPointerDrag = automation_commands.parseAutomationWidgetPointerDrag;
|
|
47
47
|
const parseAutomationResizeCommand = automation_commands.parseAutomationResizeCommand;
|
|
48
|
-
const
|
|
48
|
+
const parseAutomationTrayTarget = automation_commands.parseAutomationTrayTarget;
|
|
49
49
|
const parseAutomationScreenshotCommand = automation_commands.parseAutomationScreenshotCommand;
|
|
50
50
|
const canvas = @import("canvas");
|
|
51
51
|
|
|
@@ -362,12 +362,13 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
362
362
|
},
|
|
363
363
|
.frame_requested => try frame(self, app),
|
|
364
364
|
.bridge_message => |message| try handleBridgeMessage(self, app, message),
|
|
365
|
-
.tray_action => |
|
|
366
|
-
log(self, "tray.action", "tray item selected", &.{trace.uint("item_id", item_id)});
|
|
365
|
+
.tray_action => |action| {
|
|
366
|
+
log(self, "tray.action", "tray item selected", &.{ trace.uint("status_item_id", action.status_item_id), trace.uint("item_id", action.item_id) });
|
|
367
367
|
try dispatchCommand(self, app, .{
|
|
368
|
-
.name = SystemServiceMethods().
|
|
368
|
+
.name = SystemServiceMethods().statusItemCommandNameForItem(self, action.status_item_id, action.item_id),
|
|
369
369
|
.source = .tray,
|
|
370
|
-
.
|
|
370
|
+
.status_item_id = action.status_item_id,
|
|
371
|
+
.tray_item_id = action.item_id,
|
|
371
372
|
});
|
|
372
373
|
},
|
|
373
374
|
.shortcut => |shortcut| {
|
|
@@ -450,6 +451,14 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
450
451
|
.name = command.name,
|
|
451
452
|
.source = .tray,
|
|
452
453
|
.window_id = command.window_id,
|
|
454
|
+
.status_item_id = command.status_item_id,
|
|
455
|
+
});
|
|
456
|
+
},
|
|
457
|
+
.notification_command => |command| {
|
|
458
|
+
try dispatchCommand(self, app, .{
|
|
459
|
+
.name = command.name,
|
|
460
|
+
.source = .notification,
|
|
461
|
+
.window_id = command.window_id,
|
|
453
462
|
});
|
|
454
463
|
},
|
|
455
464
|
.timer => |timer_event| {
|
|
@@ -1002,9 +1011,12 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
1002
1011
|
// UiApp's window fallback are all the real path. A
|
|
1003
1012
|
// stale or unknown item id is loud driver misuse,
|
|
1004
1013
|
// like widget-click on an unmounted widget.
|
|
1005
|
-
const
|
|
1006
|
-
if (!
|
|
1007
|
-
try dispatchPlatformEvent(self, app, .{ .tray_action =
|
|
1014
|
+
const target = try parseAutomationTrayTarget(command.value);
|
|
1015
|
+
if (!SystemServiceMethods().statusItemMenuItemExists(self, target.status_item_id, target.item_id)) return error.InvalidCommand;
|
|
1016
|
+
try dispatchPlatformEvent(self, app, .{ .tray_action = .{
|
|
1017
|
+
.status_item_id = target.status_item_id,
|
|
1018
|
+
.item_id = target.item_id,
|
|
1019
|
+
} });
|
|
1008
1020
|
},
|
|
1009
1021
|
.focus_view => {
|
|
1010
1022
|
try WindowViewMethods().focusView(self, 1, try parseAutomationViewLabel(command.value));
|
|
@@ -1186,7 +1198,7 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
1186
1198
|
else if (is_credentials)
|
|
1187
1199
|
dispatchCredentialBridgeCommand(self, request, &result_buffer, &response_buffer)
|
|
1188
1200
|
else
|
|
1189
|
-
dispatchOsBridgeCommand(self, request, &result_buffer, &response_buffer);
|
|
1201
|
+
dispatchOsBridgeCommand(self, request, message.origin, &result_buffer, &response_buffer);
|
|
1190
1202
|
|
|
1191
1203
|
try completeBridgeResponse(self, message.window_id, message.webview_label, result);
|
|
1192
1204
|
self.invalidateFor(.command, null);
|