From d2482e20dd2f0c7c779a4e3a42d4a1a0f9c889eb Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Mon, 10 Aug 2026 11:19:05 -0400 Subject: [PATCH] Stabilize identity replacement tests --- internal/filesystem/revalidate_test.go | 5 +++-- internal/reconcile/precondition_test.go | 7 ++++--- internal/reconcile/source_snapshot_test.go | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/filesystem/revalidate_test.go b/internal/filesystem/revalidate_test.go index 523eda9..5e2706c 100644 --- a/internal/filesystem/revalidate_test.go +++ b/internal/filesystem/revalidate_test.go @@ -26,8 +26,9 @@ func testStaleIdentity(t *testing.T) { path := filepath.Join(root, "target") must(t, os.WriteFile(path, []byte("value=1"), 0o600)) facts := mustCapture(t, path) - must(t, os.Remove(path)) - must(t, os.WriteFile(path, []byte("value=1"), 0o600)) + replacement := filepath.Join(root, "replacement") + must(t, os.WriteFile(replacement, []byte("value=1"), 0o600)) + must(t, os.Rename(replacement, path)) mustFail(t, facts.Revalidate()) } diff --git a/internal/reconcile/precondition_test.go b/internal/reconcile/precondition_test.go index ada8c55..16c7404 100644 --- a/internal/reconcile/precondition_test.go +++ b/internal/reconcile/precondition_test.go @@ -119,10 +119,11 @@ func testPreconditionIdentityReplacement(t *testing.T) { path := filepath.Join(root, "file") mustTargetFile(t, path, []byte("x")) first := captureAt(t, root, "file") - if err := os.Remove(path); err != nil { - t.Fatalf("remove target: %v", err) + replacement := filepath.Join(root, "replacement") + mustTargetFile(t, replacement, []byte("x")) + if err := os.Rename(replacement, path); err != nil { + t.Fatalf("replace target: %v", err) } - mustTargetFile(t, path, []byte("x")) second := captureAt(t, root, "file") if pathsafe.SameIdentity(first.Identity(), second.Identity()) { t.Fatal("an identical-content replacement must still expose a new object identity") diff --git a/internal/reconcile/source_snapshot_test.go b/internal/reconcile/source_snapshot_test.go index bed6aae..c071f10 100644 --- a/internal/reconcile/source_snapshot_test.go +++ b/internal/reconcile/source_snapshot_test.go @@ -134,10 +134,11 @@ func testSourceReplacement(t *testing.T) { if err != nil { t.Fatal(err) } - if err := os.Remove(path); err != nil { + replacement := filepath.Join(root, "replacement") + writeSource(t, replacement, []byte("same")) + if err := os.Rename(replacement, path); err != nil { t.Fatal(err) } - writeSource(t, path, []byte("same")) second, err := CaptureSource(managedSource(path, "file", deployment.FileOrdinary), nil) if err != nil { t.Fatal(err) -- 2.51.2