Skip to content

Commit a0d5680

Browse files
test(migrate): use valid branch metadata fixtures
1 parent d622fd1 commit a0d5680

2 files changed

Lines changed: 19 additions & 34 deletions

File tree

tests/core_cli_suite/cli_non_interactive_test.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,7 @@ fn write_profile_sharded_fixture(home: &std::path::Path, project: &std::path::Pa
234234
.unwrap();
235235
std::fs::write(shard_root.join("tracedecay.db"), b"profile graph").unwrap();
236236
std::fs::write(shard_root.join("sessions.db"), b"sessions").unwrap();
237-
std::fs::write(
238-
shard_root.join("branch-meta.json"),
239-
r#"{"default_branch":"main","branches":{}}"#,
240-
)
241-
.unwrap();
237+
write_branch_meta(&shard_root, &[], false);
242238
let manifest = StoreManifest {
243239
schema_version: STORE_MANIFEST_SCHEMA_VERSION,
244240
project_id: Some("proj_cli".to_string()),
@@ -1967,11 +1963,7 @@ fn migrate_cleanup_sources_removes_source_artifacts_but_preserves_enrollment_mar
19671963
std::fs::create_dir_all(&target_root).unwrap();
19681964
std::fs::write(&source_graph, b"graph").unwrap();
19691965
std::fs::write(target_root.join("tracedecay.db"), b"graph").unwrap();
1970-
std::fs::write(
1971-
target_root.join("branch-meta.json"),
1972-
r#"{"default_branch":"main","branches":{}}"#,
1973-
)
1974-
.unwrap();
1966+
write_branch_meta(&target_root, &[], false);
19751967
let store_manifest = StoreManifest {
19761968
schema_version: STORE_MANIFEST_SCHEMA_VERSION,
19771969
project_id: Some("proj_cli".to_string()),

tests/storage_suite/migration_manifest_test.rs

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::common::sample_node;
66
#[cfg(unix)]
77
use std::os::unix::fs::symlink;
88
use tempfile::TempDir;
9+
use tracedecay::branch_meta::BranchMeta;
910
use tracedecay::global_db::GlobalDb;
1011
use tracedecay::lifecycle_lease::acquire_exclusive_for_profile;
1112
use tracedecay::migrate::inventory::{
@@ -48,6 +49,14 @@ fn canonical_temp_path(path: &Path) -> PathBuf {
4849
path.canonicalize().unwrap_or_else(|_| path.to_path_buf())
4950
}
5051

52+
fn write_valid_branch_meta(path: &Path) {
53+
fs::write(
54+
path,
55+
serde_json::to_vec_pretty(&BranchMeta::new("main")).unwrap(),
56+
)
57+
.unwrap();
58+
}
59+
5160
#[cfg(unix)]
5261
#[test]
5362
fn save_manifest_rejects_symlinked_parent_components() {
@@ -390,11 +399,7 @@ fn verify_manifest_validates_profile_store_manifest_registry_records() {
390399
fs::create_dir_all(&data_root).unwrap();
391400
fs::write(data_root.join("tracedecay.db"), b"graph").unwrap();
392401
fs::write(data_root.join("sessions.db"), b"sessions").unwrap();
393-
fs::write(
394-
data_root.join("branch-meta.json"),
395-
r#"{"default_branch":"main","branches":{}}"#,
396-
)
397-
.unwrap();
402+
write_valid_branch_meta(&data_root.join("branch-meta.json"));
398403
let store_manifest = StoreManifest {
399404
schema_version: STORE_MANIFEST_SCHEMA_VERSION,
400405
project_id: Some("proj_123".to_string()),
@@ -492,11 +497,7 @@ async fn verify_manifest_accepts_logically_equal_sqlite_artifacts_with_different
492497
target.close();
493498
assert_ne!(fs::read(&source_db).unwrap(), fs::read(&target_db).unwrap());
494499

495-
fs::write(
496-
data_root.join("branch-meta.json"),
497-
r#"{"default_branch":"main","branches":{}}"#,
498-
)
499-
.unwrap();
500+
write_valid_branch_meta(&data_root.join("branch-meta.json"));
500501
fs::write(data_root.join("sessions.db"), b"sessions").unwrap();
501502
let store_manifest = StoreManifest {
502503
schema_version: STORE_MANIFEST_SCHEMA_VERSION,
@@ -578,7 +579,7 @@ fn apply_migration_manifest_stops_at_verified_before_cutover() {
578579
fs::create_dir_all(&data_dir).unwrap();
579580
fs::write(&graph_db, b"graph").unwrap();
580581
fs::write(&sessions_db, b"sessions").unwrap();
581-
fs::write(&branch_meta, r#"{"default_branch":"main","branches":{}}"#).unwrap();
582+
write_valid_branch_meta(&branch_meta);
582583
let mut manifest = build_plan_manifest(
583584
MigrationInventory {
584585
stores: vec![StoreInventory {
@@ -604,7 +605,7 @@ fn apply_migration_manifest_stops_at_verified_before_cutover() {
604605
StoreArtifact {
605606
kind: "branch_meta".to_string(),
606607
path: branch_meta.clone(),
607-
size_bytes: 39,
608+
size_bytes: fs::metadata(&branch_meta).unwrap().len(),
608609
},
609610
],
610611
}],
@@ -649,11 +650,7 @@ fn finalize_migration_apply_marks_cutover_complete() {
649650
let profile_root = root.join("profile");
650651
fs::create_dir_all(&data_dir).unwrap();
651652
fs::write(&graph_db, b"graph").unwrap();
652-
fs::write(
653-
data_dir.join("branch-meta.json"),
654-
r#"{"default_branch":"main","branches":{}}"#,
655-
)
656-
.unwrap();
653+
write_valid_branch_meta(&data_dir.join("branch-meta.json"));
657654
let mut manifest = build_plan_manifest(
658655
MigrationInventory {
659656
stores: vec![StoreInventory {
@@ -944,7 +941,7 @@ fn migrate_apply_copies_single_store_and_cuts_over_profile_shard() {
944941
fs::create_dir_all(&data_dir).unwrap();
945942
fs::write(&graph_db, b"graph").unwrap();
946943
fs::write(&sessions_db, b"sessions").unwrap();
947-
fs::write(&branch_meta, r#"{"default_branch":"main","branches":{}}"#).unwrap();
944+
write_valid_branch_meta(&branch_meta);
948945
let manifest = build_plan_manifest(
949946
MigrationInventory {
950947
stores: vec![StoreInventory {
@@ -970,7 +967,7 @@ fn migrate_apply_copies_single_store_and_cuts_over_profile_shard() {
970967
StoreArtifact {
971968
kind: "branch_meta".to_string(),
972969
path: branch_meta.clone(),
973-
size_bytes: 39,
970+
size_bytes: fs::metadata(&branch_meta).unwrap().len(),
974971
},
975972
],
976973
}],
@@ -1185,11 +1182,7 @@ fn migrate_reconstruct_reports_registry_plans_without_applying_them() {
11851182
fs::create_dir_all(&project).unwrap();
11861183
fs::create_dir_all(&data_root).unwrap();
11871184
fs::write(data_root.join("tracedecay.db"), b"graph").unwrap();
1188-
fs::write(
1189-
data_root.join("branch-meta.json"),
1190-
r#"{"default_branch":"main","branches":{}}"#,
1191-
)
1192-
.unwrap();
1185+
write_valid_branch_meta(&data_root.join("branch-meta.json"));
11931186
let store_manifest = StoreManifest {
11941187
schema_version: STORE_MANIFEST_SCHEMA_VERSION,
11951188
project_id: Some("proj_123".to_string()),

0 commit comments

Comments
 (0)