Remove the organizer's Preview and apply section

The preview/apply flow on the Organize tab did not work as expected, so
it is removed along with its backend: the stored per-pair preview, the
/organize/preview, /organize/plan and /organize/apply endpoints and
their UI and types.

The File naming card stays, and renaming now happens only through
"Organize automatically" during scans, which keeps the underlying
planning/moving code (now internal), undo, crash recovery and dry run.
The rename-folders warning is unchanged. Tests now drive the kept
planning and moving code directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cdnutterandClaude Opus 5.5 committed 2026-09-29 13:18:40 -07:00
1 parent dbcf562f7e
commit 96ea856dfd
8 files changed
+76 -462

No files matched your search

+34 -25
View File
@@ -60,14 +60,34 @@ func mkTagged(t *testing.T, path string, kv ...string) {
}
}
func (ev *env) organize(t *testing.T, side string) (*OrganizePlan, []OrganizeItem) {
// plan and apply run the same code as automatic organizing.
func (ev *env) plan(t *testing.T, sides ...string) *organizePlan {
t.Helper()
if _, err := ev.e.StartOrganizePlan(ev.pair.ID, side); err != nil {
l, err := ev.e.loadPair(ctx, ev.pair.ID)
if err != nil {
t.Fatal(err)
}
ev.wait()
plan, items, _ := ev.e.OrganizePlanFor(ev.pair.ID, "", 0, 1000)
return plan, items
p, err := ev.e.planOrganize(ctx, &Job{e: ev.e, Results: map[string]int{}}, l, sides)
if err != nil {
t.Fatal(err)
}
return p
}
func (ev *env) apply(t *testing.T, p *organizePlan) *Job {
t.Helper()
l, _ := ev.e.loadPair(ctx, ev.pair.ID)
j := &Job{e: ev.e, Results: map[string]int{}}
var moves []organizeItem
for _, it := range p.Items {
if it.Move {
moves = append(moves, it)
}
}
if err := ev.e.applyOrganize(ctx, j, l, moves, "test"); err != nil {
t.Fatal(err)
}
return j
}
func TestOrganizeSlaveLibrary(t *testing.T) {
@@ -84,17 +104,14 @@ func TestOrganizeSlaveLibrary(t *testing.T) {
mkTagged(t, filepath.Join(s, "dupes/a.mp3"), "title", "Same", "artist", "X", "album", "Y", "track", "1")
mkTagged(t, filepath.Join(s, "dupes/b.mp3"), "title", "Same", "artist", "X", "album", "Y", "track", "1")
plan, items := ev.organize(t, SideSlave)
plan := ev.plan(t, SideSlave)
if plan.Conforming != 1 || plan.Moves != 2 {
t.Fatalf("want 1 conforming and 2 moves, got %+v %+v", plan, items)
t.Fatalf("want 1 conforming and 2 moves, got %+v", plan)
}
if plan.Skips["missing artist or album artist tag"] != 1 || len(plan.Skips) != 2 {
t.Fatalf("unexpected skips %+v", plan.Skips)
}
if _, err := ev.e.StartOrganizeApply(ev.pair.ID, nil); err != nil {
t.Fatal(err)
}
j := ev.wait()
j := ev.apply(t, plan)
if j.Results["renamed"] != 2 {
t.Fatalf("apply: %+v %v", j.Results, j.Skipped)
}
@@ -139,11 +156,8 @@ func TestOrganizeKeepsHardlinks(t *testing.T) {
if got := ev.match("Chris Picks/Nightmare.flac"); got.Status != store.StatusLinked || got.Kind != store.KindInode {
t.Fatalf("a hardlink at another path should be recognised, got %s/%s", got.Status, got.Kind)
}
ev.organize(t, SideSlave)
if _, err := ev.e.StartOrganizeApply(ev.pair.ID, nil); err != nil {
t.Fatal(err)
}
ev.wait()
ev.apply(t, ev.plan(t, SideSlave))
ev.scan()
moved := filepath.Join(ev.slave, "Avenged Sevenfold/Nightmare/01 Nightmare.flac")
if !sameInode(t, m, moved) {
t.Fatal("the moved slave file must still be the master's file")
@@ -157,11 +171,7 @@ func TestOrganizeDryRunAndChangedFile(t *testing.T) {
ev := tagEnv(t, true)
p := filepath.Join(ev.slave, "x/song.mp3")
mkTagged(t, p, "title", "Song", "artist", "A", "album", "B", "track", "1")
ev.organize(t, SideSlave)
if _, err := ev.e.StartOrganizeApply(ev.pair.ID, nil); err != nil {
t.Fatal(err)
}
if j := ev.wait(); j.Results["renamed"] != 1 {
if j := ev.apply(t, ev.plan(t, SideSlave)); j.Results["renamed"] != 1 {
t.Fatalf("dry run should plan the rename: %+v", j.Results)
}
if _, err := os.Stat(p); err != nil {
@@ -169,11 +179,10 @@ func TestOrganizeDryRunAndChangedFile(t *testing.T) {
}
ev.st.SetSetting(ctx, "dry_run", "0")
ev.organize(t, SideSlave)
plan := ev.plan(t, SideSlave)
mkTagged(t, p, "title", "Song", "artist", "A", "album", "B", "track", "1", "genre", "changed")
ev.e.StartOrganizeApply(ev.pair.ID, nil)
if j := ev.wait(); j.Results["renamed"] != 0 || j.Results["skipped"] != 1 {
t.Fatalf("a file changed after the preview must be skipped: %+v", j.Results)
if j := ev.apply(t, plan); j.Results["renamed"] != 0 || j.Results["skipped"] != 1 {
t.Fatalf("a file changed after planning must be skipped: %+v", j.Results)
}
}