@native-sdk/cli 0.8.4 → 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 +859 -62
- package/build.zig +543 -13
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +2 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +365 -2
- 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 +149 -0
- package/packages/core/sdk/core.ts +529 -12
- package/packages/core/sdk/events.d.ts +36 -0
- package/packages/core/sdk/events.ts +57 -0
- package/packages/core/src/checker.ts +468 -15
- package/packages/core/src/cli.ts +143 -3
- package/packages/core/src/contract.ts +26 -5
- package/packages/core/src/devhost.ts +1847 -16
- 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 +82 -16
- 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/references/project-anatomy.md +1 -1
- package/skill-data/native-ui/SKILL.md +47 -0
- package/skill-data/ts-core/SKILL.md +80 -31
- 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 +249 -8
- 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 +109 -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 +119 -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 +40 -18
- package/src/platform/macos/appkit_host.h +16 -3
- package/src/platform/macos/appkit_host.m +536 -36
- package/src/platform/macos/cef_host.mm +248 -36
- package/src/platform/macos/root.zig +244 -34
- package/src/platform/null_platform.zig +223 -19
- package/src/platform/null_platform_tests.zig +74 -0
- package/src/platform/root.zig +9 -0
- package/src/platform/types.zig +179 -15
- package/src/platform/windows/root.zig +187 -21
- package/src/platform/windows/webview2_host.cpp +293 -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 +32 -0
- package/src/primitives/app_manifest/validation.zig +19 -1
- package/src/root.zig +46 -0
- package/src/runtime/api.zig +11 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/bridge_permission_tests.zig +23 -2
- package/src/runtime/bridge_responses.zig +3 -1
- package/src/runtime/canvas_frame.zig +18 -11
- package/src/runtime/canvas_frame_animation_tests.zig +4 -0
- package/src/runtime/clock.zig +13 -1
- package/src/runtime/core.zig +133 -1
- package/src/runtime/credentials_store.zig +115 -0
- package/src/runtime/effects.zig +2295 -113
- 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 +49 -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 +4 -0
- package/src/runtime/ts_core_host.zig +788 -86
- package/src/runtime/ts_core_host_tests.zig +231 -11
- package/src/runtime/ts_ui_app.zig +499 -1
- package/src/runtime/ui_app.zig +142 -16
- package/src/runtime/ui_app_tests.zig +155 -5
- package/src/runtime/validation.zig +22 -0
- package/src/runtime/view.zig +9 -0
- package/src/runtime/window_storage.zig +1 -0
- package/src/runtime/window_view_runtime.zig +2 -3
- package/src/runtime/window_views.zig +19 -0
- package/src/tooling/android.zig +21 -16
- package/src/tooling/db.zig +160 -0
- package/src/tooling/ios.zig +7 -1
- package/src/tooling/manifest.zig +214 -2
- package/src/tooling/package.zig +116 -0
- package/src/tooling/raw_manifest.zig +30 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +161 -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 +378 -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
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
//! Tier-4 credential effect coverage. Secrets travel through the dedicated
|
|
2
|
+
//! keyed worker family, the app identity is the platform service namespace,
|
|
3
|
+
//! permission refusal is loud, and replay reconstructs only a deterministic
|
|
4
|
+
//! same-length placeholder from redacted journal metadata.
|
|
5
|
+
|
|
6
|
+
const std = @import("std");
|
|
7
|
+
const effects_mod = @import("effects.zig");
|
|
8
|
+
const core = @import("core.zig");
|
|
9
|
+
const clock_mod = @import("clock.zig");
|
|
10
|
+
const platform = @import("../platform/root.zig");
|
|
11
|
+
|
|
12
|
+
const Msg = union(enum) { result: effects_mod.EffectCredentialsResult };
|
|
13
|
+
const Fx = effects_mod.Effects(Msg);
|
|
14
|
+
|
|
15
|
+
test "credential test harness opts into hermetic backing" {
|
|
16
|
+
const harness = try core.TestHarness().createWithCredentials(std.testing.allocator, .{});
|
|
17
|
+
defer harness.destroy(std.testing.allocator);
|
|
18
|
+
try std.testing.expect(harness.runtime.options.credentials_enabled);
|
|
19
|
+
try std.testing.expectEqualStrings("dev.native_sdk.app", harness.runtime.options.platform.app_info.bundle_id);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
fn takeResult(fx: *Fx) !effects_mod.EffectCredentialsResult {
|
|
23
|
+
for (0..100_000) |_| {
|
|
24
|
+
if (fx.takeMsg()) |msg| return msg.result;
|
|
25
|
+
std.Thread.yield() catch {};
|
|
26
|
+
}
|
|
27
|
+
return error.TestExpectedMsg;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const BlockingCredentialStore = struct {
|
|
31
|
+
first_entered: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
|
|
32
|
+
release_first: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
|
|
33
|
+
first_exited: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
|
|
34
|
+
abandon_noted: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
|
|
35
|
+
call_count: std.atomic.Value(usize) = std.atomic.Value(usize).init(0),
|
|
36
|
+
mutex: std.atomic.Mutex = .unlocked,
|
|
37
|
+
first_secret: [32]u8 = undefined,
|
|
38
|
+
first_secret_len: usize = 0,
|
|
39
|
+
stored_secret: [32]u8 = undefined,
|
|
40
|
+
stored_secret_len: usize = 0,
|
|
41
|
+
|
|
42
|
+
fn lock(self: *BlockingCredentialStore) void {
|
|
43
|
+
while (!self.mutex.tryLock()) std.atomic.spinLoopHint();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fn set(context: ?*anyopaque, credential: platform.Credential) anyerror!void {
|
|
47
|
+
const self: *BlockingCredentialStore = @ptrCast(@alignCast(context));
|
|
48
|
+
const call = self.call_count.fetchAdd(1, .acq_rel);
|
|
49
|
+
if (call == 0) {
|
|
50
|
+
self.lock();
|
|
51
|
+
const first_len = @min(credential.secret.len, self.first_secret.len);
|
|
52
|
+
@memcpy(self.first_secret[0..first_len], credential.secret[0..first_len]);
|
|
53
|
+
self.first_secret_len = first_len;
|
|
54
|
+
self.mutex.unlock();
|
|
55
|
+
self.first_entered.store(true, .release);
|
|
56
|
+
while (!self.release_first.load(.acquire)) std.atomic.spinLoopHint();
|
|
57
|
+
}
|
|
58
|
+
self.lock();
|
|
59
|
+
const stored_len = @min(credential.secret.len, self.stored_secret.len);
|
|
60
|
+
@memcpy(self.stored_secret[0..stored_len], credential.secret[0..stored_len]);
|
|
61
|
+
self.stored_secret_len = stored_len;
|
|
62
|
+
self.mutex.unlock();
|
|
63
|
+
if (call == 0) self.first_exited.store(true, .release);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fn noteAbandoned(context: ?*anyopaque) void {
|
|
67
|
+
const self: *BlockingCredentialStore = @ptrCast(@alignCast(context));
|
|
68
|
+
self.abandon_noted.store(true, .release);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
fn waitFor(value: *std.atomic.Value(bool)) !void {
|
|
72
|
+
for (0..1_000_000) |_| {
|
|
73
|
+
if (value.load(.acquire)) return;
|
|
74
|
+
std.Thread.yield() catch {};
|
|
75
|
+
}
|
|
76
|
+
return error.TestExpectedSignal;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
test "credential effects round-trip through the hermetic platform backing" {
|
|
81
|
+
var null_platform = platform.NullPlatform.init(.{});
|
|
82
|
+
defer null_platform.deinit();
|
|
83
|
+
var services = null_platform.platform();
|
|
84
|
+
var fx = Fx.init(std.testing.allocator);
|
|
85
|
+
defer fx.deinit();
|
|
86
|
+
fx.bindCredentialsStore(.{
|
|
87
|
+
.services = &services.services,
|
|
88
|
+
.service = "dev.native-sdk.credentials-test",
|
|
89
|
+
.permitted = true,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
fx.credentialsSet(.{
|
|
93
|
+
.key = 1,
|
|
94
|
+
.credential_key = "api-token",
|
|
95
|
+
.secret = "live-secret",
|
|
96
|
+
.on_result = Fx.credentialsMsg(.result),
|
|
97
|
+
});
|
|
98
|
+
const set = try takeResult(&fx);
|
|
99
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.ok, set.outcome);
|
|
100
|
+
try std.testing.expectEqualStrings("dev.native-sdk.credentials-test", null_platform.lastCredentialService());
|
|
101
|
+
try std.testing.expectEqualStrings("api-token", null_platform.lastCredentialAccount());
|
|
102
|
+
|
|
103
|
+
fx.credentialsGet(.{ .key = 2, .credential_key = "api-token", .on_result = Fx.credentialsMsg(.result) });
|
|
104
|
+
const get = try takeResult(&fx);
|
|
105
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.ok, get.outcome);
|
|
106
|
+
try std.testing.expectEqualStrings("live-secret", get.bytes);
|
|
107
|
+
|
|
108
|
+
fx.credentialsDelete(.{ .key = 3, .credential_key = "api-token", .on_result = Fx.credentialsMsg(.result) });
|
|
109
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.ok, (try takeResult(&fx)).outcome);
|
|
110
|
+
fx.credentialsGet(.{ .key = 4, .credential_key = "api-token", .on_result = Fx.credentialsMsg(.result) });
|
|
111
|
+
const miss = try takeResult(&fx);
|
|
112
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.miss, miss.outcome);
|
|
113
|
+
try std.testing.expectEqualStrings("", miss.bytes);
|
|
114
|
+
|
|
115
|
+
// Delete is idempotent even though the platform reports absence.
|
|
116
|
+
fx.credentialsDelete(.{ .key = 5, .credential_key = "api-token", .on_result = Fx.credentialsMsg(.result) });
|
|
117
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.ok, (try takeResult(&fx)).outcome);
|
|
118
|
+
|
|
119
|
+
// Uint8Array includes the empty byte string; presence is independent
|
|
120
|
+
// from payload length all the way through the platform adapter.
|
|
121
|
+
fx.credentialsSet(.{
|
|
122
|
+
.key = 6,
|
|
123
|
+
.credential_key = "empty",
|
|
124
|
+
.secret = "",
|
|
125
|
+
.on_result = Fx.credentialsMsg(.result),
|
|
126
|
+
});
|
|
127
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.ok, (try takeResult(&fx)).outcome);
|
|
128
|
+
fx.credentialsGet(.{ .key = 7, .credential_key = "empty", .on_result = Fx.credentialsMsg(.result) });
|
|
129
|
+
const empty = try takeResult(&fx);
|
|
130
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.ok, empty.outcome);
|
|
131
|
+
try std.testing.expectEqual(@as(usize, 0), empty.bytes.len);
|
|
132
|
+
|
|
133
|
+
// The TypeScript surface accepts Uint8Array, not text: zeros and invalid
|
|
134
|
+
// UTF-8 must survive the complete worker/platform/result path.
|
|
135
|
+
const binary = [_]u8{ 0x00, 0xff, 0x80, 0x41, 0x00 };
|
|
136
|
+
fx.credentialsSet(.{
|
|
137
|
+
.key = 8,
|
|
138
|
+
.credential_key = "binary",
|
|
139
|
+
.secret = &binary,
|
|
140
|
+
.on_result = Fx.credentialsMsg(.result),
|
|
141
|
+
});
|
|
142
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.ok, (try takeResult(&fx)).outcome);
|
|
143
|
+
fx.credentialsGet(.{ .key = 9, .credential_key = "binary", .on_result = Fx.credentialsMsg(.result) });
|
|
144
|
+
const binary_get = try takeResult(&fx);
|
|
145
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.ok, binary_get.outcome);
|
|
146
|
+
try std.testing.expectEqualSlices(u8, &binary, binary_get.bytes);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
test "credential permission and bounds failures are staged closed outcomes" {
|
|
150
|
+
try std.testing.expectEqual(@as(usize, 2_560), effects_mod.max_effect_credentials_secret_bytes);
|
|
151
|
+
var null_platform = platform.NullPlatform.init(.{});
|
|
152
|
+
defer null_platform.deinit();
|
|
153
|
+
var services = null_platform.platform();
|
|
154
|
+
var fx = Fx.init(std.testing.allocator);
|
|
155
|
+
defer fx.deinit();
|
|
156
|
+
|
|
157
|
+
// A refused batch remains loud and ordered even though no worker starts.
|
|
158
|
+
fx.credentialsSet(.{ .key = 10, .credential_key = "one", .secret = "a", .on_result = Fx.credentialsMsg(.result) });
|
|
159
|
+
fx.credentialsGet(.{ .key = 11, .credential_key = "two", .on_result = Fx.credentialsMsg(.result) });
|
|
160
|
+
fx.credentialsDelete(.{ .key = 12, .credential_key = "three", .on_result = Fx.credentialsMsg(.result) });
|
|
161
|
+
const denied_set = try takeResult(&fx);
|
|
162
|
+
const denied_get = try takeResult(&fx);
|
|
163
|
+
const denied_delete = try takeResult(&fx);
|
|
164
|
+
try std.testing.expectEqual(@as(u64, 10), denied_set.key);
|
|
165
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOperation.set, denied_set.operation);
|
|
166
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.denied, denied_set.outcome);
|
|
167
|
+
try std.testing.expectEqual(@as(u64, 11), denied_get.key);
|
|
168
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOperation.get, denied_get.operation);
|
|
169
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.denied, denied_get.outcome);
|
|
170
|
+
try std.testing.expectEqual(@as(u64, 12), denied_delete.key);
|
|
171
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOperation.delete, denied_delete.operation);
|
|
172
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.denied, denied_delete.outcome);
|
|
173
|
+
|
|
174
|
+
fx.bindCredentialsStore(.{
|
|
175
|
+
.services = &services.services,
|
|
176
|
+
.service = "dev.native-sdk.credentials-test",
|
|
177
|
+
.permitted = true,
|
|
178
|
+
});
|
|
179
|
+
var oversized_key: [effects_mod.max_effect_credentials_key_bytes + 1]u8 = undefined;
|
|
180
|
+
@memset(&oversized_key, 'k');
|
|
181
|
+
fx.credentialsGet(.{ .key = 13, .credential_key = &oversized_key, .on_result = Fx.credentialsMsg(.result) });
|
|
182
|
+
const bounded = try takeResult(&fx);
|
|
183
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.over_bound, bounded.outcome);
|
|
184
|
+
|
|
185
|
+
fx.credentialsGet(.{ .key = 14, .credential_key = "prefix\x00suffix", .on_result = Fx.credentialsMsg(.result) });
|
|
186
|
+
const nul = try takeResult(&fx);
|
|
187
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.over_bound, nul.outcome);
|
|
188
|
+
|
|
189
|
+
var oversized_secret: [effects_mod.max_effect_credentials_secret_bytes + 1]u8 = undefined;
|
|
190
|
+
@memset(&oversized_secret, 's');
|
|
191
|
+
fx.credentialsSet(.{ .key = 15, .credential_key = "token", .secret = &oversized_secret, .on_result = Fx.credentialsMsg(.result) });
|
|
192
|
+
const secret = try takeResult(&fx);
|
|
193
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.over_bound, secret.outcome);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
test "real credential replacements coalesce and execute in issue order" {
|
|
197
|
+
var backing: BlockingCredentialStore = .{};
|
|
198
|
+
var services: platform.PlatformServices = .{
|
|
199
|
+
.context = &backing,
|
|
200
|
+
.set_credential_fn = BlockingCredentialStore.set,
|
|
201
|
+
.note_blocking_call_abandoned_fn = BlockingCredentialStore.noteAbandoned,
|
|
202
|
+
};
|
|
203
|
+
var fx = Fx.init(std.testing.allocator);
|
|
204
|
+
defer fx.deinit();
|
|
205
|
+
fx.bindCredentialsStore(.{
|
|
206
|
+
.services = &services,
|
|
207
|
+
.service = "dev.native-sdk.credentials-test",
|
|
208
|
+
.permitted = true,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
fx.credentialsSet(.{ .key = 40, .credential_key = "token", .secret = "old", .on_result = Fx.credentialsMsg(.result) });
|
|
212
|
+
try BlockingCredentialStore.waitFor(&backing.first_entered);
|
|
213
|
+
fx.credentialsSet(.{ .key = 40, .credential_key = "token", .secret = "new-1", .on_result = Fx.credentialsMsg(.result) });
|
|
214
|
+
fx.credentialsSet(.{ .key = 40, .credential_key = "token", .secret = "new-2", .on_result = Fx.credentialsMsg(.result) });
|
|
215
|
+
fx.credentialsSet(.{ .key = 40, .credential_key = "token", .secret = "new-3", .on_result = Fx.credentialsMsg(.result) });
|
|
216
|
+
fx.credentialsSet(.{ .key = 40, .credential_key = "token", .secret = "new-4", .on_result = Fx.credentialsMsg(.result) });
|
|
217
|
+
fx.credentialsSet(.{ .key = 40, .credential_key = "token", .secret = "new-5", .on_result = Fx.credentialsMsg(.result) });
|
|
218
|
+
try std.testing.expectEqual(@as(usize, 1), backing.call_count.load(.acquire));
|
|
219
|
+
|
|
220
|
+
backing.release_first.store(true, .release);
|
|
221
|
+
const result = try takeResult(&fx);
|
|
222
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.ok, result.outcome);
|
|
223
|
+
try std.testing.expectEqual(@as(usize, 2), backing.call_count.load(.acquire));
|
|
224
|
+
backing.lock();
|
|
225
|
+
defer backing.mutex.unlock();
|
|
226
|
+
try std.testing.expectEqualStrings("old", backing.first_secret[0..backing.first_secret_len]);
|
|
227
|
+
try std.testing.expectEqualStrings("new-5", backing.stored_secret[0..backing.stored_secret_len]);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
test "credential teardown abandons a blocked platform call at its deadline" {
|
|
231
|
+
var backing: BlockingCredentialStore = .{};
|
|
232
|
+
var services: platform.PlatformServices = .{
|
|
233
|
+
.context = &backing,
|
|
234
|
+
.set_credential_fn = BlockingCredentialStore.set,
|
|
235
|
+
.note_blocking_call_abandoned_fn = BlockingCredentialStore.noteAbandoned,
|
|
236
|
+
};
|
|
237
|
+
var fx = Fx.init(std.testing.allocator);
|
|
238
|
+
fx.credentials_join_deadline_ms = 10;
|
|
239
|
+
fx.bindCredentialsStore(.{
|
|
240
|
+
.services = &services,
|
|
241
|
+
.service = "dev.native-sdk.credentials-test",
|
|
242
|
+
.permitted = true,
|
|
243
|
+
});
|
|
244
|
+
fx.credentialsSet(.{ .key = 41, .credential_key = "token", .secret = "blocked", .on_result = Fx.credentialsMsg(.result) });
|
|
245
|
+
try BlockingCredentialStore.waitFor(&backing.first_entered);
|
|
246
|
+
|
|
247
|
+
const start_ns = clock_mod.monotonicNanoseconds();
|
|
248
|
+
fx.deinit();
|
|
249
|
+
const elapsed_ms = (clock_mod.monotonicNanoseconds() - start_ns) / std.time.ns_per_ms;
|
|
250
|
+
try std.testing.expect(elapsed_ms < 2_000);
|
|
251
|
+
try std.testing.expectEqual(@as(u32, 1), fx.abandoned_credentials_workers);
|
|
252
|
+
try std.testing.expect(backing.abandon_noted.load(.acquire));
|
|
253
|
+
|
|
254
|
+
backing.release_first.store(true, .release);
|
|
255
|
+
try BlockingCredentialStore.waitFor(&backing.first_exited);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
test "credential effects replace by key and own four slots" {
|
|
259
|
+
var null_platform = platform.NullPlatform.init(.{});
|
|
260
|
+
defer null_platform.deinit();
|
|
261
|
+
var services = null_platform.platform();
|
|
262
|
+
var fx = Fx.init(std.testing.allocator);
|
|
263
|
+
defer fx.deinit();
|
|
264
|
+
fx.executor = .fake;
|
|
265
|
+
fx.bindCredentialsStore(.{
|
|
266
|
+
.services = &services.services,
|
|
267
|
+
.service = "dev.native-sdk.credentials-test",
|
|
268
|
+
.permitted = true,
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
fx.credentialsGet(.{ .key = 30, .credential_key = "old", .on_result = Fx.credentialsMsg(.result) });
|
|
272
|
+
fx.credentialsGet(.{ .key = 30, .credential_key = "replacement", .on_result = Fx.credentialsMsg(.result) });
|
|
273
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingHostCount());
|
|
274
|
+
try std.testing.expectEqualStrings("replacement", blk: {
|
|
275
|
+
var at: usize = 0;
|
|
276
|
+
const payload = fx.pendingHostAt(0).?.payload;
|
|
277
|
+
const len: usize = std.mem.readInt(u32, payload[0..4], .little);
|
|
278
|
+
at += 4;
|
|
279
|
+
break :blk payload[at .. at + len];
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// The replacement occupies one credential-reserved slot; three more fit,
|
|
283
|
+
// while the fifth concurrent operation is rejected without borrowing a
|
|
284
|
+
// file/fetch or record-store slot.
|
|
285
|
+
fx.credentialsGet(.{ .key = 31, .credential_key = "a", .on_result = Fx.credentialsMsg(.result) });
|
|
286
|
+
fx.credentialsGet(.{ .key = 32, .credential_key = "b", .on_result = Fx.credentialsMsg(.result) });
|
|
287
|
+
fx.credentialsGet(.{ .key = 33, .credential_key = "c", .on_result = Fx.credentialsMsg(.result) });
|
|
288
|
+
try std.testing.expectEqual(effects_mod.max_credentials_effects, fx.pendingHostCount());
|
|
289
|
+
fx.credentialsGet(.{ .key = 34, .credential_key = "full", .on_result = Fx.credentialsMsg(.result) });
|
|
290
|
+
const rejected = try takeResult(&fx);
|
|
291
|
+
try std.testing.expectEqual(@as(u64, 34), rejected.key);
|
|
292
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.rejected, rejected.outcome);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
test "credential replay delivers a deterministic redacted placeholder" {
|
|
296
|
+
var null_platform = platform.NullPlatform.init(.{});
|
|
297
|
+
defer null_platform.deinit();
|
|
298
|
+
var services = null_platform.platform();
|
|
299
|
+
var fx = Fx.init(std.testing.allocator);
|
|
300
|
+
defer fx.deinit();
|
|
301
|
+
fx.executor = .fake;
|
|
302
|
+
fx.bindCredentialsStore(.{
|
|
303
|
+
.services = &services.services,
|
|
304
|
+
.service = "dev.native-sdk.credentials-test",
|
|
305
|
+
.permitted = true,
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
fx.credentialsGet(.{ .key = 20, .credential_key = "token", .on_result = Fx.credentialsMsg(.result) });
|
|
309
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingHostCount());
|
|
310
|
+
const request = fx.pendingHostAt(0).?;
|
|
311
|
+
try std.testing.expectEqualStrings("core.credentials.get", request.name);
|
|
312
|
+
|
|
313
|
+
const digest = [_]u8{0x5a} ** 32;
|
|
314
|
+
try fx.feedCredentialsResult(20, .get, .ok, 12, digest);
|
|
315
|
+
const first = try takeResult(&fx);
|
|
316
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.ok, first.outcome);
|
|
317
|
+
try std.testing.expectEqual(@as(usize, 12), first.bytes.len);
|
|
318
|
+
try std.testing.expect(!std.mem.eql(u8, "live-secret", first.bytes));
|
|
319
|
+
var first_copy: [12]u8 = undefined;
|
|
320
|
+
@memcpy(&first_copy, first.bytes);
|
|
321
|
+
|
|
322
|
+
fx.credentialsGet(.{ .key = 21, .credential_key = "token", .on_result = Fx.credentialsMsg(.result) });
|
|
323
|
+
try fx.feedCredentialsResult(21, .get, .ok, 12, digest);
|
|
324
|
+
const second = try takeResult(&fx);
|
|
325
|
+
try std.testing.expectEqualSlices(u8, &first_copy, second.bytes);
|
|
326
|
+
|
|
327
|
+
fx.credentialsGet(.{ .key = 22, .credential_key = "missing", .on_result = Fx.credentialsMsg(.result) });
|
|
328
|
+
try fx.feedCredentialsResult(22, .get, .miss, 0, [_]u8{0} ** 32);
|
|
329
|
+
const miss = try takeResult(&fx);
|
|
330
|
+
try std.testing.expectEqual(effects_mod.EffectCredentialsOutcome.miss, miss.outcome);
|
|
331
|
+
try std.testing.expectEqualStrings("", miss.bytes);
|
|
332
|
+
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
const std = @import("std");
|
|
11
11
|
const geometry = @import("geometry");
|
|
12
12
|
const app_manifest = @import("app_manifest");
|
|
13
|
+
const platform = @import("../platform/root.zig");
|
|
13
14
|
const core = @import("core.zig");
|
|
14
15
|
const ui_app_mod = @import("ui_app.zig");
|
|
15
16
|
const effects_mod = @import("effects.zig");
|
|
@@ -64,6 +65,11 @@ const HostMsg = union(enum) {
|
|
|
64
65
|
ask_other,
|
|
65
66
|
ask_oversized,
|
|
66
67
|
ask_colliding,
|
|
68
|
+
query_launch_at_login,
|
|
69
|
+
enable_launch_at_login,
|
|
70
|
+
credential_prefixed_request,
|
|
71
|
+
open_external_url,
|
|
72
|
+
reveal_path,
|
|
67
73
|
replace,
|
|
68
74
|
drop,
|
|
69
75
|
send,
|
|
@@ -84,6 +90,14 @@ const timer_key: u64 = 9;
|
|
|
84
90
|
// Set by tests before dispatching `.ask`/`.replace`.
|
|
85
91
|
var test_payload: []const u8 = "";
|
|
86
92
|
|
|
93
|
+
fn failLaunchAtLoginStatus(_: ?*anyopaque) anyerror!platform.LaunchAtLoginStatus {
|
|
94
|
+
return error.LaunchAtLoginFailed;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
fn failSetLaunchAtLogin(_: ?*anyopaque, _: bool) anyerror!platform.LaunchAtLoginStatus {
|
|
98
|
+
return error.LaunchAtLoginFailed;
|
|
99
|
+
}
|
|
100
|
+
|
|
87
101
|
fn hostUpdate(model: *HostModel, msg: HostMsg, fx: *HostEffects) void {
|
|
88
102
|
switch (msg) {
|
|
89
103
|
.ask => fx.hostRequest(.{
|
|
@@ -110,6 +124,25 @@ fn hostUpdate(model: *HostModel, msg: HostMsg, fx: *HostEffects) void {
|
|
|
110
124
|
.name = "svc.echo",
|
|
111
125
|
.on_result = HostEffects.hostMsg(.host_result),
|
|
112
126
|
}),
|
|
127
|
+
.query_launch_at_login => fx.hostRequest(.{
|
|
128
|
+
.key = ask_key,
|
|
129
|
+
.name = "native-sdk.launch-at-login.status",
|
|
130
|
+
.on_result = HostEffects.hostMsg(.host_result),
|
|
131
|
+
}),
|
|
132
|
+
.enable_launch_at_login => fx.hostRequest(.{
|
|
133
|
+
.key = ask_key,
|
|
134
|
+
.name = "native-sdk.launch-at-login.set",
|
|
135
|
+
.payload = &.{1},
|
|
136
|
+
.on_result = HostEffects.hostMsg(.host_result),
|
|
137
|
+
}),
|
|
138
|
+
.credential_prefixed_request => fx.hostRequest(.{
|
|
139
|
+
.key = ask_key,
|
|
140
|
+
.name = "core.credentials.probe",
|
|
141
|
+
.payload = &.{1},
|
|
142
|
+
.on_result = HostEffects.hostMsg(.host_result),
|
|
143
|
+
}),
|
|
144
|
+
.open_external_url => fx.hostSend("native-sdk.os.openUrl", "https://example.com/docs"),
|
|
145
|
+
.reveal_path => fx.hostSend("native-sdk.os.revealPath", "/tmp/native-sdk.log"),
|
|
113
146
|
.replace => fx.hostRequest(.{
|
|
114
147
|
.key = ask_key,
|
|
115
148
|
.name = "svc.echo",
|
|
@@ -235,6 +268,85 @@ test "fake executor parks host requests and feeds results back as msgs" {
|
|
|
235
268
|
try std.testing.expectError(error.EffectNotFound, fx.feedHostResult(ask_key, true, ""));
|
|
236
269
|
}
|
|
237
270
|
|
|
271
|
+
test "native launch-at-login requests use the platform service without a generic host binding" {
|
|
272
|
+
var h = try Harness.create();
|
|
273
|
+
defer h.destroy();
|
|
274
|
+
|
|
275
|
+
h.harness.null_platform.launch_at_login_status = .requires_approval;
|
|
276
|
+
try h.app_state.dispatch(&h.harness.runtime, 1, .query_launch_at_login);
|
|
277
|
+
try h.wake();
|
|
278
|
+
try std.testing.expectEqual(@as(u32, 1), h.app_state.model.ok_count);
|
|
279
|
+
try std.testing.expectEqualStrings("requires_approval", h.app_state.model.bytesPrefix());
|
|
280
|
+
|
|
281
|
+
try h.app_state.dispatch(&h.harness.runtime, 1, .enable_launch_at_login);
|
|
282
|
+
try h.wake();
|
|
283
|
+
try std.testing.expectEqual(@as(u32, 2), h.app_state.model.ok_count);
|
|
284
|
+
try std.testing.expectEqualStrings("enabled", h.app_state.model.bytesPrefix());
|
|
285
|
+
try std.testing.expectEqual(@as(u32, 1), h.harness.null_platform.launch_at_login_set_count);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
test "native launch-at-login set preserves an unsupported platform result" {
|
|
289
|
+
var h = try Harness.create();
|
|
290
|
+
defer h.destroy();
|
|
291
|
+
|
|
292
|
+
// Model a host without the setter after the effects channel has bound
|
|
293
|
+
// the runtime-owned services value. Unsupported is a capability result,
|
|
294
|
+
// not an attempted registration failure.
|
|
295
|
+
h.harness.runtime.options.platform.services.set_launch_at_login_fn = null;
|
|
296
|
+
try h.app_state.dispatch(&h.harness.runtime, 1, .enable_launch_at_login);
|
|
297
|
+
try h.wake();
|
|
298
|
+
|
|
299
|
+
try std.testing.expectEqual(@as(u32, 1), h.app_state.model.err_count);
|
|
300
|
+
try std.testing.expectEqualStrings("unsupported", h.app_state.model.bytesPrefix());
|
|
301
|
+
try std.testing.expectEqual(@as(u32, 0), h.harness.null_platform.launch_at_login_set_count);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
test "native launch-at-login requests distinguish operation failures from unsupported" {
|
|
305
|
+
var h = try Harness.create();
|
|
306
|
+
defer h.destroy();
|
|
307
|
+
|
|
308
|
+
h.harness.runtime.options.platform.services.launch_at_login_status_fn = failLaunchAtLoginStatus;
|
|
309
|
+
try h.app_state.dispatch(&h.harness.runtime, 1, .query_launch_at_login);
|
|
310
|
+
try h.wake();
|
|
311
|
+
try std.testing.expectEqual(@as(u32, 1), h.app_state.model.err_count);
|
|
312
|
+
try std.testing.expectEqualStrings("failed", h.app_state.model.bytesPrefix());
|
|
313
|
+
|
|
314
|
+
h.harness.runtime.options.platform.services.set_launch_at_login_fn = failSetLaunchAtLogin;
|
|
315
|
+
try h.app_state.dispatch(&h.harness.runtime, 1, .enable_launch_at_login);
|
|
316
|
+
try h.wake();
|
|
317
|
+
try std.testing.expectEqual(@as(u32, 2), h.app_state.model.err_count);
|
|
318
|
+
try std.testing.expectEqualStrings("failed", h.app_state.model.bytesPrefix());
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
test "native system commands use runtime validation and platform services" {
|
|
322
|
+
var h = try Harness.create();
|
|
323
|
+
defer h.destroy();
|
|
324
|
+
const fx = &h.app_state.effects;
|
|
325
|
+
|
|
326
|
+
const allowed_urls = [_][]const u8{"https://example.com/*"};
|
|
327
|
+
h.harness.runtime.options.security.navigation.external_links = .{
|
|
328
|
+
.action = .open_system_browser,
|
|
329
|
+
.allowed_urls = &allowed_urls,
|
|
330
|
+
};
|
|
331
|
+
try h.app_state.dispatch(&h.harness.runtime, 1, .open_external_url);
|
|
332
|
+
try h.app_state.dispatch(&h.harness.runtime, 1, .reveal_path);
|
|
333
|
+
try std.testing.expectEqualStrings("https://example.com/docs", h.harness.null_platform.lastExternalUrl());
|
|
334
|
+
try std.testing.expectEqualStrings("/tmp/native-sdk.log", h.harness.null_platform.lastRevealedPath());
|
|
335
|
+
|
|
336
|
+
h.harness.null_platform.local_time_offset_minutes = -360;
|
|
337
|
+
var time_payload: [16]u8 = undefined;
|
|
338
|
+
std.mem.writeInt(u64, time_payload[0..8], @bitCast(@as(f64, 2)), .little);
|
|
339
|
+
std.mem.writeInt(u64, time_payload[8..16], @bitCast(@as(f64, 1_704_164_645_000)), .little);
|
|
340
|
+
fx.hostRequest(.{
|
|
341
|
+
.key = ask_key,
|
|
342
|
+
.name = "native-sdk.time.formatLocal",
|
|
343
|
+
.payload = &time_payload,
|
|
344
|
+
.on_result = HostEffects.hostMsg(.host_result),
|
|
345
|
+
});
|
|
346
|
+
try h.wake();
|
|
347
|
+
try std.testing.expectEqualStrings("2024-01-01 21:04:05", h.app_state.model.bytesPrefix());
|
|
348
|
+
}
|
|
349
|
+
|
|
238
350
|
test "re-issuing a live host key replaces the pending request and drops the undelivered result" {
|
|
239
351
|
var h = try Harness.create();
|
|
240
352
|
defer h.destroy();
|
|
@@ -385,6 +497,55 @@ test "host journal records carry the route in code and mark rejections regenerab
|
|
|
385
497
|
try std.testing.expectEqual(effects_mod.EffectExitReason.rejected, Capture.records[2].exit_reason);
|
|
386
498
|
}
|
|
387
499
|
|
|
500
|
+
test "Zig persistence restore is a staged, journaled Msg and replay ignores live storage" {
|
|
501
|
+
const PersistMsg = union(enum) { restored: effects_mod.EffectPersistResult };
|
|
502
|
+
const PersistEffects = effects_mod.Effects(PersistMsg);
|
|
503
|
+
const Capture = struct {
|
|
504
|
+
var count: usize = 0;
|
|
505
|
+
var outcome: effects_mod.EffectPersistOutcome = .none;
|
|
506
|
+
var bytes: [32]u8 = undefined;
|
|
507
|
+
var bytes_len: usize = 0;
|
|
508
|
+
|
|
509
|
+
fn note(_: *anyopaque, record: effects_mod.EffectResultRecord) void {
|
|
510
|
+
count += 1;
|
|
511
|
+
outcome = record.persist_outcome;
|
|
512
|
+
bytes_len = record.payload.len;
|
|
513
|
+
@memcpy(bytes[0..bytes_len], record.payload);
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
Capture.count = 0;
|
|
518
|
+
var context: u8 = 0;
|
|
519
|
+
var live = PersistEffects.init(std.testing.allocator);
|
|
520
|
+
defer live.deinit();
|
|
521
|
+
live.bindJournal(.{ .context = &context, .record_fn = Capture.note });
|
|
522
|
+
var source = [_]u8{ 's', 'n', 'a', 'p' };
|
|
523
|
+
live.deliverPersistRestore(.ok, &source, PersistEffects.persistMsg(.restored));
|
|
524
|
+
@memset(&source, 'x');
|
|
525
|
+
|
|
526
|
+
const live_msg = live.takeMsg() orelse return error.TestExpectedMsg;
|
|
527
|
+
try std.testing.expectEqual(effects_mod.EffectPersistOutcome.ok, live_msg.restored.outcome);
|
|
528
|
+
try std.testing.expectEqualStrings("snap", live_msg.restored.bytes);
|
|
529
|
+
try std.testing.expectEqual(@as(usize, 1), Capture.count);
|
|
530
|
+
try std.testing.expectEqual(effects_mod.EffectPersistOutcome.ok, Capture.outcome);
|
|
531
|
+
try std.testing.expectEqualStrings("snap", Capture.bytes[0..Capture.bytes_len]);
|
|
532
|
+
|
|
533
|
+
Capture.count = 0;
|
|
534
|
+
var replay = PersistEffects.init(std.testing.allocator);
|
|
535
|
+
defer replay.deinit();
|
|
536
|
+
replay.bindJournal(.{ .context = &context, .record_fn = Capture.note });
|
|
537
|
+
replay.armReplay();
|
|
538
|
+
var replay_source = "recorded".*;
|
|
539
|
+
try replay.pushReplayPersist(.ok, &replay_source);
|
|
540
|
+
@memset(&replay_source, 'x');
|
|
541
|
+
replay.deliverPersistRestore(.ok, "live bytes must lose", PersistEffects.persistMsg(.restored));
|
|
542
|
+
const replay_msg = replay.takeMsg() orelse return error.TestExpectedMsg;
|
|
543
|
+
try std.testing.expectEqual(effects_mod.EffectPersistOutcome.ok, replay_msg.restored.outcome);
|
|
544
|
+
try std.testing.expectEqualStrings("recorded", replay_msg.restored.bytes);
|
|
545
|
+
try std.testing.expectEqual(@as(usize, 0), Capture.count);
|
|
546
|
+
try replay.settleReplayFeeds();
|
|
547
|
+
}
|
|
548
|
+
|
|
388
549
|
// ------------------------------------------------------------ real executor
|
|
389
550
|
|
|
390
551
|
test "real-mode host calls ride the binding and answer through the feed" {
|
|
@@ -408,6 +569,8 @@ test "real-mode host calls ride the binding and answer through the feed" {
|
|
|
408
569
|
_ = payload;
|
|
409
570
|
if (std.mem.eql(u8, name, "svc.echo")) {
|
|
410
571
|
bound.?.feedHostResult(key, true, "echoed") catch unreachable;
|
|
572
|
+
} else if (std.mem.eql(u8, name, "core.credentials.probe")) {
|
|
573
|
+
bound.?.feedHostResult(key, false, "host-routed") catch unreachable;
|
|
411
574
|
}
|
|
412
575
|
// svc.other never answers — it stays in flight for the
|
|
413
576
|
// cancel below.
|
|
@@ -441,13 +604,57 @@ test "real-mode host calls ride the binding and answer through the feed" {
|
|
|
441
604
|
try std.testing.expectEqual(@as(u32, 1), h.app_state.model.ok_count);
|
|
442
605
|
try std.testing.expectEqualStrings("echoed", h.app_state.model.bytesPrefix());
|
|
443
606
|
|
|
607
|
+
// A generic request that happens to use the credential prefix remains a
|
|
608
|
+
// generic host call. It must never fall through to launch-at-login.
|
|
609
|
+
try h.app_state.dispatch(&h.harness.runtime, 1, .credential_prefixed_request);
|
|
610
|
+
try h.wake();
|
|
611
|
+
try std.testing.expectEqualStrings("host-routed", h.app_state.model.bytesPrefix());
|
|
612
|
+
try std.testing.expectEqual(@as(u32, 0), h.harness.null_platform.launch_at_login_set_count);
|
|
613
|
+
|
|
444
614
|
// Cancelling an unanswered request notifies the host, silently.
|
|
445
615
|
try h.app_state.dispatch(&h.harness.runtime, 1, .ask_other);
|
|
446
616
|
fx.cancelHostRequest(other_key);
|
|
447
617
|
try h.wake();
|
|
448
618
|
try std.testing.expectEqual(@as(usize, 1), Stub.cancel_count);
|
|
449
619
|
try std.testing.expectEqual(other_key, Stub.last_cancelled);
|
|
450
|
-
try std.testing.expectEqual(@as(u32,
|
|
620
|
+
try std.testing.expectEqual(@as(u32, 2), h.app_state.model.result_count);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
test "service bindings reject a duplicate live key without replacing the first request" {
|
|
624
|
+
var h = try Harness.create();
|
|
625
|
+
defer h.destroy();
|
|
626
|
+
const fx = &h.app_state.effects;
|
|
627
|
+
|
|
628
|
+
const Stub = struct {
|
|
629
|
+
var request_count: usize = 0;
|
|
630
|
+
fn send(_: *anyopaque, _: []const u8, _: []const u8) void {}
|
|
631
|
+
fn request(_: *anyopaque, _: []const u8, _: u64, _: []const u8) void {
|
|
632
|
+
request_count += 1;
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
Stub.request_count = 0;
|
|
636
|
+
var context: u8 = 0;
|
|
637
|
+
fx.bindHostCalls(.{
|
|
638
|
+
.context = &context,
|
|
639
|
+
.send_fn = Stub.send,
|
|
640
|
+
.request_fn = Stub.request,
|
|
641
|
+
.reject_duplicate_keys = true,
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
test_payload = "first";
|
|
645
|
+
try h.app_state.dispatch(&h.harness.runtime, 1, .ask);
|
|
646
|
+
test_payload = "duplicate";
|
|
647
|
+
try h.app_state.dispatch(&h.harness.runtime, 1, .replace);
|
|
648
|
+
try std.testing.expectEqual(@as(usize, 1), Stub.request_count);
|
|
649
|
+
try h.wake();
|
|
650
|
+
try std.testing.expectEqual(@as(u32, 1), h.app_state.model.err_count);
|
|
651
|
+
try std.testing.expectEqualStrings("rejected", h.app_state.model.bytesPrefix());
|
|
652
|
+
|
|
653
|
+
// The first occupancy survived the refusal and can still complete.
|
|
654
|
+
try fx.feedHostResult(ask_key, true, "first-answer");
|
|
655
|
+
try h.wake();
|
|
656
|
+
try std.testing.expectEqual(@as(u32, 1), h.app_state.model.ok_count);
|
|
657
|
+
try std.testing.expectEqualStrings("first-answer", h.app_state.model.bytesPrefix());
|
|
451
658
|
}
|
|
452
659
|
|
|
453
660
|
test "real-mode requests without bound host services reject through the err route" {
|