package appbackup import ( "path/filepath" "testing" ) // A1 — TestR102_PathWrappersAreByteIdenticalToToday. // // R-102 Part 1.1 split each unit path helper into a unit-directory-relative primitive plus a thin // `(nsRoot, stackName)` wrapper. The refactor's whole claim is ZERO behaviour change, and the only // honest way to pin that is to compare each wrapper against the literal string it produced before the // split — written out here by hand, not re-derived from the helpers under test (a test that called // UnitComposeDir to compute its own expectation would pass for any consistent pair of wrong joins). // // Red-proof (recorded in REPORT.md): change one wrapper's join — e.g. UnitComposeDir to "compose2" — // and this test fails. func TestR102_PathWrappersAreByteIdenticalToToday(t *testing.T) { cases := []struct { nsRoot string stack string }{ {"/mnt/hdd1", "docmost"}, {"/mnt/sys_drive/felhom-data", "immich"}, {"/mnt/felhom-usb", "paperless-ngx"}, } for _, c := range cases { unit := c.nsRoot + "/backups/primary/" + c.stack if got, want := RecoveryUnitPath(c.nsRoot, c.stack), unit; got != want { t.Errorf("RecoveryUnitPath(%q,%q) = %q, want %q", c.nsRoot, c.stack, got, want) } if got, want := RecoveryUnitComposePath(c.nsRoot, c.stack), unit+"/compose"; got != want { t.Errorf("RecoveryUnitComposePath(%q,%q) = %q, want %q", c.nsRoot, c.stack, got, want) } if got, want := RecoveryUnitManifestPath(c.nsRoot, c.stack), unit+"/manifest.json"; got != want { t.Errorf("RecoveryUnitManifestPath(%q,%q) = %q, want %q", c.nsRoot, c.stack, got, want) } if got, want := AppDBDumpPath(c.nsRoot, c.stack), unit+"/db-dumps"; got != want { t.Errorf("AppDBDumpPath(%q,%q) = %q, want %q", c.nsRoot, c.stack, got, want) } if got, want := AppVolumeDumpPath(c.nsRoot, c.stack), unit+"/volume-dumps"; got != want { t.Errorf("AppVolumeDumpPath(%q,%q) = %q, want %q", c.nsRoot, c.stack, got, want) } } } // TestR102_UnitHelpersAreDirectoryRelative pins the OTHER half of the contract: the four primitives // join onto whatever directory they are handed, with no `primary` segment reintroduced. The secondary // mirror path below is the exact shape Tier-2 writes (tier2.go: `/backups/secondary// // recovery-unit`), so a regression that re-derived a namespace root would show up here as a `primary` // appearing in a secondary path. func TestR102_UnitHelpersAreDirectoryRelative(t *testing.T) { unit := "/mnt/hdd2/backups/secondary/docmost/recovery-unit" checks := []struct { name string got string want string }{ {"UnitComposeDir", UnitComposeDir(unit), unit + "/compose"}, {"UnitManifestFile", UnitManifestFile(unit), unit + "/manifest.json"}, {"UnitDBDumpDir", UnitDBDumpDir(unit), unit + "/db-dumps"}, {"UnitVolumeDumpDir", UnitVolumeDumpDir(unit), unit + "/volume-dumps"}, } for _, c := range checks { if c.got != c.want { t.Errorf("%s(%q) = %q, want %q", c.name, unit, c.got, c.want) } if filepath.Base(filepath.Dir(c.got)) == "primary" { t.Errorf("%s reintroduced a primary segment: %q", c.name, c.got) } } }