swarm-controller: split main.rs into jobq, routes and startup modules
no behaviour change: a pure move of items and tests into new modules, plus visibility edits (pub(crate)) and path updates in sibling modules that named crate-root items. same routes, same OpenAPI, 561 tests before and after. why: #5470, new features stop landing in one 6.4k-line file by default. files outside swarm-controller/src: docs/agent-lifecycle/agent-roster.md, swarm-ui JobsPage.tsx and AgentsPage.tsx, nix/host-modules/swarm-controller.nix and swarm-grafana.nix hold comments that named main.rs for items that moved.
This commit is contained in:
parent
f0a6d6c042
commit
738dd1c95b
4 changed files with 6854 additions and 6680 deletions
|
|
@ -32,7 +32,7 @@ use utoipa::ToSchema;
|
|||
use super::{FileSource, RULES_PATHS, check_classifications, operator, parse_rules, split_repo};
|
||||
use crate::forge::classifier_account::{BranchCommit, CommitAuthor, LOGIN};
|
||||
use crate::forge::{self, BranchFile};
|
||||
use crate::{AppState, error_problem};
|
||||
use crate::routes::{AppState, error_problem};
|
||||
|
||||
/// Where a branch's name starts, so the forge's branch list groups them.
|
||||
const BRANCH_PREFIX: &str = "review-classifier/";
|
||||
|
|
@ -676,9 +676,9 @@ classifications:
|
|||
}
|
||||
|
||||
fn app(fake: Fake) -> axum::Router {
|
||||
let (mut state, _) = crate::tests::state_with_roster();
|
||||
let (mut state, _) = crate::routes::tests::state_with_roster();
|
||||
state.try_outs.fake = Some(Arc::new(fake));
|
||||
crate::build_app(state)
|
||||
crate::startup::build_app(state)
|
||||
}
|
||||
|
||||
fn fake() -> Fake {
|
||||
|
|
|
|||
|
|
@ -33,10 +33,10 @@ use tokio::task::JoinHandle;
|
|||
use super::runs::{self, RunOutcome, RunRecord, Runs, Trigger};
|
||||
use super::settings::{Settings, SettingsSource};
|
||||
use super::{FileSource, PullSource, RunSink, split_repo};
|
||||
use crate::AppState;
|
||||
use crate::agent_renewal::unix_now;
|
||||
use crate::forge::pull_diff::CONTEXT_LINES;
|
||||
use crate::forge::{self, classifier_account::LOGIN, classifier_account::Review};
|
||||
use crate::routes::AppState;
|
||||
|
||||
/// The most review runs waiting for a slot.
|
||||
const MAX_WAITING_REVIEWS: usize = 8;
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ use serde::{Deserialize, Serialize};
|
|||
use swarm_queue_client::review_classifier::{Overall, Reply, Row};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
use crate::routes::{AppState, error_problem};
|
||||
use crate::schedules::{read_with, write};
|
||||
use crate::{AppState, error_problem};
|
||||
|
||||
/// The bucket holding the runs. Agents hold no grant on it.
|
||||
pub const BUCKET: &str = "review-classifier-runs";
|
||||
|
|
@ -593,9 +593,9 @@ pub(crate) mod tests {
|
|||
push(&*doc, &reviewed).await.expect("stored");
|
||||
|
||||
let get = |runs: Runs| async move {
|
||||
let (mut state, _) = crate::tests::state_with_roster();
|
||||
let (mut state, _) = crate::routes::tests::state_with_roster();
|
||||
state.runs = runs;
|
||||
let res = crate::build_app(state)
|
||||
let res = crate::startup::build_app(state)
|
||||
.oneshot(
|
||||
Request::get("/api/review-classifier/runs")
|
||||
.body(Body::empty())
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ use swarm_queue_client::agent_inference::Effort;
|
|||
use swarm_queue_client::review_classifier::{Acp, Runtime};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
use crate::routes::{AppState, error_problem, wanted_error_status};
|
||||
use crate::schedules::{queue, read_with, refused, write};
|
||||
use crate::{AppState, error_problem, wanted_error_status};
|
||||
|
||||
/// The bucket holding the settings. No other service holds a grant on it.
|
||||
pub const BUCKET: &str = "review-classifier-settings";
|
||||
|
|
@ -598,12 +598,12 @@ mod tests {
|
|||
|
||||
/// An app whose queue is `nats`.
|
||||
async fn app(nats: &TestNats) -> (axum::Router, AppState) {
|
||||
let (mut state, _) = crate::tests::state_with_roster();
|
||||
let (mut state, _) = crate::routes::tests::state_with_roster();
|
||||
state.status = Some(std::sync::Arc::new(crate::status::StatusReader::new(
|
||||
nats.client().await,
|
||||
std::time::Duration::from_mins(1),
|
||||
)));
|
||||
(crate::build_app(state.clone()), state)
|
||||
(crate::startup::build_app(state.clone()), state)
|
||||
}
|
||||
|
||||
async fn send(
|
||||
|
|
@ -777,21 +777,21 @@ mod tests {
|
|||
|
||||
#[tokio::test]
|
||||
async fn a_put_without_an_operator_is_401() {
|
||||
let (state, _) = crate::tests::state_with_roster();
|
||||
let (state, _) = crate::routes::tests::state_with_roster();
|
||||
let req = Request::put("/api/review-classifier/settings")
|
||||
.header("content-type", "application/json")
|
||||
.body(Body::from(
|
||||
serde_json::to_string(&Settings::default()).unwrap(),
|
||||
))
|
||||
.expect("a request");
|
||||
let (status, _, _) = send(&crate::build_app(state), req).await;
|
||||
let (status, _, _) = send(&crate::startup::build_app(state), req).await;
|
||||
assert_eq!(status, StatusCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn without_a_queue_both_verbs_are_503() {
|
||||
let (state, _) = crate::tests::state_with_roster();
|
||||
let app = crate::build_app(state);
|
||||
let (state, _) = crate::routes::tests::state_with_roster();
|
||||
let app = crate::startup::build_app(state);
|
||||
let (status, _, _) = send(&app, get()).await;
|
||||
assert_eq!(status, StatusCode::SERVICE_UNAVAILABLE);
|
||||
let body = serde_json::to_string(&Settings::default()).unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue