@native-sdk/cli 0.8.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.zig +905 -61
- package/build.zig +674 -373
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +6 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +455 -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/npm_static_spike.mjs +64 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +77 -6
- package/packages/core/scripts/run_external_service_compiler.mjs +240 -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 +214 -2
- package/packages/core/sdk/core.ts +715 -42
- package/packages/core/sdk/events.d.ts +50 -0
- package/packages/core/sdk/events.ts +75 -0
- package/packages/core/src/checker.ts +528 -15
- package/packages/core/src/cli.ts +143 -3
- package/packages/core/src/contract.ts +26 -5
- package/packages/core/src/devhost.ts +1849 -18
- package/packages/core/src/devhost_journal.mjs +181 -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 +84 -18
- package/packages/core/src/frontend.ts +204 -34
- 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/core/SKILL.md +4 -2
- package/skill-data/core/references/project-anatomy.md +3 -2
- package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
- package/skill-data/native-ui/SKILL.md +55 -8
- package/skill-data/ts-core/SKILL.md +92 -40
- package/skill-data/ts-services/SKILL.md +126 -0
- package/skill-data/ts-services/references/service-surface.md +603 -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 +104 -4
- package/src/app_runner/ts_core_main.zig +268 -4
- package/src/automation/snapshot.zig +23 -5
- package/src/embed/app_exports.zig +11 -1
- package/src/embed/c_api.zig +48 -2
- package/src/embed/conversions.zig +4 -5
- package/src/embed/host.zig +115 -1
- package/src/embed/root.zig +7 -0
- package/src/embed/tests.zig +213 -0
- package/src/embed/types.zig +51 -0
- package/src/embed/ui_host.zig +121 -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 +1 -1
- package/src/platform/linux/gtk_host.c +89 -17
- package/src/platform/linux/gtk_host.h +3 -0
- package/src/platform/linux/root.zig +41 -18
- package/src/platform/macos/appkit_host.h +26 -3
- package/src/platform/macos/appkit_host.m +1051 -129
- package/src/platform/macos/capture_info_plist.c +25 -0
- package/src/platform/macos/cef_host.mm +270 -36
- package/src/platform/macos/root.zig +312 -34
- package/src/platform/null_platform.zig +281 -19
- package/src/platform/null_platform_tests.zig +74 -0
- package/src/platform/root.zig +16 -0
- package/src/platform/types.zig +279 -15
- package/src/platform/windows/root.zig +243 -21
- package/src/platform/windows/webview2_host.cpp +464 -46
- 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 +34 -0
- package/src/primitives/app_manifest/validation.zig +19 -1
- package/src/primitives/canvas/code_tests.zig +9 -9
- package/src/primitives/canvas/events.zig +12 -11
- package/src/primitives/canvas/frame.zig +44 -9
- package/src/primitives/canvas/icons/mic.svg +1 -0
- package/src/primitives/canvas/icons.zig +2 -0
- package/src/primitives/canvas/root.zig +8 -0
- package/src/primitives/canvas/text_span_tests.zig +39 -0
- package/src/primitives/canvas/ui.zig +23 -4
- package/src/primitives/canvas/ui_markup.zig +15 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
- package/src/primitives/canvas/ui_markup_tests.zig +5 -0
- package/src/primitives/canvas/ui_markup_view.zig +9 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
- package/src/primitives/canvas/ui_schema.zig +19 -10
- package/src/primitives/canvas/ui_schema_tests.zig +5 -3
- package/src/primitives/canvas/ui_tests.zig +18 -4
- package/src/primitives/canvas/widget_invalidation.zig +9 -2
- package/src/primitives/canvas/widget_render.zig +296 -114
- package/src/primitives/canvas/widget_runtime_tests.zig +133 -0
- package/src/primitives/canvas/widget_text_input.zig +10 -10
- package/src/primitives/canvas/widget_tree.zig +1 -1
- package/src/primitives/canvas/widgets.zig +29 -5
- package/src/root.zig +56 -0
- package/src/runtime/api.zig +11 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/automation_widget_dispatch.zig +1 -0
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/bridge_permission_tests.zig +23 -2
- package/src/runtime/bridge_responses.zig +3 -1
- package/src/runtime/canvas_frame.zig +31 -13
- package/src/runtime/canvas_frame_animation_tests.zig +4 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
- package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
- package/src/runtime/canvas_widget_events.zig +69 -24
- package/src/runtime/canvas_widget_runtime.zig +101 -6
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
- package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
- package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
- package/src/runtime/canvas_widget_state.zig +6 -1
- package/src/runtime/canvas_widget_text_tests.zig +112 -3
- package/src/runtime/clock.zig +13 -1
- package/src/runtime/core.zig +133 -1
- package/src/runtime/credentials_store.zig +115 -0
- package/src/runtime/effects.zig +2568 -75
- package/src/runtime/effects_audio_capture_tests.zig +251 -0
- package/src/runtime/effects_credentials_tests.zig +332 -0
- package/src/runtime/effects_host_tests.zig +208 -1
- package/src/runtime/effects_relational_tests.zig +314 -0
- package/src/runtime/effects_store_tests.zig +211 -0
- package/src/runtime/flow.zig +14 -1
- package/src/runtime/gpu_surface_events.zig +6 -1
- package/src/runtime/native_command_event_tests.zig +42 -0
- package/src/runtime/persist_store.zig +666 -0
- package/src/runtime/record_store.zig +788 -0
- package/src/runtime/relational_store.zig +854 -0
- package/src/runtime/root.zig +52 -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 +1 -1
- package/src/runtime/session_journal.zig +102 -0
- package/src/runtime/session_record.zig +177 -0
- package/src/runtime/session_replay.zig +109 -4
- 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 +6 -0
- package/src/runtime/system_services.zig +49 -10
- package/src/runtime/tests.zig +5 -0
- package/src/runtime/ts_core_host.zig +1189 -118
- package/src/runtime/ts_core_host_tests.zig +638 -11
- package/src/runtime/ts_ui_app.zig +537 -1
- package/src/runtime/ui_app.zig +160 -19
- package/src/runtime/ui_app_tests.zig +203 -5
- package/src/runtime/validation.zig +22 -0
- package/src/runtime/view.zig +11 -0
- package/src/runtime/view_widget_scroll.zig +56 -5
- package/src/runtime/view_widget_text.zig +24 -5
- package/src/runtime/view_widget_tree.zig +1 -1
- 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 +1248 -2
- package/src/tooling/package.zig +953 -6
- package/src/tooling/raw_manifest.zig +65 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +216 -4
- package/src/tooling/ts_core.zig +283 -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 +414 -23
- 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
|
@@ -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 v4
|
|
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.
|
|
@@ -17,7 +17,7 @@ const ts_core_host = @import("ts_core_host.zig");
|
|
|
17
17
|
//
|
|
18
18
|
// The emitted-core ABI in miniature: a two-region kernel, a poller
|
|
19
19
|
// model, and an update that exercises every wire record. Cmd/Sub bytes
|
|
20
|
-
// are hand-encoded to the documented
|
|
20
|
+
// are hand-encoded to the documented v4 layout. Polling starts OFF so
|
|
21
21
|
// the real-executor tests below (which bind no platform timer service)
|
|
22
22
|
// never arm a timer; the e2e suite covers boot-time subscriptions
|
|
23
23
|
// through a full UiApp with live null-platform services.
|
|
@@ -70,6 +70,8 @@ const mini_core = struct {
|
|
|
70
70
|
/// The channel event states, shuffled off the engine order for the
|
|
71
71
|
/// same by-NAME matching proof.
|
|
72
72
|
pub const ChannelState = enum { rejected, data, closed };
|
|
73
|
+
pub const CaptureState = enum { data, stopped, started, rejected, failed };
|
|
74
|
+
pub const CaptureSource = enum { system, microphone };
|
|
73
75
|
|
|
74
76
|
/// The image outcome states the mixed-rejection tests observe,
|
|
75
77
|
/// shuffled off the engine order like the other two.
|
|
@@ -115,6 +117,18 @@ const mini_core = struct {
|
|
|
115
117
|
chan_dropped_pending: f64,
|
|
116
118
|
chan_dropped_total: f64,
|
|
117
119
|
chan_events: i64,
|
|
120
|
+
// Native audio-capture stream mirrors.
|
|
121
|
+
capture_state: CaptureState,
|
|
122
|
+
capture_source: CaptureSource,
|
|
123
|
+
capture_key: f64,
|
|
124
|
+
capture_rate: f64,
|
|
125
|
+
capture_channels: f64,
|
|
126
|
+
capture_timestamp_ms: f64,
|
|
127
|
+
capture_frames: f64,
|
|
128
|
+
capture_pcm: []const u8,
|
|
129
|
+
capture_dropped_pending: f64,
|
|
130
|
+
capture_dropped_total: f64,
|
|
131
|
+
capture_events: i64,
|
|
118
132
|
// Image event mirrors.
|
|
119
133
|
img_state: ImageState,
|
|
120
134
|
img_events: i64,
|
|
@@ -145,6 +159,8 @@ const mini_core = struct {
|
|
|
145
159
|
// Unsigned-class mirrors (u64-classed arm routing).
|
|
146
160
|
ustamp_ms: u64,
|
|
147
161
|
ucode: u64,
|
|
162
|
+
db_live: bool,
|
|
163
|
+
db_live_set: u8,
|
|
148
164
|
};
|
|
149
165
|
|
|
150
166
|
pub const Msg = union(enum) {
|
|
@@ -289,10 +305,56 @@ const mini_core = struct {
|
|
|
289
305
|
uget, // 81: fetch "uget" -> ufetched/failed
|
|
290
306
|
ufetched: struct { status: u64, body: []const u8 }, // 82: fetch ok
|
|
291
307
|
// record with a u64-classed number field
|
|
308
|
+
start_capture, // 83: microphone capture key 91 -> capture_evt
|
|
309
|
+
stop_capture, // 84: stop capture key 91
|
|
310
|
+
capture_evt: struct { // 85: ten-field capture event arm
|
|
311
|
+
key: f64,
|
|
312
|
+
state: CaptureState,
|
|
313
|
+
source: CaptureSource,
|
|
314
|
+
sampleRate: f64,
|
|
315
|
+
channels: f64,
|
|
316
|
+
timestampMs: f64,
|
|
317
|
+
frames: f64,
|
|
318
|
+
pcm: []const u8,
|
|
319
|
+
droppedPending: f64,
|
|
320
|
+
droppedTotal: f64,
|
|
321
|
+
},
|
|
322
|
+
stream_get, // 86: streaming fetch "events" -> stream_line/stream_done/failed
|
|
323
|
+
stream_line: []const u8, // 87: one complete response line
|
|
324
|
+
stream_done: i64, // 88: terminal HTTP status
|
|
325
|
+
stop_stream, // 89: cancel "events" (loud -> failed "cancelled")
|
|
326
|
+
dup_stream, // 90: a second live "events" stream is rejected
|
|
327
|
+
stream_over_get, // 91: streaming fetch collides with buffered fetch "get"
|
|
328
|
+
get_over_stream, // 92: buffered fetch collides with streaming fetch "events"
|
|
329
|
+
fill_streams, // 93: seventeen distinct streams exceed the bridge table
|
|
330
|
+
hide_win, // 94: window_hide "player"
|
|
331
|
+
dock_off, // 95: dock_presence false
|
|
332
|
+
arm_db_live, // 96: install a live query under wire key "shared-db"
|
|
333
|
+
query_over_db_live, // 97: a one-shot query collides with that live key
|
|
334
|
+
stop_db_live_with_cancel, // 98: remove the Sub while Cmd.cancel names its key
|
|
335
|
+
arm_full_db_live_set, // 99: fill all relational slots with live keys
|
|
336
|
+
replace_full_db_live_set, // 100: replace them with one disjoint key
|
|
337
|
+
malformed_credential, // 101: reserved request with an invalid inner record
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const stream_fill_keys = [_][]const u8{
|
|
341
|
+
"fill-00", "fill-01", "fill-02", "fill-03",
|
|
342
|
+
"fill-04", "fill-05", "fill-06", "fill-07",
|
|
343
|
+
"fill-08", "fill-09", "fill-10", "fill-11",
|
|
344
|
+
"fill-12", "fill-13", "fill-14", "fill-15",
|
|
345
|
+
"fill-16",
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
const db_live_set_a_keys = [_][]const u8{
|
|
349
|
+
"old-db-00", "old-db-01", "old-db-02", "old-db-03",
|
|
350
|
+
"old-db-04", "old-db-05", "old-db-06", "old-db-07",
|
|
351
|
+
"old-db-08", "old-db-09", "old-db-10", "old-db-11",
|
|
352
|
+
"old-db-12", "old-db-13", "old-db-14", "old-db-15",
|
|
292
353
|
};
|
|
293
354
|
|
|
294
355
|
pub const InitResult = struct { model: *const Model, cmd: []const u8 };
|
|
295
356
|
pub const UpdateResult = struct { model: *const Model, cmd: []const u8 };
|
|
357
|
+
var initial_model_calls: usize = 0;
|
|
296
358
|
|
|
297
359
|
fn frameCreate(value: Model) *Model {
|
|
298
360
|
const slot = rt.frameAlloc(Model, 1);
|
|
@@ -301,6 +363,7 @@ const mini_core = struct {
|
|
|
301
363
|
}
|
|
302
364
|
|
|
303
365
|
pub fn initialModel() InitResult {
|
|
366
|
+
initial_model_calls += 1;
|
|
304
367
|
return .{
|
|
305
368
|
.model = frameCreate(.{
|
|
306
369
|
.polling = false,
|
|
@@ -330,6 +393,17 @@ const mini_core = struct {
|
|
|
330
393
|
.chan_dropped_pending = -1,
|
|
331
394
|
.chan_dropped_total = -1,
|
|
332
395
|
.chan_events = 0,
|
|
396
|
+
.capture_state = .stopped,
|
|
397
|
+
.capture_source = .microphone,
|
|
398
|
+
.capture_key = -1,
|
|
399
|
+
.capture_rate = 0,
|
|
400
|
+
.capture_channels = 0,
|
|
401
|
+
.capture_timestamp_ms = 0,
|
|
402
|
+
.capture_frames = 0,
|
|
403
|
+
.capture_pcm = "",
|
|
404
|
+
.capture_dropped_pending = 0,
|
|
405
|
+
.capture_dropped_total = 0,
|
|
406
|
+
.capture_events = 0,
|
|
333
407
|
.img_state = .loaded,
|
|
334
408
|
.img_events = 0,
|
|
335
409
|
.pty_key = "",
|
|
@@ -353,11 +427,17 @@ const mini_core = struct {
|
|
|
353
427
|
.video2_events = 0,
|
|
354
428
|
.ustamp_ms = 0,
|
|
355
429
|
.ucode = 0,
|
|
430
|
+
.db_live = false,
|
|
431
|
+
.db_live_set = 0,
|
|
356
432
|
}),
|
|
357
433
|
.cmd = cmdRequest("status.read", "status", 7, 8, "boot"),
|
|
358
434
|
};
|
|
359
435
|
}
|
|
360
436
|
|
|
437
|
+
pub fn bootCommand() []const u8 {
|
|
438
|
+
return cmdRequest("status.read", "status", 7, 8, "boot");
|
|
439
|
+
}
|
|
440
|
+
|
|
361
441
|
pub fn update(model: *const Model, msg: Msg) UpdateResult {
|
|
362
442
|
switch (msg) {
|
|
363
443
|
.toggle => {
|
|
@@ -371,6 +451,7 @@ const mini_core = struct {
|
|
|
371
451
|
return .{ .model = out, .cmd = "" };
|
|
372
452
|
},
|
|
373
453
|
.refresh => return .{ .model = model, .cmd = cmdRequest("status.read", "status", 7, 8, model.status) },
|
|
454
|
+
.malformed_credential => return .{ .model = model, .cmd = cmdRequest("core.credentials.get", "bad-credential", 7, 8, "") },
|
|
374
455
|
.pair => {
|
|
375
456
|
const first = cmdRequest("a.read", "", 7, 8, "1");
|
|
376
457
|
const second = cmdRequest("b.read", "", 7, 8, "2");
|
|
@@ -457,6 +538,93 @@ const mini_core = struct {
|
|
|
457
538
|
out.status = response.body;
|
|
458
539
|
return .{ .model = out, .cmd = "" };
|
|
459
540
|
},
|
|
541
|
+
.stream_get => {
|
|
542
|
+
const headers = [_]FetchHeader{.{ .name = "accept", .value = "text/event-stream" }};
|
|
543
|
+
return .{ .model = model, .cmd = cmdFetchStream(
|
|
544
|
+
"events",
|
|
545
|
+
@intFromEnum(@as(std.meta.Tag(Msg), .stream_line)),
|
|
546
|
+
@intFromEnum(@as(std.meta.Tag(Msg), .stream_done)),
|
|
547
|
+
@intFromEnum(@as(std.meta.Tag(Msg), .failed)),
|
|
548
|
+
1,
|
|
549
|
+
60_000,
|
|
550
|
+
65_536,
|
|
551
|
+
"https://status.test/events",
|
|
552
|
+
&headers,
|
|
553
|
+
"ask",
|
|
554
|
+
) };
|
|
555
|
+
},
|
|
556
|
+
.stream_line => |line| {
|
|
557
|
+
const out = frameCreate(model.*);
|
|
558
|
+
out.line_count = model.line_count + 1;
|
|
559
|
+
out.last_line = line;
|
|
560
|
+
return .{ .model = out, .cmd = "" };
|
|
561
|
+
},
|
|
562
|
+
.stream_done => |status| {
|
|
563
|
+
const out = frameCreate(model.*);
|
|
564
|
+
out.code = status;
|
|
565
|
+
return .{ .model = out, .cmd = "" };
|
|
566
|
+
},
|
|
567
|
+
.stop_stream => return .{ .model = model, .cmd = cmdCancel("events") },
|
|
568
|
+
.dup_stream => return .{ .model = model, .cmd = cmdFetchStream(
|
|
569
|
+
"events",
|
|
570
|
+
@intFromEnum(@as(std.meta.Tag(Msg), .stream_line)),
|
|
571
|
+
@intFromEnum(@as(std.meta.Tag(Msg), .stream_done)),
|
|
572
|
+
@intFromEnum(@as(std.meta.Tag(Msg), .failed)),
|
|
573
|
+
0,
|
|
574
|
+
0,
|
|
575
|
+
0,
|
|
576
|
+
"https://status.test/other",
|
|
577
|
+
&.{},
|
|
578
|
+
"",
|
|
579
|
+
) },
|
|
580
|
+
.stream_over_get => return .{ .model = model, .cmd = cmdFetchStream(
|
|
581
|
+
"get",
|
|
582
|
+
@intFromEnum(@as(std.meta.Tag(Msg), .stream_line)),
|
|
583
|
+
@intFromEnum(@as(std.meta.Tag(Msg), .stream_done)),
|
|
584
|
+
@intFromEnum(@as(std.meta.Tag(Msg), .failed)),
|
|
585
|
+
0,
|
|
586
|
+
0,
|
|
587
|
+
0,
|
|
588
|
+
"https://status.test/collision",
|
|
589
|
+
&.{},
|
|
590
|
+
"",
|
|
591
|
+
) },
|
|
592
|
+
.get_over_stream => return .{ .model = model, .cmd = cmdFetch(
|
|
593
|
+
"events",
|
|
594
|
+
@intFromEnum(@as(std.meta.Tag(Msg), .fetched)),
|
|
595
|
+
@intFromEnum(@as(std.meta.Tag(Msg), .failed)),
|
|
596
|
+
0,
|
|
597
|
+
0,
|
|
598
|
+
"https://status.test/collision",
|
|
599
|
+
&.{},
|
|
600
|
+
"",
|
|
601
|
+
) },
|
|
602
|
+
.fill_streams => {
|
|
603
|
+
var commands: [stream_fill_keys.len][]const u8 = undefined;
|
|
604
|
+
var total: usize = 0;
|
|
605
|
+
for (&commands, stream_fill_keys) |*command, key| {
|
|
606
|
+
command.* = cmdFetchStream(
|
|
607
|
+
key,
|
|
608
|
+
@intFromEnum(@as(std.meta.Tag(Msg), .stream_line)),
|
|
609
|
+
@intFromEnum(@as(std.meta.Tag(Msg), .stream_done)),
|
|
610
|
+
@intFromEnum(@as(std.meta.Tag(Msg), .failed)),
|
|
611
|
+
0,
|
|
612
|
+
0,
|
|
613
|
+
0,
|
|
614
|
+
"https://status.test/fill",
|
|
615
|
+
&.{},
|
|
616
|
+
"",
|
|
617
|
+
);
|
|
618
|
+
total += command.len;
|
|
619
|
+
}
|
|
620
|
+
const out = rt.frameAlloc(u8, total);
|
|
621
|
+
var off: usize = 0;
|
|
622
|
+
for (commands) |command| {
|
|
623
|
+
@memcpy(out[off..][0..command.len], command);
|
|
624
|
+
off += command.len;
|
|
625
|
+
}
|
|
626
|
+
return .{ .model = model, .cmd = out };
|
|
627
|
+
},
|
|
460
628
|
.run_lines => return .{ .model = model, .cmd = cmdSpawn("job", 25, 26, 8, 0, &.{ "/bin/probe", "--fast" }, "feed me") },
|
|
461
629
|
.run_quiet => return .{ .model = model, .cmd = cmdSpawn("job", 0xFF, 26, 8, 0, &.{"/bin/quiet"}, "") },
|
|
462
630
|
.run_collect => return .{ .model = model, .cmd = cmdSpawn("job", 0xFF, 27, 8, 1, &.{ "/bin/ps", "-axo" }, "") },
|
|
@@ -510,6 +678,8 @@ const mini_core = struct {
|
|
|
510
678
|
.drop_get => return .{ .model = model, .cmd = cmdCancel("get") },
|
|
511
679
|
.drop_paste => return .{ .model = model, .cmd = cmdCancel("paste") },
|
|
512
680
|
.open_win => return .{ .model = model, .cmd = cmdWindowShow("player") },
|
|
681
|
+
.hide_win => return .{ .model = model, .cmd = cmdWindowHide("player") },
|
|
682
|
+
.dock_off => return .{ .model = model, .cmd = cmdDockPresence(false) },
|
|
513
683
|
.quit_app => return .{ .model = model, .cmd = cmdQuitApp() },
|
|
514
684
|
.open_chan => return .{ .model = model, .cmd = cmdChannelOpen(41, 47) },
|
|
515
685
|
.close_chan => return .{ .model = model, .cmd = cmdChannelClose(41) },
|
|
@@ -640,6 +810,44 @@ const mini_core = struct {
|
|
|
640
810
|
@memcpy(out[first.len..], second);
|
|
641
811
|
return .{ .model = model, .cmd = out };
|
|
642
812
|
},
|
|
813
|
+
.start_capture => return .{ .model = model, .cmd = cmdAudioCaptureStart(91, 0, 16_000, 1, @intFromEnum(@as(std.meta.Tag(Msg), .capture_evt))) },
|
|
814
|
+
.stop_capture => return .{ .model = model, .cmd = cmdAudioCaptureStop(91) },
|
|
815
|
+
.capture_evt => |event| {
|
|
816
|
+
const out = frameCreate(model.*);
|
|
817
|
+
out.capture_state = event.state;
|
|
818
|
+
out.capture_source = event.source;
|
|
819
|
+
out.capture_key = event.key;
|
|
820
|
+
out.capture_rate = event.sampleRate;
|
|
821
|
+
out.capture_channels = event.channels;
|
|
822
|
+
out.capture_timestamp_ms = event.timestampMs;
|
|
823
|
+
out.capture_frames = event.frames;
|
|
824
|
+
out.capture_pcm = event.pcm;
|
|
825
|
+
out.capture_dropped_pending = event.droppedPending;
|
|
826
|
+
out.capture_dropped_total = event.droppedTotal;
|
|
827
|
+
out.capture_events = model.capture_events + 1;
|
|
828
|
+
return .{ .model = out, .cmd = "" };
|
|
829
|
+
},
|
|
830
|
+
.arm_db_live => {
|
|
831
|
+
const out = frameCreate(model.*);
|
|
832
|
+
out.db_live = true;
|
|
833
|
+
return .{ .model = out, .cmd = "" };
|
|
834
|
+
},
|
|
835
|
+
.query_over_db_live => return .{ .model = model, .cmd = cmdDbQuery("shared-db", 7, 12, 8, "SELECT id FROM item") },
|
|
836
|
+
.stop_db_live_with_cancel => {
|
|
837
|
+
const out = frameCreate(model.*);
|
|
838
|
+
out.db_live = false;
|
|
839
|
+
return .{ .model = out, .cmd = cmdCancel("shared-db") };
|
|
840
|
+
},
|
|
841
|
+
.arm_full_db_live_set => {
|
|
842
|
+
const out = frameCreate(model.*);
|
|
843
|
+
out.db_live_set = 1;
|
|
844
|
+
return .{ .model = out, .cmd = "" };
|
|
845
|
+
},
|
|
846
|
+
.replace_full_db_live_set => {
|
|
847
|
+
const out = frameCreate(model.*);
|
|
848
|
+
out.db_live_set = 2;
|
|
849
|
+
return .{ .model = out, .cmd = "" };
|
|
850
|
+
},
|
|
643
851
|
}
|
|
644
852
|
}
|
|
645
853
|
|
|
@@ -651,8 +859,24 @@ const mini_core = struct {
|
|
|
651
859
|
}
|
|
652
860
|
|
|
653
861
|
pub fn subscriptions(model: *const Model) []const u8 {
|
|
654
|
-
if (
|
|
655
|
-
|
|
862
|
+
const timer = if (model.polling) subTimer("tick", if (model.fast) 40 else 100, 9) else "";
|
|
863
|
+
const live = if (model.db_live) subDbLive("shared-db", 7, 12, 8, "SELECT id FROM item", "item") else "";
|
|
864
|
+
const live_set = switch (model.db_live_set) {
|
|
865
|
+
1 => subDbLiveBatch(&db_live_set_a_keys),
|
|
866
|
+
2 => subDbLive("new-db", 7, 12, 8, "SELECT id FROM item", "item"),
|
|
867
|
+
else => "",
|
|
868
|
+
};
|
|
869
|
+
const parts = [_][]const u8{ timer, live, live_set };
|
|
870
|
+
var total: usize = 0;
|
|
871
|
+
for (parts) |part| total += part.len;
|
|
872
|
+
if (total == 0) return "";
|
|
873
|
+
const out = rt.frameAlloc(u8, total);
|
|
874
|
+
var at: usize = 0;
|
|
875
|
+
for (parts) |part| {
|
|
876
|
+
@memcpy(out[at..][0..part.len], part);
|
|
877
|
+
at += part.len;
|
|
878
|
+
}
|
|
879
|
+
return out;
|
|
656
880
|
}
|
|
657
881
|
|
|
658
882
|
pub fn commitModelRoot(next: *const Model) *const Model {
|
|
@@ -665,6 +889,7 @@ const mini_core = struct {
|
|
|
665
889
|
out[0].output = commitBytes(next.output);
|
|
666
890
|
out[0].bands = commitBytes(next.bands);
|
|
667
891
|
out[0].chan_bytes = commitBytes(next.chan_bytes);
|
|
892
|
+
out[0].capture_pcm = commitBytes(next.capture_pcm);
|
|
668
893
|
out[0].pty_bytes = commitBytes(next.pty_bytes);
|
|
669
894
|
out[0].order = commitBytes(next.order);
|
|
670
895
|
return &out[0];
|
|
@@ -677,7 +902,7 @@ const mini_core = struct {
|
|
|
677
902
|
return out;
|
|
678
903
|
}
|
|
679
904
|
|
|
680
|
-
// Hand-encoded
|
|
905
|
+
// Hand-encoded v4 wire records (rt.zig's documented layout).
|
|
681
906
|
|
|
682
907
|
fn cmdNow(msg_tag: u8) []const u8 {
|
|
683
908
|
const out = rt.frameAlloc(u8, 2);
|
|
@@ -709,7 +934,7 @@ const mini_core = struct {
|
|
|
709
934
|
}
|
|
710
935
|
|
|
711
936
|
fn cmdRequest(name: []const u8, key: []const u8, ok_tag: u8, err_tag: u8, payload: []const u8) []const u8 {
|
|
712
|
-
const out = rt.frameAlloc(u8, 2 + name.len + 1 + key.len +
|
|
937
|
+
const out = rt.frameAlloc(u8, 2 + name.len + 1 + key.len + 3 + 4 + payload.len);
|
|
713
938
|
out[0] = 0x05;
|
|
714
939
|
out[1] = @intCast(name.len);
|
|
715
940
|
@memcpy(out[2..][0..name.len], name);
|
|
@@ -719,8 +944,9 @@ const mini_core = struct {
|
|
|
719
944
|
off += 1 + key.len;
|
|
720
945
|
out[off] = ok_tag;
|
|
721
946
|
out[off + 1] = err_tag;
|
|
722
|
-
|
|
723
|
-
|
|
947
|
+
out[off + 2] = 0; // raw byte request, not a generated typed service call
|
|
948
|
+
std.mem.writeInt(u32, out[off + 3 ..][0..4], @intCast(payload.len), .little);
|
|
949
|
+
@memcpy(out[off + 7 ..][0..payload.len], payload);
|
|
724
950
|
return out;
|
|
725
951
|
}
|
|
726
952
|
|
|
@@ -785,6 +1011,34 @@ const mini_core = struct {
|
|
|
785
1011
|
return out;
|
|
786
1012
|
}
|
|
787
1013
|
|
|
1014
|
+
fn cmdFetchStream(key: []const u8, line_tag: u8, ok_tag: u8, err_tag: u8, method: u8, timeout_ms: u32, max_line_bytes: u32, url: []const u8, headers: []const FetchHeader, body: []const u8) []const u8 {
|
|
1015
|
+
var header_bytes: usize = 0;
|
|
1016
|
+
for (headers) |h| header_bytes += 1 + h.name.len + 4 + h.value.len;
|
|
1017
|
+
const out = rt.frameAlloc(u8, 2 + key.len + 3 + 1 + 4 + 4 + 4 + url.len + 1 + header_bytes + 4 + body.len);
|
|
1018
|
+
out[0] = 0x20;
|
|
1019
|
+
out[1] = @intCast(key.len);
|
|
1020
|
+
@memcpy(out[2..][0..key.len], key);
|
|
1021
|
+
var off: usize = 2 + key.len;
|
|
1022
|
+
out[off] = line_tag;
|
|
1023
|
+
out[off + 1] = ok_tag;
|
|
1024
|
+
out[off + 2] = err_tag;
|
|
1025
|
+
out[off + 3] = method;
|
|
1026
|
+
std.mem.writeInt(u32, out[off + 4 ..][0..4], timeout_ms, .little);
|
|
1027
|
+
std.mem.writeInt(u32, out[off + 8 ..][0..4], max_line_bytes, .little);
|
|
1028
|
+
off += 12;
|
|
1029
|
+
off = writeLongBytes(out, off, url);
|
|
1030
|
+
out[off] = @intCast(headers.len);
|
|
1031
|
+
off += 1;
|
|
1032
|
+
for (headers) |h| {
|
|
1033
|
+
out[off] = @intCast(h.name.len);
|
|
1034
|
+
@memcpy(out[off + 1 ..][0..h.name.len], h.name);
|
|
1035
|
+
off += 1 + h.name.len;
|
|
1036
|
+
off = writeLongBytes(out, off, h.value);
|
|
1037
|
+
}
|
|
1038
|
+
_ = writeLongBytes(out, off, body);
|
|
1039
|
+
return out;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
788
1042
|
fn cmdClipWrite(bytes: []const u8) []const u8 {
|
|
789
1043
|
const out = rt.frameAlloc(u8, 1 + 4 + bytes.len);
|
|
790
1044
|
out[0] = 0x0A;
|
|
@@ -885,6 +1139,21 @@ const mini_core = struct {
|
|
|
885
1139
|
return out;
|
|
886
1140
|
}
|
|
887
1141
|
|
|
1142
|
+
fn cmdWindowHide(label: []const u8) []const u8 {
|
|
1143
|
+
const out = rt.frameAlloc(u8, 2 + label.len);
|
|
1144
|
+
out[0] = 0x21;
|
|
1145
|
+
out[1] = @intCast(label.len);
|
|
1146
|
+
@memcpy(out[2..][0..label.len], label);
|
|
1147
|
+
return out;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
fn cmdDockPresence(visible: bool) []const u8 {
|
|
1151
|
+
const out = rt.frameAlloc(u8, 2);
|
|
1152
|
+
out[0] = 0x22;
|
|
1153
|
+
out[1] = if (visible) 1 else 0;
|
|
1154
|
+
return out;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
888
1157
|
fn cmdQuitApp() []const u8 {
|
|
889
1158
|
const out = rt.frameAlloc(u8, 1);
|
|
890
1159
|
out[0] = 0x11;
|
|
@@ -905,10 +1174,11 @@ const mini_core = struct {
|
|
|
905
1174
|
}
|
|
906
1175
|
|
|
907
1176
|
fn cmdChannelOpen(key: f64, event_tag: u8) []const u8 {
|
|
908
|
-
const out = rt.frameAlloc(u8, 1 + 8 + 1);
|
|
1177
|
+
const out = rt.frameAlloc(u8, 1 + 8 + 1 + 1);
|
|
909
1178
|
out[0] = 0x15;
|
|
910
1179
|
std.mem.writeInt(u64, out[1..][0..8], @bitCast(key), .little);
|
|
911
1180
|
out[9] = event_tag;
|
|
1181
|
+
out[10] = 64;
|
|
912
1182
|
return out;
|
|
913
1183
|
}
|
|
914
1184
|
|
|
@@ -919,6 +1189,24 @@ const mini_core = struct {
|
|
|
919
1189
|
return out;
|
|
920
1190
|
}
|
|
921
1191
|
|
|
1192
|
+
fn cmdAudioCaptureStart(key: f64, source: u8, sample_rate: u32, channels: u8, event_tag: u8) []const u8 {
|
|
1193
|
+
const out = rt.frameAlloc(u8, 16);
|
|
1194
|
+
out[0] = 0x1E;
|
|
1195
|
+
std.mem.writeInt(u64, out[1..9], @bitCast(key), .little);
|
|
1196
|
+
out[9] = source;
|
|
1197
|
+
std.mem.writeInt(u32, out[10..14], sample_rate, .little);
|
|
1198
|
+
out[14] = channels;
|
|
1199
|
+
out[15] = event_tag;
|
|
1200
|
+
return out;
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
fn cmdAudioCaptureStop(key: f64) []const u8 {
|
|
1204
|
+
const out = rt.frameAlloc(u8, 9);
|
|
1205
|
+
out[0] = 0x1F;
|
|
1206
|
+
std.mem.writeInt(u64, out[1..9], @bitCast(key), .little);
|
|
1207
|
+
return out;
|
|
1208
|
+
}
|
|
1209
|
+
|
|
922
1210
|
fn cmdPtySpawn(key: []const u8, event_tag: u8, cols: f64, rows: f64, term: []const u8, argv: []const []const u8) []const u8 {
|
|
923
1211
|
var argv_bytes: usize = 0;
|
|
924
1212
|
for (argv) |arg| argv_bytes += 4 + arg.len;
|
|
@@ -967,6 +1255,27 @@ const mini_core = struct {
|
|
|
967
1255
|
return out;
|
|
968
1256
|
}
|
|
969
1257
|
|
|
1258
|
+
fn cmdDbQuery(key: []const u8, page_tag: u8, done_tag: u8, err_tag: u8, sql: []const u8) []const u8 {
|
|
1259
|
+
const out = rt.frameAlloc(u8, 1 + 1 + key.len + 3 + 4 + sql.len + 4);
|
|
1260
|
+
var at: usize = 0;
|
|
1261
|
+
out[at] = 0x29;
|
|
1262
|
+
at += 1;
|
|
1263
|
+
out[at] = @intCast(key.len);
|
|
1264
|
+
at += 1;
|
|
1265
|
+
@memcpy(out[at..][0..key.len], key);
|
|
1266
|
+
at += key.len;
|
|
1267
|
+
out[at] = page_tag;
|
|
1268
|
+
out[at + 1] = done_tag;
|
|
1269
|
+
out[at + 2] = err_tag;
|
|
1270
|
+
at += 3;
|
|
1271
|
+
std.mem.writeInt(u32, out[at..][0..4], @intCast(sql.len), .little);
|
|
1272
|
+
at += 4;
|
|
1273
|
+
@memcpy(out[at..][0..sql.len], sql);
|
|
1274
|
+
at += sql.len;
|
|
1275
|
+
std.mem.writeInt(u32, out[at..][0..4], 0, .little);
|
|
1276
|
+
return out;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
970
1279
|
fn subTimer(key: []const u8, every_ms: f64, msg_tag: u8) []const u8 {
|
|
971
1280
|
const out = rt.frameAlloc(u8, 2 + key.len + 8 + 1);
|
|
972
1281
|
out[0] = 0x01;
|
|
@@ -976,6 +1285,50 @@ const mini_core = struct {
|
|
|
976
1285
|
out[2 + key.len + 8] = msg_tag;
|
|
977
1286
|
return out;
|
|
978
1287
|
}
|
|
1288
|
+
|
|
1289
|
+
fn subDbLive(key: []const u8, page_tag: u8, done_tag: u8, err_tag: u8, sql: []const u8, table: []const u8) []const u8 {
|
|
1290
|
+
const out = rt.frameAlloc(u8, 1 + 1 + key.len + 3 + 4 + sql.len + 4 + 4 + 1 + table.len);
|
|
1291
|
+
var at: usize = 0;
|
|
1292
|
+
out[at] = 0x02;
|
|
1293
|
+
at += 1;
|
|
1294
|
+
out[at] = @intCast(key.len);
|
|
1295
|
+
at += 1;
|
|
1296
|
+
@memcpy(out[at..][0..key.len], key);
|
|
1297
|
+
at += key.len;
|
|
1298
|
+
out[at] = page_tag;
|
|
1299
|
+
out[at + 1] = done_tag;
|
|
1300
|
+
out[at + 2] = err_tag;
|
|
1301
|
+
at += 3;
|
|
1302
|
+
std.mem.writeInt(u32, out[at..][0..4], @intCast(sql.len), .little);
|
|
1303
|
+
at += 4;
|
|
1304
|
+
@memcpy(out[at..][0..sql.len], sql);
|
|
1305
|
+
at += sql.len;
|
|
1306
|
+
std.mem.writeInt(u32, out[at..][0..4], 0, .little);
|
|
1307
|
+
at += 4;
|
|
1308
|
+
std.mem.writeInt(u32, out[at..][0..4], 1, .little);
|
|
1309
|
+
at += 4;
|
|
1310
|
+
out[at] = @intCast(table.len);
|
|
1311
|
+
at += 1;
|
|
1312
|
+
@memcpy(out[at..][0..table.len], table);
|
|
1313
|
+
return out;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
fn subDbLiveBatch(keys: []const []const u8) []const u8 {
|
|
1317
|
+
var records: [effects_mod.max_db_effects][]const u8 = undefined;
|
|
1318
|
+
std.debug.assert(keys.len <= records.len);
|
|
1319
|
+
var total: usize = 0;
|
|
1320
|
+
for (keys, 0..) |key, index| {
|
|
1321
|
+
records[index] = subDbLive(key, 7, 12, 8, "SELECT id FROM item", "item");
|
|
1322
|
+
total += records[index].len;
|
|
1323
|
+
}
|
|
1324
|
+
const out = rt.frameAlloc(u8, total);
|
|
1325
|
+
var at: usize = 0;
|
|
1326
|
+
for (records[0..keys.len]) |record| {
|
|
1327
|
+
@memcpy(out[at..][0..record.len], record);
|
|
1328
|
+
at += record.len;
|
|
1329
|
+
}
|
|
1330
|
+
return out;
|
|
1331
|
+
}
|
|
979
1332
|
};
|
|
980
1333
|
|
|
981
1334
|
const Host = ts_core_host.TsCoreHost(mini_core);
|
|
@@ -1103,6 +1456,20 @@ test "unkeyed requests dispatch in completion order" {
|
|
|
1103
1456
|
try std.testing.expectEqualStrings("from-a", Host.model().status);
|
|
1104
1457
|
}
|
|
1105
1458
|
|
|
1459
|
+
test "malformed credential request records reject instead of panicking" {
|
|
1460
|
+
const fx = freshChannel();
|
|
1461
|
+
defer fx.deinit();
|
|
1462
|
+
Host.init(fx);
|
|
1463
|
+
try fx.feedHostResult(boot_request_key, true, "");
|
|
1464
|
+
Host.drain(fx);
|
|
1465
|
+
|
|
1466
|
+
Host.dispatch(fx, .malformed_credential);
|
|
1467
|
+
Host.drain(fx);
|
|
1468
|
+
try std.testing.expectEqual(@as(i64, 1), Host.model().errs);
|
|
1469
|
+
try std.testing.expectEqualStrings("rejected", Host.model().last_err);
|
|
1470
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingHostCount());
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1106
1473
|
test "subscription reconcile arms, pauses, resumes, and re-arms on interval change" {
|
|
1107
1474
|
const fx = freshChannel();
|
|
1108
1475
|
defer fx.deinit();
|
|
@@ -1132,6 +1499,55 @@ test "subscription reconcile arms, pauses, resumes, and re-arms on interval chan
|
|
|
1132
1499
|
try std.testing.expectEqual(@as(u64, 40), fx.pendingTimerAt(0).?.interval_ms);
|
|
1133
1500
|
}
|
|
1134
1501
|
|
|
1502
|
+
test "a one-shot database query cannot overwrite a live subscription slot with the same wire key" {
|
|
1503
|
+
const fx = freshChannel();
|
|
1504
|
+
defer fx.deinit();
|
|
1505
|
+
Host.init(fx);
|
|
1506
|
+
|
|
1507
|
+
Host.dispatch(fx, .arm_db_live);
|
|
1508
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1509
|
+
|
|
1510
|
+
const errors_before = Host.model().errs;
|
|
1511
|
+
Host.dispatch(fx, .query_over_db_live);
|
|
1512
|
+
Host.drain(fx);
|
|
1513
|
+
try std.testing.expectEqual(errors_before + 1, Host.model().errs);
|
|
1514
|
+
try std.testing.expectEqualStrings("rejected", Host.model().last_err);
|
|
1515
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
test "Cmd.cancel leaves a live query to declarative subscription reconciliation" {
|
|
1519
|
+
const fx = freshChannel();
|
|
1520
|
+
defer fx.deinit();
|
|
1521
|
+
Host.init(fx);
|
|
1522
|
+
|
|
1523
|
+
Host.dispatch(fx, .arm_db_live);
|
|
1524
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1525
|
+
|
|
1526
|
+
// The command walk sees Cmd.cancel first, then reconciliation sees that
|
|
1527
|
+
// the committed model no longer declares the Sub. Cancel must leave the
|
|
1528
|
+
// bridge entry intact so that reconciliation can retire the engine slot.
|
|
1529
|
+
Host.dispatch(fx, .stop_db_live_with_cancel);
|
|
1530
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingDbCount());
|
|
1531
|
+
|
|
1532
|
+
// The same bridge/engine slot is immediately reusable by a one-shot read.
|
|
1533
|
+
Host.dispatch(fx, .query_over_db_live);
|
|
1534
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
test "live-query reconciliation retires stale slots before arming disjoint replacements" {
|
|
1538
|
+
const fx = freshChannel();
|
|
1539
|
+
defer fx.deinit();
|
|
1540
|
+
Host.init(fx);
|
|
1541
|
+
|
|
1542
|
+
Host.dispatch(fx, .arm_full_db_live_set);
|
|
1543
|
+
try std.testing.expectEqual(effects_mod.max_db_effects, fx.pendingDbCount());
|
|
1544
|
+
|
|
1545
|
+
// Every old key disappears at once. The final declaration contains one
|
|
1546
|
+
// query and must fit without trying to hold its sixteen predecessors too.
|
|
1547
|
+
Host.dispatch(fx, .replace_full_db_live_set);
|
|
1548
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1135
1551
|
test "timer fires dispatch the named arm with the fire time" {
|
|
1136
1552
|
const fx = freshChannel();
|
|
1137
1553
|
defer fx.deinit();
|
|
@@ -1552,6 +1968,174 @@ test "cancel is silent for every named-op family - write_file, fetch, clip_read"
|
|
|
1552
1968
|
try std.testing.expectEqualStrings("", Host.model().status);
|
|
1553
1969
|
}
|
|
1554
1970
|
|
|
1971
|
+
// ------------------------------------------------------ fetch streams
|
|
1972
|
+
|
|
1973
|
+
const event_fetch_key: u64 = ts_core_host.spawn_key_base + 0;
|
|
1974
|
+
|
|
1975
|
+
test "a streaming fetch decodes whole, routes lines repeatedly, and terminates with the HTTP status" {
|
|
1976
|
+
const fx = freshChannel();
|
|
1977
|
+
defer fx.deinit();
|
|
1978
|
+
Host.init(fx);
|
|
1979
|
+
|
|
1980
|
+
Host.dispatch(fx, .stream_get);
|
|
1981
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingFetchCount());
|
|
1982
|
+
const request = fx.pendingFetchAt(0).?;
|
|
1983
|
+
try std.testing.expectEqual(event_fetch_key, request.key);
|
|
1984
|
+
try std.testing.expectEqual(std.http.Method.POST, request.method);
|
|
1985
|
+
try std.testing.expectEqual(effects_mod.FetchResponseMode.stream, request.response);
|
|
1986
|
+
try std.testing.expectEqual(@as(usize, 65_536), request.max_line_bytes);
|
|
1987
|
+
try std.testing.expectEqualStrings("https://status.test/events", request.url);
|
|
1988
|
+
try std.testing.expectEqual(@as(usize, 1), request.headers.len);
|
|
1989
|
+
try std.testing.expectEqualStrings("accept", request.headers[0].name);
|
|
1990
|
+
try std.testing.expectEqualStrings("text/event-stream", request.headers[0].value);
|
|
1991
|
+
try std.testing.expectEqualStrings("ask", request.body);
|
|
1992
|
+
|
|
1993
|
+
try fx.feedLine(event_fetch_key, "data: one");
|
|
1994
|
+
Host.drain(fx);
|
|
1995
|
+
try std.testing.expectEqual(@as(i64, 1), Host.model().line_count);
|
|
1996
|
+
try std.testing.expectEqualStrings("data: one", Host.model().last_line);
|
|
1997
|
+
|
|
1998
|
+
try fx.feedLine(event_fetch_key, "data: two");
|
|
1999
|
+
try fx.feedLine(event_fetch_key, "");
|
|
2000
|
+
Host.drain(fx);
|
|
2001
|
+
try std.testing.expectEqual(@as(i64, 3), Host.model().line_count);
|
|
2002
|
+
try std.testing.expectEqualStrings("", Host.model().last_line);
|
|
2003
|
+
|
|
2004
|
+
// A non-2xx status is still a delivered response and therefore the
|
|
2005
|
+
// successful terminal. Stream terminals carry no body.
|
|
2006
|
+
try fx.feedResponse(event_fetch_key, 429, "ignored");
|
|
2007
|
+
Host.drain(fx);
|
|
2008
|
+
try std.testing.expectEqual(@as(i64, 429), Host.model().code);
|
|
2009
|
+
try std.testing.expectError(error.EffectNotFound, fx.feedLine(event_fetch_key, "late"));
|
|
2010
|
+
try std.testing.expectEqual(@as(i64, 0), Host.model().errs);
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
test "streaming fetch failures and cancellation are loud terminals" {
|
|
2014
|
+
const fx = freshChannel();
|
|
2015
|
+
defer fx.deinit();
|
|
2016
|
+
Host.init(fx);
|
|
2017
|
+
|
|
2018
|
+
Host.dispatch(fx, .stream_get);
|
|
2019
|
+
try fx.feedResponseOutcome(event_fetch_key, .timed_out, 0, "");
|
|
2020
|
+
Host.drain(fx);
|
|
2021
|
+
try std.testing.expectEqual(@as(i64, 1), Host.model().errs);
|
|
2022
|
+
try std.testing.expectEqualStrings("timed_out", Host.model().last_err);
|
|
2023
|
+
|
|
2024
|
+
Host.dispatch(fx, .stream_get);
|
|
2025
|
+
try fx.feedLine(event_fetch_key, "queued before cancel");
|
|
2026
|
+
Host.dispatch(fx, .stop_stream);
|
|
2027
|
+
Host.drain(fx);
|
|
2028
|
+
try std.testing.expectEqual(@as(i64, 0), Host.model().line_count);
|
|
2029
|
+
try std.testing.expectEqual(@as(i64, 2), Host.model().errs);
|
|
2030
|
+
try std.testing.expectEqualStrings("cancelled", Host.model().last_err);
|
|
2031
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingFetchCount());
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
test "a lossy streaming fetch terminates as truncated instead of success" {
|
|
2035
|
+
const fx = freshChannel();
|
|
2036
|
+
defer fx.deinit();
|
|
2037
|
+
Host.init(fx);
|
|
2038
|
+
|
|
2039
|
+
// A later delivered line reports earlier queue loss. The line still
|
|
2040
|
+
// routes, but even a normal HTTP terminal cannot certify the response as
|
|
2041
|
+
// complete afterward.
|
|
2042
|
+
Host.dispatch(fx, .stream_get);
|
|
2043
|
+
try fx.feedLineWithMetadata(event_fetch_key, "data: [DONE]", false, 2);
|
|
2044
|
+
Host.drain(fx);
|
|
2045
|
+
try std.testing.expectEqual(@as(i64, 1), Host.model().line_count);
|
|
2046
|
+
try fx.feedResponse(event_fetch_key, 200, "");
|
|
2047
|
+
Host.drain(fx);
|
|
2048
|
+
try std.testing.expectEqual(@as(i64, 1), Host.model().errs);
|
|
2049
|
+
try std.testing.expectEqualStrings("truncated", Host.model().last_err);
|
|
2050
|
+
try std.testing.expectEqual(@as(i64, -1), Host.model().code);
|
|
2051
|
+
|
|
2052
|
+
// Loss with no later line rides the response terminal itself. Cover both
|
|
2053
|
+
// terminal metadata fields: either one must suppress the ok arm.
|
|
2054
|
+
Host.dispatch(fx, .stream_get);
|
|
2055
|
+
try fx.feedResponseOutcomeWithMetadata(event_fetch_key, .ok, 204, "", true, 0);
|
|
2056
|
+
Host.drain(fx);
|
|
2057
|
+
try std.testing.expectEqual(@as(i64, 2), Host.model().errs);
|
|
2058
|
+
try std.testing.expectEqualStrings("truncated", Host.model().last_err);
|
|
2059
|
+
try std.testing.expectEqual(@as(i64, -1), Host.model().code);
|
|
2060
|
+
|
|
2061
|
+
Host.dispatch(fx, .stream_get);
|
|
2062
|
+
try fx.feedResponseOutcomeWithMetadata(event_fetch_key, .ok, 206, "", false, 3);
|
|
2063
|
+
Host.drain(fx);
|
|
2064
|
+
try std.testing.expectEqual(@as(i64, 3), Host.model().errs);
|
|
2065
|
+
try std.testing.expectEqualStrings("truncated", Host.model().last_err);
|
|
2066
|
+
try std.testing.expectEqual(@as(i64, -1), Host.model().code);
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
test "a duplicate live streaming fetch key is rejected without replacing the stream" {
|
|
2070
|
+
const fx = freshChannel();
|
|
2071
|
+
defer fx.deinit();
|
|
2072
|
+
Host.init(fx);
|
|
2073
|
+
|
|
2074
|
+
Host.dispatch(fx, .stream_get);
|
|
2075
|
+
Host.dispatch(fx, .dup_stream);
|
|
2076
|
+
Host.drain(fx);
|
|
2077
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingFetchCount());
|
|
2078
|
+
try std.testing.expectEqual(@as(i64, 1), Host.model().errs);
|
|
2079
|
+
try std.testing.expectEqualStrings("rejected", Host.model().last_err);
|
|
2080
|
+
|
|
2081
|
+
try fx.feedLine(event_fetch_key, "original still live");
|
|
2082
|
+
try fx.feedResponse(event_fetch_key, 204, "");
|
|
2083
|
+
Host.drain(fx);
|
|
2084
|
+
try std.testing.expectEqual(@as(i64, 1), Host.model().line_count);
|
|
2085
|
+
try std.testing.expectEqualStrings("original still live", Host.model().last_line);
|
|
2086
|
+
try std.testing.expectEqual(@as(i64, 204), Host.model().code);
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
test "buffered and streaming fetch modes cannot share a live public key" {
|
|
2090
|
+
const fx = freshChannel();
|
|
2091
|
+
defer fx.deinit();
|
|
2092
|
+
Host.init(fx);
|
|
2093
|
+
|
|
2094
|
+
// A buffered fetch owns "get", so a streaming fetch cannot make
|
|
2095
|
+
// cancel ambiguous by claiming the same public key beside it.
|
|
2096
|
+
Host.dispatch(fx, .get);
|
|
2097
|
+
Host.dispatch(fx, .stream_over_get);
|
|
2098
|
+
Host.drain(fx);
|
|
2099
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingFetchCount());
|
|
2100
|
+
try std.testing.expectEqual(@as(i64, 1), Host.model().errs);
|
|
2101
|
+
try std.testing.expectEqualStrings("rejected", Host.model().last_err);
|
|
2102
|
+
|
|
2103
|
+
Host.dispatch(fx, .drop_get);
|
|
2104
|
+
Host.drain(fx);
|
|
2105
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingFetchCount());
|
|
2106
|
+
|
|
2107
|
+
// The same shared namespace applies in the opposite order. The
|
|
2108
|
+
// rejected buffered fetch must not hide the live stream from cancel.
|
|
2109
|
+
Host.dispatch(fx, .stream_get);
|
|
2110
|
+
Host.dispatch(fx, .get_over_stream);
|
|
2111
|
+
Host.drain(fx);
|
|
2112
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingFetchCount());
|
|
2113
|
+
try std.testing.expectEqual(@as(i64, 2), Host.model().errs);
|
|
2114
|
+
try std.testing.expectEqualStrings("rejected", Host.model().last_err);
|
|
2115
|
+
|
|
2116
|
+
Host.dispatch(fx, .stop_stream);
|
|
2117
|
+
Host.drain(fx);
|
|
2118
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingFetchCount());
|
|
2119
|
+
try std.testing.expectEqual(@as(i64, 3), Host.model().errs);
|
|
2120
|
+
try std.testing.expectEqualStrings("cancelled", Host.model().last_err);
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2123
|
+
test "a seventeenth live stream is rejected instead of panicking" {
|
|
2124
|
+
const fx = freshChannel();
|
|
2125
|
+
defer fx.deinit();
|
|
2126
|
+
Host.init(fx);
|
|
2127
|
+
// Retire init's host request so all sixteen shared engine effect
|
|
2128
|
+
// slots are available to the streams this test is isolating.
|
|
2129
|
+
try fx.feedHostResult(boot_request_key, true, "ready");
|
|
2130
|
+
Host.drain(fx);
|
|
2131
|
+
|
|
2132
|
+
Host.dispatch(fx, .fill_streams);
|
|
2133
|
+
Host.drain(fx);
|
|
2134
|
+
try std.testing.expectEqual(@as(usize, 16), fx.pendingFetchCount());
|
|
2135
|
+
try std.testing.expectEqual(@as(i64, 1), Host.model().errs);
|
|
2136
|
+
try std.testing.expectEqualStrings("rejected", Host.model().last_err);
|
|
2137
|
+
}
|
|
2138
|
+
|
|
1555
2139
|
// ------------------------------------------------------ spawn streams
|
|
1556
2140
|
|
|
1557
2141
|
const job_spawn_key: u64 = ts_core_host.spawn_key_base + 0;
|
|
@@ -2093,12 +2677,14 @@ test "boot commits the model before any effects and performBoot fires the boot c
|
|
|
2093
2677
|
// The pre-effects half: the committed boot model is readable, no
|
|
2094
2678
|
// effect has been issued, and the frame arena is reset.
|
|
2095
2679
|
Host.boot();
|
|
2680
|
+
const calls_after_boot = mini_core.initial_model_calls;
|
|
2096
2681
|
try std.testing.expect(!Host.model().polling);
|
|
2097
2682
|
try std.testing.expectEqual(@as(usize, 0), fx.pendingHostCount());
|
|
2098
2683
|
|
|
2099
|
-
// The effects half
|
|
2100
|
-
//
|
|
2684
|
+
// The effects half retrieves only the command. Re-running initialModel
|
|
2685
|
+
// here would also reset a compiled core after persistence restore.
|
|
2101
2686
|
Host.performBoot(fx);
|
|
2687
|
+
try std.testing.expectEqual(calls_after_boot, mini_core.initial_model_calls);
|
|
2102
2688
|
try std.testing.expectEqual(@as(usize, 1), fx.pendingHostCount());
|
|
2103
2689
|
const request = fx.pendingHostAt(0).?;
|
|
2104
2690
|
try std.testing.expectEqual(boot_request_key, request.key);
|
|
@@ -2145,6 +2731,14 @@ test "window verbs bridge to the effects channel's label-addressed verbs" {
|
|
|
2145
2731
|
try std.testing.expectEqual(@as(u32, 1), fx.windowActionState().show_count);
|
|
2146
2732
|
try std.testing.expectEqualStrings("player", fx.windowActionState().lastLabel());
|
|
2147
2733
|
|
|
2734
|
+
Host.dispatch(fx, .hide_win);
|
|
2735
|
+
try std.testing.expectEqual(@as(u32, 1), fx.windowActionState().hide_count);
|
|
2736
|
+
try std.testing.expectEqualStrings("player", fx.windowActionState().lastLabel());
|
|
2737
|
+
|
|
2738
|
+
Host.dispatch(fx, .dock_off);
|
|
2739
|
+
try std.testing.expectEqual(@as(u32, 1), fx.windowActionState().dock_presence_count);
|
|
2740
|
+
try std.testing.expect(!fx.windowActionState().dock_visible);
|
|
2741
|
+
|
|
2148
2742
|
// quit_app decodes onto fx.quitApp — the graceful terminate request.
|
|
2149
2743
|
Host.dispatch(fx, .quit_app);
|
|
2150
2744
|
try std.testing.expectEqual(@as(u32, 1), fx.windowActionState().quit_count);
|
|
@@ -2200,6 +2794,39 @@ test "a channel opens, posts route the five-field arm by name, and close retires
|
|
|
2200
2794
|
try std.testing.expect(fx.channelHandle(41) != null);
|
|
2201
2795
|
}
|
|
2202
2796
|
|
|
2797
|
+
test "audio capture wire records route canonical PCM through the ten-field arm" {
|
|
2798
|
+
const fx = freshChannel();
|
|
2799
|
+
defer fx.deinit();
|
|
2800
|
+
Host.init(fx);
|
|
2801
|
+
|
|
2802
|
+
Host.dispatch(fx, .start_capture);
|
|
2803
|
+
Host.drain(fx);
|
|
2804
|
+
try std.testing.expectEqual(@as(i64, 1), Host.model().capture_events);
|
|
2805
|
+
try std.testing.expectEqual(mini_core.CaptureState.started, Host.model().capture_state);
|
|
2806
|
+
try std.testing.expectEqual(mini_core.CaptureSource.microphone, Host.model().capture_source);
|
|
2807
|
+
try std.testing.expectEqual(@as(f64, 91), Host.model().capture_key);
|
|
2808
|
+
try std.testing.expectEqual(@as(f64, 16_000), Host.model().capture_rate);
|
|
2809
|
+
try std.testing.expectEqual(@as(f64, 1), Host.model().capture_channels);
|
|
2810
|
+
|
|
2811
|
+
const pcm = [_]u8{ 1, 0, 2, 0 };
|
|
2812
|
+
try fx.feedAudioCapture(91, 9_876_543, &pcm);
|
|
2813
|
+
Host.drain(fx);
|
|
2814
|
+
try std.testing.expectEqual(@as(i64, 2), Host.model().capture_events);
|
|
2815
|
+
try std.testing.expectEqual(mini_core.CaptureState.data, Host.model().capture_state);
|
|
2816
|
+
try std.testing.expectEqual(@as(f64, 9), Host.model().capture_timestamp_ms);
|
|
2817
|
+
try std.testing.expectEqual(@as(f64, 2), Host.model().capture_frames);
|
|
2818
|
+
try std.testing.expectEqualStrings(&pcm, Host.model().capture_pcm);
|
|
2819
|
+
|
|
2820
|
+
Host.dispatch(fx, .stop_capture);
|
|
2821
|
+
Host.drain(fx);
|
|
2822
|
+
try std.testing.expectEqual(@as(i64, 3), Host.model().capture_events);
|
|
2823
|
+
try std.testing.expectEqual(mini_core.CaptureState.stopped, Host.model().capture_state);
|
|
2824
|
+
// Terminal channel envelopes carry no PCM packet; the bridge retains
|
|
2825
|
+
// the requested source/format so every event arm stays self-describing.
|
|
2826
|
+
try std.testing.expectEqual(mini_core.CaptureSource.microphone, Host.model().capture_source);
|
|
2827
|
+
try std.testing.expectEqual(@as(f64, 16_000), Host.model().capture_rate);
|
|
2828
|
+
}
|
|
2829
|
+
|
|
2203
2830
|
test "a mixed refused batch dispatches its rejections in command-stream order" {
|
|
2204
2831
|
const fx = freshChannel();
|
|
2205
2832
|
defer fx.deinit();
|