devbox/internal/syncer/push_delete_test.go
shoemoney 764d7d9a16 fix: push carries forward locally-excluded paths instead of deleting them 🩹
Push always treated the local .devignore/secret-guard-filtered manifest as
the FULL shared head, even on a whole-share mount — so a device with its own
--exclude for a path silently deleted that path from every other device's
copy on their next pull.

splice() now merges local entries over the parent head instead of the parent
head being consulted only for sub-path mounts: a parent-head path missing
from the local manifest is carried forward when the local ignore rules are
why it's invisible (excluded from view, not deleted). It is NOT carried
forward when the secret guard blocked it (the guard's job is to keep that
content out of the head) or when it's genuinely gone from disk with no
ignore rule hiding it (a real delete must still delete).

under()/strip() already treat subpath="" as "the whole path space," so this
is one code path for both mount kinds, not a special case bolted onto the
old one.

Includes the two repro tests (deduped from a near-copy) and a new delete-case
regression proving the fix didn't make real deletes un-deletable.
2026-08-05 02:34:38 -05:00

63 lines
2 KiB
Go

package syncer
import (
"net/http/httptest"
"os"
"path/filepath"
"testing"
"github.com/shoemoney/devbox/internal/hub"
"github.com/shoemoney/devbox/internal/hub/blobstore"
"github.com/shoemoney/devbox/internal/hub/meta"
"github.com/shoemoney/devbox/internal/secret"
)
// Companion to the locally-excluded-file preserve case: a path that's genuinely
// gone from disk (no .devignore rule hides it — the user just deleted it) must
// still delete on push. The carry-forward fix for excluded paths must not make
// real deletes un-deletable.
func TestPushRealDeletePropagates(t *testing.T) {
db, _ := meta.Open(":memory:")
defer db.Close()
store, _ := blobstore.NewDisk(t.TempDir())
srv := httptest.NewServer(hub.NewServer(db, store).Handler())
defer srv.Close()
guard, _ := secret.New(nil)
igEmpty, _ := LoadIgnore(t.TempDir())
A := joinDevice(t, db, srv.URL, "alice")
B := joinDevice(t, db, srv.URL, "bob")
if err := A.Publish("s"); err != nil {
t.Fatal(err)
}
rootA := t.TempDir()
writeFile(t, rootA, "data.bin", "precious\n")
writeFile(t, rootA, "app.txt", "x\n")
snapA, _, err := Sync(A, rootA, "s", "", "", "alice", 1, igEmpty, guard, nil)
if err != nil {
t.Fatalf("A sync: %v", err)
}
// B mounts the whole share (no exclude), then genuinely deletes data.bin.
rootB := t.TempDir()
baseB, _, err := Sync(B, rootB, "s", "", "", "bob", 2, igEmpty, guard, nil)
if err != nil {
t.Fatalf("B initial sync: %v", err)
}
if err := os.Remove(filepath.Join(rootB, "data.bin")); err != nil {
t.Fatalf("B delete: %v", err)
}
if _, _, err := Sync(B, rootB, "s", "", baseB, "bob", 3, igEmpty, guard, nil); err != nil {
t.Fatalf("B sync after delete: %v", err)
}
// A pulls: the real delete must land, unlike the excluded-file case.
pr, err := Pull(A, rootA, "s", "", snapA, "alice", 4, igEmpty, guard, nil)
if err != nil {
t.Fatalf("A pull: %v", err)
}
if _, err := os.Stat(filepath.Join(rootA, "data.bin")); !os.IsNotExist(err) {
t.Fatalf("B's genuine delete did not propagate to A: deleted=%v", pr.Deleted)
}
}