Synced from monorepo
Changes: - Non-blocking coding-data sharing upsell banner - Consolidate remediation in Doctor - Auto mode defers fail-closed gate asks to the classifier - Coalesce marketplace list fetches - Allow removing a marketplace source by name - Contain hung git marketplace sources (timeouts, non-blocking refresh, unbrick modal) - Label failed workspace RPCs with error_kind - Drop redundant explicit tonic/prost deps from xai-grok-shell - Report real exit codes for completed background shells - Narrow the date-rollover reminder to date-bearing templates - Wire toolOverrides through the session and agent - Security: Bash(git:*) allowlist matches whole command chain by prefix - Split prompt-trigger telemetry and record classifier provenance - Raise connectors-manager timeout to 60s - Auto classifier honors recorded approvals for repeat actions - Apply doctor fixes in the TUI - Auto-mode classifier timeouts prompt instead of silently denying - Scope subagent completion drains to the owning session - Add the toolOverrides wire types - Set client_identifier=grok-agent-sdk - Accept both spellings of the workspace-teleport kill switch - Persist one-shot occurrence journal - Stop turns that poll the exact same tool call 16x in a row - Copy compaction checkpoint files when forking sessions - Auto-focus permission prompt from scrollback - Esc cancels the running turn in non-vim and minimal modes - List Ctrl+Z undo and redo in keyboard shortcuts - Out-of-process macOS mic capture - Show active auth mode on session-info - Install the npm binary under $GROK_HOME - Remove hover/click dead zones between dashboard items - Route startup warnings to doctor - Document [feedback.user] author identity config - Extend bang command timeout - Close combine-queued edit-hold race - Integrate relocation recovery - Expose privacy notice rollout flag - Break harness discovery ref cycle so connections can idle-evict - Shift/Alt+Enter inserts newline when editing a queued prompt - Gate project Claude permissions on folder trust - Echo response.create.event_id on response.created - Toast when session creation fails from disk full - Add shared test process lifecycle - Enable dynamic workflows by default - Add relocation transaction state machine - Add shared test sandbox - Surface auth failures on model-switch compact - Persist durable scheduler expiry - Confirm before removing extensions-modal items - Re-run compact and prompt after login when compact hit expired auth - Recap sends hosted tools under backend search
This commit is contained in:
parent
3af4d5d398
commit
a5727c5960
482 changed files with 37627 additions and 13402 deletions
|
|
@ -2,15 +2,307 @@
|
|||
|
||||
use xai_grok_shell::sampling::{ApiBackend, Client, SamplerConfig};
|
||||
|
||||
#[cfg(unix)]
|
||||
pub mod leader {
|
||||
use std::future::Future;
|
||||
use std::io;
|
||||
use std::pin::Pin;
|
||||
|
||||
use futures::FutureExt as _;
|
||||
use xai_grok_test_support::leader::{LeaderFixture, LeaderStdioClient};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub type TestBody<'a> = Pin<Box<dyn Future<Output = ()> + 'a>>;
|
||||
|
||||
type PanicPayload = Box<dyn std::any::Any + Send>;
|
||||
|
||||
fn finish_body(body_result: Result<(), PanicPayload>, cleanup_error: Option<io::Error>) {
|
||||
match body_result {
|
||||
Ok(()) => {
|
||||
if let Some(error) = cleanup_error {
|
||||
panic!("leader integration cleanup failed: {error}");
|
||||
}
|
||||
}
|
||||
Err(payload) => {
|
||||
if let Some(error) = cleanup_error {
|
||||
eprintln!("leader integration cleanup after panic failed: {error}");
|
||||
}
|
||||
std::panic::resume_unwind(payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait CleanupClient {
|
||||
async fn graceful_close(&mut self) -> io::Result<()>;
|
||||
async fn hard_close(&mut self) -> io::Result<()>;
|
||||
fn contain_failed_cleanup_for_unwind(&mut self);
|
||||
}
|
||||
|
||||
impl CleanupClient for LeaderStdioClient {
|
||||
async fn graceful_close(&mut self) -> io::Result<()> {
|
||||
self.close().await.map(|_| ())
|
||||
}
|
||||
|
||||
async fn hard_close(&mut self) -> io::Result<()> {
|
||||
self.kill_and_close().await.map(|_| ())
|
||||
}
|
||||
|
||||
fn contain_failed_cleanup_for_unwind(&mut self) {
|
||||
LeaderStdioClient::contain_failed_cleanup_for_unwind(self);
|
||||
}
|
||||
}
|
||||
|
||||
trait CleanupFixture {
|
||||
async fn close_fixture(&self) -> io::Result<()>;
|
||||
fn contain_failed_cleanup_for_unwind(&self);
|
||||
}
|
||||
|
||||
impl CleanupFixture for LeaderFixture {
|
||||
async fn close_fixture(&self) -> io::Result<()> {
|
||||
self.close().await
|
||||
}
|
||||
|
||||
fn contain_failed_cleanup_for_unwind(&self) {
|
||||
LeaderFixture::contain_failed_cleanup_for_unwind(self);
|
||||
}
|
||||
}
|
||||
|
||||
struct ClientCleanupOutcome {
|
||||
all_closed: bool,
|
||||
error: Option<io::Error>,
|
||||
}
|
||||
|
||||
async fn close_clients<C: CleanupClient>(clients: &mut Vec<C>) -> ClientCleanupOutcome {
|
||||
let pending = std::mem::take(clients).into_iter();
|
||||
let mut retained = Vec::new();
|
||||
let mut first_error = None;
|
||||
for mut client in pending {
|
||||
match client.graceful_close().await {
|
||||
Ok(()) => {}
|
||||
Err(close_error) => match client.hard_close().await {
|
||||
Ok(()) => {}
|
||||
Err(kill_error) => {
|
||||
if first_error.is_none() {
|
||||
first_error = Some(io::Error::new(
|
||||
close_error.kind(),
|
||||
format!(
|
||||
"leader client close failed: {close_error}; bounded hard cleanup also failed: {kill_error}"
|
||||
),
|
||||
));
|
||||
}
|
||||
retained.push(client);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
*clients = retained;
|
||||
ClientCleanupOutcome {
|
||||
all_closed: clients.is_empty(),
|
||||
error: first_error,
|
||||
}
|
||||
}
|
||||
|
||||
async fn cleanup_owned_processes<C, F>(fixture: &F, clients: &mut Vec<C>) -> Option<io::Error>
|
||||
where
|
||||
C: CleanupClient,
|
||||
F: CleanupFixture,
|
||||
{
|
||||
let cleanup = close_clients(clients).await;
|
||||
let mut cleanup_error = cleanup.error;
|
||||
if !cleanup.all_closed {
|
||||
// This error-only path requests hard kills, then intentionally
|
||||
// leaks concrete owners so panic unwind cannot run blocking Drop.
|
||||
// The leak is bounded by the lifetime of the test process.
|
||||
for client in clients.iter_mut() {
|
||||
client.contain_failed_cleanup_for_unwind();
|
||||
}
|
||||
let retained = std::mem::take(clients);
|
||||
std::mem::forget(retained);
|
||||
fixture.contain_failed_cleanup_for_unwind();
|
||||
return cleanup_error;
|
||||
}
|
||||
if let Err(error) = fixture.close_fixture().await {
|
||||
cleanup_error = Some(match cleanup_error {
|
||||
Some(client_error) => io::Error::new(
|
||||
client_error.kind(),
|
||||
format!("{client_error}; fixture cleanup also failed: {error}"),
|
||||
),
|
||||
None => error,
|
||||
});
|
||||
}
|
||||
cleanup_error
|
||||
}
|
||||
|
||||
/// Run a leader test body, then close only directly-owned stdio clients and
|
||||
/// the concrete initial fixture leader. Detached replacement leaders are
|
||||
/// intentionally outside cleanup ownership; tests that create one remain
|
||||
/// ignored/manual until OS containment or a test-only leader binary exists.
|
||||
#[allow(dead_code)]
|
||||
pub async fn run_with_cleanup<F>(
|
||||
fixture: &LeaderFixture,
|
||||
clients: &mut Vec<LeaderStdioClient>,
|
||||
body: F,
|
||||
) where
|
||||
F: for<'a> FnOnce(&'a LeaderFixture, &'a mut Vec<LeaderStdioClient>) -> TestBody<'a>,
|
||||
{
|
||||
let body_result = std::panic::AssertUnwindSafe(body(fixture, clients))
|
||||
.catch_unwind()
|
||||
.await;
|
||||
let cleanup_error = cleanup_owned_processes(fixture, clients).await;
|
||||
finish_body(body_result, cleanup_error);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use super::*;
|
||||
|
||||
struct FakeClient {
|
||||
graceful_fails: bool,
|
||||
hard_fails: bool,
|
||||
graceful_calls: Arc<AtomicUsize>,
|
||||
hard_calls: Arc<AtomicUsize>,
|
||||
drops: Arc<AtomicUsize>,
|
||||
containment_calls: Arc<AtomicUsize>,
|
||||
}
|
||||
|
||||
impl CleanupClient for FakeClient {
|
||||
async fn graceful_close(&mut self) -> io::Result<()> {
|
||||
self.graceful_calls.fetch_add(1, Ordering::SeqCst);
|
||||
if self.graceful_fails {
|
||||
Err(io::Error::other("injected graceful failure"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn hard_close(&mut self) -> io::Result<()> {
|
||||
self.hard_calls.fetch_add(1, Ordering::SeqCst);
|
||||
if self.hard_fails {
|
||||
Err(io::Error::other("injected hard failure"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn contain_failed_cleanup_for_unwind(&mut self) {
|
||||
self.containment_calls.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for FakeClient {
|
||||
fn drop(&mut self) {
|
||||
self.drops.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct FakeFixture {
|
||||
close_calls: AtomicUsize,
|
||||
containment_calls: AtomicUsize,
|
||||
}
|
||||
|
||||
impl CleanupFixture for FakeFixture {
|
||||
async fn close_fixture(&self) -> io::Result<()> {
|
||||
self.close_calls.fetch_add(1, Ordering::SeqCst);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn contain_failed_cleanup_for_unwind(&self) {
|
||||
self.containment_calls.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn double_failed_client_transfers_to_unwind_containment() {
|
||||
let graceful_calls = Arc::new(AtomicUsize::new(0));
|
||||
let hard_calls = Arc::new(AtomicUsize::new(0));
|
||||
let drops = Arc::new(AtomicUsize::new(0));
|
||||
let containment_calls = Arc::new(AtomicUsize::new(0));
|
||||
let mut clients = vec![FakeClient {
|
||||
graceful_fails: true,
|
||||
hard_fails: true,
|
||||
graceful_calls: graceful_calls.clone(),
|
||||
hard_calls: hard_calls.clone(),
|
||||
drops: drops.clone(),
|
||||
containment_calls: containment_calls.clone(),
|
||||
}];
|
||||
let fixture = FakeFixture::default();
|
||||
|
||||
let error = cleanup_owned_processes(&fixture, &mut clients)
|
||||
.await
|
||||
.expect("double failure must be reported");
|
||||
|
||||
assert!(error.to_string().contains("injected graceful failure"));
|
||||
assert!(error.to_string().contains("injected hard failure"));
|
||||
assert!(
|
||||
clients.is_empty(),
|
||||
"retained owner must transfer to leaked containment"
|
||||
);
|
||||
assert_eq!(drops.load(Ordering::SeqCst), 0);
|
||||
assert_eq!(graceful_calls.load(Ordering::SeqCst), 1);
|
||||
assert_eq!(hard_calls.load(Ordering::SeqCst), 1);
|
||||
assert_eq!(containment_calls.load(Ordering::SeqCst), 1);
|
||||
assert_eq!(fixture.close_calls.load(Ordering::SeqCst), 0);
|
||||
assert_eq!(fixture.containment_calls.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn successful_owners_drop_before_fixture_close() {
|
||||
let graceful_calls = Arc::new(AtomicUsize::new(0));
|
||||
let hard_calls = Arc::new(AtomicUsize::new(0));
|
||||
let drops = Arc::new(AtomicUsize::new(0));
|
||||
let containment_calls = Arc::new(AtomicUsize::new(0));
|
||||
let mut clients = vec![
|
||||
FakeClient {
|
||||
graceful_fails: false,
|
||||
hard_fails: false,
|
||||
graceful_calls: graceful_calls.clone(),
|
||||
hard_calls: hard_calls.clone(),
|
||||
drops: drops.clone(),
|
||||
containment_calls: containment_calls.clone(),
|
||||
},
|
||||
FakeClient {
|
||||
graceful_fails: true,
|
||||
hard_fails: false,
|
||||
graceful_calls: graceful_calls.clone(),
|
||||
hard_calls: hard_calls.clone(),
|
||||
drops: drops.clone(),
|
||||
containment_calls: containment_calls.clone(),
|
||||
},
|
||||
];
|
||||
let fixture = FakeFixture::default();
|
||||
|
||||
let error = cleanup_owned_processes(&fixture, &mut clients).await;
|
||||
|
||||
assert!(
|
||||
error.is_none(),
|
||||
"successful bounded hard cleanup must recover the graceful failure"
|
||||
);
|
||||
assert!(clients.is_empty());
|
||||
assert_eq!(drops.load(Ordering::SeqCst), 2);
|
||||
assert_eq!(graceful_calls.load(Ordering::SeqCst), 2);
|
||||
assert_eq!(hard_calls.load(Ordering::SeqCst), 1);
|
||||
assert_eq!(containment_calls.load(Ordering::SeqCst), 0);
|
||||
assert_eq!(fixture.close_calls.load(Ordering::SeqCst), 1);
|
||||
assert_eq!(fixture.containment_calls.load(Ordering::SeqCst), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a sampling client configured for a mock server. Shared by the
|
||||
/// integration tests so the ~30-field `SamplerConfig` literal lives in one
|
||||
/// place (`SamplerConfig` has no `Default`).
|
||||
#[allow(dead_code)]
|
||||
pub fn create_test_client(base_url: &str, api_backend: ApiBackend) -> Client {
|
||||
create_test_client_with_extra_headers(base_url, api_backend, &[])
|
||||
}
|
||||
|
||||
/// Like [`create_test_client`] but seeds `SamplerConfig::extra_headers`, so a
|
||||
/// test can assert that session-injected headers reach the wire.
|
||||
#[allow(dead_code)]
|
||||
pub fn create_test_client_with_extra_headers(
|
||||
base_url: &str,
|
||||
api_backend: ApiBackend,
|
||||
|
|
@ -22,6 +314,7 @@ pub fn create_test_client_with_extra_headers(
|
|||
/// The shared mock-server `SamplerConfig`; tests needing a non-default field
|
||||
/// (e.g. `doom_loop_recovery`) mutate the returned value before building the
|
||||
/// client themselves.
|
||||
#[allow(dead_code)]
|
||||
pub fn test_sampler_config(
|
||||
base_url: &str,
|
||||
api_backend: ApiBackend,
|
||||
|
|
|
|||
Loading…
Reference in a new issue