use std::sync::Arc;
use crate::context::builder::test_support::{StubSubScheduler, named_agent};
use crate::context::{ContextDelta, InvocationContext};
#[test]
fn test_nil_delta_still_reaches_the_invocation() {
let inner = InvocationContext::builder()
.agent(named_agent("parent"))
.build_invocation();
let tool_ctx = inner.into_context().with_delta(ContextDelta {
function_call_id: Some("fc-1".into()),
..Default::default()
});
let c = tool_ctx.with_delta(ContextDelta {
path: Some("wf/n@1".into()),
..Default::default()
});
assert_eq!(c.agent().name(), "parent");
assert_eq!(c.agent_name(), "parent");
}
#[test]
fn test_delta_reaches_the_invocation() {
let ic = InvocationContext::builder()
.agent(named_agent("parent"))
.branch("parent-branch")
.build_invocation();
let c = ic.into_context().with_delta(ContextDelta {
agent: Some(named_agent("child")),
branch: Some("child-branch".into()),
..Default::default()
});
assert_eq!(c.agent().name(), "child");
assert_eq!(c.branch(), "child-branch");
}
#[test]
fn test_discard_keeps_the_rest_of_the_delta() {
let ic = InvocationContext::builder()
.agent(named_agent("parent"))
.build_invocation();
let c = ic.into_context().with_delta(ContextDelta {
branch: Some("child-branch".into()),
run_id: Some("run-7".into()),
path: Some("wf/n@1".into()),
output_for_ancestors: Some(vec!["a".into(), "b".into()]),
sub_scheduler: Some(Some(Arc::new(StubSubScheduler))),
..Default::default()
});
assert_eq!(c.run_id(), "run-7");
assert!(c.sub_scheduler().is_some());
assert_eq!(c.path(), "wf/n@1");
assert_eq!(c.branch(), "child-branch");
assert_eq!(
c.output_for_ancestors(),
vec!["a".to_string(), "b".to_string()]
);
}