cargo fmt

This commit is contained in:
2026-04-27 22:51:07 +09:00
parent bcaa4645f7
commit 7a0ed7d744
62 changed files with 485 additions and 527 deletions
+37 -62
View File
@@ -1,6 +1,6 @@
use std::pin::Pin;
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
use async_trait::async_trait;
use futures::{Stream, StreamExt};
@@ -169,10 +169,7 @@ async fn run_updates_shared_state_to_idle_after_completion() {
let pod = make_pod(client).await;
let handle = spawn_controller(pod).await;
handle
.send(Method::run_text("Hello"))
.await
.unwrap();
handle.send(Method::run_text("Hello")).await.unwrap();
// Wait for the run to complete
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
@@ -186,10 +183,7 @@ async fn run_populates_history() {
let pod = make_pod(client).await;
let handle = spawn_controller(pod).await;
handle
.send(Method::run_text("Hello"))
.await
.unwrap();
handle.send(Method::run_text("Hello")).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
@@ -207,10 +201,7 @@ async fn events_are_broadcast() {
let handle = spawn_controller(pod).await;
let mut rx = handle.subscribe();
handle
.send(Method::run_text("Hello"))
.await
.unwrap();
handle.send(Method::run_text("Hello")).await.unwrap();
let mut saw_turn_start = false;
let mut saw_text_delta = false;
@@ -258,16 +249,10 @@ async fn double_run_returns_error() {
let mut rx = handle.subscribe();
// Send first run
handle
.send(Method::run_text("first"))
.await
.unwrap();
handle.send(Method::run_text("first")).await.unwrap();
// Immediately send second run (should get error)
handle
.send(Method::run_text("second"))
.await
.unwrap();
handle.send(Method::run_text("second")).await.unwrap();
// Look for the error event
let mut saw_already_running = false;
@@ -410,8 +395,14 @@ async fn run_with_paste_segment_inlines_content_and_emits_typed_user_message() {
.iter()
.find_map(|i| i.as_text().map(|s| s.to_string()))
.unwrap_or_default();
assert!(user_text.contains("see line1\nline2 thanks"), "got: {user_text:?}");
assert!(!user_text.contains("[Clipboard"), "label must not leak: {user_text:?}");
assert!(
user_text.contains("see line1\nline2 thanks"),
"got: {user_text:?}"
);
assert!(
!user_text.contains("[Clipboard"),
"label must not leak: {user_text:?}"
);
}
#[tokio::test]
@@ -424,12 +415,11 @@ async fn run_with_unresolved_segment_emits_alert_and_placeholder() {
let segments = vec![
protocol::Segment::text("look at "),
protocol::Segment::FileRef { path: "src/lib.rs".into() },
protocol::Segment::FileRef {
path: "src/lib.rs".into(),
},
];
handle
.send(Method::Run { input: segments })
.await
.unwrap();
handle.send(Method::Run { input: segments }).await.unwrap();
let deadline = tokio::time::Instant::now() + std::time::Duration::from_secs(2);
let mut saw_alert_for_file_ref = false;
@@ -527,10 +517,7 @@ async fn notify_while_running_does_not_emit_already_running_error() {
let handle = spawn_controller(pod).await;
let mut rx = handle.subscribe();
handle
.send(Method::run_text("start"))
.await
.unwrap();
handle.send(Method::run_text("start")).await.unwrap();
handle
.send(Method::Notify {
message: "ping".into(),
@@ -591,10 +578,7 @@ async fn socket_run_receives_events() {
let mut writer = JsonLineWriter::new(writer);
// Send run method via socket
writer
.write(&Method::run_text("Hello"))
.await
.unwrap();
writer.write(&Method::run_text("Hello")).await.unwrap();
// Collect events
let mut saw_turn_start = false;
@@ -739,10 +723,7 @@ async fn pause_then_resume_transitions_and_preserves_history_consistency() {
let handle = spawn_controller(pod).await;
let mut rx = handle.subscribe();
handle
.send(Method::run_text("hello"))
.await
.unwrap();
handle.send(Method::run_text("hello")).await.unwrap();
// Wait for the partial text_delta to confirm the first stream is
// live before we pause.
@@ -794,10 +775,7 @@ async fn pause_then_resume_transitions_and_preserves_history_consistency() {
// (partial text is not committed), no orphan tool_use.
let history_json = handle.shared_state.history_json();
let items: Vec<serde_json::Value> = serde_json::from_str(&history_json).unwrap();
let roles: Vec<&str> = items
.iter()
.filter_map(|i| i["role"].as_str())
.collect();
let roles: Vec<&str> = items.iter().filter_map(|i| i["role"].as_str()).collect();
assert_eq!(
roles,
vec!["user", "assistant"],
@@ -850,10 +828,7 @@ async fn paused_then_run_closes_orphan_tool_use_for_next_request() {
let handle = spawn_controller(pod).await;
let mut rx = handle.subscribe();
handle
.send(Method::run_text("first"))
.await
.unwrap();
handle.send(Method::run_text("first")).await.unwrap();
// Wait for ToolCallDone — the ToolCall is committed to history
// right before the Worker enters tool execution and pends.
@@ -883,10 +858,7 @@ async fn paused_then_run_closes_orphan_tool_use_for_next_request() {
// New user input while Paused → controller routes to
// `Pod::interrupt_and_run`, which closes the orphan + injects a
// system note before the fresh user message.
handle
.send(Method::run_text("new request"))
.await
.unwrap();
handle.send(Method::run_text("new request")).await.unwrap();
assert!(
drain_until(&mut rx, std::time::Duration::from_secs(2), |e| matches!(
e,
@@ -925,9 +897,7 @@ async fn paused_then_run_closes_orphan_tool_use_for_next_request() {
saw_interruption_note = true;
}
}
llm_worker::Item::Message { role, content, .. }
if *role == llm_worker::Role::User =>
{
llm_worker::Item::Message { role, content, .. } if *role == llm_worker::Role::User => {
let text: String = content.iter().map(|p| p.as_text()).collect();
if text.contains("new request") {
saw_new_user = true;
@@ -952,10 +922,10 @@ async fn paused_then_run_closes_orphan_tool_use_for_next_request() {
// Also confirm the closure chain is ordered: tool_result for the
// orphan precedes the system note, which precedes the new user
// message.
let idx = |pred: &dyn Fn(&llm_worker::Item) -> bool| {
items.iter().position(pred).unwrap()
};
let tool_result_idx = idx(&|i| matches!(i, llm_worker::Item::ToolResult { call_id, .. } if call_id == "call_orphan"));
let idx = |pred: &dyn Fn(&llm_worker::Item) -> bool| items.iter().position(pred).unwrap();
let tool_result_idx = idx(
&|i| matches!(i, llm_worker::Item::ToolResult { call_id, .. } if call_id == "call_orphan"),
);
let sys_idx = idx(&|i| match i {
llm_worker::Item::Message {
role: llm_worker::Role::System,
@@ -980,7 +950,12 @@ async fn paused_then_run_closes_orphan_tool_use_for_next_request() {
.contains("new request"),
_ => false,
});
assert!(tool_result_idx < sys_idx, "tool_result must precede system note");
assert!(sys_idx < user_idx, "system note must precede new user message");
assert!(
tool_result_idx < sys_idx,
"tool_result must precede system note"
);
assert!(
sys_idx < user_idx,
"system note must precede new user message"
);
}
+17 -5
View File
@@ -14,11 +14,11 @@ use std::sync::{Arc, LazyLock, Mutex};
use llm_worker::llm_client::types::{ContentPart, Item, Role};
use llm_worker::tool::ToolOutput;
use manifest::{Permission, ScopeRule};
use pod::runtime::dir::{RuntimeDir, SpawnedPodRecord};
use pod::runtime::scope_lock::{self, LockFileGuard};
use pod::spawn::comm_tools::{
list_pods_tool, read_pod_output_tool, send_to_pod_tool, stop_pod_tool,
};
use pod::runtime::dir::{RuntimeDir, SpawnedPodRecord};
use pod::runtime::scope_lock::{self, LockFileGuard};
use pod::spawn::registry::SpawnedPodRegistry;
use protocol::stream::{JsonLineReader, JsonLineWriter};
use protocol::{ErrorCode, Event, Greeting, Method};
@@ -211,7 +211,11 @@ async fn send_to_pod_delivers_run_method() {
let (_meta, tool) = def();
let input = json!({ "name": "child", "message": "hello there" }).to_string();
let output: ToolOutput = tool.execute(&input).await.unwrap();
assert!(output.summary.contains("child"), "summary: {}", output.summary);
assert!(
output.summary.contains("child"),
"summary: {}",
output.summary
);
let method = received.await.unwrap().expect("expected a method");
match method {
@@ -292,7 +296,11 @@ async fn read_pod_output_returns_new_assistant_text_then_empty_on_second_call()
// Cursor now points past all items — second call returns no new text.
let second: ToolOutput = tool.execute(&input).await.unwrap();
assert!(second.content.is_none(), "unexpected content: {:?}", second.content);
assert!(
second.content.is_none(),
"unexpected content: {:?}",
second.content
);
assert!(
second.summary.contains("no new assistant text"),
"summary: {}",
@@ -451,6 +459,10 @@ async fn list_pods_empty_when_nothing_registered() {
let def = list_pods_tool(registry);
let (_meta, tool) = def();
let output: ToolOutput = tool.execute("{}").await.unwrap();
assert!(output.summary.contains("no spawned pods"), "{}", output.summary);
assert!(
output.summary.contains("no spawned pods"),
"{}",
output.summary
);
assert!(output.content.is_none());
}
+1 -3
View File
@@ -77,9 +77,7 @@ fn clear_runtime_dir() {
}
/// Accept a single connection, read one `Method`, and return it.
fn accept_one_method(
listener: UnixListener,
) -> tokio::task::JoinHandle<Option<Method>> {
fn accept_one_method(listener: UnixListener) -> tokio::task::JoinHandle<Option<Method>> {
tokio::spawn(async move {
let (stream, _) = listener.accept().await.ok()?;
let (reader, _writer) = stream.into_split();
+11 -6
View File
@@ -14,8 +14,8 @@ use llm_worker::tool::{ToolError, ToolOutput};
use manifest::{AuthRef, ModelManifest, Permission, SchemeKind, ScopeRule};
use pod::runtime::dir::{RuntimeDir, SpawnedPodRecord};
use pod::runtime::scope_lock::{self, LockFileGuard};
use pod::spawn::tool::spawn_pod_tool;
use pod::spawn::registry::SpawnedPodRegistry;
use pod::spawn::tool::spawn_pod_tool;
use protocol::Method;
use protocol::stream::JsonLineReader;
use serde_json::json;
@@ -99,9 +99,7 @@ async fn bind_mock_pod_socket(runtime_base: &Path, pod_name: &str) -> (PathBuf,
/// `Method` line, then returns it. `wait_for_socket` inside the tool
/// makes a probe connection that carries no data, so the task must
/// tolerate an empty connection and keep listening.
fn accept_one_method(
listener: UnixListener,
) -> tokio::task::JoinHandle<Option<Method>> {
fn accept_one_method(listener: UnixListener) -> tokio::task::JoinHandle<Option<Method>> {
tokio::spawn(async move {
loop {
let (stream, _) = listener.accept().await.ok()?;
@@ -192,7 +190,11 @@ async fn spawn_pod_delegates_scope_and_sends_run() {
.to_string();
let output: ToolOutput = tool.execute(&input).await.unwrap();
assert!(output.summary.contains("child"), "summary: {}", output.summary);
assert!(
output.summary.contains("child"),
"summary: {}",
output.summary
);
// Verify the tool delivered Method::Run to the socket.
let method = received.await.unwrap().expect("expected one Method line");
@@ -261,7 +263,10 @@ async fn spawn_pod_rejects_scope_outside_spawner() {
let err = tool.execute(&input).await.unwrap_err();
match err {
ToolError::InvalidArgument(msg) => {
assert!(msg.contains("not within"), "expected NotSubset wording: {msg}");
assert!(
msg.contains("not within"),
"expected NotSubset wording: {msg}"
);
}
other => panic!("expected InvalidArgument, got {other:?}"),
}
@@ -246,11 +246,11 @@ async fn agents_md_absent_omits_trailing_section() {
#[tokio::test]
async fn agents_md_not_reread_after_compact() {
let client = MockClient::new(vec![
single_text_events("a"), // pod.run_text("first")
single_text_events("b"), // pod.run_text("second")
single_text_events("a"), // pod.run_text("first")
single_text_events("b"), // pod.run_text("second")
write_summary_tool_use_events("call-1", "compacted summary"), // compact worker: tool_use
single_text_events("done"), // compact worker: close
single_text_events("c"), // pod.run_text("third")
single_text_events("done"), // compact worker: close
single_text_events("c"), // pod.run_text("third")
]);
let (mut pod, pwd) = make_pod_with_body("BODY", client).await.unwrap();
let agents_path = pwd.join("AGENTS.md");
@@ -278,11 +278,11 @@ async fn agents_md_not_reread_after_compact() {
#[tokio::test]
async fn compact_preserves_system_prompt() {
let client = MockClient::new(vec![
single_text_events("a"), // pod.run_text("first")
single_text_events("b"), // pod.run_text("second")
single_text_events("a"), // pod.run_text("first")
single_text_events("b"), // pod.run_text("second")
write_summary_tool_use_events("call-1", "compacted summary"), // compact worker: tool_use
single_text_events("done"), // compact worker: close
single_text_events("c"), // pod.run_text("third")
single_text_events("done"), // compact worker: close
single_text_events("c"), // pod.run_text("third")
]);
let (mut pod, _pwd) = make_pod_with_body("SP cwd={{ cwd }}", client)
.await