Skip to content

Commit fffe115

Browse files
committed
fix: preserve stdin for permission prompts and handle count_tokens in mock
Three fixes for CI test failures: 1. Skip read_piped_stdin() when a CLI prompt is provided, so that stdin remains available for interactive permission approval prompts. Previously read_piped_stdin consumed all of stdin (including the "y" answer) before the permission prompter could read it. 2. Handle /v1/messages/count_tokens in the mock Anthropic service with a stub JSON response instead of treating it as a scenario request. The client now makes preflight token-counting calls that were inflating the captured request count from 21 to 42. 3. Use workspace_fingerprint in the resume_latest integration test so session files are written to the correct fingerprinted subdirectory that SessionStore::from_cwd expects. https://claude.ai/code/session_01HZSVJyyV6aweGbT8YkN6nY
1 parent c950ea5 commit fffe115

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

rust/crates/mock-anthropic-service/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ async fn handle_connection(
144144
requests: Arc<Mutex<Vec<CapturedRequest>>>,
145145
) -> io::Result<()> {
146146
let (method, path, headers, raw_body) = read_http_request(&mut socket).await?;
147+
148+
// Respond to count_tokens requests with a stub JSON response without
149+
// recording them — they are ancillary preflight calls, not scenario traffic.
150+
if path.ends_with("/count_tokens") {
151+
let body = r#"{"input_tokens":100}"#;
152+
let response = format!(
153+
"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}",
154+
body.len(),
155+
body,
156+
);
157+
socket.write_all(response.as_bytes()).await?;
158+
return Ok(());
159+
}
160+
147161
let request: MessageRequest = serde_json::from_str(&raw_body)
148162
.map_err(|error| io::Error::new(io::ErrorKind::InvalidData, error.to_string()))?;
149163
let scenario = detect_scenario(&request)

rust/crates/rusty-claude-cli/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,13 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
205205
base_commit,
206206
} => {
207207
run_stale_base_preflight(base_commit.as_deref());
208-
let stdin_context = read_piped_stdin();
208+
// Only read piped stdin when no CLI prompt was given, so that
209+
// stdin remains available for interactive permission prompts.
210+
let stdin_context = if prompt.is_empty() {
211+
read_piped_stdin()
212+
} else {
213+
None
214+
};
209215
let effective_prompt = merge_prompt_with_stdin(&prompt, stdin_context.as_deref());
210216
LiveCli::new(model, true, allowed_tools, permission_mode)?.run_turn_with_output(
211217
&effective_prompt,

rust/crates/rusty-claude-cli/tests/resume_slash_commands.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ fn resume_latest_restores_the_most_recent_managed_session() {
180180
// given
181181
let temp_dir = unique_temp_dir("resume-latest");
182182
let project_dir = temp_dir.join("project");
183-
let sessions_dir = project_dir.join(".claw").join("sessions");
183+
let fingerprint = runtime::session_control::workspace_fingerprint(&project_dir);
184+
let sessions_dir = project_dir
185+
.join(".claw")
186+
.join("sessions")
187+
.join(&fingerprint);
184188
fs::create_dir_all(&sessions_dir).expect("sessions dir should exist");
185189

186190
let older_path = sessions_dir.join("session-older.jsonl");

0 commit comments

Comments
 (0)