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

@@ -2,12 +2,14 @@ mod common;
use std::collections::HashMap;
use std::fs;
use std::panic::AssertUnwindSafe;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
use std::time::{SystemTime, UNIX_EPOCH};
use common::MockTransport;
use futures_util::FutureExt;
use serde_json::json;
use sgclaw::browser::{BrowserBackend, PipeBrowserBackend};
use sgclaw::compat::browser_script_skill_tool::{
@@ -201,6 +203,77 @@ async fn execute_browser_script_tool_rejects_missing_expected_domain() {
assert!(transport.sent_messages().is_empty());
}
#[tokio::test]
async fn execute_browser_script_tool_handles_multibyte_wrapped_script_preview_without_panicking() {
let skill_dir = unique_temp_dir("sgclaw-browser-script-helper-utf8-preview");
let scripts_dir = skill_dir.join("scripts");
fs::create_dir_all(&scripts_dir).unwrap();
let args_json = json!({
"expected_domain": "www.zhihu.com"
});
let prefix_len = format!("(function() {{\nconst args = {};\n", args_json)
.len();
let comment_prefix = "//";
let ascii_padding = (0..3)
.find(|pad| (500usize - (prefix_len + comment_prefix.len() + *pad)) % 3 != 0)
.expect("should find a padding value that forces byte 500 off a char boundary");
let script_body = format!(
"{}{}{}\nreturn {{ ok: true }};\n",
comment_prefix,
"a".repeat(ascii_padding),
"".repeat(220)
);
fs::write(scripts_dir.join("utf8_preview.js"), script_body).unwrap();
let transport = Arc::new(MockTransport::new(vec![BrowserMessage::Response {
seq: 1,
success: true,
data: json!({
"text": {
"ok": true
}
}),
aom_snapshot: vec![],
timing: Timing {
queue_ms: 1,
exec_ms: 5,
},
}]));
let browser_tool = BrowserPipeTool::new(
transport.clone(),
test_policy(),
vec![1, 2, 3, 4, 5, 6, 7, 8],
)
.with_response_timeout(Duration::from_secs(1));
let skill_tool = SkillTool {
name: "utf8_preview".to_string(),
description: "Regression for UTF-8 safe wrapped script preview logging".to_string(),
kind: "browser_script".to_string(),
command: "scripts/utf8_preview.js".to_string(),
args: HashMap::new(),
};
let result = AssertUnwindSafe(execute_browser_script_tool(
&skill_tool,
&skill_dir,
&PipeBrowserBackend::from_inner(browser_tool),
json!({
"expected_domain": "www.zhihu.com"
}),
))
.catch_unwind()
.await;
assert!(
result.is_ok(),
"wrapped script preview should not panic on multibyte UTF-8 content"
);
let tool_result = result.unwrap().unwrap();
assert!(tool_result.success);
}
#[tokio::test]
async fn browser_script_skill_tool_executes_packaged_script_via_eval() {
let skill_dir = unique_temp_dir("sgclaw-browser-script-skill");