Files
cleveractors-core/features/bridge_coverage_gaps.feature
CoreRasurae 9753b31c7e
CI / quality (push) Successful in 36s
CI / lint (push) Successful in 38s
CI / typecheck (push) Successful in 49s
CI / security (push) Successful in 51s
CI / integration_tests (push) Successful in 55s
CI / unit_tests (push) Successful in 3m35s
CI / build (push) Successful in 33s
CI / coverage (push) Successful in 3m36s
CI / status-check (push) Successful in 3s
test: add coverage gap tests improving coverage from 81.4% to 96.90%
Add 13 BDD scenarios covering previously uncovered code paths:
- SAFE_BUILTINS validation (sandbox.py: 0% → 100%)
- ConfigurationError re-raise path (config.py: 99.3% → 100%)
- CLI hello/main functions (cli.py: 72.7% → 90.9%)
- GraphState message truncation (state.py: 98.7% → 100%)
- ProgressBarManager update/context rendering (progress.py: 0% → 87.7%)
- MessageRouter regex/exact/contains routing (message_router.py: 0% → 59.4%)
- RoutingAdapter parse_routing_command (routing_adapter.py)
- DynamicRouterNode pattern-based routing (dynamic_router.py)
- EnhancedTemplateRegistry unknown template type (enhanced_registry.py: 99.2%)
- CompositeAgent null-graph error path (composite.py: 97.8% → 98.6%)

Cover routing_adapter.py (17% → 100%): all GOTO/ROUTE patterns,
create_routing_node, create_conditional_router, dynamic config conversion.

Cover dynamic_router.py (21% → 87%): execute with empty/dict/string
messages, extract_message with colon parsing, config creation, graph
extension with edge generation.

Cover message_router.py (59% → 78%): regex, exact, contains, prefix,
suffix match types, invalid regex handling, non-string message, set_state.

Exercise Node._prepare_conversation_history with invalid configs,
_runtime error paths, _execute_message_router with rules,
_execute_agent with current_message and metadata propagation,
_execute_function with dynamic_router, and _execute_conditional
with content_contains/content_not_contains/content_starts_with
and custom condition types. Improves nodes.py from 71.3% to 72.5%.

Exercise PureGraphConfig, PureLangGraph init with dict/config,
RxPyLangGraphBridge registration/connection/lookup,
ReactiveStreamRouter operator creation and condition functions,
ReactiveConfigParser config/route/graph parsing,
ToolAgent tool execution with JSON, space-separated, single,
file_read, progress_bar invocations, and
ReactiveCleverAgentsApp init/dispose/visualization.
2026-06-02 20:02:01 +01:00

153 lines
7.5 KiB
Gherkin

