mirror of
https://github.com/Tencent/BrowserSkill.git
synced 2026-09-10 13:01:23 +08:00
feat: add console observation command
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -67,6 +67,43 @@ fn parses_top_level_status_and_doctor() {
|
||||
assert!(matches!(cli.command, Command::Doctor));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_console_command_with_context_safety_flags() {
|
||||
let cli = parse(&[
|
||||
"bsk",
|
||||
"console",
|
||||
"--session",
|
||||
"s1",
|
||||
"--tab-id",
|
||||
"9",
|
||||
"--since",
|
||||
"12",
|
||||
"--limit",
|
||||
"75",
|
||||
"--max-text-chars",
|
||||
"2048",
|
||||
"--include-stack",
|
||||
]);
|
||||
let Command::Console(args) = cli.command else {
|
||||
panic!("expected console command");
|
||||
};
|
||||
assert_eq!(args.session, "s1");
|
||||
assert_eq!(args.tab_id, Some(9));
|
||||
assert_eq!(args.since, Some(12));
|
||||
assert_eq!(args.limit, Some(75));
|
||||
assert_eq!(args.max_text_chars, Some(2048));
|
||||
assert!(args.include_stack);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_zero_console_bounds() {
|
||||
assert!(Cli::try_parse_from(["bsk", "console", "--session", "s1", "--limit", "0"]).is_err());
|
||||
assert!(
|
||||
Cli::try_parse_from(["bsk", "console", "--session", "s1", "--max-text-chars", "0"])
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_install_skill_subcommand() {
|
||||
let cli = parse(&["bsk", "install-skill", "--list"]);
|
||||
|
||||
@@ -428,8 +428,8 @@ async fn read_only_tool_passes_through_without_consuming_interrupt_marker() {
|
||||
let (ws_sink, ws_stream) = ws.split();
|
||||
let ws_sink = Arc::new(tokio::sync::Mutex::new(ws_sink));
|
||||
|
||||
// Fake extension: replies to session_start AND to snapshot
|
||||
// (snapshot must succeed transparently). Records click count
|
||||
// Fake extension: replies to session_start, console, and snapshot
|
||||
// (read-only tools must succeed transparently). Records click count
|
||||
// — must remain 0 because the daemon should reject the click
|
||||
// without forwarding.
|
||||
let ws_sink_for_responder = Arc::clone(&ws_sink);
|
||||
@@ -454,6 +454,12 @@ async fn read_only_tool_passes_through_without_consuming_interrupt_marker() {
|
||||
})
|
||||
.unwrap(),
|
||||
),
|
||||
Method::ToolConsole => ResponseBody::Ok(json!({
|
||||
"tab_id": 7,
|
||||
"entries": [],
|
||||
"next_since": 0,
|
||||
"truncated": false
|
||||
})),
|
||||
Method::ToolSnapshot => ResponseBody::Ok(json!({"ok": true})),
|
||||
Method::ToolClick => {
|
||||
observed_click_count_clone
|
||||
@@ -511,8 +517,24 @@ async fn read_only_tool_passes_through_without_consuming_interrupt_marker() {
|
||||
let state = handle.state();
|
||||
wait_for_session_interrupt_pending(&state, &start.session_id).await;
|
||||
|
||||
// Read-only snapshot must succeed AND must not consume the
|
||||
// marker.
|
||||
// Read-only console must succeed AND must not consume the marker.
|
||||
let console_outcome = ipc
|
||||
.call::<_, serde_json::Value>(
|
||||
"console-after-interrupt",
|
||||
Method::ToolConsole,
|
||||
Some(json!({"session_id": start.session_id.clone()})),
|
||||
Duration::from_secs(3),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
console_outcome.is_ok(),
|
||||
"read-only tool.console must pass through transparently (got {:?})",
|
||||
console_outcome
|
||||
);
|
||||
|
||||
// Existing read-only snapshot must still succeed after console,
|
||||
// proving console did not consume the marker.
|
||||
let snapshot_outcome = ipc
|
||||
.call::<_, serde_json::Value>(
|
||||
"snap-after-interrupt",
|
||||
|
||||
@@ -10,9 +10,9 @@ use bsk::daemon::{self, DaemonConfig};
|
||||
use bsk::ipc_client::IpcClient;
|
||||
use bsk_protocol::system::{HandshakeParams, HandshakeResult};
|
||||
use bsk_protocol::tools::{
|
||||
GetHtmlParams, GetHtmlResult, ScreenshotParams, ScreenshotResult, SessionStartParams,
|
||||
SessionStartResult, SnapshotParams, SnapshotResult, TabInfo, TabListParams, TabListResult,
|
||||
TabScope,
|
||||
ConsoleEntry, ConsoleEntryKind, ConsoleParams, ConsoleResult, GetHtmlParams, GetHtmlResult,
|
||||
ScreenshotParams, ScreenshotResult, SessionStartParams, SessionStartResult, SnapshotParams,
|
||||
SnapshotResult, TabInfo, TabListParams, TabListResult, TabScope,
|
||||
};
|
||||
use bsk_protocol::{
|
||||
BrowserPeerInfo, ErrorCode, Frame, Method, RequestFrame, ResponseBody, ResponseFrame, RpcError,
|
||||
@@ -311,6 +311,63 @@ async fn screenshot_forwards_ref_to_extension() {
|
||||
handle.shutdown().await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn console_returns_buffered_entries() {
|
||||
let (handle, sock) = spawn_daemon().await;
|
||||
let mut ws = connect_ext(handle.ws_addr()).await;
|
||||
let _ = do_handshake(&mut ws).await;
|
||||
|
||||
run_extension(ws, |req| {
|
||||
assert_eq!(req.method, Method::ToolConsole);
|
||||
let params: ConsoleParams = serde_json::from_value(req.params.clone().unwrap()).unwrap();
|
||||
assert_eq!(params.tab_id, Some(7));
|
||||
assert_eq!(params.since, Some(3));
|
||||
assert_eq!(params.limit, Some(50));
|
||||
assert_eq!(params.max_text_chars, Some(1000));
|
||||
assert_eq!(params.include_stack, Some(false));
|
||||
ResponseBody::Ok(
|
||||
serde_json::to_value(ConsoleResult {
|
||||
tab_id: 7,
|
||||
entries: vec![ConsoleEntry {
|
||||
sequence: 4,
|
||||
kind: ConsoleEntryKind::Console,
|
||||
level: "warn".into(),
|
||||
text: "deprecated API".into(),
|
||||
url: Some("https://example.test/app.js".into()),
|
||||
line: Some(10),
|
||||
column: Some(2),
|
||||
timestamp: None,
|
||||
stack_trace: vec![],
|
||||
truncated: false,
|
||||
}],
|
||||
next_since: 4,
|
||||
truncated: false,
|
||||
})
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let session_id = ipc_session_start(&sock).await;
|
||||
let result: ConsoleResult = ipc_tool_call(
|
||||
&sock,
|
||||
Method::ToolConsole,
|
||||
ConsoleParams {
|
||||
session_id,
|
||||
tab_id: Some(7),
|
||||
since: Some(3),
|
||||
limit: Some(50),
|
||||
max_text_chars: Some(1000),
|
||||
include_stack: Some(false),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("console ok");
|
||||
assert_eq!(result.tab_id, 7);
|
||||
assert_eq!(result.next_since, 4);
|
||||
assert_eq!(result.entries[0].text, "deprecated API");
|
||||
handle.shutdown().await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn snapshot_returns_text_and_ref_count() {
|
||||
let (handle, sock) = spawn_daemon().await;
|
||||
|
||||
Reference in New Issue
Block a user