use super::common::TestFixture;
use crate::reducer::boundary::MainEffectHandler;
use crate::reducer::event::{CommitEvent, PipelineEvent};
#[test]
fn handle_configure_git_auth_calls_configure_ssh_command_for_specific_key() {
let mut fixture = TestFixture::new();
let ctx = fixture.ctx();
let result =
MainEffectHandler::handle_configure_git_auth(&ctx, "ssh-key:/home/user/.ssh/id_ed25519");
let configured_keys = fixture.git_env.configured_ssh_keys();
assert_eq!(
configured_keys.len(),
1,
"configure_git_ssh_command must be called exactly once for ssh-key:<path> auth"
);
assert!(
configured_keys[0].contains("id_ed25519"),
"SSH command must reference the provided key path, got: {:?}",
configured_keys[0]
);
assert!(
matches!(
result.event,
PipelineEvent::Commit(CommitEvent::GitAuthConfigured)
),
"expected GitAuthConfigured event, got: {:?}",
result.event
);
}
#[test]
fn handle_configure_git_auth_does_not_call_configure_ssh_for_default_ssh_key() {
let mut fixture = TestFixture::new();
let ctx = fixture.ctx();
let result = MainEffectHandler::handle_configure_git_auth(&ctx, "ssh-key:default");
let configured_keys = fixture.git_env.configured_ssh_keys();
assert!(
configured_keys.is_empty(),
"configure_git_ssh_command must NOT be called for ssh-key:default"
);
assert!(
matches!(
result.event,
PipelineEvent::Commit(CommitEvent::GitAuthConfigured)
),
"expected GitAuthConfigured event, got: {:?}",
result.event
);
}
#[test]
fn handle_configure_git_auth_emits_git_auth_configured_even_when_ssh_key_path_invalid() {
let mut fixture = TestFixture::new();
let ctx = fixture.ctx();
let result = MainEffectHandler::handle_configure_git_auth(&ctx, "ssh-key:");
assert!(
matches!(
result.event,
PipelineEvent::Commit(CommitEvent::GitAuthConfigured)
),
"GitAuthConfigured must be emitted even when SSH key validation fails, got: {:?}",
result.event
);
}
#[test]
fn handle_configure_git_auth_disables_terminal_prompt_for_token_auth() {
let mut fixture = TestFixture::new();
let ctx = fixture.ctx();
let result = MainEffectHandler::handle_configure_git_auth(&ctx, "token:x-access-token");
assert!(
fixture.git_env.terminal_prompt_disabled(),
"disable_git_terminal_prompt must be called for token auth to prevent interactive prompts"
);
assert!(
matches!(
result.event,
PipelineEvent::Commit(CommitEvent::GitAuthConfigured)
),
"expected GitAuthConfigured event, got: {:?}",
result.event
);
}
#[test]
fn handle_configure_git_auth_disables_terminal_prompt_for_credential_helper() {
let mut fixture = TestFixture::new();
let ctx = fixture.ctx();
let result =
MainEffectHandler::handle_configure_git_auth(&ctx, "credential-helper:osxkeychain");
assert!(
fixture.git_env.terminal_prompt_disabled(),
"disable_git_terminal_prompt must be called for credential-helper auth"
);
assert!(matches!(
result.event,
PipelineEvent::Commit(CommitEvent::GitAuthConfigured)
));
}