diff options
Diffstat (limited to 'tests/pipeline.rs')
| -rw-r--r-- | tests/pipeline.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/pipeline.rs b/tests/pipeline.rs index 0da1612..59a1b35 100644 --- a/tests/pipeline.rs +++ b/tests/pipeline.rs @@ -442,3 +442,53 @@ fn a_stale_accepted_pointer_refuses_to_publish() { } assert!(in_index(&env).is_empty()); } + +// ------------------------------------------------------- withdrawal and cleanup -- + +#[test] +fn withdrawing_a_release_twice_is_refused_the_second_time() { + // m-10: the second withdraw used to report success while rewriting nothing, + // so an operator who clicked twice got a green result and no explanation. + let (env, _fx) = env_with_fixture("plain-make"); + let c = approve_fixture(&env, "plain-make"); + run_for(&env, &c); + let rid = db::accepted_release(&env.db, "plain-make").unwrap().unwrap().id; + approve::withdraw(&env.db, "tester", rid, "upstream pulled the tarball").unwrap(); + let err = approve::withdraw(&env.db, "tester", rid, "again").unwrap_err(); + assert!(err.to_string().contains("not published"), "{err}"); + let err = approve::withdraw(&env.db, "tester", rid + 999, "x").unwrap_err(); + assert!(err.to_string().contains("no release"), "{err}"); + // The first withdrawal stands: the index no longer serves it. + assert!(in_index(&env).is_empty(), "the withdrawn release is still in the index"); +} + +#[test] +fn a_publish_that_does_not_land_leaves_no_orphan_files_in_the_served_tree() { + // m-16: the artifacts are copied into the served tree before the DB commit, + // and when the commit refused, those bytes used to stay — files no index + // names, sitting in the directory consumers download from. + let (mut env, _fx) = env_with_fixture("plain-make"); + let c = approve_fixture(&env, "plain-make"); + env.set_publish_fault("before-rename"); + let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap(); + assert!(matches!( + pipeline::run(&env.cfg, &env.db, &id).unwrap(), + pipeline::Outcome::Failed { .. } + )); + let stray: Vec<String> = std::fs::read_dir(env.cfg.repo_arch_dir()) + .expect("arch dir") + .filter_map(|e| e.ok()) + .map(|e| e.file_name().to_string_lossy().to_string()) + .filter(|n| n.ends_with(".pkg.tar.zst") || n.ends_with(".sig")) + .collect(); + assert!(stray.is_empty(), "a publish that did not land left files behind: {stray:?}"); + + // And the retry still works: the artifacts come from the collect dir, not + // from the served tree, so cleaning up costs nothing but the copy. + env.clear_publish_fault(); + assert!( + matches!(pipeline::run(&env.cfg, &env.db, &id).unwrap(), pipeline::Outcome::Succeeded { .. }), + "the retry after cleanup failed" + ); + assert_eq!(in_index(&env), vec![("plain-make".into(), "1.0-1".into())]); +} |
