Files
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.1 KiB
Go

package postgres
import (
"context"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.kenn.io/agentsview/internal/db"
)
// TestBatchedDependencyFingerprintMatchesPerSession pins that the chunked
// prefetch path the push loop uses produces the exact fingerprint the
// per-session path produces. A divergence would change every stored session
// fingerprint and re-push the entire archive on the next push.
func TestBatchedDependencyFingerprintMatchesPerSession(t *testing.T) {
local, err := db.Open(filepath.Join(t.TempDir(), "local.db"))
require.NoError(t, err)
defer local.Close()
ctx := context.Background()
require.NoError(t, local.UpsertSession(db.Session{
ID: "dep-a", Project: "alpha", Machine: "m1", Agent: "claude-code",
}))
require.NoError(t, local.UpsertSession(db.Session{
ID: "dep-empty", Project: "alpha", Machine: "m1", Agent: "claude-code",
}))
note := "pinned"
require.NoError(t, local.InsertMessages([]db.Message{
{
SessionID: "dep-a", Ordinal: 0, Role: "user",
Content: "hello", ContentLength: 5,
Timestamp: "2026-07-01T10:00:00Z", IsSystem: true,
},
{
SessionID: "dep-a", Ordinal: 1, Role: "assistant",
Content: "with\x00nul", ContentLength: 8,
ThinkingText: "thinking", HasThinking: true, HasToolUse: true,
Model: "claude-test", ContextTokens: 10, OutputTokens: 2,
HasContextTokens: true, HasOutputTokens: true,
ToolCalls: []db.ToolCall{
{
ToolName: "Bash", Category: "execution",
ToolUseID: "tu-1", InputJSON: `{"command":"ls"}`,
ResultContentLength: 2, ResultContent: "ok",
ResultEvents: []db.ToolResultEvent{{
ToolUseID: "tu-1", Source: "cli", Status: "ok",
Content: "ok", ContentLength: 2,
Timestamp: "2026-07-01T10:00:01Z",
}},
},
{ToolName: "Read", Category: "file"},
},
},
}))
require.NoError(t, local.ReplaceSessionSecretFindings("dep-a",
[]db.SecretFinding{{
SessionID: "dep-a", RuleName: "token", Confidence: "high",
LocationKind: "message", MessageOrdinal: 1,
MatchStart: 0, MatchEnd: 4, RedactedMatch: "w…",
RulesVersion: "v1",
}}, 1, "v1"))
pinned, err := local.GetMessageByOrdinal("dep-a", 1)
require.NoError(t, err)
require.NotNil(t, pinned)
pinID, err := local.PinMessage("dep-a", pinned.ID, &note)
require.NoError(t, err)
require.NotZero(t, pinID)
ids := []string{"dep-a", "dep-empty", "dep-missing"}
usageFPs, err := local.UsageEventFingerprints(ids)
require.NoError(t, err)
state, err := readLocalPushDependencyState(ctx, local, ids)
require.NoError(t, err)
for _, id := range ids {
for _, usageKnown := range []bool{true, false} {
want, err := localSessionDependencyPushFingerprint(
ctx, local, id, usageFPs[id], usageKnown,
)
require.NoError(t, err, id)
got, err := state.dependencyFingerprint(
local, id, usageFPs[id], usageKnown,
)
require.NoError(t, err, id)
assert.Equal(t, want, got,
"dependency fingerprint %s (usageKnown=%t)", id, usageKnown)
}
}
assert.NotEqual(t, "", state.contentHashFP["dep-a"],
"fixture must exercise the message fingerprint maps")
}