feat: add generated scene skill platform hardening
This commit is contained in:
@@ -14,14 +14,26 @@ use ws_probe::{
|
||||
|
||||
#[derive(Clone)]
|
||||
enum ServerStep {
|
||||
ReceiveThenReply { expected: String, reply: String },
|
||||
ReceiveThenReplyFrames { expected: String, replies: Vec<String> },
|
||||
ReceiveThenStaySilent { expected: String },
|
||||
ReceiveThenClose { expected: String },
|
||||
ReceiveThenReply {
|
||||
expected: String,
|
||||
reply: String,
|
||||
},
|
||||
ReceiveThenReplyFrames {
|
||||
expected: String,
|
||||
replies: Vec<String>,
|
||||
},
|
||||
ReceiveThenStaySilent {
|
||||
expected: String,
|
||||
},
|
||||
ReceiveThenClose {
|
||||
expected: String,
|
||||
},
|
||||
CloseBeforeReceive,
|
||||
}
|
||||
|
||||
fn spawn_fake_server(script: Vec<ServerStep>) -> (String, Arc<Mutex<Vec<String>>>, thread::JoinHandle<()>) {
|
||||
fn spawn_fake_server(
|
||||
script: Vec<ServerStep>,
|
||||
) -> (String, Arc<Mutex<Vec<String>>>, thread::JoinHandle<()>) {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let addr = listener.local_addr().unwrap();
|
||||
let received = Arc::new(Mutex::new(Vec::new()));
|
||||
@@ -157,10 +169,7 @@ fn parse_probe_args_accepts_ws_url_timeout_and_ordered_steps() {
|
||||
|
||||
#[test]
|
||||
fn parse_probe_args_defaults_register_step_when_step_is_omitted() {
|
||||
let args = vec![
|
||||
"--ws-url".to_string(),
|
||||
"ws://127.0.0.1:12345".to_string(),
|
||||
];
|
||||
let args = vec!["--ws-url".to_string(), "ws://127.0.0.1:12345".to_string()];
|
||||
|
||||
let parsed = parse_probe_args(&args).unwrap();
|
||||
|
||||
@@ -227,7 +236,10 @@ fn probe_records_welcome_then_silence_transcript() {
|
||||
|
||||
assert_eq!(
|
||||
received.lock().unwrap().clone(),
|
||||
steps.iter().map(|step| step.payload.clone()).collect::<Vec<_>>()
|
||||
steps
|
||||
.iter()
|
||||
.map(|step| step.payload.clone())
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
assert_eq!(
|
||||
results,
|
||||
@@ -263,7 +275,8 @@ fn probe_runs_ordered_frame_script_and_records_per_step_results() {
|
||||
},
|
||||
ProbeStep {
|
||||
label: "action".to_string(),
|
||||
payload: r#"["about:blank","sgBrowerserOpenPage","https://www.zhihu.com/hot"]"#.to_string(),
|
||||
payload: r#"["about:blank","sgBrowerserOpenPage","https://www.zhihu.com/hot"]"#
|
||||
.to_string(),
|
||||
expect_reply: true,
|
||||
},
|
||||
];
|
||||
@@ -285,15 +298,27 @@ fn probe_runs_ordered_frame_script_and_records_per_step_results() {
|
||||
|
||||
assert_eq!(
|
||||
received.lock().unwrap().clone(),
|
||||
steps.iter().map(|step| step.payload.clone()).collect::<Vec<_>>()
|
||||
steps
|
||||
.iter()
|
||||
.map(|step| step.payload.clone())
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
assert_eq!(results.len(), 3);
|
||||
assert_eq!(results[0].label, "bootstrap-1");
|
||||
assert_eq!(results[0].outcome, ProbeOutcome::Received(vec!["welcome".to_string()]));
|
||||
assert_eq!(
|
||||
results[0].outcome,
|
||||
ProbeOutcome::Received(vec!["welcome".to_string()])
|
||||
);
|
||||
assert_eq!(results[1].label, "bootstrap-2");
|
||||
assert_eq!(results[1].outcome, ProbeOutcome::Received(vec!["0".to_string()]));
|
||||
assert_eq!(
|
||||
results[1].outcome,
|
||||
ProbeOutcome::Received(vec!["0".to_string()])
|
||||
);
|
||||
assert_eq!(results[2].label, "action");
|
||||
assert_eq!(results[2].sent, r#"["about:blank","sgBrowerserOpenPage","https://www.zhihu.com/hot"]"#);
|
||||
assert_eq!(
|
||||
results[2].sent,
|
||||
r#"["about:blank","sgBrowerserOpenPage","https://www.zhihu.com/hot"]"#
|
||||
);
|
||||
assert_eq!(results[2].outcome, ProbeOutcome::TimedOut);
|
||||
|
||||
handle.join().unwrap();
|
||||
@@ -313,7 +338,10 @@ fn probe_records_multiple_frames_for_one_step_within_timeout_window() {
|
||||
|
||||
let results = run_probe_script(&ws_url, Duration::from_millis(40), steps.clone()).unwrap();
|
||||
|
||||
assert_eq!(received.lock().unwrap().as_slice(), [steps[0].payload.as_str()]);
|
||||
assert_eq!(
|
||||
received.lock().unwrap().as_slice(),
|
||||
[steps[0].payload.as_str()]
|
||||
);
|
||||
assert_eq!(
|
||||
results,
|
||||
vec![ProbeStepResult {
|
||||
@@ -336,16 +364,18 @@ fn probe_records_steps_that_do_not_wait_for_reply_without_ambiguity() {
|
||||
payload: r#"["about:blank","sgNoop"]"#.to_string(),
|
||||
expect_reply: false,
|
||||
}];
|
||||
let (ws_url, received, handle) =
|
||||
spawn_fake_server(vec![ServerStep::ReceiveThenStaySilent {
|
||||
expected: steps[0].payload.clone(),
|
||||
}]);
|
||||
let (ws_url, received, handle) = spawn_fake_server(vec![ServerStep::ReceiveThenStaySilent {
|
||||
expected: steps[0].payload.clone(),
|
||||
}]);
|
||||
|
||||
let results = run_probe_script(&ws_url, Duration::from_millis(40), steps.clone()).unwrap();
|
||||
|
||||
handle.join().unwrap();
|
||||
|
||||
assert_eq!(received.lock().unwrap().as_slice(), [steps[0].payload.as_str()]);
|
||||
assert_eq!(
|
||||
received.lock().unwrap().as_slice(),
|
||||
[steps[0].payload.as_str()]
|
||||
);
|
||||
assert_eq!(
|
||||
results,
|
||||
vec![ProbeStepResult {
|
||||
@@ -380,7 +410,10 @@ fn probe_records_close_when_server_closes_before_next_send() {
|
||||
|
||||
let results = run_probe_script(&ws_url, Duration::from_millis(40), steps.clone()).unwrap();
|
||||
|
||||
assert_eq!(received.lock().unwrap().as_slice(), [steps[0].payload.as_str()]);
|
||||
assert_eq!(
|
||||
received.lock().unwrap().as_slice(),
|
||||
[steps[0].payload.as_str()]
|
||||
);
|
||||
assert_eq!(
|
||||
results,
|
||||
vec![
|
||||
@@ -413,7 +446,10 @@ fn probe_reports_socket_close_separately_from_timeout() {
|
||||
|
||||
let results = run_probe_script(&ws_url, Duration::from_millis(40), vec![step]).unwrap();
|
||||
|
||||
assert_eq!(received.lock().unwrap().as_slice(), [r#"["about:blank","sgOpenAgent"]"#]);
|
||||
assert_eq!(
|
||||
received.lock().unwrap().as_slice(),
|
||||
[r#"["about:blank","sgOpenAgent"]"#]
|
||||
);
|
||||
assert_eq!(results.len(), 1);
|
||||
assert_eq!(results[0].label, "close-case");
|
||||
assert_eq!(results[0].outcome, ProbeOutcome::Closed);
|
||||
|
||||
Reference in New Issue
Block a user