From 4c143e969dcd7b6a18e5a86f9a754c9b62979ccf Mon Sep 17 00:00:00 2001 From: aur-build Date: Mon, 23 Nov 2026 13:44:20 +0000 Subject: usecase,http,pipeline,ops: keep the contract, drop the argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A workflow's doc now says what it guarantees and stops defending its existence: `subscribe` resolves the repo row, `approve` queues what the approval buys, a per-item failure comes back as a value instead of a panic. The history of which front end used to open-code it is gone. The last census-war notes go with it — three places that explained why a name in a test string was not a caller. --- src/http/mod.rs | 3 +-- src/http/render.rs | 12 ++++-------- src/ops.rs | 5 ----- src/pipeline/dispatch.rs | 15 +++++---------- src/usecase/bootstrap.rs | 19 ++++++------------- src/usecase/builds.rs | 6 +----- src/usecase/detect.rs | 8 ++------ src/usecase/mod.rs | 21 +++------------------ src/usecase/reviews.rs | 29 +++++++++-------------------- src/usecase/subscriptions.rs | 6 +----- 10 files changed, 32 insertions(+), 92 deletions(-) (limited to 'src') diff --git a/src/http/mod.rs b/src/http/mod.rs index 715b448..e3a2181 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -24,7 +24,6 @@ struct Req { } impl Req { - /// Read by the route handlers, which are in this module; the word `form` in a test is a local parameter. fn form(&self) -> &[(String, String)] { &self.form_pairs } @@ -114,7 +113,7 @@ mod server { } } -/// the handle to a running HTTP listener. `spawn` returns it and `main` holds it without naming the type; the test harness stores it in a field because it needs the bound address. +/// The handle to a running HTTP listener. #[cfg(feature = "test-support")] pub use server::Server; diff --git a/src/http/render.rs b/src/http/render.rs index bc2ad3d..95e6de1 100644 --- a/src/http/render.rs +++ b/src/http/render.rs @@ -23,7 +23,7 @@ mod page { } } -/// The render model's shared header. Every template and route handler that fills it lives inside `http`; the outside readers are the page tests. +/// The render model's shared header. #[cfg(feature = "test-support")] pub use page::Page; @@ -31,8 +31,6 @@ pub use page::Page; pub(crate) use page::Page; impl Page { - /// Built by the route handlers, which are in this module; nothing outside - /// `http` constructs a page header. pub(crate) fn new(title: &str, csrf: String) -> Self { Self { title: title.into(), @@ -161,7 +159,7 @@ mod panel { } } -/// A diff panel in the render model. The tests that assert on its body drive a real review and cannot move into the module. +/// A diff panel in the render model. #[cfg(feature = "test-support")] pub use panel::Panel; @@ -169,7 +167,6 @@ pub use panel::Panel; pub(crate) use panel::Panel; impl Panel { - /// Built by the route handlers, which are in this module. pub(crate) fn new(title: &str, body: String) -> Self { Self { title: title.into(), empty: body.trim().is_empty(), empty_note: "no change".into(), body } } @@ -313,9 +310,8 @@ pub(crate) struct BuildLite { } #[derive(Debug, Clone)] -/// A row of the builds table as the templates render it. Filled and read -/// entirely inside `http`; the `BuildRow` other modules name is `db::builds::BuildRow`, -/// a different type that happens to share the name. +/// A row of the builds table as the templates render it — not the same type as +/// the `db::builds::BuildRow` other modules name. pub(crate) struct BuildRow { pub id: String, pub id_short: String, diff --git a/src/ops.rs b/src/ops.rs index ef680e9..87fa28b 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -320,11 +320,6 @@ pub fn retention(cfg: &Config, db: &Db, keep: Option) -> Result, #[cfg_attr(not(feature = "test-support"), allow(dead_code))] @@ -50,11 +48,8 @@ impl Pool { Pool { stop, handles } } - /// Stop the dispatcher threads and join them. - /// - /// Production runs the pool until the process exits; nothing asks it to - /// stop. A test needs the join, because it asserts on the pool's effects - /// and cannot do that while the threads are still running. + /// Stop the dispatcher threads and join them, so a test can assert on the + /// pool's effects. #[cfg(feature = "test-support")] pub fn shutdown(self) { self.stop.store(true, Ordering::SeqCst); @@ -110,7 +105,7 @@ fn dispatch_once_impl(cfg: &Config, db: &Db, tx: &Sender) -> Vec ids } -/// Production reaches this through `dispatch_once`, which is the only thing that acts on the answer. +/// Reached only through `dispatch_once`. #[cfg(feature = "test-support")] pub fn admissible(cfg: &Config, db: &Db) -> usize { admissible_impl(cfg, db) @@ -134,7 +129,7 @@ fn admissible_impl(cfg: &Config, db: &Db) -> usize { slots } -/// Production reaches this through `admissible`, which is the only thing that acts on the number. +/// Reached only through `admissible`. #[cfg(feature = "test-support")] pub fn free_disk_mb(path: &std::path::Path) -> u64 { free_disk_mb_impl(path) diff --git a/src/usecase/bootstrap.rs b/src/usecase/bootstrap.rs index 6793076..a4e64d2 100644 --- a/src/usecase/bootstrap.rs +++ b/src/usecase/bootstrap.rs @@ -1,5 +1,4 @@ -//! Bringing a repository up, which every command does and every front end -//! used to write out for itself. +//! Bringing a repository up, which every command does. use std::sync::atomic::AtomicBool; use std::sync::Arc; @@ -10,17 +9,13 @@ use crate::error::Result; use crate::pipeline; /// Directories exist, the schema is current, and the repo row is present. -/// -/// Four calls in an order that matters — migrate before open, `ensure_repo` -/// before anything reads `repo_id` — which is precisely the kind of sequence -/// that quietly rots when it is copied. +/// Order matters: migrate before open, `ensure_repo` before anything reads +/// `repo_id`. pub fn open(cfg: &Config) -> Result { open_and_ensure(cfg).map(|(db, _)| db) } -/// `open`, plus the id of the row named by `cfg.repo_name` — which is what -/// `init` prints, and is not necessarily the lowest repo id if a root ever -/// holds more than one repo. +/// `open`, plus the id of the row named by `cfg.repo_name`. fn open_and_ensure(cfg: &Config) -> Result<(Db, i64)> { cfg.ensure_dirs()?; db::migrate(&cfg.db_path())?; @@ -44,10 +39,8 @@ pub fn init(cfg: &Config) -> Result { /// Everything `serve` does before control passes to the UI: bring the /// repository up, finish anything a previous run left half-published, and start -/// the two background loops. -/// -/// The HTTP server is deliberately not started here. This module sits below the -/// UI and must not be able to name it. +/// the two background loops. This module sits below the UI, so it cannot start +/// the HTTP server. pub fn serve(cfg: &Config) -> Result { let db = open(cfg)?; let _ = pipeline::publish::reconcile(cfg, &db); diff --git a/src/usecase/builds.rs b/src/usecase/builds.rs index 265e6cb..152959f 100644 --- a/src/usecase/builds.rs +++ b/src/usecase/builds.rs @@ -22,11 +22,7 @@ pub fn cancel(db: &Db, build_id: &str) -> Result<()> { builds::request_cancel(db, build_id) } -/// Retry a failed build, and record that someone asked. -/// -/// The audit row is part of the workflow rather than the caller's homework: a -/// retry changes what a build means, and a retry nobody asked for is exactly -/// what the audit trail is there to rule out. +/// Retry a failed build, and audit that someone asked. pub fn retry(db: &Db, actor: &str, build_id: &str) -> Result<()> { builds::retry(db, build_id)?; db::audit(&db.writer, actor, actor, "build.retry", "build", build_id, serde_json::json!({})) diff --git a/src/usecase/detect.rs b/src/usecase/detect.rs index 67cc83c..42f98d9 100644 --- a/src/usecase/detect.rs +++ b/src/usecase/detect.rs @@ -5,12 +5,8 @@ use crate::db::{self, Db, SubscriptionState}; use crate::error::Result; use crate::watch::detect::{self, Outcome}; -/// One pkgbase's detection result. -/// -/// Per-item failures are returned rather than raised: a sweep over every -/// subscription should not stop at the first pkgbase whose mirror is -/// unreachable, and the caller decides whether a failure is a line on stderr -/// or a row in a table. +/// One pkgbase's detection result. Per-item failures are returned, not raised, +/// so a sweep does not stop at the first unreachable mirror. pub struct Checked { pub pkgbase: String, pub outcome: Result, diff --git a/src/usecase/mod.rs b/src/usecase/mod.rs index 288d71d..25f745c 100644 --- a/src/usecase/mod.rs +++ b/src/usecase/mod.rs @@ -1,21 +1,6 @@ -//! The workflows themselves — the thing between a front end and the modules. -//! -//! Before this module existed, a workflow had one implementation per front end. -//! `main` opened the repository inline before its command match; `serve` opened -//! it again; the web routes wrote subscriptions and retried builds with their -//! own `db::` calls, so the CLI and the UI could drift and nothing would notice -//! until a reviewer saw one behaviour in the browser and another in the -//! terminal. -//! -//! A function here is a workflow only if more than one step has to happen in a -//! particular order. `subscribe` is a workflow because the repo row has to be -//! resolved first and a first detection may have to follow. `candidate_by_id` -//! is not, and stays where it is. -//! -//! Nothing in here formats output or knows a terminal, a form or a status code -//! exists. Results carry enough structure for each front end to say the same -//! facts in its own voice — which is why `Approved` reports the queueing -//! outcome rather than deciding whether a failed enqueue is fatal. +//! The workflows between a front end and the modules: a function belongs here +//! only when more than one step has to happen in a particular order. Nothing in +//! here formats output or knows a terminal, a form or a status code exists. mod bootstrap; mod builds; diff --git a/src/usecase/reviews.rs b/src/usecase/reviews.rs index 8cbb534..31aa859 100644 --- a/src/usecase/reviews.rs +++ b/src/usecase/reviews.rs @@ -14,11 +14,8 @@ pub struct Prepared { } /// Render the current diff and store its digest, so the approval that follows -/// can be checked against exactly what was shown rather than whatever the tree -/// looked like a moment later. -/// -/// `Ok(None)` means there is no such candidate; each front end says so in its -/// own words. +/// is checked against what was actually shown. `Ok(None)` means no such +/// candidate. pub fn prepare_review(cfg: &Config, db: &Db, candidate_id: i64) -> Result> { let Some(c) = candidates::candidate_by_id(db, candidate_id)? else { return Ok(None); @@ -28,10 +25,8 @@ pub fn prepare_review(cfg: &Config, db: &Db, candidate_id: i64) -> Result