generated-scene: add scheduled monitoring runtime and helper lifecycle hardening

This commit is contained in:
木炎
2026-05-06 09:47:12 +08:00
parent 6cdd71b682
commit 8162118e6d
183 changed files with 103674 additions and 130 deletions

View File

@@ -1,4 +1,5 @@
use std::net::TcpListener;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
@@ -208,6 +209,84 @@ fn parse_probe_args_defaults_timeout_when_flag_is_omitted() {
);
}
fn temp_step_file(name: &str, contents: &str) -> PathBuf {
let mut path = std::env::temp_dir();
let nanos = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos();
path.push(format!("sgclaw-ws-probe-{name}-{nanos}.txt"));
std::fs::write(&path, contents).unwrap();
path
}
#[test]
fn parse_probe_args_accepts_step_file() {
let step_file = temp_step_file(
"single",
"open-agent::[\"about:blank\",\"sgOpenAgent\"]\n",
);
let args = vec![
"--ws-url".to_string(),
"ws://127.0.0.1:12345".to_string(),
"--step-file".to_string(),
step_file.display().to_string(),
];
let parsed = parse_probe_args(&args).unwrap();
assert_eq!(parsed.ws_url, "ws://127.0.0.1:12345");
assert_eq!(parsed.timeout_ms, 1500);
assert_eq!(
parsed.steps,
vec![ProbeStep {
label: "open-agent".to_string(),
payload: "[\"about:blank\",\"sgOpenAgent\"]".to_string(),
expect_reply: true,
}]
);
let _ = std::fs::remove_file(step_file);
}
#[test]
fn parse_probe_args_preserves_step_and_step_file_order() {
let step_file = temp_step_file(
"ordered",
"open-hot::[\"about:blank\",\"sgBrowerserOpenPage\",\"https://www.zhihu.com/hot\"]\n",
);
let args = vec![
"--ws-url".to_string(),
"ws://127.0.0.1:12345".to_string(),
"--step".to_string(),
"open-agent::[\"about:blank\",\"sgOpenAgent\"]".to_string(),
"--step-file".to_string(),
step_file.display().to_string(),
];
let parsed = parse_probe_args(&args).unwrap();
assert_eq!(
parsed.steps,
vec![
ProbeStep {
label: "open-agent".to_string(),
payload: "[\"about:blank\",\"sgOpenAgent\"]".to_string(),
expect_reply: true,
},
ProbeStep {
label: "open-hot".to_string(),
payload:
"[\"about:blank\",\"sgBrowerserOpenPage\",\"https://www.zhihu.com/hot\"]"
.to_string(),
expect_reply: true,
},
]
);
let _ = std::fs::remove_file(step_file);
}
#[test]
fn probe_records_welcome_then_silence_transcript() {
let steps = vec![