fix: ensure outputs are properly disabled in constructors

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-27 18:11:32 -03:00
parent 324b96d1e1
commit 42a10cc2d5
2 changed files with 103 additions and 41 deletions

View File

@@ -87,16 +87,6 @@ impl DigestMetaPlugin {
) -> DigestMetaPlugin {
let mut plugin = DigestMetaPlugin::default();
// Set default outputs
let default_outputs = vec![
("digest_md5".to_string(), serde_yaml::Value::String("digest_md5".to_string())),
("digest_sha256".to_string(), serde_yaml::Value::String("digest_sha256".to_string())),
("digest_sha512".to_string(), serde_yaml::Value::String("digest_sha512".to_string())),
];
for (key, value) in default_outputs {
plugin.outputs.insert(key, value);
}
// Apply provided options
if let Some(opts) = options {
for (key, value) in opts {
@@ -104,32 +94,56 @@ impl DigestMetaPlugin {
}
}
// Apply provided outputs
// Determine the selected method
let method = if let Some(method_value) = plugin.options.get("method") {
if let Some(method_str) = method_value.as_str() {
match method_str {
"md5" => "md5",
"sha256" => "sha256",
"sha512" => "sha512",
_ => "sha256",
}
} else {
"sha256"
}
} else {
"sha256"
};
// Initialize the hasher based on the method
plugin.hasher = match method {
"md5" => Some(Hasher::Md5(md5::Context::new())),
"sha256" => Some(Hasher::Sha256(Sha256::new())),
"sha512" => Some(Hasher::Sha512(Sha512::new())),
_ => Some(Hasher::Sha256(Sha256::new())),
};
// Add the method to options so it shows up in the status
plugin.options.insert("method".to_string(), serde_yaml::Value::String(method.to_string()));
// Set outputs based on the selected method
// Only the selected method's output should be enabled, others should be None
let all_outputs = vec!["digest_md5", "digest_sha256", "digest_sha512"];
for output_name in all_outputs {
if output_name == format!("digest_{}", method) {
plugin.outputs.insert(output_name.to_string(), serde_yaml::Value::String(output_name.to_string()));
} else {
plugin.outputs.insert(output_name.to_string(), serde_yaml::Value::Null);
}
}
// Apply provided outputs, but only for enabled outputs
if let Some(outs) = outputs {
for (key, value) in outs {
plugin.outputs.insert(key, value);
// Only update if the output is not disabled (not None)
if let Some(current_value) = plugin.outputs.get_mut(&key) {
if !current_value.is_null() {
*current_value = value;
}
}
}
}
// Initialize the hasher based on the method option
if let Some(method_value) = plugin.options.get("method") {
if let Some(method_str) = method_value.as_str() {
plugin.hasher = match method_str {
"md5" => Some(Hasher::Md5(md5::Context::new())),
"sha256" => Some(Hasher::Sha256(Sha256::new())),
"sha512" => Some(Hasher::Sha512(Sha512::new())),
_ => None,
};
}
}
// Default to sha256 if no valid method is specified
if plugin.hasher.is_none() {
plugin.hasher = Some(Hasher::Sha256(Sha256::new()));
// Add the default method to options so it shows up in the status
plugin.options.insert("method".to_string(), serde_yaml::Value::String("sha256".to_string()));
}
plugin
}