Files
wehub-resource-sync f99010fae1
Desktop Artifacts / Desktop Build (Linux) (push) Waiting to run
Desktop Artifacts / Desktop Build (Windows) (push) Waiting to run
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Waiting to run
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Waiting to run
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Waiting to run
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:36 +08:00

75 lines
2.3 KiB
Go

package postgres
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestVectorOwnerIdentityOwns(t *testing.T) {
owner := vectorOwnerIdentity{
markerID: "marker-a",
machine: "laptop",
legacyMachines: []string{"old-laptop"},
}
tests := []struct {
name string
ownerMarker string
machine string
want bool
}{
{name: "matching marker", ownerMarker: "marker-a", machine: "other", want: true},
{name: "foreign marker", ownerMarker: "marker-b", machine: "laptop", want: false},
{name: "legacy row empty machine", machine: "", want: true},
{name: "legacy row local machine", machine: "local", want: true},
{name: "legacy row own machine", machine: "laptop", want: true},
{name: "legacy row alias machine", machine: "old-laptop", want: true},
{name: "legacy row foreign machine", machine: "other-machine", want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, owner.owns(tt.ownerMarker, tt.machine))
})
}
}
// notReadyVectorSource reports a not-ready local index, as the vectors.db
// adapter does while an embeddings build is rewriting the active generation.
type notReadyVectorSource struct{}
func (notReadyVectorSource) Generation(
context.Context,
) (VectorGenerationInfo, bool, error) {
return VectorGenerationInfo{}, false, fmt.Errorf(
"%w: 7 document(s) pending", ErrVectorSourceNotReady)
}
func (notReadyVectorSource) SessionDocHashes(
context.Context,
) (map[string]string, error) {
return nil, nil
}
func (notReadyVectorSource) SessionDocs(
context.Context, string,
) ([]VectorPushDoc, string, error) {
return nil, "", nil
}
// TestPushVectorsSkipsWhenSourceNotReady pins that a not-ready source turns
// the vector phase into a clean skip — not an error, and not a push over a
// partial local view that would evict valid PG vectors.
func TestPushVectorsSkipsWhenSourceNotReady(t *testing.T) {
sync := &Sync{vectorSource: notReadyVectorSource{}}
res, err := sync.pushVectors(context.Background(), false, nil, nil)
require.NoError(t, err)
assert.True(t, res.Skipped)
assert.Contains(t, res.SkippedReason, "not fully embedded")
assert.Contains(t, res.SkippedReason, "7 document(s) pending")
}