euv_core/dynamic/wasm/enum.rs
1use super::*;
2
3/// Target execution scope for a dynamically downloaded `.wasm` module.
4#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
5pub enum WasmDynamicScope {
6 /// Scoped partial slot replacing only a single named component subtree without disturbing siblings.
7 Partial {
8 /// Unique target slot identifier (e.g. `"wasm_promo_slot"`).
9 slot_id: String,
10 },
11 /// Global full-application bundle atomically taking over the root shell and route table with LKG rollback.
12 #[default]
13 Global,
14}
15
16/// Typed lifecycle state for a dynamic WASM download, verification, execution, and mount operation.
17#[derive(Clone, Debug, Default, Eq, PartialEq)]
18pub enum WasmLoadState {
19 /// No dynamic WASM download has been initiated yet.
20 #[default]
21 Idle,
22 /// Download in progress with byte-level streaming telemetry.
23 Downloading {
24 /// Bytes received so far.
25 received_bytes: u64,
26 /// Total expected bytes (`0` if unknown).
27 total_bytes: u64,
28 },
29 /// Verifying binary size ceiling, FNV-1a checksum, and signature integrity.
30 Verifying,
31 /// Parsing WebAssembly binary sections and validating host ABI exports.
32 Compiling,
33 /// Executing sandboxed WASM bytecode to generate the native UI tree.
34 Executing,
35 /// Successfully mounted as native `euv` scene nodes.
36 Mounted {
37 /// Active module version number.
38 version: u64,
39 /// Whether bytes were served from verified offline/local cache.
40 from_cache: bool,
41 /// Exact sandbox instruction fuel consumed during render.
42 fuel_used: u64,
43 },
44 /// Automatically or manually rolled back to a previously verified Last-Known-Good snapshot.
45 RolledBack {
46 /// Version active after rollback (`0` indicates built-in native fallback).
47 active_version: u64,
48 /// Human-readable reason triggering the rollback.
49 reason: String,
50 },
51 /// Operation failed cleanly with typed diagnostics; host remains intact.
52 Failed(WasmDynamicError),
53}
54
55/// Comprehensive typed error taxonomy covering all network, integrity, ABI, and sandbox failure cases.
56#[derive(Clone, Debug, Eq, Hash, PartialEq)]
57pub enum WasmDynamicError {
58 /// Download URL was empty, malformed, or used an unsupported scheme.
59 InvalidUrl(String),
60 /// Network transport is offline and no eligible verified cache entry exists.
61 NetworkOffline(String),
62 /// Remote server returned a non-2xx HTTP status code.
63 HttpStatus {
64 /// HTTP status code (e.g. `404`, `500`, `503`).
65 status: u16,
66 /// Requested bundle URL.
67 url: String,
68 },
69 /// Download exceeded configured `timeout_ms`.
70 Timeout {
71 /// Requested bundle URL.
72 url: String,
73 /// Timeout threshold in milliseconds.
74 timeout_ms: u64,
75 },
76 /// Request was explicitly cancelled before completion.
77 Cancelled {
78 /// Cancelled monotonic request identifier.
79 request_id: u64,
80 },
81 /// Response belonged to a superseded request generation and was discarded safely.
82 StaleResponse {
83 /// Superseded request identifier.
84 request_id: u64,
85 /// Current active request identifier.
86 active_request_id: u64,
87 },
88 /// Downloaded binary exceeded `max_binary_bytes`.
89 BinaryTooLarge {
90 /// Actual byte length.
91 actual: usize,
92 /// Configured ceiling.
93 limit: usize,
94 },
95 /// Binary failed WebAssembly magic/version/section decoding.
96 InvalidWasmBinary(String),
97 /// Computed FNV-1a checksum did not match `expected_checksum`.
98 ChecksumMismatch {
99 /// Expected checksum declared by manifest.
100 expected: u64,
101 /// Actual checksum of downloaded bytes.
102 actual: u64,
103 },
104 /// Cryptographic/HMAC signature tag verification failed.
105 SignatureInvalid {
106 /// Expected signature string.
107 expected: String,
108 /// Computed signature string.
109 actual: String,
110 },
111 /// Module reported an incompatible euv host ABI version.
112 AbiMismatch {
113 /// Host ABI version required by runtime.
114 expected: u32,
115 /// ABI version returned by module.
116 actual: u32,
117 },
118 /// Required exported function (e.g. `euv_render`) was absent from `.wasm` module.
119 MissingExport(String),
120 /// Incoming version was lower than or equal to the active version without `allow_downgrade`.
121 VersionRegression {
122 /// Currently active version.
123 current: u64,
124 /// Rejected incoming version.
125 incoming: u64,
126 },
127 /// Module requested linear memory exceeding `max_memory_bytes`.
128 MemoryLimitExceeded {
129 /// Requested linear memory bytes.
130 requested: usize,
131 /// Configured sandbox ceiling.
132 limit: usize,
133 },
134 /// WASM instruction attempted an out-of-bounds linear memory read or write.
135 MemoryOutOfBounds {
136 /// Target linear memory address.
137 addr: u32,
138 /// Requested slice length.
139 len: u32,
140 /// Active memory size in bytes.
141 memory_size: usize,
142 },
143 /// Sandbox terminated runaway/infinite-loop execution upon hitting `max_fuel`.
144 OutOfFuel {
145 /// Fuel instruction ceiling exceeded.
146 limit: u64,
147 },
148 /// WASM execution trapped (`unreachable`, divide-by-zero, or stack underflow/overflow).
149 ExecutionTrap(String),
150 /// WASM emitted an invalid or unparseable native UI specification payload.
151 InvalidUiPayload(String),
152 /// Rollback requested when no prior verified snapshot exists.
153 NoRollbackSnapshot,
154}
155
156/// Deterministic fault injection scenarios for verifying every production failure path end-to-end.
157#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
158pub enum WasmFaultKind {
159 /// Normal healthy `.wasm` delivery and execution.
160 #[default]
161 None,
162 /// Simulate offline device network failure (exercises offline cache fallback when available).
163 NetworkOffline,
164 /// Simulate transient timeout on first attempt that succeeds on automatic retry.
165 TimeoutOnceThenSucceed,
166 /// Simulate persistent HTTP 500 server failure across all retry attempts.
167 Http500,
168 /// Deliver bytes with corrupted `.wasm` magic header.
169 CorruptedMagic,
170 /// Flip a byte inside a valid `.wasm` to trigger checksum rejection.
171 TamperedChecksum,
172 /// Provide a mismatched signature tag to trigger signature rejection.
173 InvalidSignature,
174 /// Execute a valid `.wasm` returning an unsupported `euv_abi_version`.
175 AbiMismatch,
176 /// Execute a valid `.wasm` missing the required `euv_render` export.
177 MissingExport,
178 /// Execute a valid `.wasm` containing an infinite `loop { br 0 }` to trigger `OutOfFuel`.
179 InfiniteLoopOutOfFuel,
180 /// Execute a valid `.wasm` executing `unreachable` to trigger `ExecutionTrap`.
181 ExecutionTrap,
182 /// Deliver a payload exceeding `max_binary_bytes` to trigger `BinaryTooLarge`.
183 OversizedBinary,
184}