release / go (push) Successful in 2m7s
release / web (push) Successful in 1m25s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 4m30s
release / android (push) Successful in 4m39s
release / Build signed APK (push) Successful in 5m10s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
- Module path: github.com/Fabled-Sword/minstrel, in go.mod, every import and the Dockerfile's version ldflags. - buildinfo.ProjectURL, the contact outside services see in Minstrel's User-Agent: https://github.com/Fabled-Sword/minstrel. - README's compose example pulls ghcr.io/fabled-sword/minstrel:latest. - docs/security.md sends problem reports to the GitHub issues. - The demo-library stack builds Minstrel from the checkout, since :dev is not published to GHCR. - hygiene.go's same-site example uses example.com names. The workbench CI (.gitea/, ci/, export-ignored) still builds and publishes :dev to the private registry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
61 lines
2.5 KiB
Go
61 lines
2.5 KiB
Go
package sync_test
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"log/slog"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/Fabled-Sword/minstrel/internal/dbtest"
|
|
"github.com/Fabled-Sword/minstrel/internal/sync"
|
|
)
|
|
|
|
// The compactor keeps each entity's latest change however old, so an app
|
|
// syncing from 0 still gets an artist nobody has touched in months. It drops
|
|
// what a newer row supersedes, and deletes past their retention, raising the
|
|
// trimmed mark past the newest delete it dropped.
|
|
func TestCompact_KeepsEachEntitysLatestChange_Integration(t *testing.T) {
|
|
pool := dbtest.Pool(t)
|
|
ctx := context.Background()
|
|
old := time.Now().Add(-90 * 24 * time.Hour)
|
|
recent := time.Now().Add(-time.Hour)
|
|
|
|
add := func(entity, op string, at time.Time) int64 {
|
|
t.Helper()
|
|
var id int64
|
|
require.NoError(t, pool.QueryRow(ctx, `INSERT INTO library_changes (entity_type, entity_id, op, changed_at)
|
|
VALUES ('artist', $1, $2, $3) RETURNING id`, entity, op, at).Scan(&id))
|
|
return id
|
|
}
|
|
untouched := add("untouched", "upsert", old) // kept: latest, however old
|
|
add("edited", "upsert", old) // dropped: superseded
|
|
edited := add("edited", "upsert", recent) // kept
|
|
add("removed-long-ago", "upsert", old) // dropped: superseded
|
|
removedLongAgo := add("removed-long-ago", "delete", old) // dropped: past retention
|
|
add("removed-lately", "upsert", old) // dropped: superseded
|
|
removedLately := add("removed-lately", "delete", recent) // kept: within retention
|
|
|
|
require.NoError(t, sync.Compact(ctx, pool, time.Now().Add(-sync.CompactorRetention),
|
|
slog.New(slog.NewTextHandler(io.Discard, nil))))
|
|
|
|
rows, err := pool.Query(ctx, `SELECT id FROM library_changes ORDER BY id`)
|
|
require.NoError(t, err)
|
|
left, err := pgx.CollectRows(rows, pgx.RowTo[int64])
|
|
require.NoError(t, err)
|
|
require.Equal(t, []int64{untouched, edited, removedLately}, left)
|
|
|
|
var through int64
|
|
require.NoError(t, pool.QueryRow(ctx, `SELECT through FROM library_changes_trimmed`).Scan(&through))
|
|
require.Equal(t, removedLongAgo, through, "the trimmed mark stands at the newest dropped delete")
|
|
|
|
// A second pass finds nothing more, and leaves the mark where it is.
|
|
require.NoError(t, sync.Compact(ctx, pool, time.Now().Add(-sync.CompactorRetention),
|
|
slog.New(slog.NewTextHandler(io.Discard, nil))))
|
|
require.NoError(t, pool.QueryRow(ctx, `SELECT through FROM library_changes_trimmed`).Scan(&through))
|
|
require.Equal(t, removedLongAgo, through)
|
|
}
|