From 7e3369e92d154c8ed532b977d5dd541398b5197d Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 23:38:28 +0000 Subject: tests: prove the per-append delivery directly on the tail The HTTP test cannot show delivery per append: the stream response is buffered until it ends, so every line lands in one read no matter what the tail is doing, and the sleeps that used to stage the appends proved nothing. The property moves to where it is observable - drive LogTail, append between reads, and each append has to arrive as its own event. The socket test keeps proving the wiring, the headers and the end event. copy_tree now names the file it failed on, which it did not do before. --- tests/common/mod.rs | 4 +++- tests/live.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 4884a19..1399179 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -430,7 +430,9 @@ fn copy_tree(from: &Path, to: &Path) { if entry.file_type().unwrap().is_dir() { copy_tree(&path, &target); } else { - std::fs::copy(&path, &target).unwrap(); + std::fs::copy(&path, &target).unwrap_or_else(|e| { + panic!("copying {} to {}: {e}", path.display(), target.display()) + }); } } } diff --git a/tests/live.rs b/tests/live.rs index b73b2f6..b891b7e 100644 --- a/tests/live.rs +++ b/tests/live.rs @@ -68,6 +68,39 @@ fn the_log_stream_delivers_bytes_as_they_are_appended_and_then_ends() { assert!(body.contains("\n\n"), "not event-framed: {body}"); } +fn read_event(tail: &mut aur_build::http::sse::LogTail) -> String { + let mut buf = [0u8; 4096]; + let n = tail.read(&mut buf).expect("tail"); + String::from_utf8_lossy(&buf[..n]).into_owned() +} + +#[test] +fn the_tail_hands_over_each_append_as_it_lands_and_then_ends() { + let (env, _fx) = env_with_fixture("plain-make"); + let id = queued(&env, "plain-make"); + let log = env.cfg.build_log_path(&id); + std::fs::create_dir_all(log.parent().unwrap()).unwrap(); + std::fs::write(&log, "==> step materialize\n").unwrap(); + + // Driven directly rather than over the socket, because the response is + // buffered until it ends: over HTTP every line lands in one read whatever + // the tail is doing, so the socket cannot show delivery per append. + let mut tail = aur_build::http::sse::LogTail::new(&env.cfg, env.db.clone(), &id); + assert_eq!(read_event(&mut tail), "data: ==> step materialize\n\n"); + append(&log, "==> step build\n"); + assert_eq!( + read_event(&mut tail), + "data: ==> step build\n\n", + "the second append did not arrive as an event of its own" + ); + append(&log, "==> step publish\n"); + assert_eq!(read_event(&mut tail), "data: ==> step publish\n\n"); + + builds::set_state(&env.db, &id, BuildState::Running, None).unwrap(); + builds::set_state(&env.db, &id, BuildState::Succeeded, None).unwrap(); + assert!(read_event(&mut tail).contains("event: end"), "the tail never ended"); +} + #[test] fn the_log_stream_is_404_for_a_build_that_does_not_exist() { let (env, fx) = env_with_fixture("plain-make"); -- cgit v1.2.3