feat(euclid): default fallback for transactions#102
feat(euclid): default fallback for transactions#102prajjwalkumar17 wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds a new DefaultFallback routing algorithm to provide a fallback set of connectors for transactions.
Key changes:
- Introduced
DefaultFallback(Vec<ConnectorInfo>)inStaticRoutingAlgorithm, AST enums, andOutput. - Updated
validate_routing_ruleandevaluate_outputto handle the new variant. - Enhanced the routing handler and output formatter to support
DefaultFallback.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/euclid/utils.rs | Accept DefaultFallback in validate_routing_rule |
| src/euclid/types.rs | Added DefaultFallback variant to StaticRoutingAlgorithm |
| src/euclid/interpreter.rs | Implemented evaluate_output arm for DefaultFallback |
| src/euclid/handlers/routing_rules.rs | Handled DefaultFallback in routing_evaluate and JSON |
| src/euclid/ast.rs | Included DefaultFallback in RoutingType and Output |
Comments suppressed due to low confidence (3)
src/euclid/handlers/routing_rules.rs:648
- There are no existing tests verifying the behavior of the new
DefaultFallbackinrouting_evaluateorformat_output. Please add unit tests to cover both success and failure paths for this variant.
Output::DefaultFallback(connectors) => {
src/euclid/types.rs:50
- Public API surface was extended with
DefaultFallback. Consider adding or updating doc comments in this enum (and any user-facing docs) to explain when and how this fallback is applied.
DefaultFallback(Vec<ConnectorInfo>),
src/euclid/handlers/routing_rules.rs:591
- [nitpick] The error context only includes the algorithm’s
to_string()output. It may be more helpful to include the connector list or a descriptive message (e.g., number of fallback connectors) to aid debugging.
EuclidErrors::FailedToEvaluateOutput(format!(
| vec![first_connector.unwrap_or_default()], | ||
| )) | ||
| } | ||
| Output::DefaultFallback(connectors) => Ok((connectors.clone(), connectors.to_vec())), |
There was a problem hiding this comment.
Cloning the connectors vector twice causes two allocations. You can clone once and reuse the result, e.g. let cloned = connectors.clone(); Ok((cloned.clone(), cloned)) to reduce overhead.
| Output::DefaultFallback(connectors) => Ok((connectors.clone(), connectors.to_vec())), | |
| Output::DefaultFallback(connectors) => { | |
| let cloned = connectors.clone(); | |
| Ok((cloned.clone(), cloned)) | |
| }, |
| match &rule.algorithm { | ||
| StaticRoutingAlgorithm::Single(_) | ||
| | StaticRoutingAlgorithm::Priority(_) | ||
| | StaticRoutingAlgorithm::DefaultFallback(_) |
There was a problem hiding this comment.
The DefaultFallback variant is always considered valid, even if its connector list is empty. Consider adding a check to ensure the fallback list is non-empty to prevent downstream runtime errors.
| | StaticRoutingAlgorithm::DefaultFallback(_) | |
| | StaticRoutingAlgorithm::DefaultFallback(connectors) => { | |
| if connectors.is_empty() { | |
| return Err(EuclidErrors::InvalidRequest( | |
| "DefaultFallback connector list cannot be empty".to_string(), | |
| ) | |
| .into()); | |
| } | |
| Ok(()) | |
| } |
Description
This PR introduces support for a new routing algorithm variant:
DefaultFallback. The purpose of this routing type is to provide a simple, last-resort fallback mechanism when no other routing logic matches or is applicable.The following updates are included:
DefaultFallbackin theRoutingType,Output, andStaticRoutingAlgorithmenums.DefaultFallbackby returning the provided connectors directly as eligible connectors.routing_evaluatehandler.format_outputto support serialization ofDefaultFallbackfor API responses.DefaultFallbackalgorithms to pass without evaluation.Outcomes
Diff Hunk Explanation
src/euclid/ast.rsDefaultFallbackas a new variant inRoutingTypeandOutputenums.src/euclid/types.rsDefaultFallback(Vec<ConnectorInfo>)to theStaticRoutingAlgorithmenum.src/euclid/handlers/routing_rules.rsDefaultFallbackalgorithm.format_output) forDefaultFallback.src/euclid/interpreter.rsevaluate_outputwhen usingDefaultFallback.src/euclid/utils.rsvalidate_routing_ruleto acceptDefaultFallbackas a valid static routing configuration.This PR is linked to Issue #101 and provides the implementation required to resolve it.