@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//! The native host consumer for compiled TypeScript app cores: bridges
|
|
2
2
|
//! the versioned command/subscription wire format a compiled core
|
|
3
|
-
//! emits (`cmd_format_version`
|
|
3
|
+
//! emits (`cmd_format_version` 7) onto the real effect engine
|
|
4
4
|
//! (`effects.zig`). The TypeScript tier's core module is a pure
|
|
5
5
|
//! Model/Msg/update core whose effects are INERT BYTES — this module is
|
|
6
6
|
//! the one place those bytes become engine calls, so the entire
|
|
@@ -436,6 +436,9 @@ pub const pty_key_base: u64 = 0x5453_5054_0000_0000;
|
|
|
436
436
|
/// its own engine table, so these never consume the general request slots.
|
|
437
437
|
pub const db_key_base: u64 = 0x5453_4442_0000_0000;
|
|
438
438
|
|
|
439
|
+
/// Dedicated raw-file stream key namespace ("TSFS").
|
|
440
|
+
pub const file_stream_key_base: u64 = 0x5453_4653_0000_0000;
|
|
441
|
+
|
|
439
442
|
/// The spawn wire record's "no line routing" tag sentinel (the wire
|
|
440
443
|
/// format's shared constant).
|
|
441
444
|
pub const spawn_no_line_tag: u8 = 0xFF;
|
|
@@ -574,6 +577,21 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
574
577
|
}
|
|
575
578
|
};
|
|
576
579
|
|
|
580
|
+
const FileStreamEntry = struct {
|
|
581
|
+
used: bool = false,
|
|
582
|
+
sink: bool = false,
|
|
583
|
+
busy: bool = false,
|
|
584
|
+
key_len: usize = 0,
|
|
585
|
+
key: [max_wire_key_bytes]u8 = undefined,
|
|
586
|
+
chunk_tag: u8 = 0,
|
|
587
|
+
done_tag: u8 = 0,
|
|
588
|
+
err_tag: u8 = 0,
|
|
589
|
+
cancelling: bool = false,
|
|
590
|
+
fn wireKey(entry: *const FileStreamEntry) []const u8 {
|
|
591
|
+
return entry.key[0..entry.key_len];
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
|
|
577
595
|
/// The single audio stream entry (one player is the whole
|
|
578
596
|
/// engine surface). Non-retiring: audio_ctl `stop` closes it, a
|
|
579
597
|
/// new audio_play re-keys and re-routes it in place.
|
|
@@ -694,6 +712,7 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
694
712
|
var effects_table: [runtime_effects.max_effects]EffectEntry = @splat(.{});
|
|
695
713
|
var delays: [runtime_effects.max_effect_timers]DelayEntry = @splat(.{});
|
|
696
714
|
var streams: [runtime_effects.max_effects]StreamEntry = @splat(.{});
|
|
715
|
+
var file_streams: [runtime_effects.max_effect_file_streams]FileStreamEntry = @splat(.{});
|
|
697
716
|
var audio_entry: AudioEntry = .{};
|
|
698
717
|
var video_entry: VideoEntry = .{};
|
|
699
718
|
var images: [runtime_effects.max_effects]ImageEntry = @splat(.{});
|
|
@@ -1018,8 +1037,9 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
1018
1037
|
0x07 => {
|
|
1019
1038
|
const head = takeRoutedHead(cmd, &at);
|
|
1020
1039
|
const file_path = takeLongBytes(cmd, &at);
|
|
1040
|
+
const effect_index = allocEffectEntry(fx, head) orelse continue;
|
|
1021
1041
|
fx.readFile(.{
|
|
1022
|
-
.key = effect_key_base +
|
|
1042
|
+
.key = effect_key_base + effect_index,
|
|
1023
1043
|
.path = file_path,
|
|
1024
1044
|
.on_result = fileResultMsg,
|
|
1025
1045
|
});
|
|
@@ -1030,13 +1050,53 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
1030
1050
|
const head = takeRoutedHead(cmd, &at);
|
|
1031
1051
|
const file_path = takeLongBytes(cmd, &at);
|
|
1032
1052
|
const bytes = takeLongBytes(cmd, &at);
|
|
1053
|
+
const effect_index = allocEffectEntry(fx, head) orelse continue;
|
|
1033
1054
|
fx.writeFile(.{
|
|
1034
|
-
.key = effect_key_base +
|
|
1055
|
+
.key = effect_key_base + effect_index,
|
|
1035
1056
|
.path = file_path,
|
|
1036
1057
|
.bytes = bytes,
|
|
1037
1058
|
.on_result = fileResultMsg,
|
|
1038
1059
|
});
|
|
1039
1060
|
},
|
|
1061
|
+
// append/stat and streaming raw-file effects.
|
|
1062
|
+
0x2B => {
|
|
1063
|
+
const head = takeRoutedHead(cmd, &at);
|
|
1064
|
+
const file_path = takeLongBytes(cmd, &at);
|
|
1065
|
+
const bytes = takeLongBytes(cmd, &at);
|
|
1066
|
+
const effect_index = allocEffectEntry(fx, head) orelse continue;
|
|
1067
|
+
fx.appendFile(.{ .key = effect_key_base + effect_index, .path = file_path, .bytes = bytes, .on_result = fileResultMsg });
|
|
1068
|
+
},
|
|
1069
|
+
0x2C => {
|
|
1070
|
+
const head = takeRoutedHead(cmd, &at);
|
|
1071
|
+
const file_path = takeLongBytes(cmd, &at);
|
|
1072
|
+
const effect_index = allocEffectEntry(fx, head) orelse continue;
|
|
1073
|
+
fx.statFile(.{ .key = effect_key_base + effect_index, .path = file_path, .on_result = fileResultMsg });
|
|
1074
|
+
},
|
|
1075
|
+
0x32 => {
|
|
1076
|
+
const head = takeRoutedHead(cmd, &at);
|
|
1077
|
+
const file_path = takeLongBytes(cmd, &at);
|
|
1078
|
+
const effect_index = allocEffectEntry(fx, head) orelse continue;
|
|
1079
|
+
fx.deleteFile(.{ .key = effect_key_base + effect_index, .path = file_path, .on_result = fileResultMsg });
|
|
1080
|
+
},
|
|
1081
|
+
0x2D => {
|
|
1082
|
+
const key = takeShortBytes(cmd, &at);
|
|
1083
|
+
const chunk_tag = takeByte(cmd, &at);
|
|
1084
|
+
const done_tag = takeByte(cmd, &at);
|
|
1085
|
+
const err_tag = takeByte(cmd, &at);
|
|
1086
|
+
const file_path = takeLongBytes(cmd, &at);
|
|
1087
|
+
issueReadFileStream(fx, key, chunk_tag, done_tag, err_tag, file_path);
|
|
1088
|
+
},
|
|
1089
|
+
0x2E => {
|
|
1090
|
+
const head = takeRoutedHead(cmd, &at);
|
|
1091
|
+
const file_path = takeLongBytes(cmd, &at);
|
|
1092
|
+
issueWriteFileStream(fx, head, file_path);
|
|
1093
|
+
},
|
|
1094
|
+
0x2F => {
|
|
1095
|
+
const head = takeRoutedHead(cmd, &at);
|
|
1096
|
+
const bytes = takeLongBytes(cmd, &at);
|
|
1097
|
+
issueWriteFileChunk(fx, head, bytes);
|
|
1098
|
+
},
|
|
1099
|
+
0x30 => issueWriteFileClose(fx, takeRoutedHead(cmd, &at)),
|
|
1040
1100
|
// fetch [op][key_len][key][ok][err][method u8][timeout u32 LE]
|
|
1041
1101
|
// [url_len u32 LE][url][header_count u8]
|
|
1042
1102
|
// ([name_len u8][name][value_len u32 LE][value])*
|
|
@@ -1064,11 +1124,12 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
1064
1124
|
// otherwise find this named op first and leave the
|
|
1065
1125
|
// stream running. The live stream owns the key, so
|
|
1066
1126
|
// reject the newcomer through its own err arm.
|
|
1067
|
-
if (head.key.len > 0 and findStream(head.key) != null) {
|
|
1127
|
+
if (head.key.len > 0 and (findStream(head.key) != null or fileStreamOccupiesKey(head.key))) {
|
|
1068
1128
|
fx.stageLoopMsg(msgFromTagStaticBytes(head.err_tag, "rejected"));
|
|
1069
1129
|
} else {
|
|
1130
|
+
const effect_index = allocEffectEntry(fx, head) orelse continue;
|
|
1070
1131
|
fx.fetch(.{
|
|
1071
|
-
.key = effect_key_base +
|
|
1132
|
+
.key = effect_key_base + effect_index,
|
|
1072
1133
|
.method = method,
|
|
1073
1134
|
.url = url,
|
|
1074
1135
|
.headers = headers[0..header_count],
|
|
@@ -1096,8 +1157,9 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
1096
1157
|
// clip_read [op][key_len][key][ok][err]
|
|
1097
1158
|
0x0B => {
|
|
1098
1159
|
const head = takeRoutedHead(cmd, &at);
|
|
1160
|
+
const effect_index = allocEffectEntry(fx, head) orelse continue;
|
|
1099
1161
|
fx.readClipboard(.{
|
|
1100
|
-
.key = effect_key_base +
|
|
1162
|
+
.key = effect_key_base + effect_index,
|
|
1101
1163
|
.on_result = clipboardResultMsg,
|
|
1102
1164
|
});
|
|
1103
1165
|
},
|
|
@@ -1353,6 +1415,24 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
1353
1415
|
.body = body,
|
|
1354
1416
|
});
|
|
1355
1417
|
},
|
|
1418
|
+
// actionable_notification [op 0x31][id/title/subtitle/body/
|
|
1419
|
+
// action_label/action_command as u32-length bytes]
|
|
1420
|
+
0x31 => {
|
|
1421
|
+
const notification_id = takeLongBytes(cmd, &at);
|
|
1422
|
+
const title = takeLongBytes(cmd, &at);
|
|
1423
|
+
const subtitle = takeLongBytes(cmd, &at);
|
|
1424
|
+
const body = takeLongBytes(cmd, &at);
|
|
1425
|
+
const action_label = takeLongBytes(cmd, &at);
|
|
1426
|
+
const action_command = takeLongBytes(cmd, &at);
|
|
1427
|
+
fx.showNotification(.{
|
|
1428
|
+
.id = notification_id,
|
|
1429
|
+
.title = title,
|
|
1430
|
+
.subtitle = subtitle,
|
|
1431
|
+
.body = body,
|
|
1432
|
+
.action_label = action_label,
|
|
1433
|
+
.action_command = action_command,
|
|
1434
|
+
});
|
|
1435
|
+
},
|
|
1356
1436
|
// audio_capture_start [op][key f64 LE][source u8]
|
|
1357
1437
|
// [sample_rate u32 LE][channels u8]
|
|
1358
1438
|
// [event_tag u8]
|
|
@@ -1639,8 +1719,12 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
1639
1719
|
/// mirrors the engine's slot count, which cannot hold more in
|
|
1640
1720
|
/// flight either (a dropped entry holds its slot only until
|
|
1641
1721
|
/// its `.cancelled` terminal drains).
|
|
1642
|
-
fn allocEffectEntry(fx: *Fx, head: RoutedHead) u64 {
|
|
1722
|
+
fn allocEffectEntry(fx: *Fx, head: RoutedHead) ?u64 {
|
|
1643
1723
|
if (head.key.len > 0) {
|
|
1724
|
+
if (fileStreamOccupiesKey(head.key)) {
|
|
1725
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(head.err_tag, "rejected"));
|
|
1726
|
+
return null;
|
|
1727
|
+
}
|
|
1644
1728
|
if (findEffect(head.key)) |existing| dropEffectEntry(fx, existing);
|
|
1645
1729
|
}
|
|
1646
1730
|
const index = freeEffectIndex() orelse
|
|
@@ -1684,6 +1768,10 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
1684
1768
|
/// slot: the engine timer replaces in place under the same
|
|
1685
1769
|
/// engine key and restarts from now — the debounce discipline.
|
|
1686
1770
|
fn armDelay(fx: *Fx, key: []const u8, after_ms: f64, tag: u8) void {
|
|
1771
|
+
// A delay has no err arm. Preserve an incumbent file stream and
|
|
1772
|
+
// fail closed instead of creating a second owner that Cmd.cancel
|
|
1773
|
+
// could not address unambiguously.
|
|
1774
|
+
if (fileStreamOccupiesKey(key)) return;
|
|
1687
1775
|
const index = blk: {
|
|
1688
1776
|
if (key.len > 0) {
|
|
1689
1777
|
if (findDelay(key)) |existing| break :blk existing;
|
|
@@ -1737,7 +1825,7 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
1737
1825
|
argv: []const []const u8,
|
|
1738
1826
|
stdin: []const u8,
|
|
1739
1827
|
) void {
|
|
1740
|
-
if (head.key.len > 0 and findStream(head.key) != null) {
|
|
1828
|
+
if (head.key.len > 0 and (findStream(head.key) != null or fileStreamOccupiesKey(head.key))) {
|
|
1741
1829
|
fx.stageLoopMsg(msgFromTagStaticBytes(head.err_tag, "rejected"));
|
|
1742
1830
|
return;
|
|
1743
1831
|
}
|
|
@@ -1784,7 +1872,7 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
1784
1872
|
/// two HTTP responses into one app-owned stream.
|
|
1785
1873
|
fn issueFetchStream(fx: *Fx, head: SpawnHead, options: FetchStreamOptions) void {
|
|
1786
1874
|
if (head.key.len > 0 and
|
|
1787
|
-
(findStream(head.key) != null or findEffect(head.key) != null))
|
|
1875
|
+
(findStream(head.key) != null or findEffect(head.key) != null or fileStreamOccupiesKey(head.key)))
|
|
1788
1876
|
{
|
|
1789
1877
|
fx.stageLoopMsg(msgFromTagStaticBytes(head.err_tag, "rejected"));
|
|
1790
1878
|
return;
|
|
@@ -1831,6 +1919,148 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
1831
1919
|
return null;
|
|
1832
1920
|
}
|
|
1833
1921
|
|
|
1922
|
+
fn findFileStream(key: []const u8) ?usize {
|
|
1923
|
+
for (&file_streams, 0..) |*entry, index| {
|
|
1924
|
+
if (entry.used and std.mem.eql(u8, entry.wireKey(), key)) return index;
|
|
1925
|
+
}
|
|
1926
|
+
return null;
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
fn fileStreamOccupiesKey(key: []const u8) bool {
|
|
1930
|
+
return key.len > 0 and findFileStream(key) != null;
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
/// Every string-keyed command family shares one authored key surface.
|
|
1934
|
+
/// File streams use a distinct numeric engine namespace, so admission
|
|
1935
|
+
/// must consult the bridge tables explicitly before claiming a slot.
|
|
1936
|
+
fn wireKeyOccupiedOutsideFileStreams(key: []const u8) bool {
|
|
1937
|
+
if (key.len == 0) return false;
|
|
1938
|
+
return findRequest(key) != null or
|
|
1939
|
+
findEffect(key) != null or
|
|
1940
|
+
findStream(key) != null or
|
|
1941
|
+
findDelay(key) != null or
|
|
1942
|
+
findPty(key) != null or
|
|
1943
|
+
findDb(key) != null;
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
fn freeFileStreamIndex() ?usize {
|
|
1947
|
+
for (&file_streams, 0..) |*entry, index| if (!entry.used) return index;
|
|
1948
|
+
return null;
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
fn issueReadFileStream(fx: *Fx, key: []const u8, chunk_tag: u8, done_tag: u8, err_tag: u8, path: []const u8) void {
|
|
1952
|
+
if (wireKeyOccupiedOutsideFileStreams(key)) {
|
|
1953
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(err_tag, "rejected"));
|
|
1954
|
+
return;
|
|
1955
|
+
}
|
|
1956
|
+
const index = if (key.len > 0 and findFileStream(key) != null) replace: {
|
|
1957
|
+
const existing = findFileStream(key).?;
|
|
1958
|
+
if (file_streams[existing].sink) {
|
|
1959
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(err_tag, "rejected"));
|
|
1960
|
+
return;
|
|
1961
|
+
}
|
|
1962
|
+
// The engine retires the old read generation silently when
|
|
1963
|
+
// this same engine key is reissued. Reuse the bridge slot so
|
|
1964
|
+
// the replacement's tags become authoritative atomically.
|
|
1965
|
+
break :replace existing;
|
|
1966
|
+
} else freeFileStreamIndex() orelse {
|
|
1967
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(err_tag, "rejected"));
|
|
1968
|
+
return;
|
|
1969
|
+
};
|
|
1970
|
+
const entry = &file_streams[index];
|
|
1971
|
+
entry.* = .{ .used = true, .key_len = key.len, .chunk_tag = chunk_tag, .done_tag = done_tag, .err_tag = err_tag };
|
|
1972
|
+
@memcpy(entry.key[0..key.len], key);
|
|
1973
|
+
fx.readFileStream(.{ .key = file_stream_key_base + index, .path = path, .on_result = fileStreamResultMsg });
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
fn issueWriteFileStream(fx: *Fx, head: RoutedHead, path: []const u8) void {
|
|
1977
|
+
if (head.key.len == 0 or findFileStream(head.key) != null or wireKeyOccupiedOutsideFileStreams(head.key)) {
|
|
1978
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(head.err_tag, "rejected"));
|
|
1979
|
+
return;
|
|
1980
|
+
}
|
|
1981
|
+
const index = freeFileStreamIndex() orelse {
|
|
1982
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(head.err_tag, "rejected"));
|
|
1983
|
+
return;
|
|
1984
|
+
};
|
|
1985
|
+
const entry = &file_streams[index];
|
|
1986
|
+
entry.* = .{ .used = true, .sink = true, .busy = true, .key_len = head.key.len, .done_tag = head.ok_tag, .err_tag = head.err_tag };
|
|
1987
|
+
@memcpy(entry.key[0..head.key.len], head.key);
|
|
1988
|
+
fx.writeFileStream(.{ .key = file_stream_key_base + index, .path = path, .on_result = fileStreamResultMsg });
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
fn issueWriteFileChunk(fx: *Fx, head: RoutedHead, bytes: []const u8) void {
|
|
1992
|
+
const index = findFileStream(head.key) orelse {
|
|
1993
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(head.err_tag, "sink_missing"));
|
|
1994
|
+
return;
|
|
1995
|
+
};
|
|
1996
|
+
if (!file_streams[index].sink) {
|
|
1997
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(head.err_tag, "sink_missing"));
|
|
1998
|
+
return;
|
|
1999
|
+
}
|
|
2000
|
+
if (file_streams[index].cancelling) {
|
|
2001
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(head.err_tag, "sink_missing"));
|
|
2002
|
+
return;
|
|
2003
|
+
}
|
|
2004
|
+
if (file_streams[index].busy) {
|
|
2005
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(head.err_tag, "out_of_order"));
|
|
2006
|
+
return;
|
|
2007
|
+
}
|
|
2008
|
+
file_streams[index].busy = true;
|
|
2009
|
+
file_streams[index].done_tag = head.ok_tag;
|
|
2010
|
+
file_streams[index].err_tag = head.err_tag;
|
|
2011
|
+
fx.writeFileChunk(.{ .key = file_stream_key_base + index, .bytes = bytes, .on_result = fileStreamResultMsg });
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
fn issueWriteFileClose(fx: *Fx, head: RoutedHead) void {
|
|
2015
|
+
const index = findFileStream(head.key) orelse {
|
|
2016
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(head.err_tag, "sink_missing"));
|
|
2017
|
+
return;
|
|
2018
|
+
};
|
|
2019
|
+
if (!file_streams[index].sink) {
|
|
2020
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(head.err_tag, "sink_missing"));
|
|
2021
|
+
return;
|
|
2022
|
+
}
|
|
2023
|
+
if (file_streams[index].cancelling) {
|
|
2024
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(head.err_tag, "sink_missing"));
|
|
2025
|
+
return;
|
|
2026
|
+
}
|
|
2027
|
+
if (file_streams[index].busy) {
|
|
2028
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(head.err_tag, "out_of_order"));
|
|
2029
|
+
return;
|
|
2030
|
+
}
|
|
2031
|
+
file_streams[index].busy = true;
|
|
2032
|
+
file_streams[index].done_tag = head.ok_tag;
|
|
2033
|
+
file_streams[index].err_tag = head.err_tag;
|
|
2034
|
+
fx.writeFileClose(.{ .key = file_stream_key_base + index, .on_result = fileStreamResultMsg });
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
fn fileStreamResultMsg(result: runtime_effects.EffectFileResult) Msg {
|
|
2038
|
+
if (result.key < file_stream_key_base) @panic("ts core host: file stream result outside its namespace");
|
|
2039
|
+
const index = result.key - file_stream_key_base;
|
|
2040
|
+
if (index >= file_streams.len or !file_streams[index].used) @panic("ts core host: untracked file stream result");
|
|
2041
|
+
const entry = &file_streams[index];
|
|
2042
|
+
if (entry.cancelling and result.outcome == .cancelled) {
|
|
2043
|
+
entry.used = false;
|
|
2044
|
+
return msgFromTagBytes(entry.err_tag, "cancelled");
|
|
2045
|
+
}
|
|
2046
|
+
if (result.op == .read_stream and result.event == .chunk and result.outcome == .ok) return msgFromTagBytes(entry.chunk_tag, result.bytes);
|
|
2047
|
+
if (result.op == .read_stream and result.event == .done and result.outcome == .ok) {
|
|
2048
|
+
entry.used = false;
|
|
2049
|
+
return msgFromTagNumber(entry.done_tag, @floatFromInt(result.total));
|
|
2050
|
+
}
|
|
2051
|
+
if (result.outcome == .ok) {
|
|
2052
|
+
entry.busy = false;
|
|
2053
|
+
if (result.op == .write_stream_close) entry.used = false;
|
|
2054
|
+
return msgFromTagVoid(entry.done_tag);
|
|
2055
|
+
}
|
|
2056
|
+
if (result.op == .write_stream_chunk and (result.outcome == .rejected or result.outcome == .out_of_order)) {
|
|
2057
|
+
entry.busy = false;
|
|
2058
|
+
return msgFromTagBytes(entry.err_tag, @tagName(result.outcome));
|
|
2059
|
+
}
|
|
2060
|
+
entry.used = false;
|
|
2061
|
+
return msgFromTagBytes(entry.err_tag, @tagName(result.outcome));
|
|
2062
|
+
}
|
|
2063
|
+
|
|
1834
2064
|
/// The stream entry an engine spawn/fetch result names — looked up
|
|
1835
2065
|
/// WITHOUT retiring (lines flow through it repeatedly; only the
|
|
1836
2066
|
/// terminal retires it).
|
|
@@ -2397,7 +2627,7 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
2397
2627
|
term: []const u8,
|
|
2398
2628
|
argv: []const []const u8,
|
|
2399
2629
|
) void {
|
|
2400
|
-
if (key.len > 0 and findPty(key) != null) {
|
|
2630
|
+
if (key.len > 0 and (findPty(key) != null or fileStreamOccupiesKey(key))) {
|
|
2401
2631
|
// The rejection is STAGED (delivered a later frame), so its
|
|
2402
2632
|
// key must be self-contained: the wire key points into this
|
|
2403
2633
|
// dispatch's command buffer, gone by delivery, so intern
|
|
@@ -2510,6 +2740,10 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
2510
2740
|
done_tag: u8,
|
|
2511
2741
|
err_tag: u8,
|
|
2512
2742
|
) ?usize {
|
|
2743
|
+
if (fileStreamOccupiesKey(key)) {
|
|
2744
|
+
fx.stageLoopMsg(msgFromTagStaticBytes(err_tag, "rejected"));
|
|
2745
|
+
return null;
|
|
2746
|
+
}
|
|
2513
2747
|
const index = blk: {
|
|
2514
2748
|
if (key.len > 0) {
|
|
2515
2749
|
if (findDb(key)) |existing| {
|
|
@@ -2610,6 +2844,17 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
2610
2844
|
fx.cancel(spawn_key_base + index);
|
|
2611
2845
|
return;
|
|
2612
2846
|
}
|
|
2847
|
+
if (findFileStream(key)) |index| {
|
|
2848
|
+
if (!file_streams[index].sink) {
|
|
2849
|
+
// Read streams are file-style: cancel is silent and the
|
|
2850
|
+
// bridge entry retires immediately. Sinks remain loud.
|
|
2851
|
+
file_streams[index].used = false;
|
|
2852
|
+
} else {
|
|
2853
|
+
file_streams[index].cancelling = true;
|
|
2854
|
+
}
|
|
2855
|
+
fx.cancel(file_stream_key_base + index);
|
|
2856
|
+
return;
|
|
2857
|
+
}
|
|
2613
2858
|
if (findDelay(key)) |index| {
|
|
2614
2859
|
fx.cancelTimer(delay_key_base + index);
|
|
2615
2860
|
delays[index].used = false;
|
|
@@ -2651,6 +2896,7 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
2651
2896
|
ok_void: bool,
|
|
2652
2897
|
pool: RequestPool,
|
|
2653
2898
|
) ?u64 {
|
|
2899
|
+
if (fileStreamOccupiesKey(key)) return null;
|
|
2654
2900
|
const index = blk: {
|
|
2655
2901
|
if (key.len > 0) {
|
|
2656
2902
|
if (findRequest(key)) |existing| {
|
|
@@ -2818,7 +3064,7 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
2818
3064
|
max_pending: u8,
|
|
2819
3065
|
payload: []const u8,
|
|
2820
3066
|
) void {
|
|
2821
|
-
if (key.len > 0 and findRequest(key) != null) {
|
|
3067
|
+
if (key.len > 0 and (findRequest(key) != null or fileStreamOccupiesKey(key))) {
|
|
2822
3068
|
stageRequestRejected(fx, err_tag);
|
|
2823
3069
|
return;
|
|
2824
3070
|
}
|
|
@@ -2950,11 +3196,35 @@ pub fn TsCoreHost(comptime core: type) type {
|
|
|
2950
3196
|
if (tags.dropped) return swallowedMsg(tags.err_tag);
|
|
2951
3197
|
if (result.outcome == .ok) {
|
|
2952
3198
|
if (result.op == .read) return msgFromTagBytes(tags.ok_tag, result.bytes);
|
|
3199
|
+
if (result.op == .stat) return msgFromTagFileStat(tags.ok_tag, result);
|
|
2953
3200
|
return msgFromTagVoid(tags.ok_tag);
|
|
2954
3201
|
}
|
|
2955
3202
|
return msgFromTagBytes(tags.err_tag, @tagName(result.outcome));
|
|
2956
3203
|
}
|
|
2957
3204
|
|
|
3205
|
+
fn msgFromTagFileStat(tag: u8, result: runtime_effects.EffectFileResult) Msg {
|
|
3206
|
+
inline for (msg_arms, 0..) |arm, index| {
|
|
3207
|
+
if (tag == index) {
|
|
3208
|
+
const info = @typeInfo(arm.type);
|
|
3209
|
+
if (comptime info == .@"struct" and info.@"struct".fields.len == 3) {
|
|
3210
|
+
var payload: arm.type = undefined;
|
|
3211
|
+
inline for (info.@"struct".fields) |field| {
|
|
3212
|
+
if (comptime std.mem.eql(u8, field.name, "exists") and field.type == bool) {
|
|
3213
|
+
@field(payload, field.name) = result.exists;
|
|
3214
|
+
} else if (comptime std.mem.eql(u8, field.name, "size") and (field.type == i64 or field.type == u64 or field.type == f64)) {
|
|
3215
|
+
@field(payload, field.name) = if (comptime field.type == f64) @floatFromInt(result.total) else @intCast(result.total);
|
|
3216
|
+
} else if (comptime std.mem.eql(u8, field.name, "mtimeMs") and (field.type == i64 or field.type == u64 or field.type == f64)) {
|
|
3217
|
+
@field(payload, field.name) = if (comptime field.type == f64) @floatFromInt(result.mtime_ms) else @intCast(result.mtime_ms);
|
|
3218
|
+
} else @panic("ts core host: stat_file ok arm has the wrong fields");
|
|
3219
|
+
}
|
|
3220
|
+
return @unionInit(Msg, arm.name, payload);
|
|
3221
|
+
}
|
|
3222
|
+
@panic("ts core host: stat_file ok arm must be { exists, size, mtimeMs }");
|
|
3223
|
+
}
|
|
3224
|
+
}
|
|
3225
|
+
@panic("ts core host: stat_file ok tag is outside Msg");
|
|
3226
|
+
}
|
|
3227
|
+
|
|
2958
3228
|
/// `ResponseMsgFn` for fetch: an `.ok` un-truncated response
|
|
2959
3229
|
/// routes the ok arm as `{ status, body }`; everything else —
|
|
2960
3230
|
/// truncation included, so a cut body never parses as whole —
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//! Bridge coverage for `TsCoreHost` against a hand-written core that
|
|
2
2
|
//! replicates the transpiler's emitted ABI (rt kernel, commit walker,
|
|
3
3
|
//! `UpdateResult`/`InitResult`, wire-encoded commands and
|
|
4
|
-
//! subscriptions). Hand-encoding the wire records here pins the
|
|
4
|
+
//! subscriptions). Hand-encoding the wire records here pins the v5
|
|
5
5
|
//! byte layout independently of the rt builders that normally produce
|
|
6
6
|
//! it; the transpiled-fixture end-to-end suite (tests/ts-core) drives
|
|
7
7
|
//! the same bridge with genuinely emitted code through a full UiApp.
|
|
@@ -12,6 +12,7 @@ const std = @import("std");
|
|
|
12
12
|
const effects_mod = @import("effects.zig");
|
|
13
13
|
const runtime_clock = @import("clock.zig");
|
|
14
14
|
const ts_core_host = @import("ts_core_host.zig");
|
|
15
|
+
const platform = @import("../platform/root.zig");
|
|
15
16
|
|
|
16
17
|
// ------------------------------------------------------ the mini core
|
|
17
18
|
//
|
|
@@ -335,6 +336,10 @@ const mini_core = struct {
|
|
|
335
336
|
arm_full_db_live_set, // 99: fill all relational slots with live keys
|
|
336
337
|
replace_full_db_live_set, // 100: replace them with one disjoint key
|
|
337
338
|
malformed_credential, // 101: reserved request with an invalid inner record
|
|
339
|
+
open_save_sink, // 102: write_file_stream "save" -> wrote/failed
|
|
340
|
+
write_save_chunk, // 103: write_file_chunk "save" -> wrote/failed
|
|
341
|
+
close_save_sink, // 104: write_file_close "save" -> wrote/failed
|
|
342
|
+
dock_on, // 105: dock_presence true
|
|
338
343
|
};
|
|
339
344
|
|
|
340
345
|
const stream_fill_keys = [_][]const u8{
|
|
@@ -485,6 +490,9 @@ const mini_core = struct {
|
|
|
485
490
|
return .{ .model = out, .cmd = "" };
|
|
486
491
|
},
|
|
487
492
|
.save_file => return .{ .model = model, .cmd = cmdWriteFile("save", 12, 8, "notes.bin", model.status) },
|
|
493
|
+
.open_save_sink => return .{ .model = model, .cmd = cmdWriteFileStream("save", 12, 8, "notes.bin") },
|
|
494
|
+
.write_save_chunk => return .{ .model = model, .cmd = cmdWriteFileChunk("save", 12, 8, "next") },
|
|
495
|
+
.close_save_sink => return .{ .model = model, .cmd = cmdWriteFileClose("save", 12, 8) },
|
|
488
496
|
.wrote => {
|
|
489
497
|
const out = frameCreate(model.*);
|
|
490
498
|
out.saved = true;
|
|
@@ -680,6 +688,7 @@ const mini_core = struct {
|
|
|
680
688
|
.open_win => return .{ .model = model, .cmd = cmdWindowShow("player") },
|
|
681
689
|
.hide_win => return .{ .model = model, .cmd = cmdWindowHide("player") },
|
|
682
690
|
.dock_off => return .{ .model = model, .cmd = cmdDockPresence(false) },
|
|
691
|
+
.dock_on => return .{ .model = model, .cmd = cmdDockPresence(true) },
|
|
683
692
|
.quit_app => return .{ .model = model, .cmd = cmdQuitApp() },
|
|
684
693
|
.open_chan => return .{ .model = model, .cmd = cmdChannelOpen(41, 47) },
|
|
685
694
|
.close_chan => return .{ .model = model, .cmd = cmdChannelClose(41) },
|
|
@@ -990,6 +999,26 @@ const mini_core = struct {
|
|
|
990
999
|
return out;
|
|
991
1000
|
}
|
|
992
1001
|
|
|
1002
|
+
fn cmdWriteFileStream(key: []const u8, ok_tag: u8, err_tag: u8, file_path: []const u8) []const u8 {
|
|
1003
|
+
const out = rt.frameAlloc(u8, 4 + key.len + 4 + file_path.len);
|
|
1004
|
+
var off = writeRoutedHead(out, 0x2E, key, ok_tag, err_tag);
|
|
1005
|
+
off = writeLongBytes(out, off, file_path);
|
|
1006
|
+
return out;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
fn cmdWriteFileChunk(key: []const u8, ok_tag: u8, err_tag: u8, bytes: []const u8) []const u8 {
|
|
1010
|
+
const out = rt.frameAlloc(u8, 4 + key.len + 4 + bytes.len);
|
|
1011
|
+
var off = writeRoutedHead(out, 0x2F, key, ok_tag, err_tag);
|
|
1012
|
+
off = writeLongBytes(out, off, bytes);
|
|
1013
|
+
return out;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
fn cmdWriteFileClose(key: []const u8, ok_tag: u8, err_tag: u8) []const u8 {
|
|
1017
|
+
const out = rt.frameAlloc(u8, 4 + key.len);
|
|
1018
|
+
_ = writeRoutedHead(out, 0x30, key, ok_tag, err_tag);
|
|
1019
|
+
return out;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
993
1022
|
fn cmdFetch(key: []const u8, ok_tag: u8, err_tag: u8, method: u8, timeout_ms: u32, url: []const u8, headers: []const FetchHeader, body: []const u8) []const u8 {
|
|
994
1023
|
var header_bytes: usize = 0;
|
|
995
1024
|
for (headers) |h| header_bytes += 1 + h.name.len + 4 + h.value.len;
|
|
@@ -1758,6 +1787,74 @@ test "write_file routes its payload-less ok arm and err reasons" {
|
|
|
1758
1787
|
try std.testing.expectEqualStrings("io_failed", Host.model().last_err);
|
|
1759
1788
|
}
|
|
1760
1789
|
|
|
1790
|
+
test "file streams and buffered effects cannot share a public key" {
|
|
1791
|
+
const fx = freshChannel();
|
|
1792
|
+
defer fx.deinit();
|
|
1793
|
+
Host.init(fx);
|
|
1794
|
+
|
|
1795
|
+
// The buffered effect owns "save", so the sink refuses without parking a
|
|
1796
|
+
// second engine key that would make Cmd.cancel ambiguous.
|
|
1797
|
+
Host.dispatch(fx, .save_file);
|
|
1798
|
+
Host.dispatch(fx, .open_save_sink);
|
|
1799
|
+
Host.drain(fx);
|
|
1800
|
+
try std.testing.expectEqual(@as(i64, 1), Host.model().errs);
|
|
1801
|
+
try std.testing.expectEqualStrings("rejected", Host.model().last_err);
|
|
1802
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingFileCount());
|
|
1803
|
+
try std.testing.expectError(error.EffectNotFound, fx.acknowledgeFakeFileStreamOpen(ts_core_host.file_stream_key_base));
|
|
1804
|
+
|
|
1805
|
+
Host.dispatch(fx, .drop_save);
|
|
1806
|
+
Host.drain(fx);
|
|
1807
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingFileCount());
|
|
1808
|
+
|
|
1809
|
+
// The same invariant holds in the opposite order. The rejected buffered
|
|
1810
|
+
// write does not hide the live sink, and cancel reaches that sink loudly.
|
|
1811
|
+
Host.dispatch(fx, .open_save_sink);
|
|
1812
|
+
try fx.acknowledgeFakeFileStreamOpen(ts_core_host.file_stream_key_base);
|
|
1813
|
+
try fx.feedFileResultDetailed(.{ .key = ts_core_host.file_stream_key_base, .op = .write_stream_open, .outcome = .ok });
|
|
1814
|
+
Host.drain(fx);
|
|
1815
|
+
Host.dispatch(fx, .save_file);
|
|
1816
|
+
Host.drain(fx);
|
|
1817
|
+
try std.testing.expectEqual(@as(i64, 2), Host.model().errs);
|
|
1818
|
+
try std.testing.expectEqualStrings("rejected", Host.model().last_err);
|
|
1819
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingFileCount());
|
|
1820
|
+
|
|
1821
|
+
Host.dispatch(fx, .drop_save);
|
|
1822
|
+
Host.drain(fx);
|
|
1823
|
+
try std.testing.expectEqual(@as(i64, 3), Host.model().errs);
|
|
1824
|
+
try std.testing.expectEqualStrings("cancelled", Host.model().last_err);
|
|
1825
|
+
try std.testing.expectError(error.EffectNotFound, fx.acknowledgeFakeFileStreamOpen(ts_core_host.file_stream_key_base));
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
test "a cancelling file sink rejects later chunk and close commands without orphaning callbacks" {
|
|
1829
|
+
const fx = freshChannel();
|
|
1830
|
+
defer fx.deinit();
|
|
1831
|
+
Host.init(fx);
|
|
1832
|
+
|
|
1833
|
+
Host.dispatch(fx, .open_save_sink);
|
|
1834
|
+
try fx.acknowledgeFakeFileStreamOpen(ts_core_host.file_stream_key_base);
|
|
1835
|
+
try fx.feedFileResultDetailed(.{ .key = ts_core_host.file_stream_key_base, .op = .write_stream_open, .outcome = .ok });
|
|
1836
|
+
Host.drain(fx);
|
|
1837
|
+
|
|
1838
|
+
// Cancel keeps the bridge entry until the engine's loud terminal arrives.
|
|
1839
|
+
// A command in that window must reject locally instead of overwriting the
|
|
1840
|
+
// cancellation route and queuing a second callback against the same entry.
|
|
1841
|
+
Host.dispatch(fx, .drop_save);
|
|
1842
|
+
Host.dispatch(fx, .write_save_chunk);
|
|
1843
|
+
Host.drain(fx);
|
|
1844
|
+
try std.testing.expectEqual(@as(i64, 2), Host.model().errs);
|
|
1845
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingFileCount());
|
|
1846
|
+
|
|
1847
|
+
Host.dispatch(fx, .open_save_sink);
|
|
1848
|
+
try fx.acknowledgeFakeFileStreamOpen(ts_core_host.file_stream_key_base);
|
|
1849
|
+
try fx.feedFileResultDetailed(.{ .key = ts_core_host.file_stream_key_base, .op = .write_stream_open, .outcome = .ok });
|
|
1850
|
+
Host.drain(fx);
|
|
1851
|
+
Host.dispatch(fx, .drop_save);
|
|
1852
|
+
Host.dispatch(fx, .close_save_sink);
|
|
1853
|
+
Host.drain(fx);
|
|
1854
|
+
try std.testing.expectEqual(@as(i64, 4), Host.model().errs);
|
|
1855
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingFileCount());
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1761
1858
|
test "fetch decodes the wire record whole and routes the { status, body } ok arm by field type" {
|
|
1762
1859
|
const fx = freshChannel();
|
|
1763
1860
|
defer fx.deinit();
|
|
@@ -2748,6 +2845,50 @@ test "window verbs bridge to the effects channel's label-addressed verbs" {
|
|
|
2748
2845
|
try std.testing.expectEqual(boot_pending, fx.pendingHostCount());
|
|
2749
2846
|
}
|
|
2750
2847
|
|
|
2848
|
+
test "an accessory launch composes with a TypeScript dock-presence promotion" {
|
|
2849
|
+
var null_platform = platform.NullPlatform.initWithOptions(.{}, .system, .{
|
|
2850
|
+
.app_name = "Menu Bar",
|
|
2851
|
+
.dock_visible = false,
|
|
2852
|
+
});
|
|
2853
|
+
try std.testing.expect(!null_platform.dock_visible);
|
|
2854
|
+
|
|
2855
|
+
const Actions = struct {
|
|
2856
|
+
fn window(_: *anyopaque, _: []const u8) bool {
|
|
2857
|
+
return true;
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
fn dock(context: *anyopaque, visible: bool) bool {
|
|
2861
|
+
const host: *platform.NullPlatform = @ptrCast(@alignCast(context));
|
|
2862
|
+
host.platform().services.setDockPresence(visible) catch return false;
|
|
2863
|
+
return true;
|
|
2864
|
+
}
|
|
2865
|
+
|
|
2866
|
+
fn quit(_: *anyopaque) bool {
|
|
2867
|
+
return true;
|
|
2868
|
+
}
|
|
2869
|
+
};
|
|
2870
|
+
|
|
2871
|
+
const fx = freshChannel();
|
|
2872
|
+
defer fx.deinit();
|
|
2873
|
+
Host.init(fx);
|
|
2874
|
+
fx.bindWindowActions(.{
|
|
2875
|
+
.context = &null_platform,
|
|
2876
|
+
.close_fn = Actions.window,
|
|
2877
|
+
.minimize_fn = Actions.window,
|
|
2878
|
+
.hide_fn = Actions.window,
|
|
2879
|
+
.show_fn = Actions.window,
|
|
2880
|
+
.dock_presence_fn = Actions.dock,
|
|
2881
|
+
.quit_fn = Actions.quit,
|
|
2882
|
+
});
|
|
2883
|
+
fx.executor = .real;
|
|
2884
|
+
|
|
2885
|
+
Host.dispatch(fx, .dock_on);
|
|
2886
|
+
try std.testing.expect(fx.windowActionState().dock_visible);
|
|
2887
|
+
try std.testing.expectEqual(@as(u32, 1), fx.windowActionState().dock_presence_count);
|
|
2888
|
+
try std.testing.expect(null_platform.dock_visible);
|
|
2889
|
+
try std.testing.expectEqual(@as(u32, 1), null_platform.dock_presence_count);
|
|
2890
|
+
}
|
|
2891
|
+
|
|
2751
2892
|
test "a channel opens, posts route the five-field arm by name, and close retires the key" {
|
|
2752
2893
|
const fx = freshChannel();
|
|
2753
2894
|
defer fx.deinit();
|