test(build): prove stale artifact refresh

Drive AppBuilder through a changed template and prove generated Rust and symbols replace stale handles. Tighten the internal write helper to return only the result its callers use and classify the filesystem-equivalent read-guard mutant.

req: build/009

req: test/021
This commit is contained in:
slhx agent
2026-07-17 03:20:53 +02:00
parent 8a21cad98e
commit db5e4bf56c
3 changed files with 47 additions and 5 deletions
+42 -4
View File
@@ -236,15 +236,14 @@ impl AppBuilder {
}
}
fn write_if_changed(path: &Path, contents: &[u8]) -> io::Result<bool> {
fn write_if_changed(path: &Path, contents: &[u8]) -> io::Result<()> {
match std::fs::read(path) {
Ok(existing) if existing == contents => return Ok(false),
Ok(existing) if existing == contents => return Ok(()),
Ok(_) => {}
Err(error) if error.kind() == io::ErrorKind::NotFound => {}
Err(error) => return Err(error),
}
std::fs::write(path, contents)?;
Ok(true)
std::fs::write(path, contents)
}
pub fn app() -> AppBuilder {
@@ -2593,6 +2592,45 @@ mod tests {
let _ = std::fs::remove_dir_all(&base);
}
#[test]
fn changed_template_refreshes_generated_artifacts() {
let base = test_dir("hemx-build-refresh");
let templates = base.join("templates");
let out = base.join("out");
let template = templates.join("panel.heml");
let _ = std::fs::remove_dir_all(&base);
std::fs::create_dir_all(&templates).unwrap();
std::fs::write(
&template,
r#"<button data-hemx-handle="save">Save</button>"#,
)
.unwrap();
app().template_dir(&templates).out_dir(&out).run().unwrap();
let initial_generated = std::fs::read_to_string(out.join("hemx.generated.rs")).unwrap();
let initial_symbols = std::fs::read_to_string(out.join("hemx.syms")).unwrap();
assert!(initial_generated.contains("pub const save"));
assert!(initial_symbols.contains("save"));
std::fs::write(
&template,
r#"<button data-hemx-handle="cancel">Cancel</button>"#,
)
.unwrap();
app().template_dir(&templates).out_dir(&out).run().unwrap();
let refreshed_generated = std::fs::read_to_string(out.join("hemx.generated.rs")).unwrap();
let refreshed_symbols = std::fs::read_to_string(out.join("hemx.syms")).unwrap();
assert_ne!(refreshed_generated, initial_generated);
assert_ne!(refreshed_symbols, initial_symbols);
assert!(refreshed_generated.contains("pub const cancel"));
assert!(!refreshed_generated.contains("pub const save"));
assert!(refreshed_symbols.contains("cancel"));
assert!(!refreshed_symbols.contains("save"));
let _ = std::fs::remove_dir_all(&base);
// test req: build/009
}
#[test]
fn emits_generated_resources_from_heml() {
// req: codegen/003