1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
use std::collections::HashMap;
use std::time::Duration;
use serde::Deserialize;
use serde::Serialize;
use ts_rs::TS;
use super::SourceLocation;
use super::span::SpanId;
pub type EventSeq = u64;
/// Structured representation of an effective timeout (the `IrTimeout` value
/// that bounded a wait or was installed by a `timeout` statement). Pre-formatted
/// with humantime so consumers never do duration arithmetic.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
#[cfg_attr(
feature = "ts-export",
ts(export, export_to = "../../../viewer/src/types/")
)]
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum TimeoutValue {
Tolerance {
duration: String,
multiplier: String,
total_duration: String,
source: Option<SourceLocation>,
},
Assertion {
duration: String,
source: Option<SourceLocation>,
},
}
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
#[cfg_attr(
feature = "ts-export",
ts(export, export_to = "../../../viewer/src/types/")
)]
pub struct Event {
pub seq: EventSeq,
#[serde(with = "super::ts_duration_ms")]
#[ts(as = "f64")]
pub ts: Duration,
pub span: SpanId,
pub shell: Option<String>,
/// Stable identity for the shell, when present. Present iff
/// `shell` is present. Viewers index by marker; `shell` is the
/// display name at emit time (qualified post-export, bare pre).
pub shell_marker: Option<String>,
/// Source byte range that produced this event, when one is in
/// scope at the emit site. Resolves against `StructuredLog.sources`.
pub source: Option<SourceLocation>,
#[serde(flatten)]
pub kind: EventKind,
}
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
#[cfg_attr(
feature = "ts-export",
ts(export, export_to = "../../../viewer/src/types/")
)]
#[serde(tag = "kind", rename_all = "kebab-case")]
pub enum EventKind {
// Shell lifecycle
ShellSpawn {
name: String,
command: String,
},
ShellReady {
name: String,
},
ShellSwitch {
name: String,
},
ShellTerminate {
name: String,
},
// Effect exposes — emitted at the end of effect setup, one per
// expose decl. Hidden from the viewer timeline; surfaced as inline
// props on the owning effect-setup span.
EffectExposeShell {
/// Caller-visible name (the rename target, or the source name
/// when no `as <name>`).
name: String,
/// Source name in the local scope: a local shell key, or an
/// imported dep's exposed-shell key.
target: String,
/// `Some(alias)` when re-exposing from a dependency
/// (`expose shell <alias>.<target> as <name>`).
qualifier: Option<String>,
},
EffectExposeVar {
name: String,
target: String,
qualifier: Option<String>,
/// Resolved value at expose time.
value: String,
},
// I/O
Send {
data: String,
},
Recv {
data: String,
},
// Matching — buffer_seq references the corresponding buffer_events entry.
MatchStart {
pattern: String,
is_regex: bool,
/// The timeout that bounds this wait.
effective: TimeoutValue,
},
MatchDone {
matched: String,
#[serde(with = "super::ts_duration_ms")]
#[ts(as = "f64")]
elapsed: Duration,
captures: Option<HashMap<String, String>>,
buffer_seq: EventSeq,
},
Timeout {
pattern: String,
/// `None` when no buffer event corresponds (the failure record's
/// `buffer_tail` is canonical for the timeout state).
buffer_seq: Option<EventSeq>,
/// The timeout that fired.
effective: TimeoutValue,
},
// Fail patterns
FailPatternSet {
pattern: String,
is_regex: bool,
},
FailPatternCleared,
FailPatternTriggered {
pattern: String,
is_regex: bool,
matched_line: String,
/// `None` for fail-pattern hits — they observe without advancing the
/// cursor, so no `Matched` buffer event corresponds.
buffer_seq: Option<EventSeq>,
},
// Control flow
SleepStart {
#[serde(with = "super::ts_duration_ms")]
#[ts(as = "f64")]
duration: Duration,
},
SleepDone,
TimeoutSet {
timeout: TimeoutValue,
previous: TimeoutValue,
},
// Values
VarLet {
name: String,
value: String,
},
VarAssign {
name: String,
value: String,
previous: String,
},
StringEval {
result: String,
},
Interpolation {
template: String,
result: String,
bindings: Vec<(String, String)>,
},
/// Pure string-match. Today: marker `expr ? ^pat$` conditions.
/// `result` is the matched substring (`$0`) or `""` on no match.
/// `captures` mirrors shell-buffer match captures.
PureMatch {
match_kind: super::span::MatchKind,
value: String,
pattern: String,
result: String,
captures: HashMap<String, String>,
},
/// Pure variable read: a bare-var expression resolved against the
/// active scope or environment. `value` is the resolved string
/// (`""` when the variable is undefined). Read counterpart to
/// `var-let` / `var-assign`.
VarRead {
name: String,
value: String,
},
/// Final truthy/falsy evaluation of a marker condition. Carries
/// the shape-specific payload (Unconditional / Bare / Eq / Regex)
/// and the `met` outcome that determined the marker's decision.
/// Emitted as the last event inside a `marker-eval` span.
BoolCheck {
evaluation: super::span::MarkerEvalDetail,
},
// Diagnostics
Annotate {
text: String,
},
Log {
message: String,
},
Warning {
message: String,
},
Error {
message: String,
},
// External interruption observed by the VM. Tagged with the reason
// (test-timeout, suite-timeout, fail-fast, sigint). Emitted on the
// span the VM was in when it noticed `cancel.is_cancelled()`.
Cancelled {
reason: CancelReasonRecord,
},
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
#[cfg_attr(
feature = "ts-export",
ts(export, export_to = "../../../viewer/src/types/")
)]
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum CancelReasonRecord {
TestTimeout { duration_ms: u64 },
SuiteTimeout { duration_ms: u64 },
FailFast { trigger_test: String },
Sigint,
}
impl CancelReasonRecord {
pub fn tag(&self) -> &'static str {
match self {
Self::TestTimeout { .. } => "test-timeout",
Self::SuiteTimeout { .. } => "suite-timeout",
Self::FailFast { .. } => "fail-fast",
Self::Sigint => "sigint",
}
}
}
impl From<&crate::cancel::CancelReason> for CancelReasonRecord {
fn from(r: &crate::cancel::CancelReason) -> Self {
use crate::cancel::CancelReason;
match r {
CancelReason::TestTimeout { duration } => Self::TestTimeout {
duration_ms: duration.as_millis() as u64,
},
CancelReason::SuiteTimeout { duration } => Self::SuiteTimeout {
duration_ms: duration.as_millis() as u64,
},
CancelReason::FailFast { trigger_test } => Self::FailFast {
trigger_test: trigger_test.clone(),
},
CancelReason::Sigint => Self::Sigint,
}
}
}
#[cfg(test)]
mod pure_match_tests {
use super::*;
use std::collections::HashMap;
#[test]
fn pure_match_event_kind_serialises() {
let mut caps = HashMap::new();
caps.insert("0".to_string(), "abc".to_string());
let k = EventKind::PureMatch {
match_kind: super::super::span::MatchKind::Regex,
value: "abc".into(),
pattern: "^a.c$".into(),
result: "abc".into(),
captures: caps,
};
let v = serde_json::to_value(&k).unwrap();
assert_eq!(v["kind"], serde_json::json!("pure-match"));
assert_eq!(v["match_kind"], serde_json::json!("regex"));
assert_eq!(v["result"], serde_json::json!("abc"));
}
}