diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-25 10:50:59 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-25 10:50:59 +0000 |
| commit | cd01c7379f23d9189beef840ddc523a3c90a9a10 (patch) | |
| tree | d1a83d2b3cd8813f3ec586694158be70a026e091 /grasp-audit/src/fixtures.rs | |
| parent | 7f71a2e75a66bcacad9057f5e339e511e689b828 (diff) | |
add probe subcommand for end-to-end relay health checks
Implements grasp-audit probe with full write path (publish events,
poll for repo init, push, verify refs match state) and read-only
fallback (find existing announcement, fetch refs). Supports --nsec
for whitelisted relays, --json output, and --watch for continuous
monitoring.
Diffstat (limited to 'grasp-audit/src/fixtures.rs')
| -rw-r--r-- | grasp-audit/src/fixtures.rs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/grasp-audit/src/fixtures.rs b/grasp-audit/src/fixtures.rs index 0a9bf65..4678790 100644 --- a/grasp-audit/src/fixtures.rs +++ b/grasp-audit/src/fixtures.rs | |||
| @@ -2516,6 +2516,78 @@ pub fn try_push_to_ref(clone_path: &Path, ref_name: &str) -> Result<bool, String | |||
| 2516 | Ok(output.status.success()) | 2516 | Ok(output.status.success()) |
| 2517 | } | 2517 | } |
| 2518 | 2518 | ||
| 2519 | /// Initialise a fresh local git repo with a remote URL configured, ready for push. | ||
| 2520 | /// | ||
| 2521 | /// Creates a new git repository at `path`, configures user identity, | ||
| 2522 | /// sets the default branch to `main`, and adds `remote_url` as the `origin` remote. | ||
| 2523 | /// After calling this, use `create_commit()` then `try_push()`. | ||
| 2524 | /// | ||
| 2525 | /// # Arguments | ||
| 2526 | /// * `path` - Directory to initialise (must not already exist as a git repo) | ||
| 2527 | /// * `remote_url` - The remote URL to add as `origin` | ||
| 2528 | pub fn init_local_repo(path: &Path, remote_url: &str) -> Result<(), String> { | ||
| 2529 | // Step 1: git init <path> | ||
| 2530 | let output = Command::new("git") | ||
| 2531 | .args(["init", path.to_str().unwrap_or(".")]) | ||
| 2532 | .output() | ||
| 2533 | .map_err(|e| format!("Failed to execute git init: {}", e))?; | ||
| 2534 | |||
| 2535 | if !output.status.success() { | ||
| 2536 | let stderr = String::from_utf8_lossy(&output.stderr); | ||
| 2537 | return Err(format!("git init failed: {}", stderr)); | ||
| 2538 | } | ||
| 2539 | |||
| 2540 | // Step 2: git config user.email | ||
| 2541 | let output = Command::new("git") | ||
| 2542 | .args(["config", "user.email", "probe@grasp-audit.local"]) | ||
| 2543 | .current_dir(path) | ||
| 2544 | .output() | ||
| 2545 | .map_err(|e| format!("Failed to set git user.email: {}", e))?; | ||
| 2546 | |||
| 2547 | if !output.status.success() { | ||
| 2548 | let stderr = String::from_utf8_lossy(&output.stderr); | ||
| 2549 | return Err(format!("git config user.email failed: {}", stderr)); | ||
| 2550 | } | ||
| 2551 | |||
| 2552 | // Step 3: git config user.name | ||
| 2553 | let output = Command::new("git") | ||
| 2554 | .args(["config", "user.name", "GRASP Probe"]) | ||
| 2555 | .current_dir(path) | ||
| 2556 | .output() | ||
| 2557 | .map_err(|e| format!("Failed to set git user.name: {}", e))?; | ||
| 2558 | |||
| 2559 | if !output.status.success() { | ||
| 2560 | let stderr = String::from_utf8_lossy(&output.stderr); | ||
| 2561 | return Err(format!("git config user.name failed: {}", stderr)); | ||
| 2562 | } | ||
| 2563 | |||
| 2564 | // Step 4: git symbolic-ref HEAD refs/heads/main (sets default branch to main) | ||
| 2565 | let output = Command::new("git") | ||
| 2566 | .args(["symbolic-ref", "HEAD", "refs/heads/main"]) | ||
| 2567 | .current_dir(path) | ||
| 2568 | .output() | ||
| 2569 | .map_err(|e| format!("Failed to set default branch: {}", e))?; | ||
| 2570 | |||
| 2571 | if !output.status.success() { | ||
| 2572 | let stderr = String::from_utf8_lossy(&output.stderr); | ||
| 2573 | return Err(format!("git symbolic-ref HEAD failed: {}", stderr)); | ||
| 2574 | } | ||
| 2575 | |||
| 2576 | // Step 5: git remote add origin <remote_url> | ||
| 2577 | let output = Command::new("git") | ||
| 2578 | .args(["remote", "add", "origin", remote_url]) | ||
| 2579 | .current_dir(path) | ||
| 2580 | .output() | ||
| 2581 | .map_err(|e| format!("Failed to add remote: {}", e))?; | ||
| 2582 | |||
| 2583 | if !output.status.success() { | ||
| 2584 | let stderr = String::from_utf8_lossy(&output.stderr); | ||
| 2585 | return Err(format!("git remote add origin failed: {}", stderr)); | ||
| 2586 | } | ||
| 2587 | |||
| 2588 | Ok(()) | ||
| 2589 | } | ||
| 2590 | |||
| 2519 | #[cfg(test)] | 2591 | #[cfg(test)] |
| 2520 | mod tests { | 2592 | mod tests { |
| 2521 | use super::*; | 2593 | use super::*; |