test(derive): close fifth mutation shard

Fail closed when generated form field names cannot map to Rust identifiers and delete the redundant empty generated-parameter branch.

req: form/004

req: diagnostics/003

req: test/022

req: test/023
This commit is contained in:
slhx agent
2026-07-17 14:32:48 +02:00
parent 78a0d91223
commit 31c52698e3
2 changed files with 14 additions and 7 deletions
+13 -6
View File
@@ -670,12 +670,8 @@ fn rust_ident(name: &str) -> Option<String> {
}
fn missing_handle_params(path: &PathBuf, ident: &str, function: &ItemFn) -> Vec<String> {
let required = handle_params(path, ident);
if required.is_empty() {
return Vec::new();
}
let args = handler_arg_names(function);
required
handle_params(path, ident)
.into_iter()
.filter(|param| !args.contains(param))
.collect()
@@ -1029,7 +1025,7 @@ mod tests {
handler_syms_path, has_form_param, has_non_unit_return, is_type_named,
join_contract_errors, missing_component_handlers, missing_form_generated_files_message,
missing_handle_params, missing_handler_generated_files_message, parser_type,
returns_result, syms_contains_handle, HandlerPlacement,
returns_result, rust_ident, syms_contains_handle, HandlerPlacement,
};
use quote::{quote, ToTokens};
use syn::{parse_quote, ItemFn, Type};
@@ -1432,6 +1428,16 @@ mod tests {
assert!(form_model_type(&foreign_form).is_none());
}
#[test]
fn generated_form_field_names_map_only_to_valid_rust_identifiers() {
assert_eq!(rust_ident("first-name").as_deref(), Some("first_name"));
assert_eq!(rust_ident("_private2").as_deref(), Some("_private2"));
for invalid in ["", "2fast", "with space", "naïve"] {
assert_eq!(rust_ident(invalid), None, "{invalid:?} must fail closed");
}
// test req: form/004 req: diagnostics/003
}
#[test]
fn handler_params_match_generated_param_names() {
let path = std::env::temp_dir().join("hemx-derive-param-test.syms");
@@ -1453,6 +1459,7 @@ mod tests {
assert!(missing_handle_params(&path, "show", &complete).is_empty());
assert_eq!(missing_handle_params(&path, "show", &missing), vec!["mode"]);
assert!(missing_handle_params(&path, "unknown", &missing).is_empty());
let _ = std::fs::remove_file(path);
}