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
138 lines
4.5 KiB
Go
138 lines
4.5 KiB
Go
package parser
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestIflowProviderSourceMethods(t *testing.T) {
|
|
root := t.TempDir()
|
|
projectDir := filepath.Join(root, "test-project")
|
|
rawID := "5de701fc-7454-4858-a249-95cac4fd3b51"
|
|
sourcePath := filepath.Join(projectDir, "session-"+rawID+".jsonl")
|
|
copyFixtureFile(t, "testdata/iflow/session-"+rawID+".jsonl", sourcePath)
|
|
writeSourceFile(t, filepath.Join(projectDir, rawID+".jsonl"), "{}\n")
|
|
|
|
provider, ok := NewProvider(AgentIflow, ProviderConfig{
|
|
Roots: []string{root},
|
|
Machine: "devbox",
|
|
})
|
|
require.True(t, ok)
|
|
|
|
discovered, err := provider.Discover(context.Background())
|
|
require.NoError(t, err)
|
|
require.Len(t, discovered, 1)
|
|
assert.Equal(t, AgentIflow, discovered[0].Provider)
|
|
assert.Equal(t, sourcePath, discovered[0].DisplayPath)
|
|
assert.Equal(t, "test-project", discovered[0].ProjectHint)
|
|
|
|
found, ok, err := provider.FindSource(context.Background(), FindSourceRequest{
|
|
FullSessionID: "host~iflow:" + rawID,
|
|
})
|
|
require.NoError(t, err)
|
|
require.True(t, ok)
|
|
assert.Equal(t, sourcePath, found.DisplayPath)
|
|
|
|
forkID := rawID + "-6f5d8718-7a95-4bb8-965f-faa23246c82d"
|
|
found, ok, err = provider.FindSource(context.Background(), FindSourceRequest{
|
|
RawSessionID: forkID,
|
|
})
|
|
require.NoError(t, err)
|
|
require.True(t, ok)
|
|
assert.Equal(t, sourcePath, found.DisplayPath)
|
|
|
|
require.NoError(t, os.Remove(sourcePath))
|
|
changed, err := provider.SourcesForChangedPath(
|
|
context.Background(),
|
|
ChangedPathRequest{Path: sourcePath, EventKind: "remove", WatchRoot: root},
|
|
)
|
|
require.NoError(t, err)
|
|
require.Len(t, changed, 1)
|
|
assert.Equal(t, sourcePath, changed[0].DisplayPath)
|
|
}
|
|
|
|
func TestIflowProviderDiscoversSymlinkedProjectDirectory(t *testing.T) {
|
|
root := t.TempDir()
|
|
realProjectDir := filepath.Join(t.TempDir(), "real-project")
|
|
linkProjectDir := filepath.Join(root, "linked-project")
|
|
rawID := "5de701fc-7454-4858-a249-95cac4fd3b51"
|
|
// Populate the target directory before symlinking so Windows records a
|
|
// directory symlink. Symlinking a not-yet-existent target yields a file
|
|
// symlink there, which discovery cannot descend into.
|
|
copyFixtureFile(
|
|
t,
|
|
"testdata/iflow/session-"+rawID+".jsonl",
|
|
filepath.Join(realProjectDir, "session-"+rawID+".jsonl"),
|
|
)
|
|
if err := os.Symlink(realProjectDir, linkProjectDir); err != nil {
|
|
t.Skipf("symlink not supported: %v", err)
|
|
}
|
|
sourcePath := filepath.Join(linkProjectDir, "session-"+rawID+".jsonl")
|
|
|
|
provider, ok := NewProvider(AgentIflow, ProviderConfig{
|
|
Roots: []string{root},
|
|
Machine: "devbox",
|
|
})
|
|
require.True(t, ok)
|
|
|
|
discovered, err := provider.Discover(context.Background())
|
|
require.NoError(t, err)
|
|
require.Len(t, discovered, 1)
|
|
assert.Equal(t, sourcePath, discovered[0].DisplayPath)
|
|
assert.Equal(t, "linked-project", discovered[0].ProjectHint)
|
|
|
|
found, ok, err := provider.FindSource(context.Background(), FindSourceRequest{
|
|
RawSessionID: rawID,
|
|
})
|
|
require.NoError(t, err)
|
|
require.True(t, ok)
|
|
assert.Equal(t, sourcePath, found.DisplayPath)
|
|
}
|
|
|
|
func TestIflowProviderParse(t *testing.T) {
|
|
root := t.TempDir()
|
|
project := "test-project"
|
|
rawID := "5de701fc-7454-4858-a249-95cac4fd3b51"
|
|
sourcePath := filepath.Join(root, project, "session-"+rawID+".jsonl")
|
|
copyFixtureFile(t, "testdata/iflow/session-"+rawID+".jsonl", sourcePath)
|
|
|
|
provider, ok := NewProvider(AgentIflow, ProviderConfig{
|
|
Roots: []string{root},
|
|
Machine: "devbox",
|
|
})
|
|
require.True(t, ok)
|
|
sources, err := provider.Discover(context.Background())
|
|
require.NoError(t, err)
|
|
require.Len(t, sources, 1)
|
|
|
|
outcome, err := provider.Parse(context.Background(), ParseRequest{
|
|
Source: sources[0],
|
|
Fingerprint: SourceFingerprint{Key: sourcePath, Hash: "abc123"},
|
|
})
|
|
require.NoError(t, err)
|
|
require.True(t, outcome.ResultSetComplete)
|
|
require.Len(t, outcome.Results, 1)
|
|
assert.Equal(t, DataVersionCurrent, outcome.Results[0].DataVersion)
|
|
assert.Equal(t, "iflow:"+rawID, outcome.Results[0].Result.Session.ID)
|
|
// The provider mirrors the legacy sync project resolution, deriving the
|
|
// canonical project from the session's recorded cwd rather than the raw
|
|
// project directory name.
|
|
assert.Equal(t, "docker_image_retagger", outcome.Results[0].Result.Session.Project)
|
|
assert.Equal(t, "devbox", outcome.Results[0].Result.Session.Machine)
|
|
assert.Equal(t, "abc123", outcome.Results[0].Result.Session.File.Hash)
|
|
assert.Len(t, outcome.Results[0].Result.Messages, 11)
|
|
}
|
|
|
|
func copyFixtureFile(t *testing.T, src, dst string) {
|
|
t.Helper()
|
|
|
|
data, err := os.ReadFile(src)
|
|
require.NoError(t, err)
|
|
writeSourceFile(t, dst, string(data))
|
|
}
|