Files
minstrel/internal/sync/changes_test.go
T
bvandeusenandClaude Opus 5.5 58fb2bbe9d
release / go (push) Successful in 1m56s
release / web (push) Successful in 1m18s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m0s
release / android (push) Successful in 4m20s
release / Build signed APK (push) Successful in 4m52s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 25s
release / Verify release artifacts (tag releases only) (push) Skipped
refactor: drop code nothing calls, and the sync log rows no app reads (#8002)
- library.ProbeDurationMs and IsAudioFile, and db.MigrationsFS, had no
  callers.
- The delta sync logged and hydrated like and playlist changes on every
  like, playlist edit and duplicate merge, including a GetPlaylistsByIDs
  query per sync. Android applies only artists, albums and tracks, and
  the web doesn't sync; likes and playlists reach both through their own
  endpoints and live events. The like and playlist-entry deletes also
  went to every caller unscoped, user ids included. They are no longer
  written or served, and migration 0112 clears the rows already logged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 12:52:35 -05:00

52 lines
1.4 KiB
Go

package sync_test
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
"git.fabledsword.com/bvandeusen/minstrel/internal/dbtest"
"git.fabledsword.com/bvandeusen/minstrel/internal/sync"
)
func TestLogChange_WritesRowInTx(t *testing.T) {
pool := dbtest.Pool(t)
ctx := context.Background()
tx, err := pool.Begin(ctx)
require.NoError(t, err)
defer func() { _ = tx.Rollback(ctx) }()
require.NoError(t, sync.LogChange(ctx, tx, sync.EntityArtist, "artist-123", sync.OpUpsert))
require.NoError(t, tx.Commit(ctx))
q := dbq.New(pool)
rows, err := q.GetLibraryChangesSince(ctx, dbq.GetLibraryChangesSinceParams{ID: 0, Limit: 10})
require.NoError(t, err)
require.NotEmpty(t, rows)
last := rows[len(rows)-1]
require.Equal(t, "artist", last.EntityType)
require.Equal(t, "artist-123", last.EntityID)
require.Equal(t, "upsert", last.Op)
}
func TestLogChange_RollbackDoesNotPersist(t *testing.T) {
pool := dbtest.Pool(t)
ctx := context.Background()
q := dbq.New(pool)
cursorBefore, err := q.GetMaxLibraryChangeCursor(ctx)
require.NoError(t, err)
tx, err := pool.Begin(ctx)
require.NoError(t, err)
require.NoError(t, sync.LogChange(ctx, tx, sync.EntityAlbum, "album-456", sync.OpDelete))
require.NoError(t, tx.Rollback(ctx))
cursorAfter, err := q.GetMaxLibraryChangeCursor(ctx)
require.NoError(t, err)
require.Equal(t, cursorBefore, cursorAfter, "rollback must not advance cursor")
}