Skip to content

Commit a375b36

Browse files
committed
Merge remote-tracking branch 'origin/main' into HEAD
2 parents 1bbcd72 + dc9af2a commit a375b36

8 files changed

Lines changed: 188 additions & 64 deletions

File tree

‎docs/commands.md‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,12 @@ Enable or disable sandboxed execution of shell commands. When sandbox mode is on
11071107
## Coven Substrate
11081108

11091109
These commands integrate Coven Code with the local Coven daemon
1110-
(`~/.coven/coven.sock`, contract `coven.daemon.v1`). They degrade
1110+
(the socket `$COVEN_HOME/coven.sock`, or `~/.coven/coven.sock` when
1111+
`COVEN_HOME` is unset or empty; contract `coven.daemon.v1`). They degrade
11111112
gracefully when the daemon is absent — the daemon makes coven-code
1112-
richer; it is not required.
1113+
richer; it is not required. Coven Code has a daemon client only on Unix
1114+
platforms (macOS, Linux); on Windows it never connects, so the commands that
1115+
need the daemon report it as absent.
11131116

11141117
### /coven
11151118

@@ -1191,8 +1194,11 @@ the slash invocation acts as the confirmation).
11911194

11921195
#### Offline behaviour
11931196

1194-
When `~/.coven/coven.sock` is missing, every `/coven` subcommand
1195-
returns the same hint:
1197+
When the daemon socket is missing, `/coven` and `/coven status` name
1198+
the path they checked:
1199+
`Coven daemon socket not found at <path>.`
1200+
followed by `Start it with /coven daemon start (or coven daemon start).`
1201+
The other subcommands that need the daemon return:
11961202
`Coven daemon offline. Try /coven daemon start.`
11971203
The rest of coven-code keeps working — you just lose substrate
11981204
integration.
@@ -1210,7 +1216,7 @@ for the canonical error code list.
12101216
### /handoff
12111217

