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.
This commit is contained in:
David Mann committed 2026-11-12 17:07:23 +01:00
1 parent 88864de95f
commit 4a3bb60b82
1 file changed
+8 -5
+8 -5
View File
@@ -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");
}