package external import ( "io" "os" "path/filepath" "testing" "git.hypertheory-labs.dev/loom/loom-cli/internal/lock" ) // apply used to write the staged record verbatim, and a staged record carried no // visibility — so every update silently dropped a column the lock header says is // recorded because access is checked once and the copy is durable. func TestApplyDoesNotDropVisibility(t *testing.T) { root := t.TempDir() locks, _ := lock.LoadFile(lock.Path(root)) locks.Put(lock.Record{Path: "h/o/r/d.md", URL: "https://h/d", ETag: `"old"`, Visibility: lock.NotPublic}) if err := locks.Save(); err != nil { t.Fatal(err) } // A polad staged by a build that did not record visibility. if err := stage(root, "h/o/r/d.md", []byte("new"), lock.Record{ Path: "h/o/r/d.md", URL: "https://h/d", ETag: `"new"`, }); err != nil { t.Fatal(err) } if err := Apply(root, nil, io.Discard); err != nil { t.Fatal(err) } after, _ := lock.Load(root) got, ok := after.Get("h/o/r/d.md") if !ok { t.Fatal("record vanished") } if got.ETag != `"new"` { t.Errorf("etag = %q, want the staged one", got.ETag) } if got.Visibility != lock.NotPublic { t.Errorf("visibility = %q, want it preserved as %q", got.Visibility, lock.NotPublic) } if b, err := os.ReadFile(filepath.Join(root, lock.Dir, "h/o/r/d.md")); err != nil || string(b) != "new" { t.Errorf("applied content = %q, %v", b, err) } }