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.
60 lines
1.9 KiB
Go
60 lines
1.9 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"
|
|
)
|
|
|
|
// Repro for audit finding: device B's device-local exclude drops a shared file
|
|
// from the pushed head, and device A's next pull deletes it from disk.
|
|
func TestReproPushDropsLocallyExcludedFile(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()
|
|
|
|
// A publishes data.bin + app.txt.
|
|
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 share with a device-local exclude for data.bin and syncs.
|
|
rootB := t.TempDir()
|
|
igB, err := LoadIgnoreWith(rootB, []string{"data.bin"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, _, err := Sync(B, rootB, "s", "", "", "bob", 2, igB, guard, nil); err != nil {
|
|
t.Fatalf("B sync: %v", err)
|
|
}
|
|
|
|
// A pulls the new head. If push dropped data.bin from the head, A deletes it.
|
|
pr, err := Pull(A, rootA, "s", "", snapA, "alice", 3, igEmpty, guard, nil)
|
|
if err != nil {
|
|
t.Fatalf("A pull: %v", err)
|
|
}
|
|
t.Logf("A pull result: written=%v deleted=%v conflicts=%v", pr.Written, pr.Deleted, pr.Conflicts)
|
|
if _, err := os.Stat(filepath.Join(rootA, "data.bin")); os.IsNotExist(err) {
|
|
t.Fatalf("CONFIRMED: A's data.bin was deleted by B's device-local exclude (deleted=%v)", pr.Deleted)
|
|
}
|
|
}
|