Feature: Bridge Event Loop Management, Task Cleanup, and Metadata Handling
As a developer
I want the bridge to handle closed event loops, cancelled tasks, metadata in executors, and cleanup with async/sync paths
So that the bridge recovers from event loop failures, cleans up tasks, and propagates metadata correctly
Background:
Given a fresh bridge gaps test context (brg)
Scenario: Metadata passed to graph state in executor
Given a bridge with a mock graph named "meta_graph" (brg)
When I invoke the graph executor with metadata (brg)
Then the metadata should be passed to the graph input (brg)
Scenario: No running loop in graph executor with closed loop
Given a bridge with a mock graph named "cl_loop_graph" (brg)
When I invoke the graph executor with no running loop and a closed event loop (brg)
Then a new event loop should be created and used (brg)
Scenario: Exception in no-running-loop graph executor
Given a bridge with a mock graph named "err_loop_graph" (brg)
When I invoke the graph executor with no running loop and graph execution fails (brg)
Then the exception should be set on the future (brg)
Scenario: Task result handler handles CancelledError
Given a bridge gaps test context (brg)
When I simulate a task CancelledError in the result handler (brg)
Then the task should be removed from active tasks (brg)
Scenario: Task result handler handles generic Exception
Given a bridge gaps test context (brg)
When I simulate a task generic Exception in the result handler (brg)
Then the task should be removed from active tasks gracefully (brg)
Scenario: Node operator no running loop path
Given a bridge has mock graph named "node_graph" with node named "worker_node" (brg)
When I invoke the node operator with no running loop (brg)
Then a new event loop should be used for node execution (brg)
Scenario: Node operator exception in no-running-loop path
Given a bridge has mock graph named "node_err_graph" with node named "worker_node" (brg)
When I invoke the node operator with no running loop and node execution fails (brg)
Then the exception should be captured on the future (brg)
Scenario: Node operator task handler CancelledError
Given a bridge gaps test context (brg)
When I simulate a node operator task CancelledError (brg)
Then the node task should be removed from active tasks (brg)
Scenario: Node operator task handler generic Exception
Given a bridge gaps test context (brg)
When I simulate a node operator task generic Exception (brg)
Then the node task should be removed from active tasks gracefully (brg)
Scenario: connect_stream_to_graph no running loop path
Given a bridge with a stream "stm_graph" and graph "stm_graph" (brg)
When I connect stream to graph with no running loop (brg)
Then a new event loop should be created for the stream-to-graph connection (brg)
Given a bridge gaps test context (brg)
When I simulate a connect_stream_to_graph task CancelledError (brg)
Then the task should be cleaned up (brg)
Scenario: connect_stream_to_graph task result generic Exception
Given a bridge gaps test context (brg)
When I simulate a connect_stream_to_graph task generic Exception (brg)
Then the task should be cleaned up gracefully (brg)
Scenario: connect_graph_to_stream creates on_state_update
Given a bridge with a graph "gts_graph" and stream "gts_stream" (brg)
When I connect the graph to the stream via bridge (brg)
Then on_state_update should send StreamMessages to the target stream (brg)
Scenario: cleanup_async cancels pending tasks
Given a bridge with active tasks (brg)
When I call cleanup_async (brg)
Then all pending tasks should be cancelled and awaited (brg)
Scenario: cleanup sync inside running loop
Given a bridge with active tasks and a running event loop (brg)
When I call cleanup synchronously (brg)
Then tasks should be cancelled without awaiting (brg)
Scenario: cleanup sync with closed loop creates new loop
Given a bridge with active tasks and a closed event loop (brg)
When I call cleanup synchronously (brg)
Then a new event loop should be created for cleanup (brg)
Scenario: cleanup sync with loop running uses cancel-only path
Given a bridge with active tasks where the loop is running (brg)
When I call cleanup synchronously (brg)
Then tasks should be cancelled without blocking (brg)
Scenario: cleanup sync fallback exception path
Given a bridge with active tasks and a broken loop (brg)
When I call cleanup and the loop operations fail (brg)
Then tasks should be cancelled via fallback (brg)
Scenario: Node operator extracts messages result
Given a bridge has mock graph named "msg_out_graph" with node named "msg_node" (brg)
When node execution returns messages format (brg)
Then the result should be extracted and returned with metadata (brg)
Scenario: Node operator returns full updates when no messages
Given a bridge has mock graph named "data_graph" with node named "data_node" (brg)
When node execution returns non-messages data (brg)
Then the full updates dict should be returned as result (brg)
Scenario: cleanup_tasks cancels and clears active tasks
Given a fresh bridge gaps test context (brg)
Given a bridge with active tasks (brg)
When I call cleanup_tasks directly (brg)
Then all tasks should be cancelled and the set cleared (brg)
Scenario: _run_async_safely returns coroutine unchanged
Given a fresh bridge gaps test context (brg)
Given a bridge has graph named "async_safe" (brg)
When I call _run_async_safely with a coroutine (brg)
Then the coroutine should be returned unchanged (brg)
Scenario: create_graph_from_config creates MESSAGE_ROUTER node with rules
Given a fresh bridge gaps test context (brg)
Given a bridge has graph named "router_config" (brg)
When I call create_graph_from_config with message router rules (brg)
Then the MESSAGE_ROUTER node should have rules in metadata (brg)
Scenario: Graph executor with no running loop and closed loop path
Given a fresh bridge gaps test context (brg)
Given a bridge has mock graph named "cl_exec_graph" (brg)
When I invoke graph executor with get_event_loop returning closed loop (brg)
Then a new event loop should be created for executor (brg)
Scenario: Node operator with no running loop and closed loop path
Given a fresh bridge gaps test context (brg)
Given a bridge has graph named "node_cl" plus node "nl_node" (brg)
When I invoke node operator with closed event loop fallback (brg)
Then a new event loop should be created for node operator (brg)
Scenario: Conditional router content_not_contains condition
Given a fresh bridge gaps test context (brg)
Given a bridge has graph named "cond_graph" (brg)
When I evaluate content_not_contains condition via bridge (brg)
Then the condition should return correct boolean values (brg)
Scenario: connect_stream_to_graph validation error for missing graph
Given a fresh bridge gaps test context (brg)
Given a bridge with a stream "only_stream" without graph (brg)
When I call connect_stream_to_graph with missing graph (brg)
Then a ValueError should be raised about missing graph (brg)
Scenario: cleanup sync cancels tasks via fallback cancel
Given a fresh bridge gaps test context (brg)
Given a bridge with active tasks where the loop is running (brg)
When I call cleanup synchronously (brg)
Then tasks should be cancelled without blocking (brg)