Files
kenn-io--agentsview/internal/db/search_content_chunk_test.go
wehub-resource-sync f99010fae1
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
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Windows) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:36 +08:00

98 lines
3.3 KiB
Go

package db
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestSemanticAllowedSessionIDsOverSQLiteVarLimit forces the reader pool's
// SQLite bind-variable limit down to 999 (mirroring
// forceReaderVarLimit's rationale in activityreport_test.go: some builds
// compile against SQLite's older 999 default), then asks
// semanticAllowedSessionIDs to scope a candidate set of 1002 session IDs — a
// count a deep semantic overfetch (thousands of hits from distinct
// sessions) can plausibly produce and single-shot IN (...) query would
// exceed. It must chunk the query and still return exactly the real,
// filter-passing sessions.
func TestSemanticAllowedSessionIDsOverSQLiteVarLimit(t *testing.T) {
d := testDB(t)
ctx := context.Background()
forceReaderVarLimit(t, d, 999)
// Guard: prove the lowered limit is live on the pool, so a setup that
// failed to constrain it cannot mask the regression checked below.
overLimitPh, overLimitArgs := inPlaceholders(make([]string, 1001))
_, probeErr := d.getReader().QueryContext(
ctx, "SELECT 1 WHERE '' IN "+overLimitPh, overLimitArgs...)
require.Error(t, probeErr, "reader variable limit was not constrained")
insertSession(t, d, "real-1", "proj")
insertSession(t, d, "real-2", "proj")
ids := []string{"real-1", "real-2"}
for i := range 1000 {
ids = append(ids, fmt.Sprintf("fake-%d", i))
}
f := ContentSearchFilter{IncludeOneShot: true, IncludeAutomated: true}
allowed, err := d.semanticAllowedSessionIDs(ctx, f, ids)
require.NoError(t, err)
assert.True(t, allowed["real-1"])
assert.True(t, allowed["real-2"])
assert.Len(t, allowed, 2, "no nonexistent id should appear in the result")
}
// TestEnrichSemanticHitsOverSQLiteVarLimit forces the reader pool's SQLite
// bind-variable limit down to 999, then asks enrichSemanticHits to enrich
// 1002 (session_id, ordinal) hits — each binding 2 params in the VALUES CTE,
// so 2004 total, well past a single query's budget. It must chunk and still
// resolve exactly the hits with a real backing message/session row.
func TestEnrichSemanticHitsOverSQLiteVarLimit(t *testing.T) {
d := testDB(t)
ctx := context.Background()
forceReaderVarLimit(t, d, 999)
overLimitPh, overLimitArgs := inPlaceholders(make([]string, 1001))
_, probeErr := d.getReader().QueryContext(
ctx, "SELECT 1 WHERE '' IN "+overLimitPh, overLimitArgs...)
require.Error(t, probeErr, "reader variable limit was not constrained")
insertSession(t, d, "real-sess", "proj")
insertMessages(t, d,
Message{
SessionID: "real-sess", Ordinal: 0, Role: "user",
Content: "hello there", ContentLength: len("hello there"),
Timestamp: tsZero,
},
Message{
SessionID: "real-sess", Ordinal: 1, Role: "assistant",
Content: "hi back", ContentLength: len("hi back"),
Timestamp: tsZeroS1,
},
)
hits := []VectorHit{
{SessionID: "real-sess", Ordinal: 0},
{SessionID: "real-sess", Ordinal: 1},
}
for i := range 1000 {
hits = append(hits, VectorHit{
SessionID: fmt.Sprintf("no-such-session-%d", i), Ordinal: i,
})
}
meta, err := d.enrichSemanticHits(ctx, hits)
require.NoError(t, err)
require.Len(t, meta, 2)
assert.Equal(t, "hello there",
meta[semanticHitKey{"real-sess", 0}].content)
assert.Equal(t, "hi back",
meta[semanticHitKey{"real-sess", 1}].content)
}