Update build/test scripts with clean progress indicators and minimal output
This commit is contained in:
@@ -1,78 +0,0 @@
|
||||
/// Generate test secp256k1 keypairs for supervisor authentication testing
|
||||
///
|
||||
/// Run with: cargo run --example generate_test_keys
|
||||
|
||||
use secp256k1::{Secp256k1, SecretKey, PublicKey};
|
||||
use hex;
|
||||
|
||||
fn main() {
|
||||
let secp = Secp256k1::new();
|
||||
|
||||
println!("\n╔════════════════════════════════════════════════════════════╗");
|
||||
println!("║ Test Keypairs for Supervisor Auth ║");
|
||||
println!("╚════════════════════════════════════════════════════════════╝\n");
|
||||
println!("⚠️ WARNING: These are TEST keypairs only! Never use in production!\n");
|
||||
|
||||
// Generate 5 keypairs with simple private keys for testing
|
||||
let test_keys = vec![
|
||||
("Alice (Admin)", "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"),
|
||||
("Bob (User)", "fedcba0987654321fedcba0987654321fedcba0987654321fedcba0987654321"),
|
||||
("Charlie (Register)", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
|
||||
("Dave (Test)", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
|
||||
("Eve (Test)", "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"),
|
||||
];
|
||||
|
||||
for (i, (name, privkey_hex)) in test_keys.iter().enumerate() {
|
||||
println!("## Keypair {} - {}", i + 1, name);
|
||||
println!("─────────────────────────────────────────────────────────────");
|
||||
|
||||
// Parse private key
|
||||
let privkey_bytes = hex::decode(privkey_hex).expect("Invalid hex");
|
||||
let secret_key = SecretKey::from_slice(&privkey_bytes).expect("Invalid private key");
|
||||
|
||||
// Derive public key
|
||||
let public_key = PublicKey::from_secret_key(&secp, &secret_key);
|
||||
|
||||
// Serialize keys
|
||||
let pubkey_uncompressed = hex::encode(public_key.serialize_uncompressed());
|
||||
let pubkey_compressed = hex::encode(public_key.serialize());
|
||||
|
||||
println!("Private Key (hex): 0x{}", privkey_hex);
|
||||
println!("Public Key (uncomp): 0x{}", pubkey_uncompressed);
|
||||
println!("Public Key (comp): 0x{}", pubkey_compressed);
|
||||
println!();
|
||||
}
|
||||
|
||||
println!("\n╔════════════════════════════════════════════════════════════╗");
|
||||
println!("║ Usage Examples ║");
|
||||
println!("╚════════════════════════════════════════════════════════════╝\n");
|
||||
|
||||
println!("### Using with OpenRPC Client (Rust)\n");
|
||||
println!("```rust");
|
||||
println!("use secp256k1::{{Secp256k1, SecretKey}};");
|
||||
println!("use hex;");
|
||||
println!();
|
||||
println!("// Alice's private key for admin access");
|
||||
println!("let privkey_hex = \"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\";");
|
||||
println!("let privkey_bytes = hex::decode(privkey_hex).unwrap();");
|
||||
println!("let secret_key = SecretKey::from_slice(&privkey_bytes).unwrap();");
|
||||
println!();
|
||||
println!("// Use with client");
|
||||
println!("let client = SupervisorClient::new_with_keypair(");
|
||||
println!(" \"http://127.0.0.1:3030\",");
|
||||
println!(" secret_key");
|
||||
println!(");");
|
||||
println!("```\n");
|
||||
|
||||
println!("### Testing Different Scopes\n");
|
||||
println!("1. **Admin Scope** - Use Alice's keypair for full admin access");
|
||||
println!("2. **User Scope** - Use Bob's keypair for limited user access");
|
||||
println!("3. **Register Scope** - Use Charlie's keypair for runner registration\n");
|
||||
|
||||
println!("### Quick Copy-Paste Keys\n");
|
||||
println!("Alice (Admin): 1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef");
|
||||
println!("Bob (User): fedcba0987654321fedcba0987654321fedcba0987654321fedcba0987654321");
|
||||
println!("Charlie (Reg): aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||
println!("Dave (Test): bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
|
||||
println!("Eve (Test): cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n");
|
||||
}
|
||||
@@ -629,348 +629,4 @@ impl SupervisorClient {
|
||||
.await.map_err(|e| ClientError::JsonRpc(e))?;
|
||||
Ok(info)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_client_creation() {
|
||||
let client = SupervisorClient::new("http://127.0.0.1:3030");
|
||||
assert!(client.is_ok());
|
||||
|
||||
let client = client.unwrap();
|
||||
assert_eq!(client.server_url(), "http://127.0.0.1:3030");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_job_builder() {
|
||||
let job = JobBuilder::new()
|
||||
.caller_id("test_client")
|
||||
.context_id("test_context")
|
||||
.payload("print('Hello, World!');")
|
||||
.executor("osis")
|
||||
.runner("test_runner")
|
||||
.timeout(60)
|
||||
.env_var("TEST_VAR", "test_value")
|
||||
.build();
|
||||
|
||||
assert!(job.is_ok());
|
||||
let job = job.unwrap();
|
||||
|
||||
assert_eq!(job.caller_id, "test_client");
|
||||
assert_eq!(job.context_id, "test_context");
|
||||
assert_eq!(job.payload, "print('Hello, World!');");
|
||||
assert_eq!(job.executor, "osis");
|
||||
assert_eq!(job.runner, "test_runner");
|
||||
assert_eq!(job.timeout, 60);
|
||||
assert_eq!(job.env_vars.get("TEST_VAR"), Some(&"test_value".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_job_builder_validation() {
|
||||
// Missing caller_id
|
||||
let result = JobBuilder::new()
|
||||
.context_id("test")
|
||||
.payload("test")
|
||||
.runner("test")
|
||||
.build();
|
||||
assert!(result.is_err());
|
||||
|
||||
// Missing context_id
|
||||
let result = JobBuilder::new()
|
||||
.caller_id("test")
|
||||
.payload("test")
|
||||
.runner("test")
|
||||
.build();
|
||||
assert!(result.is_err());
|
||||
|
||||
// Missing payload
|
||||
let result = JobBuilder::new()
|
||||
.caller_id("test")
|
||||
.context_id("test")
|
||||
.runner("test")
|
||||
.executor("test")
|
||||
.build();
|
||||
assert!(result.is_err());
|
||||
|
||||
// Missing runner
|
||||
let result = JobBuilder::new()
|
||||
.caller_id("test")
|
||||
.context_id("test")
|
||||
.payload("test")
|
||||
.executor("test")
|
||||
.build();
|
||||
assert!(result.is_err());
|
||||
|
||||
// Missing executor
|
||||
let result = JobBuilder::new()
|
||||
.caller_id("test")
|
||||
.context_id("test")
|
||||
.payload("test")
|
||||
.runner("test")
|
||||
.build();
|
||||
assert!(result.is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod client_tests {
|
||||
use super::*;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod native_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_client_creation() {
|
||||
let client = SupervisorClient::new("http://localhost:3030");
|
||||
assert!(client.is_ok());
|
||||
let client = client.unwrap();
|
||||
assert_eq!(client.server_url(), "http://localhost:3030");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_client_creation_invalid_url() {
|
||||
let client = SupervisorClient::new("invalid-url");
|
||||
// HTTP client builder validates URLs and should fail on invalid ones
|
||||
assert!(client.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_process_status_wrapper_serialization() {
|
||||
let status = ProcessStatusWrapper::Running;
|
||||
let serialized = serde_json::to_string(&status).unwrap();
|
||||
assert_eq!(serialized, "\"Running\"");
|
||||
|
||||
let status = ProcessStatusWrapper::Error("test error".to_string());
|
||||
let serialized = serde_json::to_string(&status).unwrap();
|
||||
assert!(serialized.contains("Error"));
|
||||
assert!(serialized.contains("test error"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_log_info_wrapper_serialization() {
|
||||
let log = LogInfoWrapper {
|
||||
timestamp: "2023-01-01T00:00:00Z".to_string(),
|
||||
level: "INFO".to_string(),
|
||||
message: "test message".to_string(),
|
||||
};
|
||||
|
||||
let serialized = serde_json::to_string(&log).unwrap();
|
||||
assert!(serialized.contains("2023-01-01T00:00:00Z"));
|
||||
assert!(serialized.contains("INFO"));
|
||||
assert!(serialized.contains("test message"));
|
||||
|
||||
let deserialized: LogInfoWrapper = serde_json::from_str(&serialized).unwrap();
|
||||
assert_eq!(deserialized.timestamp, log.timestamp);
|
||||
assert_eq!(deserialized.level, log.level);
|
||||
assert_eq!(deserialized.message, log.message);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_runner_type_serialization() {
|
||||
let runner_type = RunnerType::SALRunner;
|
||||
let serialized = serde_json::to_string(&runner_type).unwrap();
|
||||
assert_eq!(serialized, "\"SALRunner\"");
|
||||
|
||||
let deserialized: RunnerType = serde_json::from_str(&serialized).unwrap();
|
||||
assert_eq!(deserialized, RunnerType::SALRunner);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_job_type_conversion() {
|
||||
assert_eq!(JobType::SAL, JobType::SAL);
|
||||
assert_eq!(JobType::OSIS, JobType::OSIS);
|
||||
assert_eq!(JobType::V, JobType::V);
|
||||
assert_eq!(JobType::Python, JobType::Python);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_job_status_serialization() {
|
||||
let status = JobStatus::Started;
|
||||
let serialized = serde_json::to_string(&status).unwrap();
|
||||
assert_eq!(serialized, "\"Started\"");
|
||||
|
||||
let deserialized: JobStatus = serde_json::from_str(&serialized).unwrap();
|
||||
assert_eq!(deserialized, JobStatus::Started);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod wasm_tests {
|
||||
use super::*;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
wasm_bindgen_test_configure!(run_in_browser);
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_wasm_client_creation() {
|
||||
let client = crate::wasm::WasmSupervisorClient::new("http://localhost:3030".to_string());
|
||||
assert_eq!(client.server_url(), "http://localhost:3030");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_wasm_job_creation() {
|
||||
let job = crate::wasm::hero_job::Job::new(
|
||||
"test-id".to_string(),
|
||||
"test payload".to_string(),
|
||||
"SAL".to_string(),
|
||||
"test-runner".to_string(),
|
||||
);
|
||||
|
||||
assert_eq!(job.id(), "test-id");
|
||||
assert_eq!(job.payload(), "test payload");
|
||||
assert_eq!(job.job_type(), "SAL");
|
||||
assert_eq!(job.runner(), "test-runner");
|
||||
assert_eq!(job.caller_id(), "wasm_client");
|
||||
assert_eq!(job.context_id(), "wasm_context");
|
||||
assert_eq!(job.timeout_secs(), 30);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_wasm_job_setters() {
|
||||
let mut job = crate::wasm::hero_job::Job::new(
|
||||
"test-id".to_string(),
|
||||
"test payload".to_string(),
|
||||
"SAL".to_string(),
|
||||
"test-runner".to_string(),
|
||||
);
|
||||
|
||||
job.set_caller_id("custom-caller".to_string());
|
||||
job.set_context_id("custom-context".to_string());
|
||||
job.set_timeout_secs(60);
|
||||
job.set_env_vars("{\"KEY\":\"VALUE\"}".to_string());
|
||||
|
||||
assert_eq!(job.caller_id(), "custom-caller");
|
||||
assert_eq!(job.context_id(), "custom-context");
|
||||
assert_eq!(job.timeout_secs(), 60);
|
||||
assert_eq!(job.env_vars(), "{\"KEY\":\"VALUE\"}");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_wasm_job_id_generation() {
|
||||
let mut job = crate::wasm::hero_job::Job::new(
|
||||
"original-id".to_string(),
|
||||
"test payload".to_string(),
|
||||
"SAL".to_string(),
|
||||
"test-runner".to_string(),
|
||||
);
|
||||
|
||||
let original_id = job.id();
|
||||
job.generate_id();
|
||||
let new_id = job.id();
|
||||
|
||||
assert_ne!(original_id, new_id);
|
||||
assert!(new_id.len() > 0);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_create_job_function() {
|
||||
let job = crate::wasm::create_job(
|
||||
"func-test-id".to_string(),
|
||||
"func test payload".to_string(),
|
||||
"OSIS".to_string(),
|
||||
"func-test-runner".to_string(),
|
||||
);
|
||||
|
||||
assert_eq!(job.id(), "func-test-id");
|
||||
assert_eq!(job.payload(), "func test payload");
|
||||
assert_eq!(job.job_type(), "OSIS");
|
||||
assert_eq!(job.runner(), "func-test-runner");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_wasm_job_type_enum() {
|
||||
use crate::wasm::hero_job::JobType;
|
||||
|
||||
// Test that enum variants exist and can be created
|
||||
let sal = hero_job::JobType::SAL;
|
||||
let osis = hero_job::JobType::OSIS;
|
||||
let v = hero_job::JobType::V;
|
||||
|
||||
// Test equality
|
||||
assert_eq!(sal, hero_job::JobType::SAL);
|
||||
assert_eq!(osis, hero_job::JobType::OSIS);
|
||||
assert_eq!(v, hero_job::JobType::V);
|
||||
|
||||
// Test inequality
|
||||
assert_ne!(sal, osis);
|
||||
assert_ne!(osis, v);
|
||||
assert_ne!(v, sal);
|
||||
}
|
||||
}
|
||||
|
||||
// Common tests that work on both native and WASM
|
||||
#[test]
|
||||
fn test_process_status_wrapper_variants() {
|
||||
let running = ProcessStatusWrapper::Running;
|
||||
let stopped = ProcessStatusWrapper::Stopped;
|
||||
let starting = ProcessStatusWrapper::Starting;
|
||||
let stopping = ProcessStatusWrapper::Stopping;
|
||||
let error = ProcessStatusWrapper::Error("test".to_string());
|
||||
|
||||
// Test that all variants can be created
|
||||
assert_eq!(running, ProcessStatusWrapper::Running);
|
||||
assert_eq!(stopped, ProcessStatusWrapper::Stopped);
|
||||
assert_eq!(starting, ProcessStatusWrapper::Starting);
|
||||
assert_eq!(stopping, ProcessStatusWrapper::Stopping);
|
||||
|
||||
if let ProcessStatusWrapper::Error(msg) = error {
|
||||
assert_eq!(msg, "test");
|
||||
} else {
|
||||
panic!("Expected Error variant");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_job_type_variants() {
|
||||
assert_eq!(JobType::SAL, JobType::SAL);
|
||||
assert_eq!(JobType::OSIS, JobType::OSIS);
|
||||
assert_eq!(JobType::V, JobType::V);
|
||||
assert_eq!(JobType::Python, JobType::Python);
|
||||
|
||||
assert_ne!(JobType::SAL, JobType::OSIS);
|
||||
assert_ne!(JobType::OSIS, JobType::V);
|
||||
assert_ne!(JobType::V, JobType::Python);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_job_status_variants() {
|
||||
assert_eq!(JobStatus::Created, JobStatus::Created);
|
||||
assert_eq!(JobStatus::Dispatched, JobStatus::Dispatched);
|
||||
assert_eq!(JobStatus::Started, JobStatus::Started);
|
||||
assert_eq!(JobStatus::Finished, JobStatus::Finished);
|
||||
assert_eq!(JobStatus::Error, JobStatus::Error);
|
||||
|
||||
assert_ne!(JobStatus::Created, JobStatus::Dispatched);
|
||||
assert_ne!(JobStatus::Started, JobStatus::Finished);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_runner_type_variants() {
|
||||
assert_eq!(RunnerType::SALRunner, RunnerType::SALRunner);
|
||||
assert_eq!(RunnerType::OSISRunner, RunnerType::OSISRunner);
|
||||
assert_eq!(RunnerType::VRunner, RunnerType::VRunner);
|
||||
assert_eq!(RunnerType::PyRunner, RunnerType::PyRunner);
|
||||
|
||||
assert_ne!(RunnerType::SALRunner, RunnerType::OSISRunner);
|
||||
assert_ne!(RunnerType::VRunner, RunnerType::PyRunner);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_process_manager_type_variants() {
|
||||
let simple = ProcessManagerType::Simple;
|
||||
let tmux = ProcessManagerType::Tmux("test-session".to_string());
|
||||
|
||||
assert_eq!(simple, ProcessManagerType::Simple);
|
||||
|
||||
if let ProcessManagerType::Tmux(session) = tmux {
|
||||
assert_eq!(session, "test-session");
|
||||
} else {
|
||||
panic!("Expected Tmux variant");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user