test(cli): assert .relkey never enters git tree + init failure-path coverage + display polish

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01McMF5pUJbCMricmFEnf2sG
This commit is contained in:
adlee-was-taken
2026-06-25 23:43:31 -04:00
parent 2daa3502e9
commit 23c8bbea65
3 changed files with 67 additions and 6 deletions

View File

@@ -48,7 +48,7 @@ pub fn cmd_init(image: Option<PathBuf>, output: PathBuf, key_file: Option<PathBu
// Write the container (key file or reference image) and record which
// second-factor type this vault uses.
let (gitignore_name, second_factor): (String, SecondFactor) = match (&key_file, &image) {
let (gitignore_name, container_display, second_factor): (String, String, SecondFactor) = match (&key_file, &image) {
(Some(kf), _) => {
// Key-file mode: write the armored secret in the clear.
// SECURITY: this file holds the 256-bit secret in the clear and
@@ -63,7 +63,7 @@ pub fn cmd_init(image: Option<PathBuf>, output: PathBuf, key_file: Option<PathBu
.ok_or_else(|| anyhow::anyhow!("key-file path has no filename: {}", kf.display()))?
.to_string_lossy()
.into_owned();
(name, SecondFactor::Keyfile)
(name, kf_path.display().to_string(), SecondFactor::Keyfile)
}
(None, Some(img)) => {
// Image mode: embed into a carrier JPEG, write the reference image.
@@ -79,7 +79,7 @@ pub fn cmd_init(image: Option<PathBuf>, output: PathBuf, key_file: Option<PathBu
})?
.to_string_lossy()
.into_owned();
(name, SecondFactor::Image)
(name, output.display().to_string(), SecondFactor::Image)
}
(None, None) => {
anyhow::bail!(
@@ -133,11 +133,11 @@ pub fn cmd_init(image: Option<PathBuf>, output: PathBuf, key_file: Option<PathBu
eprintln!("Vault initialized at {}", root.display());
match second_factor {
SecondFactor::Keyfile => {
eprintln!("Key file: {gitignore_name}");
eprintln!("Key file: {container_display}");
eprintln!(" \u{2192} back this file up somewhere safe; it is your second factor.");
}
SecondFactor::Image => {
eprintln!("Reference image: {}", output.display());
eprintln!("Reference image: {container_display}");
eprintln!(" \u{2192} back this file up somewhere safe; it is your second factor.");
}
}

View File

@@ -35,7 +35,7 @@ enum Commands {
/// Carrier JPEG to embed the secret into (image second factor).
#[arg(long)]
image: Option<PathBuf>,
/// Output path for the reference image (gitignored).
/// Output path for the reference image (gitignored); ignored when --key-file is used.
#[arg(long, default_value = "reference.jpg")]
output: PathBuf,
/// Generate a key-file second factor at this path instead of a reference image (gitignored).