Skip to content

Commit d3055e3

Browse files
author
ScriptedAlchemy
committed
test(storage): normalize profile shard path assertions
1 parent a357bd8 commit d3055e3

3 files changed

Lines changed: 51 additions & 30 deletions

File tree

tests/core_cli_suite/cli_non_interactive_test.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,7 @@ use tracedecay::storage::{
2424
use tracedecay::tracedecay::{TraceDecay, TraceDecayOpenOptions};
2525

2626
fn canonical_temp_path(path: &Path) -> PathBuf {
27-
#[cfg(windows)]
28-
{
29-
path.to_path_buf()
30-
}
31-
#[cfg(not(windows))]
32-
{
33-
path.canonicalize().unwrap_or_else(|_| path.to_path_buf())
34-
}
27+
path.canonicalize().unwrap_or_else(|_| path.to_path_buf())
3528
}
3629

3730
fn profile_root(home: &Path) -> PathBuf {

tests/storage_suite/profile_storage_migration_test.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ fn canonical_temp_path(path: &Path) -> PathBuf {
7373
path.canonicalize().unwrap_or_else(|_| path.to_path_buf())
7474
}
7575

76+
fn normalize_test_path(path: &Path) -> String {
77+
path.to_string_lossy()
78+
.replace('\\', "/")
79+
.trim_start_matches("//?/")
80+
.to_string()
81+
}
82+
83+
fn assert_path_eq(actual: impl AsRef<Path>, expected: impl AsRef<Path>) {
84+
assert_eq!(
85+
normalize_test_path(actual.as_ref()),
86+
normalize_test_path(expected.as_ref())
87+
);
88+
}
89+
7690
fn portable_relpath(path: &str) -> String {
7791
path.replace('\\', "/")
7892
}
@@ -481,8 +495,8 @@ async fn trace_decay_init_uses_profile_shard_when_enrolled() {
481495

482496
let cg = TraceDecay::init(&project).await.unwrap();
483497

484-
assert_eq!(cg.store_layout().data_root, shard_root);
485-
assert_eq!(cg.db_path(), shard_root.join("tracedecay.db"));
498+
assert_path_eq(&cg.store_layout().data_root, &shard_root);
499+
assert_path_eq(cg.db_path(), shard_root.join("tracedecay.db"));
486500
assert!(shard_root.join("config.json").is_file());
487501
assert!(shard_root.join(STORE_MANIFEST_FILENAME).is_file());
488502
assert!(
@@ -749,8 +763,8 @@ async fn trace_decay_open_branch_uses_profile_shard_branch_db() {
749763
.await
750764
.unwrap();
751765

752-
assert_eq!(cg.store_layout().data_root, shard_root);
753-
assert_eq!(cg.db_path(), branch_db);
766+
assert_path_eq(&cg.store_layout().data_root, &shard_root);
767+
assert_path_eq(cg.db_path(), &branch_db);
754768
assert_eq!(cg.serving_branch(), Some("feature/profile"));
755769
}
756770

tests/storage_suite/storage_resolver_test.rs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ fn canonical_temp_path(path: &Path) -> PathBuf {
8080
path.canonicalize().unwrap_or_else(|_| path.to_path_buf())
8181
}
8282

83+
fn normalize_test_path(path: &Path) -> String {
84+
path.to_string_lossy()
85+
.replace('\\', "/")
86+
.trim_start_matches("//?/")
87+
.to_string()
88+
}
89+
90+
fn assert_path_eq(actual: impl AsRef<Path>, expected: impl AsRef<Path>) {
91+
assert_eq!(
92+
normalize_test_path(actual.as_ref()),
93+
normalize_test_path(expected.as_ref())
94+
);
95+
}
96+
8397
fn test_home(dir: &TempDir) -> PathBuf {
8498
let home = dir.path().join("home");
8599
fs::create_dir_all(&home).unwrap();
@@ -359,7 +373,7 @@ async fn config_path_uses_profile_shard_when_enrolled() {
359373
)
360374
.unwrap();
361375

362-
assert_eq!(get_config_path(&project), shard_root.join("config.json"));
376+
assert_path_eq(get_config_path(&project), shard_root.join("config.json"));
363377
assert_eq!(
364378
load_config(&project).unwrap().root_dir,
365379
"profile-shard-config"
@@ -377,9 +391,9 @@ async fn config_path_defaults_to_profile_shard_without_enrollment() {
377391
let _home_guard = HomeGuard::set(&home);
378392
let project_id = default_profile_project_id(&project);
379393

380-
assert_eq!(
394+
assert_path_eq(
381395
get_config_path(&project),
382-
profile_root.join(format!("projects/{project_id}/config.json"))
396+
profile_root.join(format!("projects/{project_id}/config.json")),
383397
);
384398
}
385399

@@ -555,21 +569,21 @@ async fn resolved_project_store_helpers_route_profile_sharded_session_artifacts(
555569
let _home_guard = HomeGuard::set(&home);
556570
write_enrollment(&project);
557571

558-
assert_eq!(
572+
assert_path_eq(
559573
resolve_project_session_db_path(&project).unwrap(),
560-
profile_root.join("projects/proj_123/sessions.db")
574+
profile_root.join("projects/proj_123/sessions.db"),
561575
);
562-
assert_eq!(
576+
assert_path_eq(
563577
resolve_response_handle_root(&project).unwrap(),
564-
profile_root.join("projects/proj_123/response-handles")
578+
profile_root.join("projects/proj_123/response-handles"),
565579
);
566-
assert_eq!(
580+
assert_path_eq(
567581
resolve_lcm_payload_root(&project).unwrap(),
568-
profile_root.join("projects/proj_123/lcm-payloads")
582+
profile_root.join("projects/proj_123/lcm-payloads"),
569583
);
570-
assert_eq!(
584+
assert_path_eq(
571585
project_session_db_path(&project),
572-
profile_root.join("projects/proj_123/sessions.db")
586+
profile_root.join("projects/proj_123/sessions.db"),
573587
);
574588
}
575589

@@ -584,13 +598,13 @@ async fn resolved_project_store_helpers_default_to_profile_sharded_artifact_path
584598
let _home_guard = HomeGuard::set(&home);
585599
let project_id = default_profile_project_id(&project);
586600

587-
assert_eq!(
601+
assert_path_eq(
588602
resolve_project_session_db_path(&project).unwrap(),
589-
profile_root.join(format!("projects/{project_id}/sessions.db"))
603+
profile_root.join(format!("projects/{project_id}/sessions.db")),
590604
);
591-
assert_eq!(
605+
assert_path_eq(
592606
project_session_db_path(&project),
593-
profile_root.join(format!("projects/{project_id}/sessions.db"))
607+
profile_root.join(format!("projects/{project_id}/sessions.db")),
594608
);
595609
}
596610

@@ -636,8 +650,8 @@ async fn trace_decay_init_defaults_to_profile_shard_without_repo_marker() {
636650
let cg = TraceDecay::init(&project).await.unwrap();
637651

638652
assert_eq!(cg.store_layout().storage_mode, StorageMode::ProfileSharded);
639-
assert_eq!(cg.store_layout().data_root, shard_root);
640-
assert_eq!(cg.db_path(), shard_root.join("tracedecay.db"));
653+
assert_path_eq(&cg.store_layout().data_root, &shard_root);
654+
assert_path_eq(cg.db_path(), shard_root.join("tracedecay.db"));
641655
assert_eq!(discover_project_root(&child), Some(project.clone()));
642656
assert!(!project.join(".tracedecay").exists());
643657
assert!(shard_root.join("config.json").exists());
@@ -867,7 +881,7 @@ async fn trace_decay_open_uses_profile_shard_paths_from_enrollment_marker() {
867881

868882
let opened = TraceDecay::open(&project).await.unwrap();
869883

870-
assert_eq!(opened.db_path(), shard_root.join("tracedecay.db"));
884+
assert_path_eq(opened.db_path(), shard_root.join("tracedecay.db"));
871885
assert_eq!(opened.get_config().root_dir, project.to_string_lossy());
872886
assert_eq!(opened.serving_branch(), Some("main"));
873887
}

0 commit comments

Comments
 (0)