diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/http/mod.rs | 3 | ||||
| -rw-r--r-- | src/http/render.rs | 12 | ||||
| -rw-r--r-- | src/ops.rs | 5 | ||||
| -rw-r--r-- | src/pipeline/dispatch.rs | 15 | ||||
| -rw-r--r-- | src/usecase/bootstrap.rs | 19 | ||||
| -rw-r--r-- | src/usecase/builds.rs | 6 | ||||
| -rw-r--r-- | src/usecase/detect.rs | 8 | ||||
| -rw-r--r-- | src/usecase/mod.rs | 21 | ||||
| -rw-r--r-- | src/usecase/reviews.rs | 29 | ||||
| -rw-r--r-- | src/usecase/subscriptions.rs | 6 |
10 files changed, 32 insertions, 92 deletions
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, @@ -320,11 +320,6 @@ pub fn retention(cfg: &Config, db: &Db, keep: Option<usize>) -> Result<Retention } /// How long a file may sit in staging before the sweep considers it abandoned. -/// -/// The value lives once, in a private const, so the two visibility aliases below -/// cannot drift apart. Production reaches the grace period through -/// `run_maintenance`, which is the only thing that sweeps; a test that pins the -/// number is a test, not a caller. const STAGING_GRACE_SECS_VALUE: i64 = 3600; #[cfg(feature = "test-support")] diff --git a/src/pipeline/dispatch.rs b/src/pipeline/dispatch.rs index ad2d627..13590ae 100644 --- a/src/pipeline/dispatch.rs +++ b/src/pipeline/dispatch.rs @@ -9,9 +9,7 @@ use crate::db::{self, builds, Db}; use crate::pipeline::{self, Outcome}; pub struct Pool { - // Read only by `shutdown`, which is compiled for the test tier: a release - // build starts the dispatcher and runs it until the process exits, so in - // that build these two fields are stored and never read. + // Read only by `shutdown`; a release build runs the pool until exit. #[cfg_attr(not(feature = "test-support"), allow(dead_code))] stop: Arc<AtomicBool>, #[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<String>) -> Vec<String> 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<Db> { 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<i64> { /// 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<Db> { 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<Outcome>, 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<Option<Prepared>> { 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<Option Ok(Some(Prepared { candidate: c, text, digest })) } -/// `prepare_review`, plus recording that a human actually looked at it. -/// -/// The review queue uses "viewed" to stop surfacing candidates nobody is -/// reading, so looking and approving are separate facts. +/// `prepare_review`, plus recording that a human looked at it — looking and +/// approving are separate facts. pub fn view_review(cfg: &Config, db: &Db, candidate_id: i64) -> Result<Option<Prepared>> { let Some(p) = prepare_review(cfg, db, candidate_id)? else { return Ok(None); @@ -43,10 +38,7 @@ pub fn view_review(cfg: &Config, db: &Db, candidate_id: i64) -> Result<Option<Pr /// An approval that was recorded, and whether a build came out of it. pub struct Approved { pub approval: ap::Approval, - /// Queuing is fatal in the CLI — an approved candidate with no build is a - /// silent stall — and a soft failure in the UI, which has already committed - /// the decision and can retry from the package page. So the workflow - /// reports it rather than choosing for both. + /// Fatal in the CLI, soft in the UI: reported, not decided for both. pub queued: Result<String>, } @@ -56,11 +48,8 @@ pub enum Approval { Refused(ap::Stale), } -/// Record an approval and queue the build it authorises. -/// -/// These are one workflow because an approval that never queues is the bug the -/// whole review queue exists to prevent, and both front ends had to remember to -/// pair them. +/// Record an approval and queue the build it authorises; one workflow, so an +/// approval can never fail to queue. pub fn approve( cfg: &Config, db: &Db, @@ -92,8 +81,8 @@ pub enum Decision { } /// Apply one decision to many candidates, queueing a build for each that -/// passed. Items that were refused — high risk without a confirmation, say — -/// come back with the reason rather than aborting the batch. +/// passed. A refused item comes back with its reason rather than aborting the +/// batch. pub fn bulk( cfg: &Config, db: &Db, diff --git a/src/usecase/subscriptions.rs b/src/usecase/subscriptions.rs index c504cfe..a37e650 100644 --- a/src/usecase/subscriptions.rs +++ b/src/usecase/subscriptions.rs @@ -9,11 +9,7 @@ pub struct Subscribe { pub url: String, } -/// Start watching a pkgbase. -/// -/// The repo row has to be resolved first, which is the step every front end -/// previously open-coded — and the web layer got it wrong, falling back to repo -/// id 1 rather than saying the repository was not initialised. +/// Start watching a pkgbase, resolving the repo row first. pub fn subscribe(db: &Db, pkgbase: &str, url: Option<String>) -> Result<Subscribe> { let rid = db::repo_id(db)?; let url = url.unwrap_or_else(|| format!("https://aur.archlinux.org/{pkgbase}.git")); |
