Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore: remove unused QueuedFollowups component and add event bus tests

Steven Enamakelfceab2cd3051
diff --git a/app/src/components/chat/QueuedFollowups.tsx b/app/src/components/chat/QueuedFollowups.tsx
deleted file mode 100644
index 7f01fd1233..0000000000
--- a/app/src/components/chat/QueuedFollowups.tsx
+++ /dev/null
@@ -1,52 +0,0 @@
-import { useT } from '../../lib/i18n/I18nContext';
-import type { QueuedFollowup } from '../../store/chatRuntimeSlice';
-import { Button } from '../ui';
-
-interface QueuedFollowupsProps {
- /** Follow-ups queued for the current thread while a turn is streaming. */
- items: QueuedFollowup[];
- /** Dismiss every queued follow-up (clears the backend run-queue too). */
- onClear: () => void;
-}
-
-/**
- * Compact strip rendered above the composer while one or more follow-up
- * messages are queued behind a streaming turn. Lets the user see what they
- * queued (so a typed follow-up is never silently lost) and clear the queue
- * before the backend dispatches them. Send/queueing happens in the composer;
- * this is a read-only surface plus a single clear action.
- */
-export default function QueuedFollowups({ items, onClear }: QueuedFollowupsProps) {
- const { t } = useT();
- if (items.length === 0) return null;
-
- return (
- <div
- data-testid="queued-followups"
- className="mb-2 rounded-xl border border-line bg-surface px-3 py-2">
- <div className="flex items-center justify-between gap-2 mb-1.5">
- <span className="text-xs font-medium text-content-muted">
- {t('chat.queuedFollowups.label')} · {items.length}
- </span>
- <Button
- variant="tertiary"
- size="xs"
- analyticsId="chat-queued-followups-clear"
- onClick={onClear}
- className="h-auto p-0 font-medium text-content-muted hover:bg-transparent hover:text-coral-500">
- {t('chat.queuedFollowups.clear')}
- </Button>
- </div>
- <ul className="flex flex-col gap-1">
- {items.map(item => (
- <li
- key={item.message.id}
- className="truncate text-sm text-content-secondary"
- title={item.label}>
- {item.label}
- </li>
- ))}
- </ul>
- </div>
- );
-}
diff --git a/app/src/components/chat/__tests__/QueuedFollowups.test.tsx b/app/src/components/chat/__tests__/QueuedFollowups.test.tsx
deleted file mode 100644
index 2fc551841d..0000000000
--- a/app/src/components/chat/__tests__/QueuedFollowups.test.tsx
+++ /dev/null
@@ -1,54 +0,0 @@
-import { fireEvent, render, screen } from '@testing-library/react';
-import { describe, expect, it, vi } from 'vitest';
-
-import type { QueuedFollowup } from '../../../store/chatRuntimeSlice';
-import QueuedFollowups from '../QueuedFollowups';
-
-vi.mock('../../../lib/i18n/I18nContext', () => ({ useT: () => ({ t: (k: string) => k }) }));
-
-const fup = (id: string, label: string, content = label): QueuedFollowup => ({
- message: {
- id,
- content,
- type: 'text',
- extraMetadata: {},
- sender: 'user',
- createdAt: '2026-01-01T00:00:00.000Z',
- },
- label,
-});
-
-describe('QueuedFollowups', () => {
- it('renders nothing when there are no queued items', () => {
- const { container } = render(<QueuedFollowups items={[]} onClear={vi.fn()} />);
- expect(container.firstChild).toBeNull();
- });
-
- it('lists queued follow-up labels with a count', () => {
- render(
- <QueuedFollowups
- items={[fup('a', 'ask about pricing'), fup('b', 'and the timeline')]}
- onClear={vi.fn()}
- />
- );
-
- expect(screen.getByText('ask about pricing')).toBeInTheDocument();
- expect(screen.getByText('and the timeline')).toBeInTheDocument();
- // Label key + count are rendered together ("chat.queuedFollowups.label · 2").
- expect(screen.getByText(/chat\.queuedFollowups\.label · 2/)).toBeInTheDocument();
- });
-
- it('falls back to the attachment-name label for an attachments-only follow-up', () => {
- render(<QueuedFollowups items={[fup('a', 'photo.png', '')]} onClear={vi.fn()} />);
- // content is empty (attachments only) but the label keeps the row non-blank.
- expect(screen.getByText('photo.png')).toBeInTheDocument();
- });
-
- it('invokes onClear when the clear control is pressed', () => {
- const onClear = vi.fn();
- render(<QueuedFollowups items={[fup('a', 'one')]} onClear={onClear} />);
-
- fireEvent.click(screen.getByText('chat.queuedFollowups.clear'));
- expect(onClear).toHaveBeenCalledTimes(1);
- });
-});
diff --git a/app/src/features/conversations/aui/useRunMode.ts b/app/src/features/conversations/aui/useRunMode.ts
index edd2f17d18..3e04945280 100644
--- a/app/src/features/conversations/aui/useRunMode.ts
+++ b/app/src/features/conversations/aui/useRunMode.ts
@@ -33,6 +33,11 @@ export function useRunMode(threadId: string | null): UseRunModeResult {
const mode = useAppSelector(state =>
threadId ? state.runMode.byThread[threadId] ?? DEFAULT_MODE : DEFAULT_MODE
);
+ // Presence (not the defaulted `mode` above) — needed so the load-on-open
+ // effect can tell "no entry yet" apart from "explicitly build".
+ const hasEntry = useAppSelector(state => (threadId ? threadId in state.runMode.byThread : false));
+ const hasEntryRef = useRef(hasEntry);
+ hasEntryRef.current = hasEntry;
const loadedFor = useRef<string | null>(null);
useEffect(() => {
@@ -40,7 +45,7 @@ export function useRunMode(threadId: string | null): UseRunModeResult {
loadedFor.current = threadId;
// Only fetch when the slice has no live entry yet — a value already set
// (e.g. by a `run_mode_changed` event that arrived first) wins.
- if (store.getState().runMode.byThread[threadId] !== undefined) return;
+ if (hasEntryRef.current) return;
let cancelled = false;
void (async () => {
try {
diff --git a/crates/openhuman-core/src/threads/ops/live_state_tests.rs b/crates/openhuman-core/src/threads/ops/live_state_tests.rs
index efe407ea51..fa99be23f6 100644
--- a/crates/openhuman-core/src/threads/ops/live_state_tests.rs
+++ b/crates/openhuman-core/src/threads/ops/live_state_tests.rs
@@ -1,11 +1,14 @@
-//! Behavior tests for `threads::ops::live_state` — direct store-level checks
-//! that don't need the process-wide `Config::load_or_init()` a `workspace_dir()`
-//! RPC call resolves against (full RPC-path coverage is in
-//! `tests/json_rpc_e2e.rs`).
+//! Behavior tests for `threads::ops::live_state`.
+//!
+//! `goal_get`/`todos_get` resolve their workspace through
+//! `Config::load_or_init()` (the same process-global config every RPC
+//! handler reads), so — like the other `OPENHUMAN_WORKSPACE`-dependent config
+//! tests — these serialize on `crate::config::TEST_ENV_LOCK` and point that
+//! env var at a fresh tempdir for the duration of the test.
use super::*;
-use crate::agent::goals::goal_to_value;
use crate::agent::todos::ops::{TodoItem, TodoStatus};
+use crate::config::TEST_ENV_LOCK;
#[test]
fn thread_live_state_request_parses_thread_id() {
@@ -14,35 +17,88 @@ fn thread_live_state_request_parses_thread_id() {
assert_eq!(parsed.thread_id, "thread-1");
}
-/// `goal_to_value` (the field `goal_get`'s response and `ThreadGoalUpdated`
-/// share) round-trips a goal's shape losslessly — a smoke check that the
-/// shared serializer doesn't silently drop fields the frontend goal chip
-/// reads.
+struct WorkspaceGuard {
+ _lock: std::sync::MutexGuard<'static, ()>,
+ _tmp: tempfile::TempDir,
+}
+
+impl WorkspaceGuard {
+ fn new() -> Self {
+ let lock = TEST_ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+ let tmp = tempfile::tempdir().expect("tempdir");
+ unsafe {
+ std::env::set_var("OPENHUMAN_WORKSPACE", tmp.path());
+ }
+ Self {
+ _lock: lock,
+ _tmp: tmp,
+ }
+ }
+}
+
+impl Drop for WorkspaceGuard {
+ fn drop(&mut self) {
+ unsafe {
+ std::env::remove_var("OPENHUMAN_WORKSPACE");
+ }
+ }
+}
+
+/// `threads.goal_get` returns `{ goal: null }` for a thread with no goal, and
+/// the full goal payload — the same shape `ThreadGoalUpdated` carries — once
+/// one is set.
#[tokio::test]
-async fn goal_to_value_round_trips_the_stored_goal() {
- let dir = std::env::temp_dir().join(format!(
- "openhuman-goal-live-state-test-{}",
- uuid::Uuid::new_v4()
- ));
- std::fs::create_dir_all(&dir).unwrap();
- let goal = crate::agent::goals::store::set(&dir, "thread-goal-live", "ship it", Some(1000))
+async fn goal_get_reads_back_a_stored_goal() {
+ let _ws = WorkspaceGuard::new();
+
+ let empty = goal_get(ThreadLiveStateRequest {
+ thread_id: "thread-goal-live".to_string(),
+ })
+ .await
+ .unwrap();
+ let empty_json = empty.into_cli_compatible_json().unwrap();
+ assert!(empty_json["result"]["goal"].is_null(), "{empty_json}");
+
+ let dir = crate::config::Config::load_or_init()
+ .await
+ .unwrap()
+ .workspace_dir;
+ crate::agent::goals::store::set(&dir, "thread-goal-live", "ship it", Some(1000))
.await
.unwrap();
- let value = goal_to_value(&goal);
- assert_eq!(value["objective"], "ship it");
- assert_eq!(value["status"], "active");
- assert_eq!(value["tokenBudget"], 1000);
+
+ let filled = goal_get(ThreadLiveStateRequest {
+ thread_id: "thread-goal-live".to_string(),
+ })
+ .await
+ .unwrap();
+ let filled_json = filled.into_cli_compatible_json().unwrap();
+ let goal = &filled_json["result"]["goal"];
+ assert_eq!(goal["objective"], "ship it");
+ assert_eq!(goal["status"], "active");
}
-/// `todos_get`'s store read returns the items a `TodoTool` call wrote under
-/// the same thread-id key.
+/// `threads.todos_get` reads back what a `TodoTool` call (thread-id-keyed)
+/// wrote for the same thread.
#[tokio::test]
async fn todos_get_reads_back_what_the_todo_tool_wrote() {
- let dir = std::env::temp_dir().join(format!(
- "openhuman-todos-live-state-test-{}",
- uuid::Uuid::new_v4()
- ));
- std::fs::create_dir_all(&dir).unwrap();
+ let _ws = WorkspaceGuard::new();
+ let dir = crate::config::Config::load_or_init()
+ .await
+ .unwrap()
+ .workspace_dir;
+
+ let empty = todos_get(ThreadLiveStateRequest {
+ thread_id: "thread-todos-live".to_string(),
+ })
+ .await
+ .unwrap();
+ let empty_json = empty.into_cli_compatible_json().unwrap();
+ assert!(empty_json["result"]["todos"]
+ .as_array()
+ .unwrap()
+ .is_empty());
+
let scope = crate::agent::todos::ops::TodoScope::Session {
id: "thread-todos-live".to_string(),
};
@@ -54,13 +110,13 @@ async fn todos_get_reads_back_what_the_todo_tool_wrote() {
.await
.unwrap();
- let response = todos_get(ThreadLiveStateRequest {
+ let filled = todos_get(ThreadLiveStateRequest {
thread_id: "thread-todos-live".to_string(),
})
.await
.unwrap();
- let json = response.into_cli_compatible_json().unwrap();
- let todos = json["result"]["todos"].as_array().unwrap();
+ let filled_json = filled.into_cli_compatible_json().unwrap();
+ let todos = filled_json["result"]["todos"].as_array().unwrap();
assert_eq!(todos.len(), 1);
assert_eq!(todos[0]["content"], "write tests");
}
diff --git a/crates/openhuman-core/src/web_chat/event_bus_tests.rs b/crates/openhuman-core/src/web_chat/event_bus_tests.rs
index 5aff620a7e..59215c457c 100644
--- a/crates/openhuman-core/src/web_chat/event_bus_tests.rs
+++ b/crates/openhuman-core/src/web_chat/event_bus_tests.rs
@@ -397,3 +397,116 @@ async fn agent_surface_bridges_queue_item_delivered_with_lane() {
assert_eq!(item.id, "item-2");
assert_eq!(item.lane, Some("collect".to_string()));
}
+
+/// `ThreadRunModeChanged` bridges to `run_mode_changed` with the mode label
+/// carried on `message` and an empty `client_id` (thread-scoped, not
+/// client-scoped, like the goal/todo/queue events above).
+#[tokio::test]
+async fn agent_surface_bridges_run_mode_changed() {
+ crate::core::bus::init().await.expect("bus init");
+ let _handle = crate::core::bus::BUS.subscribe(Arc::new(AgentSurfaceSubscriber));
+ let mut web_rx = subscribe_web_channel_events();
+
+ let thread_id = "thread-run-mode-changed";
+ crate::core::bus::BUS.publish(DomainEvent::ThreadRunModeChanged {
+ thread_id: thread_id.to_string(),
+ mode: "plan".to_string(),
+ });
+
+ let ev = find_agent_web_event(&mut web_rx, "run_mode_changed", thread_id).await;
+ assert_eq!(ev.client_id, "");
+ assert_eq!(ev.message, Some("plan".to_string()));
+}
+
+/// `ApprovalDecided` with both `thread_id`/`client_id` set bridges to
+/// `approval_decided`, mirroring `tool_call_id` and carrying `resolution` on
+/// `cancel_reason`.
+#[tokio::test]
+async fn approval_surface_bridges_approval_decided_with_resolution() {
+ crate::core::bus::init().await.expect("bus init");
+ let _handle = crate::core::bus::BUS.subscribe(Arc::new(ApprovalSurfaceSubscriber));
+ let mut web_rx = subscribe_web_channel_events();
+
+ crate::core::bus::BUS.publish(DomainEvent::ApprovalDecided {
+ request_id: "req-decided-1".to_string(),
+ tool_name: "composio".to_string(),
+ decision: "deny".to_string(),
+ thread_id: Some("thread-decided-1".to_string()),
+ client_id: Some("client-decided-1".to_string()),
+ tool_call_id: Some("call-decided-1".to_string()),
+ resolution: Some("expired".to_string()),
+ });
+
+ let ev = find_agent_web_event(&mut web_rx, "approval_decided", "thread-decided-1").await;
+ assert_eq!(ev.client_id, "client-decided-1");
+ assert_eq!(ev.request_id, "req-decided-1");
+ assert_eq!(ev.tool_call_id, Some("call-decided-1".to_string()));
+ assert_eq!(ev.cancel_reason, Some("expired".to_string()));
+ assert_eq!(ev.message, Some("deny".to_string()));
+}
+
+/// `ApprovalDecided` with no thread/client routing (a non-chat origin) is
+/// intentionally NOT surfaced — there is no room to deliver it to.
+#[tokio::test]
+async fn approval_surface_drops_approval_decided_without_chat_routing() {
+ crate::core::bus::init().await.expect("bus init");
+ let _handle = crate::core::bus::BUS.subscribe(Arc::new(ApprovalSurfaceSubscriber));
+ let mut web_rx = subscribe_web_channel_events();
+
+ crate::core::bus::BUS.publish(DomainEvent::ApprovalDecided {
+ request_id: "req-decided-no-route".to_string(),
+ tool_name: "composio".to_string(),
+ decision: "deny".to_string(),
+ thread_id: None,
+ client_id: None,
+ tool_call_id: None,
+ resolution: Some("expired".to_string()),
+ });
+ // A sibling event we know fires, so we don't just race an empty channel.
+ crate::core::bus::BUS.publish(DomainEvent::ThreadGoalCleared {
+ thread_id: "thread-decided-no-route-sentinel".to_string(),
+ });
+
+ // `ThreadGoalCleared` isn't in ApprovalSurfaceSubscriber's domain filter,
+ // so use a short bounded wait instead: if `approval_decided` were going
+ // to arrive, it would arrive well within this window.
+ let outcome = tokio::time::timeout(std::time::Duration::from_millis(200), async {
+ loop {
+ match web_rx.recv().await {
+ Ok(ev) if ev.event == "approval_decided" => return Some(ev),
+ Ok(_) => continue,
+ Err(broadcast::error::RecvError::Lagged(_)) => continue,
+ Err(broadcast::error::RecvError::Closed) => return None,
+ }
+ }
+ })
+ .await;
+ assert!(
+ outcome.is_err(),
+ "approval_decided must not surface without thread_id/client_id routing"
+ );
+}
+
+/// `PlanReviewDecided` bridges to `plan_review_decided`.
+#[tokio::test]
+async fn plan_review_surface_bridges_plan_review_decided() {
+ crate::core::bus::init().await.expect("bus init");
+ let _handle = crate::core::bus::BUS.subscribe(Arc::new(ApprovalSurfaceSubscriber));
+ let mut web_rx = subscribe_web_channel_events();
+
+ crate::core::bus::BUS.publish(DomainEvent::PlanReviewDecided {
+ request_id: "plan-decided-1".to_string(),
+ decision: "approve".to_string(),
+ thread_id: Some("thread-plan-decided-1".to_string()),
+ client_id: Some("client-plan-decided-1".to_string()),
+ tool_call_id: Some("call-plan-decided-1".to_string()),
+ resolution: None,
+ });
+
+ let ev =
+ find_agent_web_event(&mut web_rx, "plan_review_decided", "thread-plan-decided-1").await;
+ assert_eq!(ev.client_id, "client-plan-decided-1");
+ assert_eq!(ev.tool_call_id, Some("call-plan-decided-1".to_string()));
+ assert_eq!(ev.cancel_reason, None);
+ assert_eq!(ev.message, Some("approve".to_string()));
+}