open-standards/eoc/eoc-rs/crates/eoc-agent/tests/tot_branch.rs
Transaction Science 94681289e6 ingest wave A2: 3 crates · op-dispute-evidence + smart-byte-edv + eoc-agent
OpenPay (1 crate, ~2287 LOC, 15 tests)
  op-dispute-evidence  Chargeback lifecycle + evidence packaging across Visa
                       VCR (10.x/11.x/12.x/13.x), Mastercard Mastercom
                       (4837/4853/1240/1442), Amex SafeKey + DRR, Discover DRR,
                       PayPal. CE3.0 compelling-evidence qualifier (120-365d
                       window, ≥2 qualifiers, ≥2 linking matches, 10.4-only).
                       Phase state machine + ReasonCodeCatalog + sealed
                       EvidencePackageBuilder + win-rate scoring.

Smart Byte (1 crate, ~2479 LOC, 44 tests)
  smart-byte-edv       Encrypted Data Vaults (DIF v0.10).
                       JWE ECDH-ES P-256 + HKDF-SHA256-Concat-KDF + AES-256-GCM,
                       multi-recipient; HMAC-SHA-256 encrypted index with
                       AND-equality queries; full ZCAP-LD chain validation;
                       chunked AES-256-GCM streaming with per-chunk AAD;
                       Vault trait + InMemoryVault + one-way pull replication.

EOC (1 crate, ~2065 LOC, 29 tests)
  eoc-agent            Agentic loops with per-step joule accounting.
                       ReAct, Reflexion (PASS/FAIL judge + episodic memory),
                       Tree of Thoughts (BFS/DFS + self-scoring), LATS
                       (MCTS-UCT select/expand/simulate/backprop),
                       Plan-and-Execute, CodeAct (fenced-block + pluggable
                       runtime). Budget enforcement (tokens/joules/tool-calls),
                       trace spans, JouleCounter integration.

Three other batch-5 deferrals (op-ewallets-asia, smart-byte-zk, eoc-rag)
will land in wave A3.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-24 11:42:26 -04:00

64 lines
2 KiB
Rust

//! Integration test: Tree of Thoughts BFS expands branches and finishes
//! when a FINISH thought appears.
use std::sync::Arc;
use std::sync::Mutex;
use async_trait::async_trait;
use eoc_agent::agent::{Agent, Budget, LlmProvider, LlmReply};
use eoc_agent::error::AgentResult;
use eoc_agent::tot::{Search, ToTLoop};
use eoc_agent::StopReason;
struct Scripted {
replies: Mutex<Vec<String>>,
}
#[async_trait]
impl LlmProvider for Scripted {
async fn complete(&self, _prompt: &str) -> AgentResult<LlmReply> {
let text = {
let mut q = self.replies.lock().expect("lock");
if q.is_empty() {
"0.0".to_string()
} else {
q.remove(0)
}
};
Ok(LlmReply::new(text, 3, 100))
}
}
#[tokio::test]
async fn tot_finishes_on_finish_thought() {
// ToT alternates expansion + scoring. Branch=2, max_depth=2.
// Sequence (BFS):
// root -> expand child A => "consider this" (score "0.4")
// root -> expand child B => "FINISH: 7" (score irrelevant)
let replies = vec![
"consider this".to_string(),
"0.4".to_string(),
"FINISH: 7".to_string(),
"0.9".to_string(),
];
let provider = Arc::new(Scripted {
replies: Mutex::new(replies),
});
let mut agent = ToTLoop::new(provider, Budget::unlimited(20), 2, 2, Search::Bfs);
let (out, stop) = agent.run("solve").await.expect("ok");
assert_eq!(stop, StopReason::Done);
assert_eq!(out, "7");
// 3 nodes: root + 2 children.
assert_eq!(agent.nodes().len(), 3);
}
#[tokio::test]
async fn tot_dfs_respects_iteration_cap() {
// Provider always returns a never-finishing thought.
let provider = Arc::new(Scripted {
replies: Mutex::new(vec!["keep going".to_string(); 100]),
});
let mut agent = ToTLoop::new(provider, Budget::unlimited(2), 2, 4, Search::Dfs);
let (_out, stop) = agent.run("loop").await.expect("ok");
assert_eq!(stop, StopReason::MaxIterations);
}