From 4a3bb60b828feaae94de67e00db3c25040f19ec7 Mon Sep 17 00:00:00 2001 From: David Mann Date: Thu, 12 Nov 2026 17:07:23 +0100 Subject: [PATCH] test(flags): the oversized-write fixture is readable, so the test reaches the output-size check The padding loop made the fixture 65,538 bytes, past the read limit, so set() refused while reading and the test passed without the output-size check. The fixture is now exactly MAX_FILE_BYTES - 4 bytes; with the check removed the test fails. --- crates/flags/src/tests.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/flags/src/tests.rs b/crates/flags/src/tests.rs index 92f690037..66c00855b 100644 --- a/crates/flags/src/tests.rs +++ b/crates/flags/src/tests.rs @@ -122,12 +122,15 @@ mod file { fn set_refuses_to_write_what_could_not_be_read_back() { let dir = tempfile::tempdir().unwrap(); let path = dir.path().join(FILE_NAME); - let mut text = String::from("[flags]\n"); - while (text.len() as u64) < MAX_FILE_BYTES - 4 { - text.push_str("# padding\n"); - } + // Readable (just under the limit), so the refusal comes from the size of what `set` would + // write, not from reading. + let mut text = String::from("[flags]\n# "); + let pad = MAX_FILE_BYTES as usize - 4 - text.len(); + text.push_str(&"x".repeat(pad)); + assert_eq!(text.len() as u64, MAX_FILE_BYTES - 4); std::fs::write(&path, &text).unwrap(); - assert!(matches!(set(&path, "AI-MODELS", true), Err(FlagError::Unreadable(_)))); + assert!(Flags::from_parts(Some(&text), None).problems.is_empty(), "the fixture itself reads"); + assert!(matches!(set(&path, "AI-MODELS", true), Err(FlagError::Unreadable(e)) if e.contains("would grow"))); assert_eq!(std::fs::read_to_string(&path).unwrap(), text, "left as it was"); }