12121218
Hand off the current session context to a Coven familiar. Sends the
1213-
recent transcript to `~/.coven/coven.sock` as a new session under
1219+
recent transcript to the Coven daemon (see [Coven Substrate](#coven-substrate)) as a new session under
12141220
the named familiar, returning the session id.
12151221

12161222
```

‎docs/familiars.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ access = "read-only"
169169

170170
`~/.coven/familiars.toml` is **owned by the Coven daemon** when it is running. In that mode coven-code treats the roster as read-only and directs all edits to the daemon.
171171

172-
**Standalone mode** (no daemon socket at `~/.coven/coven.sock`) is different: coven-code owns the file and can write it directly.
172+
**Standalone mode** (no daemon socket at `$COVEN_HOME/coven.sock`, default `~/.coven/coven.sock`) is different: coven-code owns the file and can write it directly.
173173

174174
- **First-run bootstrap.** Press **F2** with no familiars configured and coven-code writes a starter `~/.coven/familiars.toml` (a `read-only` guide and a `full`-access builder) and opens the switcher so you have something to pick and a template to edit.
175175
- **Create / rename / remove** from the prompt:

‎src-rust/crates/cli/tests/workspace_policy.rs‎

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::{
1313
path::Path,
1414
process::{Child, Command, ExitStatus, Stdio},
1515
thread,
16-
time::{Duration, Instant},
16+
time::{Duration, Instant, SystemTime},
1717
};
1818

1919
mod workspace_policy_fixture;
@@ -331,10 +331,15 @@ fn stop_mid_command(background: bool) {
331331
logs(&base, "stop")
332332
),
333333
}
334+
// Should the delayed write be found below, these tell a runner that
335+
// stalled before the stop from a write that landed after it (#568).
336+
let stop_delay = stopped_at.elapsed();
337+
let stop_began = SystemTime::now();
334338
// Coven's Stop for a harness run: one SIGKILL to the run's process group
335339
// (`terminate_unix_process_group` in coven-cli's pty_runner.rs).
336340
killpg(group_of(&engine.0), Signal::SIGKILL)
337341
.unwrap_or_else(|error| panic!("the stop failed: {error}\n{}", logs(&base, "stop")));
342+
let stop_ended = SystemTime::now();
338343
let status = engine.0.wait().unwrap();
339344
assert_eq!(
340345
status.signal(),
@@ -349,11 +354,51 @@ fn stop_mid_command(background: bool) {
349354
// The shell is gone, so nothing should write now. Outlast the command's
350355
// own delay anyway before looking for its write.
351356
thread::sleep((stopped_at + Duration::from_secs(6)).saturating_duration_since(Instant::now()));
352-
assert!(
353-
!late.exists(),
354-
"a stopped scoped run still wrote after its delay\n{}",
355-
logs(&base, "stop")
356-
);
357+
if late.exists() {
358+
// The cause of one hosted failure here is not established (#568):
359+
// say when the shell started and whether its write landed before the
360+
// stop, during it or after it.
361+
let dated = |file: &Path| fs::metadata(file).and_then(|meta| meta.modified());
362+
let shell_started = match dated(&started).map(|at| stop_began.duration_since(at)) {
363+
Ok(Ok(before)) => format!("{before:?} before the stop"),
364+
Ok(Err(after)) => format!("{:?} after the stop began", after.duration()),
365+
Err(error) => format!("at an unknown time ({error})"),
366+
};
367+
// Only a write clearly before the stop counts as a stall; one within
368+
// the clock's margin of it is reported as during the stop.
369+
let (when, stalled) = match dated(&late) {
370+
Ok(written) if written + Duration::from_millis(50) < stop_began => (
371+
format!(
372+
"{:?} before the stop",
373+
stop_began.duration_since(written).unwrap_or_default()
374+
),
375+
true,
376+
),
377+
Ok(written) if written <= stop_ended + Duration::from_millis(50) => {
378+
("while the stop was sent".to_string(), false)
379+
}
380+
Ok(written) => (
381+
format!(
382+
"{:?} after the stop",
383+
written.duration_since(stop_ended).unwrap_or_default()
384+
),
385+
false,
386+
),
387+
Err(error) => (format!("at an unknown time ({error})"), false),
388+
};
389+
panic!(
390+
"a stopped scoped run still wrote after its delay: the shell started {shell_started}, \
391+
the stop came {stop_delay:?} after the test read the shell's PID, and the write \
392+
is dated {when}{}\n{}",
393+
if stalled {
394+
"; the test runner stalled before the stop, so the host is likely too busy \
395+
to run this test"
396+
} else {
397+
""
398+
},
399+
logs(&base, "stop")
400+
);
401+
}
357402
let frames = frames(&base, "stop");
358403
assert_eq!(
359404
admission(&frames),

‎src-rust/crates/mcp/src/oauth.rs‎

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,14 +2422,34 @@ mod tests {
24222422

24232423
#[tokio::test]
24242424
async fn bind_callback_listener_reuses_redirect_port() {
2425-
let (listener, authority, callback_path) =
2426-
bind_callback_listener("http://127.0.0.1:14555/callback")
2425+
// A fixed port collides with any other process that holds it, such
2426+
// as a second copy of this binary. A port from `oauth_port_alloc` is
2427+
// freed before the bind, so another test can take it in between: try
2428+
// a fresh port, at most three times, and only for a bind error.
2429+
let mut attempts = 0;
2430+
let (listener, authority, callback_path, redirect_port) = loop {
2431+
attempts += 1;
2432+
let redirect_port = oauth_port_alloc().expect("free port");
2433+
match bind_callback_listener(&format!("http://127.0.0.1:{redirect_port}/callback"))
24272434
.await
2428-
.expect("listener should bind");
2435+
{
2436+
Ok((listener, authority, callback_path)) => {
2437+
break (listener, authority, callback_path, redirect_port)
2438+
}
2439+
Err(error)
2440+
if attempts < 3
2441+
&& error
2442+
.to_string()
2443+
.starts_with("Failed to bind OAuth callback listener") => {}
2444+
Err(error) => {
2445+
panic!("listener should bind on attempt {attempts} of 3: {error:#}")
2446+
}
2447+
}
2448+
};
24292449
let port = listener.local_addr().expect("listener addr").port();
2430-
assert_eq!(authority, "127.0.0.1:14555");
2450+
assert_eq!(authority, format!("127.0.0.1:{redirect_port}"));
24312451
assert_eq!(callback_path, "/callback");
2432-
assert_eq!(port, 14555);
2452+
assert_eq!(port, redirect_port);
24332453
drop(listener);
24342454
}
24352455

@@ -2757,28 +2777,69 @@ mod plugin_session_tests {
27572777
async fn plugin_revocation_releases_pending_oauth_callback_listener() {
27582778
let _home = test_support::TokenHomeGuard::new();
27592779
let root = tempfile::tempdir().unwrap();
2760-
let (plugin, session) = session(root.path(), "http://127.0.0.1:1/token");
2761-
let redirect_uri = session.redirect_uri.clone();
2762-
let (opened, ready) = oneshot::channel();
2763-
let task = tokio::spawn(run_mcp_auth_session_with(session, move |_| {
2764-
let _ = opened.send(());
2765-
Ok(())
2766-
}));
2767-
timeout(Duration::from_secs(2), ready)
2768-
.await
2769-
.unwrap()
2770-
.unwrap();
2780+
// `session` takes its callback port from `oauth_port_alloc`, which
2781+
// frees it before the flow binds it, so on a busy host another test
2782+
// can take it in between. The flow then fails to bind and drops the
2783+
// opener without calling it, and the scenario runs again on a fresh
2784+
// port, at most three times, and only for that bind error.
2785+
let mut attempts = 0;
2786+
let (plugin, task, redirect_uri) = loop {
2787+
attempts += 1;
2788+
let (plugin, session) = session(root.path(), "http://127.0.0.1:1/token");
2789+
let redirect_uri = session.redirect_uri.clone();
2790+
let (opened, ready) = oneshot::channel();
2791+
let task = tokio::spawn(run_mcp_auth_session_with(session, move |_| {
2792+
let _ = opened.send(());
2793+
Ok(())
2794+
}));
2795+
if timeout(Duration::from_secs(10), ready)
2796+
.await
2797+
.expect("the flow neither opened the browser nor ended within 10s")
2798+
.is_ok()
2799+
{
2800+
break (plugin, task, redirect_uri);
2801+
}
2802+
let error = task.await.unwrap().unwrap_err();
2803+
assert!(
2804+
attempts < 3
2805+
&& error
2806+
.to_string()
2807+
.starts_with("Failed to bind OAuth callback listener"),
2808+
"the flow ended before it opened the browser on attempt {attempts} of 3: {error:#}"
2809+
);
2810+
};
27712811
plugin.revoke();
2772-
timeout(Duration::from_secs(2), plugin.wait_retired())
2812+
timeout(Duration::from_secs(10), plugin.wait_retired())
27732813
.await
2774-
.unwrap()
2814+
.expect("retirement did not complete within 10s")
27752815
.unwrap();
27762816
let error = task.await.unwrap().unwrap_err();
27772817
assert!(error.to_string().contains("revoked"));
2778-
assert!(
2779-
bind_callback_listener(&redirect_uri).await.is_ok(),
2780-
"callback socket must be released when retirement completes"
2818+
// The flow's listener is gone once the callback address can be bound
2819+
// again; a listener the flow kept would hold it for good, or at least
2820+
// until the flow's own `CALLBACK_TIMEOUT` (180 s), far past the 10 s
2821+
// here. The port is free once retirement completes, so another test
2822+
// in this process may bind it first and hold it for a while: retry
2823+
// until that test lets go, as
2824+
// `valid_callback_exchanges_once_persists_and_cannot_replay` does.
2825+
let redirect_url = url::Url::parse(&redirect_uri).unwrap();
2826+
let callback_address = (
2827+
redirect_url.host_str().unwrap(),
2828+
redirect_url.port().unwrap(),
27812829
);
2830+
let deadline = std::time::Instant::now() + Duration::from_secs(10);
2831+
loop {
2832+
let rebound = TcpListener::bind(callback_address).await;
2833+
if rebound.is_ok() {
2834+
break;
2835+
}
2836+
assert!(
2837+
std::time::Instant::now() < deadline,
2838+
"callback socket must be released when retirement completes; \
2839+
it is still in use 10s later: {rebound:?}"
2840+
);
2841+
tokio::time::sleep(Duration::from_millis(20)).await;
2842+
}
27822843
assert!(get_mcp_token("fixture").is_none());
27832844
}
27842845

‎src-rust/crates/mcp/src/rmcp_endpoint_privacy_tests.rs‎

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ use tokio::time::{timeout, Duration};
77

88
const SECRET: &str = "mcp-endpoint-privacy-canary";
99
const TOKEN: &str = "mcp-bearer-canary";
10+
/// A local address that refuses connections. This assumes nothing listens on
11+
/// port 1, and no test binds it: binding port 0 picks from the ephemeral
12+
/// range, far above it. A port freed by dropping a socket is open to any other
13+
/// test, whose server answers instead of refusing, and the error then has
14+
/// another category.
15+
const REFUSED: &str = "127.0.0.1:1";
1016

1117
fn config(url: String) -> claurst_core::config::McpServerConfig {
1218
claurst_core::config::McpServerConfig {
@@ -25,15 +31,26 @@ fn assert_private(error: &anyhow::Error, stage: &str, category: &str) {
2531
format!("{error:#}"),
2632
format!("{error:?}"),
2733
] {
28-
assert!(rendered.contains("privacy-fixture"), "missing fixture name");
29-
assert!(rendered.contains(stage), "missing transport stage");
30-
assert!(rendered.contains(category), "missing failure category");
34+
// The privacy checks come first, so the messages below can print the
35+
// error without exposing fixture secrets.
3136
for secret in [SECRET, TOKEN, "127.0.0.1", "http://", "userinfo-secret"] {
3237
assert!(
3338
!rendered.contains(secret),
3439
"rendered error contains private fixture data"
3540
);
3641
}
42+
assert!(
43+
rendered.contains("privacy-fixture"),
44+
"missing fixture name in {rendered:?}"
45+
);
46+
assert!(
47+
rendered.contains(stage),
48+
"missing transport stage {stage:?} in {rendered:?}"
49+
);
50+
assert!(
51+
rendered.contains(category),
52+
"missing failure category {category:?} in {rendered:?}"
53+
);
3754
}
3855
assert_eq!(error.chain().count(), 1, "raw sources must not escape");
3956
}
@@ -95,13 +112,8 @@ fn message() -> rmcp::service::TxJsonRpcMessage<RoleClient> {
95112

96113
#[tokio::test]
97114
async fn get_refusal_redacts_userinfo_query_and_fragment() {
98-
// Release a local port immediately before the refused connection.
99-
let socket = tokio::net::TcpSocket::new_v4().unwrap();
100-
socket.bind("127.0.0.1:0".parse().unwrap()).unwrap();
101-
let addr = socket.local_addr().unwrap();
102-
drop(socket);
103115
let error = connect_error(format!(
104-
"http://{SECRET}:userinfo-secret@{addr}/sse?key={SECRET}#{SECRET}"
116+
"http://{SECRET}:userinfo-secret@{REFUSED}/sse?key={SECRET}#{SECRET}"
105117
))
106118
.await;
107119
assert_private(&error, "GET", "connection");
@@ -118,13 +130,9 @@ async fn get_builder_failure_redacts_url() {
118130

119131
#[tokio::test]
120132
async fn discovered_post_refusal_redacts_userinfo_query_and_fragment() {
121-
let refused = tokio::net::TcpSocket::new_v4().unwrap();
122-
refused.bind("127.0.0.1:0".parse().unwrap()).unwrap();
123-
let endpoint = format!(
124-
"http://{SECRET}:userinfo-secret@{}/messages?key={SECRET}#{SECRET}",
125-
refused.local_addr().unwrap()
126-
);
127-
drop(refused);
133+
// The announced endpoint refuses.
134+
let endpoint =
135+
format!("http://{SECRET}:userinfo-secret@{REFUSED}/messages?key={SECRET}#{SECRET}");
128136
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
129137
let url = format!("http://{}/sse?get={SECRET}", listener.local_addr().unwrap());
130138
let server = tokio::spawn(async move {

‎src-rust/crates/tools/src/worktree.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,7 @@ mod tests {
551551
#[tokio::test]
552552
async fn a_post_create_command_past_its_limit_is_stopped_with_its_grandchild() {
553553
let ticker = crate::windows_ticker::Ticker::new();
554-
// Unquoted: Rust's quoting for `cmd /C` mangles an inner `"` (#517).
555-
// The runner's temporary directory has no spaces.
554+
// Unquoted, as the runner's temporary directory has no spaces.
556555
let hook = format!("cmd /D /C {}", ticker.script().display());
557556
// The loop runs 60 s unless it is stopped.
558557
let report = tokio::time::timeout(

‎src-rust/crates/tui/src/lib.rs‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,12 @@ fn restore_terminal_cleanup(out: &mut impl io::Write) -> io::Result<()> {
280280
DisableBracketedPaste,
281281
)?;
282282

283-
// On Windows, KeyboardEnhancementFlags may not have been pushed
284-
// (conhost / older terminals reject the escape). Pop is harmless
285-
// whether it succeeded or not — ignore errors on restore.
283+
// On Windows, crossterm 0.29 never sends the pop: the command reports no
284+
// ANSI support there, so `execute!` takes the WinAPI path, which always
285+
// returns `Unsupported`. The error is ignored so cleanup goes on; nothing
286+
// was pushed (see `setup_terminal`).
286287
#[cfg(target_os = "windows")]
287288
{
288-
// Pop may fail on legacy Windows conhost where the push was a no-op;
289-
// do it best-effort so cleanup never errors out the process.
290289
let _ = execute!(out, PopKeyboardEnhancementFlags);
291290
execute!(out, LeaveAlternateScreen, DisableMouseCapture)?;
292291
}
@@ -341,17 +340,15 @@ pub fn setup_terminal(renderer: application::UiRenderer) -> io::Result<AppTermin
341340
}
342341
}
343342

344-
// On Windows, keyboard enhancement is best-effort: conhost and older
345-
// terminal builds do not support the kitty keyboard protocol.
346-
// crossterm 0.29 improved detection but may still reject in some
347-
// configurations. Warn the user when it fails, then continue.
343+
// On Windows, crossterm 0.29 never sends the keyboard enhancement push,
344+
// whatever the terminal: the command reports no ANSI support there, so
345+
// `execute!` takes the WinAPI path, which always returns `Unsupported`
346+
// ("Keyboard progressive enhancement not implemented for the legacy
347+
// Windows API"). The error is ignored without a warning, so the TUI
348+
// starts without the kitty keyboard protocol.
348349
#[cfg(target_os = "windows")]
349350
{
350351
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
351-
// Kitty keyboard protocol is unsupported on legacy Windows conhost;
352-
// best-effort — modern Windows Terminal accepts it, conhost returns
353-
// "Keyboard progressive enhancement not implemented for the legacy
354-
// Windows API" which we ignore so the TUI can still start.
355352
if should_push_keyboard_enhancement_for_process() {
356353
let _ = execute!(
357354
stdout,

0 commit comments

Comments
 (0)