use akribes_sdk::AkribesClient;
fn live_client() -> Option<AkribesClient> {
let url = std::env::var("AKRIBES_LIVE_URL").ok()?;
let token = std::env::var("AKRIBES_LIVE_TOKEN").ok()?;
Some(
AkribesClient::builder(&url)
.token(token)
.name("sdk-live-test")
.id(uuid::Uuid::new_v4().to_string())
.build(),
)
}
#[tokio::test]
#[ignore]
async fn live_full_surface() {
let client = live_client().expect("set AKRIBES_LIVE_URL + AKRIBES_LIVE_TOKEN");
let suffix = uuid::Uuid::new_v4().simple().to_string();
let proj_name = format!("sdk-live-{}", &suffix[..8]);
let proj = client.projects().create(&proj_name).await.unwrap();
let fetched = client.projects().get(proj.id).await.unwrap().unwrap();
assert_eq!(fetched.name, proj.name);
let dup = client.projects().duplicate(proj.id).await.unwrap();
assert_ne!(dup.id, proj.id);
let all: Vec<i64> = client
.projects()
.list()
.await
.unwrap()
.into_iter()
.map(|p| p.id)
.collect();
client.projects().reorder(all).await.unwrap();
let p = client.project(proj.id);
let script = p.scripts().create("demo", "").await.unwrap();
let got = p.scripts().get("demo").await.unwrap().unwrap();
assert_eq!(got.id, script.id);
let script_copy = p.scripts().duplicate("demo").await.unwrap();
assert_ne!(script_copy.id, script.id);
assert!(script_copy.name.starts_with("demo"));
let moved = p
.scripts()
.move_to(&script_copy.name, dup.id)
.await
.unwrap();
assert_eq!(moved.project_id, dup.id);
let script_ids: Vec<i64> = p
.scripts()
.list()
.await
.unwrap()
.into_iter()
.map(|s| s.id)
.collect();
p.scripts().reorder(script_ids).await.unwrap();
let drift = p.mcp().drift("nope").await.unwrap();
assert!(!drift.drifted);
client.projects().delete(proj.id).await.unwrap();
client.projects().delete(dup.id).await.unwrap();
}
#[tokio::test]
#[ignore]
async fn live_duplicate_404_surfaces_http_status() {
let client = live_client().expect("set AKRIBES_LIVE_URL + AKRIBES_LIVE_TOKEN");
let err = client.projects().duplicate(99_999_999).await.unwrap_err();
match err {
akribes_sdk::AkribesError::HttpStatus { status, .. } => {
assert!(status == 404 || status == 500, "got {status}");
}
other => panic!("expected HttpStatus, got {:?}", other),
}
}