tests for the forge objects pass: team, rule, repo and mirror writes
adds routed_forge, writes and sent to the forge.rs test module: a stand-in forge that answers by path. it adds an x-total-count header to list answers, which the forgejo client reads to page; test code only, no production file changes.
This commit is contained in:
parent
ec4274f39e
commit
c1234973be
2 changed files with 576 additions and 0 deletions
|
|
@ -2819,6 +2819,80 @@ mod tests {
|
|||
(Client { api, url }, seen)
|
||||
}
|
||||
|
||||
/// A stand-in forge on a loopback port answering each request by
|
||||
/// `route(method, path, body)` with a status and JSON body, and
|
||||
/// recording every request like [`stub_forge`]. For the tests that need
|
||||
/// a different answer per path.
|
||||
pub(super) async fn routed_forge(
|
||||
route: impl Fn(&str, &str, &serde_json::Value) -> (u16, String) + Send + Sync + 'static,
|
||||
) -> (Client, Seen) {
|
||||
use axum::http::{Method, StatusCode, Uri, header::CONTENT_TYPE};
|
||||
|
||||
let seen = Seen::default();
|
||||
let recorded = seen.clone();
|
||||
let route = std::sync::Arc::new(route);
|
||||
let app = axum::Router::new().fallback(
|
||||
move |method: Method, uri: Uri, body: axum::body::Bytes| {
|
||||
let (recorded, route) = (recorded.clone(), std::sync::Arc::clone(&route));
|
||||
async move {
|
||||
let json = serde_json::from_slice(&body).unwrap_or_default();
|
||||
let (status, answer) = route(method.as_str(), uri.path(), &json);
|
||||
recorded.lock().unwrap().push((
|
||||
method.to_string(),
|
||||
uri.path().to_owned(),
|
||||
json,
|
||||
));
|
||||
let status = StatusCode::from_u16(status).unwrap();
|
||||
// A list answer carries its length, which the forge client
|
||||
// reads to know it has seen every page.
|
||||
let total = serde_json::from_str::<Vec<serde_json::Value>>(&answer)
|
||||
.map_or(0, |list| list.len());
|
||||
(
|
||||
status,
|
||||
[
|
||||
(CONTENT_TYPE, "application/json".to_owned()),
|
||||
(axum::http::HeaderName::from_static("x-total-count"), total.to_string()),
|
||||
],
|
||||
answer,
|
||||
)
|
||||
}
|
||||
},
|
||||
);
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let url = url::Url::parse(&format!("http://{}/", listener.local_addr().unwrap())).unwrap();
|
||||
tokio::spawn(async move { axum::serve(listener, app).await });
|
||||
let api = crate::forge::api::tests::fixed(url.clone(), "stub-token");
|
||||
(Client { api, url }, seen)
|
||||
}
|
||||
|
||||
/// The requests in `seen` that are not reads, as `METHOD path`.
|
||||
pub(super) fn writes(seen: &Seen) -> Vec<String> {
|
||||
seen.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|(method, _, _)| method != "GET")
|
||||
.map(|(method, path, _)| format!("{method} {path}"))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The body of the first `method path` request in `seen`, with unset
|
||||
/// (`null`) fields dropped: what the forge acts on.
|
||||
pub(super) fn sent(seen: &Seen, method: &str, path: &str) -> Option<serde_json::Value> {
|
||||
let body = seen
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|(m, p, _)| m == method && p == path)
|
||||
.map(|(_, _, body)| body.clone())?;
|
||||
Some(serde_json::Value::Object(
|
||||
body.as_object()?
|
||||
.iter()
|
||||
.filter(|(_, v)| !v.is_null())
|
||||
.map(|(k, v)| (k.clone(), v.clone()))
|
||||
.collect(),
|
||||
))
|
||||
}
|
||||
|
||||
/// The `PATCH` [`Client::ensure_agent_user`] sent, if any.
|
||||
pub(super) fn lockdown_patch(seen: &Seen, agent: &str) -> Option<serde_json::Value> {
|
||||
let path = format!("/api/v1/admin/users/{agent}");
|
||||
|
|
|
|||
|
|
@ -1499,4 +1499,506 @@ mod tests {
|
|||
assert!(team_matches(&team(&reversed)));
|
||||
assert!(!team_matches(&team(&OPERATORS_TEAM_UNITS[1..])));
|
||||
}
|
||||
|
||||
// The write side, against a stand-in forge that answers by path.
|
||||
use super::super::tests::{Seen as Requests, routed_forge, sent, writes};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
const ALL_ORGS: [&str; 4] = [CONFIG_ORG, SHARED_ORG, AGENTS_ORG, "actions"];
|
||||
|
||||
fn operators_team_json(id: i64) -> Value {
|
||||
json!({
|
||||
"id": id,
|
||||
"name": OPERATORS_TEAM,
|
||||
"description": OPERATORS_TEAM_DESCRIPTION,
|
||||
"permission": "write",
|
||||
"includes_all_repositories": true,
|
||||
"can_create_org_repo": false,
|
||||
"units": OPERATORS_TEAM_UNITS,
|
||||
})
|
||||
}
|
||||
|
||||
fn config_rule_json() -> Value {
|
||||
json!({
|
||||
"enable_merge_whitelist": true,
|
||||
"merge_whitelist_teams": [OPERATORS_TEAM],
|
||||
"merge_whitelist_usernames": [],
|
||||
"enable_approvals_whitelist": true,
|
||||
"approvals_whitelist_teams": [OPERATORS_TEAM],
|
||||
})
|
||||
}
|
||||
|
||||
/// A forge holding [`converged`]'s objects plus one config repo `atlas`
|
||||
/// with its merge gate and an archived one, each answer replaced by the
|
||||
/// matching entry of `overrides` (`"METHOD path"` → status, body). Any
|
||||
/// other write is a 200 and any other read a 404.
|
||||
async fn world(overrides: Vec<(&'static str, u16, Value)>) -> (Client, Requests) {
|
||||
let mut answers: BTreeMap<String, (u16, String)> = BTreeMap::new();
|
||||
let mut put = |key: String, status: u16, body: Value| {
|
||||
answers.insert(key, (status, body.to_string()));
|
||||
};
|
||||
for org in ALL_ORGS {
|
||||
put(
|
||||
format!("GET /api/v1/orgs/{org}"),
|
||||
200,
|
||||
json!({"username": org}),
|
||||
);
|
||||
}
|
||||
for (org, id) in [(AGENTS_ORG, 1), (CONFIG_ORG, 2)] {
|
||||
put(
|
||||
format!("GET /api/v1/orgs/{org}/teams"),
|
||||
200,
|
||||
json!([operators_team_json(id)]),
|
||||
);
|
||||
}
|
||||
put(
|
||||
format!("GET /api/v1/repos/{SHARED_ORG}/{SHARED_DOCS_REPO}"),
|
||||
200,
|
||||
json!({"private": true, "empty": true}),
|
||||
);
|
||||
put(
|
||||
format!("GET /api/v1/repos/{KNOWLEDGE_ORG}/{KNOWLEDGE_REPO}"),
|
||||
200,
|
||||
json!({"private": false, "empty": false}),
|
||||
);
|
||||
put(
|
||||
"GET /api/v1/repos/actions/checkout".to_owned(),
|
||||
200,
|
||||
json!({"mirror": true, "mirror_interval": MIRROR_INTERVAL}),
|
||||
);
|
||||
put(
|
||||
format!("GET /api/v1/orgs/{CONFIG_ORG}/repos"),
|
||||
200,
|
||||
json!([{"name": "atlas"}, {"name": "gone", "archived": true}]),
|
||||
);
|
||||
put(
|
||||
format!("GET /api/v1/repos/{CONFIG_ORG}/atlas/branch_protections/main"),
|
||||
200,
|
||||
config_rule_json(),
|
||||
);
|
||||
for (key, status, body) in overrides {
|
||||
put(key.to_owned(), status, body);
|
||||
}
|
||||
routed_forge(move |method, path, _| {
|
||||
answers
|
||||
.get(&format!("{method} {path}"))
|
||||
.cloned()
|
||||
.unwrap_or_else(|| match method {
|
||||
"GET" => (404, r#"{"message":"not found"}"#.to_owned()),
|
||||
"POST" => (201, "{}".to_owned()),
|
||||
_ => (200, "{}".to_owned()),
|
||||
})
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
/// [`desired`] without the avatar, which would read a file.
|
||||
fn desired_without_avatar() -> Desired {
|
||||
Desired::new(
|
||||
vec![mirror("actions", "checkout")],
|
||||
None,
|
||||
PathBuf::from("/state"),
|
||||
)
|
||||
}
|
||||
|
||||
fn no(path: &'static str) -> (&'static str, u16, Value) {
|
||||
(path, 404, json!({"message": "no"}))
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_converged_forge_gets_no_write_and_no_failure() {
|
||||
let (client, seen) = world(vec![]).await;
|
||||
let outcome = client.reconcile(&desired_without_avatar()).await;
|
||||
assert_eq!(
|
||||
outcome,
|
||||
PassOutcome {
|
||||
applied: 0,
|
||||
failed: 0
|
||||
}
|
||||
);
|
||||
assert!(writes(&seen).is_empty(), "{:?}", writes(&seen));
|
||||
// Control: the pass read the objects it was judging.
|
||||
assert!(
|
||||
seen.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|(_, p, _)| p == "/api/v1/orgs/agent-configs/teams")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_team_with_the_wrong_permission_is_put_back_to_write_on_its_units() {
|
||||
let mut wrong = operators_team_json(2);
|
||||
wrong["permission"] = json!("admin");
|
||||
let (client, seen) = world(vec![(
|
||||
"GET /api/v1/orgs/agent-configs/teams",
|
||||
200,
|
||||
json!([wrong]),
|
||||
)])
|
||||
.await;
|
||||
let outcome = client.reconcile(&desired_without_avatar()).await;
|
||||
assert_eq!(
|
||||
outcome,
|
||||
PassOutcome {
|
||||
applied: 1,
|
||||
failed: 0
|
||||
}
|
||||
);
|
||||
assert_eq!(writes(&seen), ["PATCH /api/v1/teams/2"]);
|
||||
let edit = sent(&seen, "PATCH", "/api/v1/teams/2").unwrap();
|
||||
assert_eq!(edit["permission"], "write");
|
||||
assert_eq!(edit["includes_all_repositories"], true);
|
||||
assert_eq!(edit["can_create_org_repo"], false);
|
||||
assert_eq!(edit["units"], json!(OPERATORS_TEAM_UNITS));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_missing_team_is_created_as_a_write_team_on_every_repo() {
|
||||
let (client, seen) = world(vec![("GET /api/v1/orgs/agents/teams", 200, json!([]))]).await;
|
||||
let outcome = client.reconcile(&desired_without_avatar()).await;
|
||||
assert_eq!(
|
||||
outcome,
|
||||
PassOutcome {
|
||||
applied: 1,
|
||||
failed: 0
|
||||
}
|
||||
);
|
||||
assert_eq!(writes(&seen), ["POST /api/v1/orgs/agents/teams"]);
|
||||
let team = sent(&seen, "POST", "/api/v1/orgs/agents/teams").unwrap();
|
||||
assert_eq!(team["name"], OPERATORS_TEAM);
|
||||
assert_eq!(team["permission"], "write");
|
||||
assert_eq!(team["includes_all_repositories"], true);
|
||||
assert_eq!(team["can_create_org_repo"], false);
|
||||
assert_eq!(team["units"], json!(OPERATORS_TEAM_UNITS));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_duplicate_team_is_not_an_error_but_a_422_without_the_team_is() {
|
||||
let (client, _) = world(vec![
|
||||
("GET /api/v1/orgs/agents/teams", 200, json!([])),
|
||||
(
|
||||
"POST /api/v1/orgs/agents/teams",
|
||||
409,
|
||||
json!({"message": "exists"}),
|
||||
),
|
||||
])
|
||||
.await;
|
||||
client
|
||||
.create_operators_team(AGENTS_ORG)
|
||||
.await
|
||||
.expect("409 is done");
|
||||
|
||||
let invalid = (
|
||||
"POST /api/v1/orgs/agents/teams",
|
||||
422,
|
||||
json!({"message": "validation failed: team already exists"}),
|
||||
);
|
||||
let (client, _) = world(vec![invalid.clone()]).await;
|
||||
client
|
||||
.create_operators_team(AGENTS_ORG)
|
||||
.await
|
||||
.expect("422 with the team present");
|
||||
let (client, _) = world(vec![
|
||||
("GET /api/v1/orgs/agents/teams", 200, json!([])),
|
||||
invalid,
|
||||
])
|
||||
.await;
|
||||
client
|
||||
.create_operators_team(AGENTS_ORG)
|
||||
.await
|
||||
.expect_err("422 and no such team is a real validation error");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_absent_org_is_created_and_a_failed_create_skips_what_needs_it() {
|
||||
let (client, seen) = world(vec![no("GET /api/v1/orgs/actions")]).await;
|
||||
let outcome = client.reconcile(&desired_without_avatar()).await;
|
||||
assert_eq!(
|
||||
outcome,
|
||||
PassOutcome {
|
||||
applied: 2,
|
||||
failed: 0
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
writes(&seen),
|
||||
["POST /api/v1/orgs", "POST /api/v1/repos/migrate"]
|
||||
);
|
||||
assert_eq!(
|
||||
sent(&seen, "POST", "/api/v1/orgs").unwrap()["username"],
|
||||
"actions"
|
||||
);
|
||||
|
||||
// The org create fails, so the mirror is not created into it.
|
||||
let (client, seen) = world(vec![
|
||||
no("GET /api/v1/orgs/actions"),
|
||||
no("GET /api/v1/repos/actions/checkout"),
|
||||
("POST /api/v1/orgs", 500, json!({"message": "boom"})),
|
||||
])
|
||||
.await;
|
||||
let outcome = client.reconcile(&desired_without_avatar()).await;
|
||||
assert_eq!(
|
||||
outcome,
|
||||
PassOutcome {
|
||||
applied: 0,
|
||||
failed: 2
|
||||
}
|
||||
);
|
||||
assert_eq!(writes(&seen), ["POST /api/v1/orgs"]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn create_org_folds_a_race_but_not_a_failure() {
|
||||
let (client, _) = world(vec![("POST /api/v1/orgs", 409, json!({"message": "x"}))]).await;
|
||||
client.create_org("actions").await.expect("409 is a race");
|
||||
let (client, _) = world(vec![("POST /api/v1/orgs", 500, json!({"message": "x"}))]).await;
|
||||
client
|
||||
.create_org("actions")
|
||||
.await
|
||||
.expect_err("500 surfaces");
|
||||
let (client, _) = world(vec![(
|
||||
"POST /api/v1/orgs",
|
||||
422,
|
||||
json!({"message": "validation failed: exists"}),
|
||||
)])
|
||||
.await;
|
||||
client
|
||||
.create_org("actions")
|
||||
.await
|
||||
.expect("422 and the org is there");
|
||||
client
|
||||
.create_org("nope")
|
||||
.await
|
||||
.expect_err("422 and the org is still absent");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_config_repo_without_the_operators_gate_gets_exactly_the_gate() {
|
||||
let path = "/api/v1/repos/agent-configs/atlas/branch_protections/main";
|
||||
let (client, seen) = world(vec![(
|
||||
"GET /api/v1/repos/agent-configs/atlas/branch_protections/main",
|
||||
200,
|
||||
json!({"enable_merge_whitelist": true, "merge_whitelist_usernames": ["mallory"]}),
|
||||
)])
|
||||
.await;
|
||||
let outcome = client.reconcile(&desired_without_avatar()).await;
|
||||
assert_eq!(
|
||||
outcome,
|
||||
PassOutcome {
|
||||
applied: 1,
|
||||
failed: 0
|
||||
}
|
||||
);
|
||||
assert_eq!(writes(&seen), [format!("PATCH {path}")]);
|
||||
assert_eq!(
|
||||
sent(&seen, "PATCH", path).unwrap(),
|
||||
json!({
|
||||
"approvals_whitelist_teams": [OPERATORS_TEAM],
|
||||
"enable_approvals_whitelist": true,
|
||||
"enable_merge_whitelist": true,
|
||||
"merge_whitelist_teams": [OPERATORS_TEAM],
|
||||
"merge_whitelist_usernames": [],
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_repo_with_no_rule_is_left_and_an_archived_repos_drifted_rule_is_not_touched() {
|
||||
let drifted = json!({"enable_merge_whitelist": false});
|
||||
let (client, seen) = world(vec![
|
||||
no("GET /api/v1/repos/agent-configs/atlas/branch_protections/main"),
|
||||
(
|
||||
"GET /api/v1/repos/agent-configs/gone/branch_protections/main",
|
||||
200,
|
||||
drifted.clone(),
|
||||
),
|
||||
])
|
||||
.await;
|
||||
client.reconcile(&desired_without_avatar()).await;
|
||||
assert!(writes(&seen).is_empty(), "{:?}", writes(&seen));
|
||||
|
||||
// Control: the same drift on the live repo is converged.
|
||||
let (client, seen) = world(vec![(
|
||||
"GET /api/v1/repos/agent-configs/atlas/branch_protections/main",
|
||||
200,
|
||||
drifted,
|
||||
)])
|
||||
.await;
|
||||
client.reconcile(&desired_without_avatar()).await;
|
||||
assert_eq!(
|
||||
writes(&seen),
|
||||
["PATCH /api/v1/repos/agent-configs/atlas/branch_protections/main"]
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_unreadable_object_is_a_failure_and_never_a_write() {
|
||||
let (client, seen) = world(vec![(
|
||||
"GET /api/v1/orgs/agent-configs/teams",
|
||||
500,
|
||||
json!({"message": "boom"}),
|
||||
)])
|
||||
.await;
|
||||
let outcome = client.reconcile(&desired_without_avatar()).await;
|
||||
assert_eq!(
|
||||
outcome,
|
||||
PassOutcome {
|
||||
applied: 0,
|
||||
failed: 1
|
||||
}
|
||||
);
|
||||
assert!(writes(&seen).is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_private_knowledge_repo_is_set_public() {
|
||||
let (client, seen) = world(vec![(
|
||||
"GET /api/v1/repos/internal/knowledge",
|
||||
200,
|
||||
json!({"private": true, "empty": false}),
|
||||
)])
|
||||
.await;
|
||||
client.reconcile(&desired_without_avatar()).await;
|
||||
assert_eq!(writes(&seen), ["PATCH /api/v1/repos/internal/knowledge"]);
|
||||
assert_eq!(
|
||||
sent(&seen, "PATCH", "/api/v1/repos/internal/knowledge").unwrap(),
|
||||
json!({"private": false})
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_mirror_with_another_interval_is_patched_to_the_interval_alone() {
|
||||
let (client, seen) = world(vec![(
|
||||
"GET /api/v1/repos/actions/checkout",
|
||||
200,
|
||||
json!({"mirror": true, "mirror_interval": "0s"}),
|
||||
)])
|
||||
.await;
|
||||
client.reconcile(&desired_without_avatar()).await;
|
||||
assert_eq!(
|
||||
sent(&seen, "PATCH", "/api/v1/repos/actions/checkout").unwrap(),
|
||||
json!({"mirror_interval": MIRROR_INTERVAL})
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_absent_repo_is_created_with_its_privacy_and_an_empty_public_one_is_seeded() {
|
||||
let (client, seen) = world(vec![
|
||||
no("GET /api/v1/repos/internal/docs"),
|
||||
no("GET /api/v1/repos/internal/knowledge"),
|
||||
])
|
||||
.await;
|
||||
client.reconcile(&desired_without_avatar()).await;
|
||||
let created: Vec<(String, bool)> = seen
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|(m, p, _)| m == "POST" && p == "/api/v1/orgs/internal/repos")
|
||||
.map(|(_, _, b)| {
|
||||
(
|
||||
b["name"].as_str().unwrap().to_owned(),
|
||||
b["private"].as_bool().unwrap(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(
|
||||
created,
|
||||
[("docs".to_owned(), true), ("knowledge".to_owned(), false)]
|
||||
);
|
||||
|
||||
let (client, seen) = world(vec![(
|
||||
"GET /api/v1/repos/internal/knowledge",
|
||||
200,
|
||||
json!({"private": false, "empty": true}),
|
||||
)])
|
||||
.await;
|
||||
client.reconcile(&desired_without_avatar()).await;
|
||||
let readme = sent(&seen, "POST", "/api/v1/repos/internal/knowledge/contents").unwrap();
|
||||
assert_eq!(readme["files"][0]["path"], "README.md");
|
||||
assert_eq!(readme["files"][0]["operation"], "create");
|
||||
// Control: a repo that already has content is not seeded.
|
||||
let (client, seen) = world(vec![]).await;
|
||||
client.reconcile(&desired_without_avatar()).await;
|
||||
assert!(sent(&seen, "POST", "/api/v1/repos/internal/knowledge/contents").is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_mirror_is_created_public_and_periodic_and_only_a_409_is_a_race() {
|
||||
let (client, seen) = world(vec![]).await;
|
||||
client
|
||||
.create_mirror("actions", "checkout", "https://example.invalid/checkout")
|
||||
.await
|
||||
.unwrap();
|
||||
let body = sent(&seen, "POST", "/api/v1/repos/migrate").unwrap();
|
||||
assert_eq!(body["mirror"], true);
|
||||
assert_eq!(body["private"], false);
|
||||
assert_eq!(body["mirror_interval"], MIRROR_INTERVAL);
|
||||
assert_eq!(body["repo_owner"], "actions");
|
||||
assert_eq!(body["clone_addr"], "https://example.invalid/checkout");
|
||||
|
||||
let (client, _) = world(vec![(
|
||||
"POST /api/v1/repos/migrate",
|
||||
409,
|
||||
json!({"message": "x"}),
|
||||
)])
|
||||
.await;
|
||||
client
|
||||
.create_mirror("actions", "checkout", "u")
|
||||
.await
|
||||
.expect("409 is a race");
|
||||
let (client, _) = world(vec![(
|
||||
"POST /api/v1/repos/migrate",
|
||||
422,
|
||||
json!({"message": "x"}),
|
||||
)])
|
||||
.await;
|
||||
client
|
||||
.create_mirror("actions", "checkout", "u")
|
||||
.await
|
||||
.expect_err("a 422 is a bad clone address, not a duplicate");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn the_avatar_is_uploaded_once_and_marked() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let png = dir.path().join("a.png");
|
||||
std::fs::write(&png, b"fixed bytes").unwrap();
|
||||
let desired = Desired::new(vec![], Some(png), dir.path().to_owned());
|
||||
let (client, seen) = world(vec![(
|
||||
"POST /api/v1/orgs/agent-configs/avatar",
|
||||
204,
|
||||
json!({}),
|
||||
)])
|
||||
.await;
|
||||
client.reconcile(&desired).await;
|
||||
assert!(sent(&seen, "POST", "/api/v1/orgs/agent-configs/avatar").is_some());
|
||||
assert!(desired.avatar_marker().exists());
|
||||
let (client, seen) = world(vec![]).await;
|
||||
client.reconcile(&desired).await;
|
||||
assert!(writes(&seen).is_empty(), "the marker stops a second upload");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn the_merge_gate_prerequisites_fail_while_the_team_cannot_be_created() {
|
||||
let (client, _) = world(vec![]).await;
|
||||
client
|
||||
.ensure_merge_gate_prerequisites()
|
||||
.await
|
||||
.expect("converged");
|
||||
let (client, seen) = world(vec![
|
||||
("GET /api/v1/orgs/agent-configs/teams", 200, json!([])),
|
||||
(
|
||||
"POST /api/v1/orgs/agent-configs/teams",
|
||||
500,
|
||||
json!({"message": "x"}),
|
||||
),
|
||||
])
|
||||
.await;
|
||||
let err = client
|
||||
.ensure_merge_gate_prerequisites()
|
||||
.await
|
||||
.expect_err("no team");
|
||||
assert!(format!("{err:#}").contains("could not be ensured"));
|
||||
assert_eq!(writes(&seen), ["POST /api/v1/orgs/agent-configs/teams"]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue