Skip to content

Commit f0fcf9b

Browse files
ticpuclaude
andcommitted
test: replace ineffective dot-slash tests with key consistency test
The tar crate's entry.path() normalizes "./" prefixes away, so the with_dot_slash_prefix() builder had no effect — tests passed with both old and new code. Replace with a test that feeds a "./" prefixed path directly into read_pathname, then verifies the stored key matches what process_orphaned_assets would look up in Pass 2. Fails without PR #7, passes with it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4ab371b commit f0fcf9b

1 file changed

Lines changed: 34 additions & 99 deletions

File tree

src/archive_operations.rs

Lines changed: 34 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ mod tests {
434434
/// Test utility for building Unity package archives with various asset types
435435
pub struct TestUnityPackageBuilder {
436436
entries: Vec<TestEntry>,
437-
path_prefix: String,
438437
}
439438

440439
#[derive(Clone)]
@@ -461,16 +460,9 @@ mod tests {
461460
pub fn new() -> Self {
462461
Self {
463462
entries: Vec::new(),
464-
path_prefix: String::new(),
465463
}
466464
}
467465

468-
/// Use "./" prefix on tar entry paths, matching real Unity packages
469-
pub fn with_dot_slash_prefix(mut self) -> Self {
470-
self.path_prefix = "./".to_string();
471-
self
472-
}
473-
474466
/// Add a folder asset (only .meta file with folderAsset: yes, no asset file)
475467
pub fn add_folder_asset(mut self, guid: &str, pathname: &str) -> Self {
476468
self.entries.push(TestEntry::FolderAsset {
@@ -533,11 +525,10 @@ mod tests {
533525
let gz_encoder = GzEncoder::new(&mut gz_buffer, Compression::default());
534526
let mut tar_builder = Builder::new(gz_encoder);
535527

536-
let pfx = &self.path_prefix;
537528
for entry in &self.entries {
538529
match entry {
539530
TestEntry::Asset { guid, data } => {
540-
add_tar_entry(&mut tar_builder, &format!("{pfx}{guid}/asset"), data);
531+
add_tar_entry(&mut tar_builder, &format!("{guid}/asset"), data);
541532
}
542533
TestEntry::FolderAsset { guid } => {
543534
let meta_content = format!(
@@ -553,7 +544,7 @@ DefaultImporter:
553544
);
554545
add_tar_entry(
555546
&mut tar_builder,
556-
&format!("{pfx}{guid}/asset.meta"),
547+
&format!("{guid}/asset.meta"),
557548
meta_content.as_bytes(),
558549
);
559550
}
@@ -562,7 +553,7 @@ DefaultImporter:
562553
data,
563554
meta_content,
564555
} => {
565-
add_tar_entry(&mut tar_builder, &format!("{pfx}{guid}/asset"), data);
556+
add_tar_entry(&mut tar_builder, &format!("{guid}/asset"), data);
566557

567558
let default_meta = format!(
568559
r#"fileFormatVersion: 2
@@ -577,14 +568,14 @@ TextureImporter:
577568
.unwrap_or(&default_meta);
578569
add_tar_entry(
579570
&mut tar_builder,
580-
&format!("{pfx}{guid}/asset.meta"),
571+
&format!("{guid}/asset.meta"),
581572
meta.as_bytes(),
582573
);
583574
}
584575
TestEntry::Pathname { guid, path } => {
585576
add_tar_entry(
586577
&mut tar_builder,
587-
&format!("{pfx}{guid}/pathname"),
578+
&format!("{guid}/pathname"),
588579
path.as_bytes(),
589580
);
590581
}
@@ -731,95 +722,39 @@ TextureImporter:
731722
process_archive_entries(&mut archive, thread_pool, 32 * MB).unwrap()
732723
}
733724

734-
#[tokio::test]
735-
async fn test_dot_slash_prefix_pathname_before_asset() {
736-
let _cwd = TempCwd::new();
737-
let package_data = TestUnityPackageBuilder::new()
738-
.with_dot_slash_prefix()
739-
.add_orphaned_pathname(TEST_GUID, TEST_PATHNAME)
740-
.add_orphaned_asset(TEST_GUID, TEST_ASSET_DATA)
741-
.build();
742-
743-
let (thread_pool, _) = make_thread_pool();
744-
let result = process_package(package_data, &thread_pool);
745-
746-
assert!(!result.context.has_orphaned_work());
747-
748-
thread_pool.shutdown().await;
749-
}
750-
751-
#[tokio::test]
752-
async fn test_dot_slash_prefix_asset_before_pathname() {
753-
let _cwd = TempCwd::new();
754-
let package_data = TestUnityPackageBuilder::new()
755-
.with_dot_slash_prefix()
756-
.add_asset(TEST_GUID, TEST_PATHNAME, TEST_ASSET_DATA)
757-
.build();
725+
/// Feed read_pathname a path with "./" prefix (which the tar crate
726+
/// normally strips) and verify the stored key matches what
727+
/// process_orphaned_assets would look up in Pass 2.
728+
#[test]
729+
fn test_pathname_key_matches_orphan_lookup_key() {
730+
let path_forms = [
731+
PathBuf::from("guid123/pathname"),
732+
PathBuf::from("./guid123/pathname"),
733+
];
758734

759-
let (thread_pool, _) = make_thread_pool();
760-
let result = process_package(package_data, &thread_pool);
735+
for path in &path_forms {
736+
let mut context = ExtractionContext::new(32 * MB);
761737

762-
assert!(result.context.has_orphaned_work());
763-
assert_eq!(result.context.orphaned_count(), 1);
764-
765-
// Verify the orphan's pathname can be found in Pass 2
766-
let (orphaned_assets, pathnames) = result.context.take_orphaned_data();
767-
let orphan_path = &orphaned_assets[0];
768-
let guid = orphan_path.to_string_lossy().to_string();
769-
let asset_path = PathBuf::from(&guid).join("asset");
770-
assert_eq!(
771-
pathnames.get(&asset_path).map(|s| s.as_str()),
772-
Some(TEST_PATHNAME),
773-
);
774-
775-
thread_pool.shutdown().await;
776-
}
777-
778-
#[tokio::test]
779-
async fn test_dot_slash_prefix_orphaned_asset() {
780-
let _cwd = TempCwd::new();
781-
let package_data = TestUnityPackageBuilder::new()
782-
.with_dot_slash_prefix()
783-
.add_orphaned_asset(TEST_GUID, TEST_ASSET_DATA)
784-
.build();
785-
786-
let (thread_pool, _) = make_thread_pool();
787-
let result = process_package(package_data, &thread_pool);
788-
789-
assert!(result.context.has_orphaned_work());
790-
assert_eq!(result.context.orphaned_count(), 1);
791-
792-
thread_pool.shutdown().await;
793-
}
794-
795-
#[tokio::test]
796-
async fn test_dot_slash_prefix_mixed_package() {
797-
let _cwd = TempCwd::new();
798-
let package_data = TestUnityPackageBuilder::new()
799-
.with_dot_slash_prefix()
800-
.add_folder_asset("folder1", "Assets/Scripts/")
801-
.add_asset("asset1", "Assets/TestFile.txt", TEST_ASSET_DATA)
802-
.add_orphaned_asset("orphan1", b"orphaned data")
803-
.build();
804-
805-
let (thread_pool, _) = make_thread_pool();
806-
let result = process_package(package_data, &thread_pool);
738+
let pathname_content = b"Assets/TestFile.txt";
739+
let mut tar_buf = Vec::new();
740+
{
741+
let mut builder = Builder::new(&mut tar_buf);
742+
add_tar_entry(&mut builder, "dummy", pathname_content);
743+
builder.finish().unwrap();
744+
}
745+
let mut archive = tar::Archive::new(Cursor::new(&tar_buf));
746+
let entry = archive.entries().unwrap().next().unwrap().unwrap();
807747

808-
assert!(result.context.has_orphaned_work());
809-
assert_eq!(result.context.orphaned_count(), 2);
748+
read_pathname(&mut context, entry, path.clone()).unwrap();
810749

811-
// asset1's pathname should be resolvable in Pass 2
812-
let (orphaned_assets, pathnames) = result.context.take_orphaned_data();
813-
let resolved_count = orphaned_assets
814-
.iter()
815-
.filter(|p| {
816-
let guid = p.to_string_lossy().to_string();
817-
let asset_path = PathBuf::from(&guid).join("asset");
818-
pathnames.contains_key(&asset_path)
819-
})
820-
.count();
821-
assert_eq!(resolved_count, 1);
750+
// process_orphaned_assets constructs this lookup key:
751+
let guid = extract_guid_from_path(path);
752+
let lookup_key = PathBuf::from(&guid).join("asset");
822753

823-
thread_pool.shutdown().await;
754+
assert!(
755+
context.get_pathname(&lookup_key).is_some(),
756+
"path {path:?}: Pass 2 lookup key {lookup_key:?} not found in pathnames map"
757+
);
758+
}
824759
}
825760
}

0 commit comments

Comments
 (0)