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-11-28 16:27:29 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-28 16:27:29 +0000
commite6ceab90de1acad154624022a6036efac18abab6 (patch)
tree315c7b7ffc22339ed6cd0a31002e2fb0df190684 /grasp-audit/src/fixtures.rs
parentb94262161df99966fbb8aa6861fb46603039111f (diff)
test: added checks that refs/nostr/<event-id> match commit in PR / update
Diffstat (limited to 'grasp-audit/src/fixtures.rs')
-rw-r--r--grasp-audit/src/fixtures.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/grasp-audit/src/fixtures.rs b/grasp-audit/src/fixtures.rs
index b6fbc79..dc4e638 100644
--- a/grasp-audit/src/fixtures.rs
+++ b/grasp-audit/src/fixtures.rs
@@ -74,6 +74,17 @@ pub const MAINTAINER_DETERMINISTIC_COMMIT_HASH: &str = "1c2d472c9b71ed51968a6650
74/// NOTE: This value is different from DETERMINISTIC_COMMIT_HASH due to different content 74/// NOTE: This value is different from DETERMINISTIC_COMMIT_HASH due to different content
75pub const RECURSIVE_MAINTAINER_DETERMINISTIC_COMMIT_HASH: &str = "05939b82de66fbdb9c077d0a64fc68522f3cb8e0"; 75pub const RECURSIVE_MAINTAINER_DETERMINISTIC_COMMIT_HASH: &str = "05939b82de66fbdb9c077d0a64fc68522f3cb8e0";
76 76
77/// Deterministic commit hash for PR test fixtures (PRTestCommit variant)
78/// This is the hash produced by creating a commit with:
79/// - Message: "PR test deterministic commit"
80/// - File: test.txt containing "PR test deterministic commit"
81/// - Author date: 2024-01-01T00:00:00Z
82/// - Committer date: 2024-01-01T00:00:00Z
83/// - GPG signing: disabled
84/// - User: "GRASP Audit Test <test@grasp-audit.local>"
85/// - Parent: none (root commit)
86pub const PR_TEST_COMMIT_HASH: &str = "8935183ff722bf04e861928c6a7e50868c6ca4a6";
87
77/// Types of test fixtures available 88/// Types of test fixtures available
78/// 89///
79/// ## Fixture Dependencies 90/// ## Fixture Dependencies
@@ -145,6 +156,15 @@ pub enum FixtureKind {
145 /// - State event points to RECURSIVE_MAINTAINER_DETERMINISTIC_COMMIT_HASH 156 /// - State event points to RECURSIVE_MAINTAINER_DETERMINISTIC_COMMIT_HASH
146 /// - Timestamp: 2 seconds in the past (most recent) 157 /// - Timestamp: 2 seconds in the past (most recent)
147 RecursiveMaintainerRepoAndState, 158 RecursiveMaintainerRepoAndState,
159
160 /// PR (Patch/Pull Request) event for the SAME repo_id as ValidRepo
161 /// - Requires ValidRepo (uses same repo_id)
162 /// - Signed by `client.pr_author_keys()`
163 /// - Kind 1617 (NIP-34 patch)
164 /// - Includes `a` tag referencing the repo
165 /// - Includes `c` tag pointing to PR_TEST_COMMIT_HASH
166 /// - Timestamp: 1 second in the past
167 PREvent,
148} 168}
149 169
150/// Context mode for fixture management 170/// Context mode for fixture management
@@ -633,6 +653,47 @@ impl<'a> TestContext<'a> {
633 // Return the state event (caller will send it) 653 // Return the state event (caller will send it)
634 self.build_recursive_maintainer_state(&repo_id) 654 self.build_recursive_maintainer_state(&repo_id)
635 } 655 }
656
657 FixtureKind::PREvent => {
658 use nostr_sdk::prelude::*;
659
660 // Reuse ValidRepo fixture to get repo_id and owner pubkey
661 let repo = self.get_or_create_repo().await?;
662
663 let repo_id = repo
664 .tags
665 .iter()
666 .find(|t| t.kind() == TagKind::d())
667 .and_then(|t| t.content())
668 .ok_or_else(|| anyhow::anyhow!("Missing repo_id in ValidRepo fixture"))?
669 .to_string();
670
671 // Create PR event 1 second in the past
672 let base_time = Timestamp::now().as_u64();
673 let pr_timestamp = Timestamp::from(base_time - 1);
674
675 // Build NIP-34 patch event (kind 1617)
676 self.client
677 .event_builder(
678 Kind::Custom(1617), // NIP-34 patch/PR kind
679 "Test PR for GRASP validation",
680 )
681 .tag(Tag::custom(
682 TagKind::custom("a"),
683 vec![format!(
684 "30617:{}:{}",
685 self.client.public_key().to_hex(), // Owner pubkey
686 repo_id
687 )],
688 ))
689 .tag(Tag::custom(
690 TagKind::custom("c"),
691 vec![PR_TEST_COMMIT_HASH.to_string()],
692 ))
693 .custom_time(pr_timestamp)
694 .build(self.client.pr_author_keys())
695 .map_err(|e| anyhow::anyhow!("Failed to build PR event: {}", e))
696 }
636 } 697 }
637 } 698 }
638 699
@@ -1071,6 +1132,8 @@ pub enum CommitVariant {
1071 Maintainer, 1132 Maintainer,
1072 /// Recursive maintainer pubkey variant - uses "Recursive maintainer initial commit" content 1133 /// Recursive maintainer pubkey variant - uses "Recursive maintainer initial commit" content
1073 RecursiveMaintainer, 1134 RecursiveMaintainer,
1135 /// PR test commit variant - for PR event tests
1136 PRTestCommit,
1074} 1137}
1075 1138
1076impl CommitVariant { 1139impl CommitVariant {
@@ -1080,6 +1143,7 @@ impl CommitVariant {
1080 CommitVariant::Owner => "Initial commit", 1143 CommitVariant::Owner => "Initial commit",
1081 CommitVariant::Maintainer => "Maintainer initial commit", 1144 CommitVariant::Maintainer => "Maintainer initial commit",
1082 CommitVariant::RecursiveMaintainer => "Recursive maintainer initial commit", 1145 CommitVariant::RecursiveMaintainer => "Recursive maintainer initial commit",
1146 CommitVariant::PRTestCommit => "PR test deterministic commit",
1083 } 1147 }
1084 } 1148 }
1085 1149
@@ -1089,6 +1153,7 @@ impl CommitVariant {
1089 CommitVariant::Owner => "Initial commit", 1153 CommitVariant::Owner => "Initial commit",
1090 CommitVariant::Maintainer => "Maintainer initial commit", 1154 CommitVariant::Maintainer => "Maintainer initial commit",
1091 CommitVariant::RecursiveMaintainer => "Recursive maintainer initial commit", 1155 CommitVariant::RecursiveMaintainer => "Recursive maintainer initial commit",
1156 CommitVariant::PRTestCommit => "PR test deterministic commit",
1092 } 1157 }
1093 } 1158 }
1094} 1159}