mod cli_test_util;
use std::path::{Path, PathBuf};
use objectiveai_sdk::RemotePathCommitOptional;
use objectiveai_sdk::cli::command::functions::execute::standard::{
Request, RequestDangerousAdvanced, RequestInput, ResponseItem,
};
use objectiveai_sdk::cli::command::functions::execute::{
FunctionSpec, ProfileSpec,
};
use objectiveai_sdk::functions::FullInlineFunctionOrRemoteCommitOptional;
use objectiveai_sdk::functions::InlineProfileOrRemoteCommitOptional;
use objectiveai_sdk::functions::executions::response::streaming::FunctionExecutionChunk;
use objectiveai_sdk::functions::executions::response::unary::FunctionExecution;
fn snapshots_dir() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/function/executions/snapshots")
}
fn update_snapshot<T: serde::Serialize>(name: &str, normalized: &T) {
let path = snapshots_dir().join(format!("{name}.json"));
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent).unwrap();
}
let value = serde_json::to_value(normalized).expect("normalized value serialises");
let rounded_value = cli_test_util::rounded(&value);
let pretty = serde_json::to_string_pretty(&rounded_value)
.expect("rounded Value serialises to pretty JSON");
std::fs::write(&path, format!("{pretty}\n")).unwrap();
eprintln!("Updated snapshot: {}", path.display());
}
#[tokio::test]
async fn test_twenty_agents_json_schema_10x_tools_seed_42() {
if cli_test_util::test_api_address().is_none() {
eprintln!(
"OBJECTIVEAI_TEST_PORT not set — skipping test_twenty_agents_json_schema_10x_tools_seed_42"
);
return;
}
let function = FunctionSpec::Resolved(FullInlineFunctionOrRemoteCommitOptional::Remote(
RemotePathCommitOptional::Mock {
name: "twenty-agents-json-schema-10x-tools-vector".to_string(),
},
));
let profile = ProfileSpec::Resolved(InlineProfileOrRemoteCommitOptional::Remote(
RemotePathCommitOptional::Mock {
name: "twenty-agents-json-schema-10x-tools-profile".to_string(),
},
));
let input_json = serde_json::json!({
"items": ["A", "B"],
});
let request = Request { path_type: objectiveai_sdk::cli::command::functions::execute::standard::Path::FunctionsExecuteStandard,
function,
profile,
input: RequestInput::Inline(
serde_json::from_value(input_json).expect("input must deserialize as InputValue"),
),
continuation: None,
retry_token: None,
split: false,
invert: false,
dangerous_advanced: Some(RequestDangerousAdvanced {
stream: Some(true),
seed: Some(42),
}),
jq: None,
};
let executor = cli_test_util::executor();
let items: Vec<ResponseItem> = cli_test_util::collect_stream(&executor, request).await;
let mut chunks = items.into_iter().filter_map(|item| match item {
ResponseItem::Chunk(c) => Some(c),
ResponseItem::Id(_) => None,
});
let mut agg: FunctionExecutionChunk =
chunks.next().expect("at least one function-execution chunk must be emitted");
for chunk in chunks {
agg.push(&chunk);
}
let mut result: FunctionExecution = agg.into();
result.normalize_for_tests();
let name = "twenty_agents_json_schema_10x_tools_seed_42";
if std::env::var("UPDATE_SNAPSHOTS").as_deref() == Ok("1") {
update_snapshot(name, &result);
return;
}
let snapshot_path = snapshots_dir().join(format!("{name}.json"));
cli_test_util::assert_normalized_snapshot(&snapshot_path, name, &result);
}