Complete the end-to-end CLI parity audit

This commit is contained in:
Hermes Agent
2026-08-10 01:51:47 +00:00
parent 4bd39b1ef2
commit 0a905e5e14
14 changed files with 1476 additions and 95 deletions

View File

@@ -1,9 +1,15 @@
#![allow(
clippy::disallowed_types,
reason = "this module is the documented CLI-only configured-editor process boundary"
)]
use std::{
error::Error,
ffi::OsString,
fmt, fs,
io::{self, Read as _, Seek as _, SeekFrom, Write as _},
path::{Path, PathBuf},
process::Command,
};
use ironstorage::{config::ResolvedEditor, repository::SecretBytes};
@@ -44,12 +50,32 @@ pub(crate) trait EditorHost {
fn edit(&mut self, invocation: &EditorInvocation) -> Result<EditorStatus, EditorHostError>;
}
pub(crate) struct NativeEditorHost;
impl EditorHost for NativeEditorHost {
fn edit(&mut self, invocation: &EditorInvocation) -> Result<EditorStatus, EditorHostError> {
let status = Command::new(invocation.program())
.args(invocation.arguments())
.status()
.map_err(|_| EditorHostError(invocation.program().to_owned()))?;
if status.success() {
Ok(EditorStatus::Saved)
} else {
Ok(EditorStatus::Failed(status.code().unwrap_or(1)))
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct EditorHostError;
pub(crate) struct EditorHostError(String);
impl fmt::Display for EditorHostError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("editor host failed")
write!(
formatter,
"editor executable could not be launched: {}",
self.0
)
}
}
@@ -305,4 +331,20 @@ mod tests {
}
Ok(())
}
#[test]
fn missing_editor_executable_has_a_clear_error() {
let invocation = EditorInvocation {
program: "ironstorage-editor-does-not-exist".to_owned(),
arguments: Vec::new(),
plaintext_path: PathBuf::from("unused"),
};
let error = NativeEditorHost
.edit(&invocation)
.expect_err("the intentionally absent editor must fail");
assert_eq!(
error.to_string(),
"editor executable could not be launched: ironstorage-editor-does-not-exist"
);
}
}

File diff suppressed because it is too large Load Diff