fix(derive): reject form type impostors

Tighten generated form-handler validation so only actual Form paths satisfy form handles; names like CreateForm no longer bypass the slhx::Form<_> requirement. Cover with unit and compile-fail tests.

req: form/004

req: form/006

req: test/003
This commit is contained in:
slhx agent
2026-05-25 22:10:19 +02:00
parent 00af1017cc
commit 6d9d5e4c4e
2 changed files with 73 additions and 10 deletions
+54
View File
@@ -163,6 +163,60 @@ fn create() -> impl slhx::IntoEffect {
);
}
#[test]
fn form_handle_rejects_form_name_suffix_impostor() {
// req: form/004 req: form/006 req: test/003
let fixture = Fixture::new("slhx-derive-form-impostor-fail");
fixture.write(
"Cargo.toml",
&format!(
r#"[package]
name = "slhx-derive-form-impostor-fail"
version = "0.0.0"
edition = "2021"
[lib]
path = "src/lib.rs"
[dependencies]
slhx = {{ path = {:?} }}
"#,
repo_path("slhx")
),
);
fixture.write(
"build.rs",
r#"fn main() {
let out = std::path::PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
std::fs::write(
out.join("slhx.syms"),
"slhx-syms-v1\nhandle\ttemplates/app.heml::create\tcreate\t1\nhandle_form\tcreate\tnew_todo\n",
)
.unwrap();
}
"#,
);
fixture.write(
"src/lib.rs",
r#"struct CreateForm;
#[slhx::handler]
fn create(_form: CreateForm) -> impl slhx::IntoEffect {
slhx::EffectBatch::default()
}
"#,
);
let output = check_fixture(&fixture);
assert!(!output.status.success(), "fixture unexpectedly compiled");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("slhx handler `create` handles a generated form and must accept slhx::Form<_>"),
"missing form-impostor diagnostic in stderr:\n{stderr}"
);
}
#[test]
fn surface_macro_reports_missing_generated_include() {
// req: build/004 req: test/003