Files
kenn-io--agentsview/internal/sync/s3_provider_discovery_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

88 lines
2.7 KiB
Go

package sync
import (
"context"
"io"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.kenn.io/agentsview/internal/parser"
"go.kenn.io/agentsview/internal/testjsonl"
)
// TestProcessFileS3ProviderDiscoveredRoutesToS3Path verifies that an s3://
// DiscoveredFile shaped exactly as discoverProviderSources now emits it -- a
// provider-authoritative agent, ProviderProcess set, and a ProviderSource
// carrying the S3DiscoveredSource opaque -- still routes through the S3 sync
// path. processProviderFile must let the s3:// guard win over the provider
// parse path (providers read local files), and the threaded Machine/size/mtime
// must drive the same namespaced result as direct S3 discovery.
func TestProcessFileS3ProviderDiscoveredRoutesToS3Path(t *testing.T) {
database := openTestDB(t)
path := "s3://bucket/laptop/raw/claude/test-proj/shared-id.jsonl"
content := testjsonl.NewSessionBuilder().
AddClaudeUser("2024-01-01T00:00:00Z", "Hello").
AddClaudeAssistant("2024-01-01T00:00:05Z", "Hi.").
String()
oldFetch := fetchS3Object
t.Cleanup(func() { fetchS3Object = oldFetch })
fetchS3Object = func(got string) (io.ReadCloser, error) {
if got != path {
return nil, missingS3ObjectError()
}
return io.NopCloser(strings.NewReader(content)), nil
}
mtime := time.Date(2026, 6, 24, 12, 0, 0, 0, time.UTC).UnixNano()
e := &Engine{
db: database,
machine: "central",
providerMigrationModes: map[parser.AgentType]parser.ProviderMigrationMode{
parser.AgentClaude: parser.ProviderMigrationProviderAuthoritative,
},
}
source := parser.SourceRef{
Provider: parser.AgentClaude,
Key: path,
DisplayPath: path,
FingerprintKey: path,
ProjectHint: "test-proj",
Opaque: parser.S3DiscoveredSource{
URI: path,
Project: "test-proj",
Machine: "laptop",
Size: int64(len(content)),
MtimeNS: mtime,
},
}
res := e.processFile(context.Background(), parser.DiscoveredFile{
Agent: parser.AgentClaude,
Path: path,
Project: "test-proj",
Machine: "laptop",
SourceSize: int64(len(content)),
SourceMtime: mtime,
ProviderSource: &source,
ProviderProcess: true,
})
require.NoError(t, res.err)
require.Len(t, res.results, 1)
written, _, failed, _ := e.writeBatch([]pendingWrite{{
sess: res.results[0].Session,
msgs: res.results[0].Messages,
}}, syncWriteDefault, false)
require.Equal(t, 1, written)
require.Equal(t, 0, failed)
sess, err := database.GetSessionFull(context.Background(), "laptop~shared-id")
require.NoError(t, err)
require.NotNil(t, sess)
assert.Equal(t, "laptop", sess.Machine)
assert.Equal(t, path, derefString(sess.FilePath))
}