From e04152da00f97c5ecc9a3f6dc5217d61274c7907 Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 15:59:10 +0000 Subject: pipeline: one lock guards the served index, and it says so once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `publish.rs` had two static mutexes, each documented as *the* "one publish per repo" guarantee — `PUBLISH_LOCK` taken at the top of `publish()`, `REPO_LOCK` taken partway through and by `withdraw_package`. Either the second was redundant or the guarantee was incomplete, and a reader could not tell which, which is worse than either answer: the comment on `REPO_LOCK` claimed a single-writer property that its own position in the function did not provide (artifacts were already staged by then), and the comment on `PUBLISH_LOCK` claimed it for a section that did not include the rename. There is one lock now. `REPO_LOCK` is taken at the top of `publish()` and held for the whole of it — staging, render, DB commit, rename, sign — which is the sequence that must not interleave, and `withdraw_package` takes the same lock for the same reason. The poison-recovery rule that belonged to both is stated once, on the lock. `reconcile` is documented as the one rewriter that does not take it, because it runs at startup before the dispatcher exists. M-5 is a clarity defect rather than a live misbehaviour, so the guard is structural: `tests/production_surface.rs` fails if `publish.rs` declares a second serialization mutex, if `PUBLISH_LOCK` comes back, or if either index writer stops taking the one that remains. A timing-based test would have been the flaky kind and would not have proven anything the I4 and I8 crash tests do not already prove. --- tests/production_surface.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/production_surface.rs') diff --git a/tests/production_surface.rs b/tests/production_surface.rs index 1fa855f..5ade95b 100644 --- a/tests/production_surface.rs +++ b/tests/production_surface.rs @@ -57,6 +57,31 @@ fn no_production_module_references_the_shim_harness() { ); } +#[test] +fn the_served_index_has_exactly_one_serialization_lock() { + // §6 M-5: two mutexes in `publish.rs`, each documented as *the* "one publish + // per repo" guarantee, with `withdraw_package` taking only one of them, is + // worse than either answer — a reader cannot tell whether the guarantee is + // redundant or incomplete. There is one lock now, and this keeps it that way. + let src = std::fs::read_to_string(Path::new(env!("CARGO_MANIFEST_DIR")).join("src/pipeline/publish.rs")) + .expect("read publish.rs"); + let mutexes = src + .lines() + .filter(|l| l.contains("static") && l.contains("Mutex<")) + .collect::>(); + assert_eq!(mutexes.len(), 1, "publish.rs must declare exactly one serialization mutex, found {mutexes:?}"); + assert!(!src.contains("PUBLISH_LOCK"), "the second lock must stay deleted"); + // And both writers of the served index take it, not just one of them. + let acquisitions = src + .lines() + .filter(|l| l.contains("lock_repo()") && !l.trim_start().starts_with("fn ")) + .count(); + assert!( + acquisitions >= 2, + "publish and withdraw_package must both take the repo lock; found {acquisitions} acquisitions" + ); +} + #[test] fn the_shim_binaries_are_test_only() { let manifest = std::fs::read_to_string(Path::new(env!("CARGO_MANIFEST_DIR")).join("Cargo.toml")) -- cgit v1.2.3