Refresh every stale post route during validation.

This commit is contained in:
2026-08-15 10:23:10 +02:00
parent 58596c8de0
commit 1f03d91c5f
9 changed files with 149 additions and 75 deletions

View File

@@ -1023,6 +1023,86 @@ fn site_validation_detects_post_sources_newer_than_generated_routes() {
);
}
#[test]
fn site_validation_repairs_every_stale_route_for_page_posts() {
use std::fs::{File, FileTimes};
use std::time::{Duration, UNIX_EPOCH};
let (db, dir) = setup();
let metadata = make_metadata();
let mut post = make_post("wiki", 1_710_000_000_000);
post.categories = vec!["page".into(), "wiki".into()];
write_published_snapshot(&dir, &mut post, "Old wiki body");
bds_core::db::queries::post::insert_post(db.conn(), &post).unwrap();
let old_source = PublishedPostSource {
post: post.clone(),
body_markdown: "Old wiki body".into(),
};
generate_starter_site(db.conn(), dir.path(), "p1", &metadata, &[old_source], "en").unwrap();
write_published_snapshot(&dir, &mut post, "Updated wiki body");
let canonical_path = "2024/03/09/wiki/index.html";
let flat_path = "wiki/index.html";
for path in [canonical_path, flat_path] {
File::options()
.write(true)
.open(dir.path().join(path))
.unwrap()
.set_times(FileTimes::new().set_modified(UNIX_EPOCH + Duration::from_secs(10)))
.unwrap();
let mut hash = bds_core::db::queries::generated_file_hash::get_generated_file_hash(
db.conn(),
"p1",
path,
)
.unwrap();
hash.updated_at = 10_000;
bds_core::db::queries::generated_file_hash::upsert_generated_file_hash(db.conn(), &hash)
.unwrap();
}
File::options()
.write(true)
.open(dir.path().join(&post.file_path))
.unwrap()
.set_times(FileTimes::new().set_modified(UNIX_EPOCH + Duration::from_secs(20)))
.unwrap();
let validation = validate_site(db.conn(), dir.path(), "p1").unwrap();
assert_eq!(
validation.stale_pages,
vec![canonical_path.to_string(), flat_path.to_string()]
);
let updated_source = load_published_post_source(dir.path(), post)
.unwrap()
.unwrap();
let sections = sections_from_validation_report(&validation, &metadata);
apply_validation_sections(
db.conn(),
dir.path(),
"p1",
&metadata,
&[updated_source],
&validation,
&sections,
)
.unwrap();
assert!(
std::fs::read_to_string(dir.path().join(canonical_path))
.unwrap()
.contains("Updated wiki body")
);
assert!(
std::fs::read_to_string(dir.path().join(flat_path))
.unwrap()
.contains("Updated wiki body")
);
let repaired = validate_site(db.conn(), dir.path(), "p1").unwrap();
assert!(repaired.stale_pages.is_empty());
}
#[test]
fn site_validation_refreshes_sitemap_without_rendering_pages() {
let (db, dir) = setup();