upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/grasp-audit/src/fixtures.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-01 22:25:39 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-01 22:25:39 +0000
commit504eaf4f5aba93a3e935bbee76042dd35cada666 (patch)
treee079d5002c08d655a3c686f1458b8d1e60c4e0b3 /grasp-audit/src/fixtures.rs
parent11870a0f810accf0431d82a74b6fd3adec9d23df (diff)
better fixtures: test_head_set_after_state_event_with_existing_commit
Diffstat (limited to 'grasp-audit/src/fixtures.rs')
-rw-r--r--grasp-audit/src/fixtures.rs89
1 files changed, 89 insertions, 0 deletions
diff --git a/grasp-audit/src/fixtures.rs b/grasp-audit/src/fixtures.rs
index d054e36..bda7a78 100644
--- a/grasp-audit/src/fixtures.rs
+++ b/grasp-audit/src/fixtures.rs
@@ -200,6 +200,26 @@ pub enum FixtureKind {
200 /// - NOT sent to relay (use `client.send_event()` to publish when ready) 200 /// - NOT sent to relay (use `client.send_event()` to publish when ready)
201 PREventGenerated, 201 PREventGenerated,
202 202
203 /// HEAD set to 'develop' branch via state event
204 ///
205 /// This fixture tests that HEAD is updated when a state event is published
206 /// with HEAD pointing to a different branch that already has git data pushed.
207 ///
208 /// GRASP-01: "MUST set repository HEAD per repository state announcement
209 /// as soon as the git data related to that branch has been received."
210 ///
211 /// Stages:
212 /// 1. **Depends on**: RecursiveMaintainerStateDataPushed (all git data exists on main)
213 /// 2. **Creates**: New state event with HEAD=refs/heads/develop pointing to existing commit
214 /// 3. **Sends**: State event to relay
215 /// 4. **Verifies**: Can be checked via get_default_branch_from_info_refs
216 ///
217 /// - Requires RecursiveMaintainerStateDataPushed (establishes full maintainer chain with git data)
218 /// - Creates state event signed by maintainer keys (`client.maintainer_keys()`)
219 /// - Points refs/heads/develop to RECURSIVE_MAINTAINER_DETERMINISTIC_COMMIT_HASH
220 /// - Sets HEAD to refs/heads/develop
221 HeadSetToDevelopBranch,
222
203 /// Wrong commit pushed to refs/nostr/<pr-event-id> BEFORE PR event is sent 223 /// Wrong commit pushed to refs/nostr/<pr-event-id> BEFORE PR event is sent
204 /// 224 ///
205 /// This is a "DataPushed" stage fixture for testing pre-event ref behavior. 225 /// This is a "DataPushed" stage fixture for testing pre-event ref behavior.
@@ -327,6 +347,10 @@ impl FixtureKind {
327 // RecursiveMaintainerStateDataPushed depends on MaintainerStateDataPushed 347 // RecursiveMaintainerStateDataPushed depends on MaintainerStateDataPushed
328 // (recursive maintainer force-pushes over maintainer's data) 348 // (recursive maintainer force-pushes over maintainer's data)
329 Self::RecursiveMaintainerStateDataPushed => vec![Self::MaintainerStateDataPushed], 349 Self::RecursiveMaintainerStateDataPushed => vec![Self::MaintainerStateDataPushed],
350
351 // HeadSetToDevelopBranch depends on RecursiveMaintainerStateDataPushed
352 // (all git data already exists, we just publish a new state event)
353 Self::HeadSetToDevelopBranch => vec![Self::RecursiveMaintainerStateDataPushed],
330 } 354 }
331 } 355 }
332 356
@@ -349,6 +373,8 @@ impl FixtureKind {
349 Self::PRWrongCommitPushedBeforeEvent => true, 373 Self::PRWrongCommitPushedBeforeEvent => true,
350 // PREventSentAfterWrongPush sends the PR event internally 374 // PREventSentAfterWrongPush sends the PR event internally
351 Self::PREventSentAfterWrongPush => true, 375 Self::PREventSentAfterWrongPush => true,
376 // HeadSetToDevelopBranch sends its state event internally
377 Self::HeadSetToDevelopBranch => true,
352 // All other fixtures return a single event for the caller to send 378 // All other fixtures return a single event for the caller to send
353 _ => false, 379 _ => false,
354 } 380 }
@@ -868,6 +894,10 @@ impl<'a> TestContext<'a> {
868 FixtureKind::RecursiveMaintainerStateDataPushed => { 894 FixtureKind::RecursiveMaintainerStateDataPushed => {
869 self.build_recursive_maintainer_state_data_pushed().await 895 self.build_recursive_maintainer_state_data_pushed().await
870 } 896 }
897
898 FixtureKind::HeadSetToDevelopBranch => {
899 self.build_head_set_to_develop_branch().await
900 }
871 } 901 }
872 } 902 }
873 903
@@ -1474,6 +1504,65 @@ impl<'a> TestContext<'a> {
1474 } 1504 }
1475 } 1505 }
1476 1506
1507 /// Build HeadSetToDevelopBranch fixture: creates state event with HEAD=develop
1508 ///
1509 /// This tests that HEAD is updated when a state event is published with HEAD
1510 /// pointing to a different branch that already has git data pushed.
1511 ///
1512 /// GRASP-01: "MUST set repository HEAD per repository state announcement
1513 /// as soon as the git data related to that branch has been received."
1514 ///
1515 /// Depends on RecursiveMaintainerStateDataPushed - all git data already exists.
1516 /// We just create a new state event with HEAD=refs/heads/develop pointing to
1517 /// the already-pushed commit.
1518 ///
1519 /// # Returns
1520 /// The state event (kind 30618) with HEAD=refs/heads/develop after it's sent
1521 async fn build_head_set_to_develop_branch(&self) -> Result<Event> {
1522 use nostr_sdk::prelude::*;
1523
1524 // ============================================================
1525 // Stage 1: RecursiveMaintainerStateDataPushed is ensured by ensure_fixture before this is called
1526 // All git data already exists on the relay (main branch with RECURSIVE_MAINTAINER_DETERMINISTIC_COMMIT_HASH)
1527 // ============================================================
1528 let recursive_state = self.get_cached_dependency(FixtureKind::RecursiveMaintainerStateDataPushed)?;
1529
1530 // Extract repo_id from the recursive maintainer's state event
1531 let repo_id = self.extract_repo_id(&recursive_state)?;
1532
1533 // ============================================================
1534 // Stage 2: Create state event with HEAD=refs/heads/develop
1535 // ============================================================
1536 // Use the same commit hash that's already pushed to the relay
1537 // but point HEAD to develop branch instead of main
1538 let base_time = Timestamp::now().as_u64();
1539 let develop_timestamp = Timestamp::from(base_time - 1); // 1 second ago (most recent)
1540
1541 let develop_state_event = self
1542 .client
1543 .event_builder(Kind::Custom(30618), "")
1544 .tag(Tag::identifier(&repo_id))
1545 .tag(Tag::custom(
1546 TagKind::custom("HEAD"),
1547 vec!["refs/heads/develop".to_string()],
1548 ))
1549 .tag(Tag::custom(
1550 TagKind::custom("refs/heads/develop"),
1551 vec![RECURSIVE_MAINTAINER_DETERMINISTIC_COMMIT_HASH.to_string()],
1552 ))
1553 .custom_time(develop_timestamp)
1554 .build(self.client.maintainer_keys())
1555 .map_err(|e| anyhow::anyhow!("Failed to build develop state event: {}", e))?;
1556
1557 // Send state event to relay
1558 self.client.send_event(develop_state_event.clone()).await?;
1559
1560 // Wait for relay to process the state event
1561 tokio::time::sleep(std::time::Duration::from_millis(500)).await;
1562
1563 Ok(develop_state_event)
1564 }
1565
1477 /// Build PRWrongCommitPushedBeforeEvent fixture 1566 /// Build PRWrongCommitPushedBeforeEvent fixture
1478 /// 1567 ///
1479 /// This fixture sets up a scenario where: 1568 /// This fixture sets up a scenario where: