test: cover remaining STRA-8 error monomorphs
Linux / verify (pull_request) Successful in 2m11s
Linux / changed-scope-coverage (pull_request) Skipped
Linux / keyless-cuda (pull_request) Skipped
Linux / hosted-cuda-package (pull_request) Skipped
Linux / linux-cli-container (pull_request) Successful in 1m33s
Linux / linux-static-cli (pull_request) Successful in 5m30s
Linux / release-cli (pull_request) Skipped

This commit is contained in:
Pavlo Ratushnyi
2026-10-07 04:03:52 +02:00
parent 3253c8fc36
commit afc6c62f8f
2 changed files with 139 additions and 5 deletions
+29 -5
View File
@@ -438,8 +438,8 @@ fn reap_stale_archive_temps_with(
let parent = destination
.parent()
.expect("canonical archive destination always has a parent");
let entries = read_directory(parent).map_err(|error| error.to_string())?;
reap_archive_temp_entries(&destination, entries)
let mut entries = read_directory(parent).map_err(|error| error.to_string())?;
reap_archive_temp_entries(&destination, &mut entries)
}
#[cfg(not(unix))]
@@ -454,7 +454,7 @@ fn reap_stale_archive_temps_with(
#[cfg(unix)]
fn reap_archive_temp_entries(
destination: &Path,
entries: impl IntoIterator<Item = io::Result<fs::DirEntry>>,
entries: &mut dyn Iterator<Item = io::Result<fs::DirEntry>>,
) -> Result<(), String> {
for entry in entries {
reap_archive_temp_entry(destination, entry.map_err(|error| error.to_string())?)?;
@@ -3414,8 +3414,8 @@ mod tests {
let root = test_dir("stale-reaper-errors");
let destination = root.join("archive.kar");
assert!(reap_stale_archive_temps_with(&destination, denied_directory_read).is_err());
let entries = std::iter::once(Err(io::ErrorKind::PermissionDenied.into()));
assert!(reap_archive_temp_entries(&destination, entries).is_err());
let mut entries = std::iter::once(Err(io::ErrorKind::PermissionDenied.into()));
assert!(reap_archive_temp_entries(&destination, &mut entries).is_err());
fs::remove_dir_all(root).unwrap();
}
@@ -3608,6 +3608,19 @@ mod tests {
let mut source = FaultReadSeek::new(Vec::new());
source.fail_seek_at = Some(1);
assert!(check_file_region(&mut source, 0, 0, RegionRule::ZeroPadding).is_err());
source.fail_seek_at = None;
source.fail_read_at = Some(1);
assert!(
check_file_region_with(
&mut source,
0,
1,
RegionRule::ZeroPadding,
Seek::seek,
Read::read_exact
)
.is_err()
);
}
#[test]
@@ -4228,6 +4241,17 @@ mod tests {
verify_reap_fixture(make_reap_fixture());
}
#[cfg(unix)]
#[test]
fn stale_archive_reaper_returns_directory_entry_errors() {
let root = test_dir("reaper-entry-error");
let destination = root.join("archive.kar");
let mut entries = std::iter::once(Err(io::ErrorKind::PermissionDenied.into()));
assert!(reap_archive_temp_entries(&destination, &mut entries).is_err());
assert!(!destination.exists());
fs::remove_dir_all(root).unwrap();
}
#[cfg(unix)]
#[test]
fn reaper_preserves_replaced_paths_and_unpublished_hard_links() {
+110
View File
@@ -3558,6 +3558,51 @@ mod tests {
assert_raw_file_flush_error();
}
#[test]
fn raw_spool_writer_preserves_file_and_cursor_source_bytes() {
let fixture = overlay_fixture();
let bytes = 2.5f32.to_le_bytes();
let source_path = fixture.directory.join("raw-spool-source.bin");
fs::write(&source_path, bytes).unwrap();
assert_file_raw_spool_matches(&source_path, &fixture.directory.join("file.raw"), &bytes);
assert_cursor_raw_spool_matches(&bytes, &fixture.directory.join("cursor.raw"));
}
fn assert_file_raw_spool_matches(source: &Path, output: &Path, bytes: &[u8; 4]) {
let mut reader = File::open(source).unwrap();
let request = raw_spool_request(output);
let result = spool_raw_f32(&mut reader, request).unwrap();
assert_raw_spool_result(output, bytes, result);
}
fn assert_cursor_raw_spool_matches(bytes: &[u8; 4], output: &Path) {
let mut reader = std::io::Cursor::new(bytes.to_vec());
let result = spool_raw_f32(&mut reader, raw_spool_request(output)).unwrap();
assert_raw_spool_result(output, bytes, result);
}
fn raw_spool_request(path: &Path) -> RawF32Spool<'_> {
RawF32Spool {
absolute: 0,
source_kind: 0,
source_bytes: 4,
path,
}
}
fn assert_raw_spool_result(
path: &Path,
source: &[u8; 4],
(source_digest, derived_digest, bytes): ([u8; 32], [u8; 32], u64),
) {
assert_eq!(fs::read(path).unwrap(), source);
let expected_digest: [u8; 32] = Sha256::digest(source).into();
assert_eq!(source_digest, expected_digest);
assert_eq!(derived_digest, expected_digest);
assert_eq!(bytes, 4);
fs::remove_file(path).unwrap();
}
#[cfg(unix)]
fn assert_raw_file_write_error() {
let Ok(file) = fs::OpenOptions::new().write(true).open("/dev/full") else {
@@ -3566,6 +3611,20 @@ mod tests {
let mut writer = BufWriter::with_capacity(0, file);
let mut reader = std::io::Cursor::new(2.5f32.to_le_bytes());
assert!(write_raw_f32_chunks(&mut reader, 0, 0, 4, &mut writer).is_err());
assert_file_reader_full_device_write_error();
}
#[cfg(unix)]
fn assert_file_reader_full_device_write_error() {
let fixture = overlay_fixture();
let source_path = fixture.directory.join("full-device-source.bin");
fs::write(&source_path, 2.5f32.to_le_bytes()).unwrap();
let mut reader = File::open(source_path).unwrap();
let Ok(file) = fs::OpenOptions::new().write(true).open("/dev/full") else {
return;
};
let mut writer = BufWriter::with_capacity(0, file);
assert!(write_raw_f32_chunks(&mut reader, 0, 0, 4, &mut writer).is_err());
}
#[cfg(unix)]
@@ -4107,6 +4166,57 @@ mod tests {
assert!(prepare_one_shard_with_open(request, &mut state, reject_source_open).is_err());
}
#[test]
fn legacy_shard_preparation_reports_malformed_index() {
let fixture = overlay_fixture();
let identity =
derived_mixed::fingerprint_shards(&fixture.manifest, &fixture.directory).unwrap();
let shard = &identity.shards[0];
let staging = StagingDir::create(&fixture.directory.join("malformed-legacy.kar")).unwrap();
fs::write(fixture.directory.join(&shard.name), b"malformed GGUF").unwrap();
let request = malformed_shard_request(&fixture, &identity, shard, &staging);
let mut state = ShardedPrepareState::new(identity.tensors.len());
let error = prepare_one_shard_with_open(request, &mut state, open_shard_file).unwrap_err();
assert!(!error.is_empty());
}
#[test]
fn streamed_shard_preparation_reports_malformed_index() {
let fixture = overlay_fixture();
let identity =
derived_mixed::fingerprint_shards(&fixture.manifest, &fixture.directory).unwrap();
let parts = stream_parts::plan_shards(&identity, &fixture.directory).unwrap();
let shard = shard_identity(&identity.shards[0]);
let archive = fixture.directory.join("malformed-index.kar");
let request = shard_prepare_request(&fixture.manifest, &fixture.directory, &archive);
let mut preparation = StreamPreparation::new(
request,
identity,
parts,
StagingDir::create(&archive).unwrap(),
);
fs::write(fixture.directory.join(&shard.name), b"malformed GGUF").unwrap();
let error = preparation
.prepare_shard_with_open(&shard, open_shard_file)
.unwrap_err();
assert!(!error.is_empty());
}
fn malformed_shard_request<'a>(
fixture: &'a OverlayFixture,
identity: &'a derived_mixed::ShardedIdentity,
shard: &'a derived_mixed::ShardIdentity,
staging: &'a StagingDir,
) -> ShardedShardRequest<'a> {
ShardedShardRequest {
identity,
shard,
source_dir: &fixture.directory,
staging,
levels: 2,
}
}
fn assert_post_index_open_error(
preparation: &mut StreamPreparation<'_>,
shard: &derived_mixed::ShardIdentity,