Skip to content

Commit 86cdee8

Browse files
test(sync): compare cortex shadow parity
Cortex is shadow-compared on this branch, so add source-level migration coverage that compares provider observation with ParseCortexSession. The fixture uses Cortex's split metadata/history format so the test proves the provider path preserves companion-history parse behavior while still planning the primary session ID. Validation: go test -tags "fts5" ./internal/parser ./internal/sync -run 'TestObserveProviderSourceMatchesCortexLegacyParser|TestCortexProvider|TestParseCortex' -count=1; go test -tags "fts5" ./internal/parser ./internal/sync -count=1; go fmt ./...; go vet ./...; git diff --check; ./custom-gcl run --config .golangci.nilaway.yml ./internal/parser/... ./internal/sync/...
1 parent 5c69815 commit 86cdee8

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package sync
2+
3+
import (
4+
"context"
5+
"path/filepath"
6+
"strings"
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
12+
"go.kenn.io/agentsview/internal/parser"
13+
)
14+
15+
func TestObserveProviderSourceMatchesCortexLegacyParser(t *testing.T) {
16+
root := t.TempDir()
17+
sessionID := "11111111-2222-3333-4444-555555555555"
18+
sourcePath := filepath.Join(root, sessionID+".json")
19+
writeProviderShadowSourceFile(t, sourcePath, cortexShadowMetadata(sessionID))
20+
writeProviderShadowSourceFile(
21+
t,
22+
filepath.Join(root, sessionID+".history.jsonl"),
23+
cortexShadowHistory(),
24+
)
25+
26+
provider, ok := parser.NewProvider(parser.AgentCortex, parser.ProviderConfig{
27+
Roots: []string{root},
28+
Machine: "devbox",
29+
})
30+
require.True(t, ok)
31+
sources, err := provider.Discover(context.Background())
32+
require.NoError(t, err)
33+
require.Len(t, sources, 1)
34+
35+
legacySession, legacyMessages, err := parser.ParseCortexSession(sourcePath, "devbox")
36+
require.NoError(t, err)
37+
require.NotNil(t, legacySession)
38+
39+
observation, err := ObserveProviderSource(context.Background(), provider, ProviderObserveRequest{
40+
Source: sources[0],
41+
Machine: "devbox",
42+
})
43+
require.NoError(t, err)
44+
require.Len(t, observation.Results, 1)
45+
legacySession.File.Hash = observation.Fingerprint.Hash
46+
47+
assert.Equal(t, *legacySession, observation.Results[0].Session)
48+
assert.Equal(t, legacyMessages, observation.Results[0].Messages)
49+
assert.Equal(t, []string{legacySession.ID}, observation.Planned.DataVersionSessionIDs())
50+
assert.Empty(t, observation.Planned.Diagnostics)
51+
}
52+
53+
func cortexShadowMetadata(sessionID string) string {
54+
return `{
55+
"session_id": "` + sessionID + `",
56+
"title": "Test session",
57+
"working_directory": "/home/user/project",
58+
"created_at": "2024-06-01T10:00:00Z",
59+
"last_updated": "2024-06-01T10:05:00Z"
60+
}`
61+
}
62+
63+
func cortexShadowHistory() string {
64+
return strings.Join([]string{
65+
`{"role":"user","id":"m1","content":[{"type":"text","text":"Hello from JSONL"}]}`,
66+
`{"role":"assistant","id":"m2","content":[{"type":"text","text":"Got it"}]}`,
67+
}, "\n")
68+
}

0 commit comments

Comments
 (0)