feat(derive): require form parameter for form handles

Emit handle-form facts from slhx-build and have #[slhx::handler] reject generated form handlers that do not accept slhx::Form<_>. Cover the boundary with compile-fail fixtures.

req: form/004

req: form/006

req: test/003
This commit is contained in:
slhx agent
2026-05-25 21:23:37 +02:00
parent 3ea596a218
commit dca26511cc
3 changed files with 81 additions and 2 deletions
+52
View File
@@ -60,6 +60,58 @@ fn known() {}
);
}
#[test]
fn form_handle_requires_form_parameter() {
// req: form/004 req: form/006 req: test/003
let fixture = Fixture::new("slhx-derive-form-handler-fail");
fixture.write(
"Cargo.toml",
&format!(
r#"[package]
name = "slhx-derive-form-handler-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#"#[slhx::handler]
fn create() -> 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-handler diagnostic in stderr:\n{stderr}"
);
}
#[test]
fn surface_macro_reports_missing_generated_include() {
// req: build/004 req: test/003