Files
ngit-grasp/tests/purgatory.rs
T
DanConwayDev 0c71e19196 fix: rewrite deletion integration tests to avoid shared-state side effects
The previous tests deleted purgatory announcements (kind 30617) and checked
for bare-repo absence via git ls-remote, which would corrupt shared-mode
test state by destroying repos other tests depend on.

New approach tests deletion of purgatory state events (kind 30618) instead:

- e-tag test: promotes a repo, creates a unique commit locally, submits a
  state event pointing to it (enters purgatory), deletes the state event by
  event ID, then verifies git push of that commit is rejected.

- a-tag coordinate test: promotes a repo, generates a fresh maintainer
  keypair, sends a replacement announcement adding that maintainer, submits
  a state event signed by the new maintainer (enters purgatory), deletes by
  coordinate 30618:<new_maintainer_pubkey>:<identifier>, then verifies git
  push is rejected.

Also extends DeletionPolicy to handle kind 30618 state events in purgatory
for both e-tag (event ID) and a-tag (coordinate) deletion paths.
2026-02-23 13:42:57 +00:00

90 lines
3.2 KiB
Rust

//! Purgatory Integration Tests
//!
//! Tests ngit-grasp relay's implementation of GRASP-01 purgatory behavior.
//! Uses grasp-audit library to avoid code duplication.
//!
//! # Test Strategy
//!
//! - Each test runs in complete isolation with its own fresh relay instance
//! - Uses macro to eliminate boilerplate while maintaining test isolation
//! - Calls individual test methods from grasp-audit for minimal duplication
//! - Automatic cleanup via TestRelay fixture (removes container and temp dirs)
//!
//! # Running Tests
//!
//! ```bash
//! # Run all purgatory tests
//! cargo test --test purgatory
//!
//! # Run specific test
//! cargo test --test purgatory test_state_event_not_served_before_git_data
//!
//! # With output
//! cargo test --test purgatory -- --nocapture
//! ```
mod common;
use common::TestRelay;
use grasp_audit::specs::grasp01::PurgatoryTests;
use grasp_audit::{AuditClient, AuditConfig};
/// Macro to generate isolated integration tests for purgatory
///
/// Each test runs with its own fresh relay instance to ensure complete isolation.
/// This eliminates issues with leftover repositories and ensures clean state.
macro_rules! isolated_purgatory_test {
($test_name:ident) => {
#[tokio::test]
async fn $test_name() {
let relay = TestRelay::start().await;
let config = AuditConfig::isolated();
let client = AuditClient::new(relay.url(), config)
.await
.expect("Failed to create audit client");
let result = PurgatoryTests::$test_name(&client).await;
relay.stop().await;
assert!(
result.passed,
"{} failed: {}",
stringify!($test_name),
result.error.as_deref().unwrap_or("unknown error")
);
}
};
}
// ============================================================
// Announcement Purgatory Tests
// ============================================================
isolated_purgatory_test!(test_announcement_not_served_before_git_data);
isolated_purgatory_test!(test_announcement_served_after_git_push);
isolated_purgatory_test!(test_bare_repo_exists_for_purgatory_announcement);
isolated_purgatory_test!(test_state_event_accepted_for_purgatory_announcement);
// ============================================================
// Deletion Event Tests (NIP-09)
// ============================================================
isolated_purgatory_test!(test_deletion_by_event_id_removes_purgatory_state_event);
isolated_purgatory_test!(test_deletion_by_coordinate_removes_purgatory_state_event);
// ============================================================
// State Event Purgatory Tests (already implemented)
// ============================================================
isolated_purgatory_test!(test_state_event_not_served_before_git_data);
isolated_purgatory_test!(test_state_event_served_after_git_push);
// ============================================================
// PR Purgatory Tests
// ============================================================
isolated_purgatory_test!(test_pr_event_accepted_into_purgatory_and_isnt_served);
isolated_purgatory_test!(test_pr_event_in_purgatory_git_push_accepted);
isolated_purgatory_test!(test_pr_event_served_after_git_push);