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

88 lines
2.8 KiB
Go

package parser
import (
"context"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDirectoryJSONLSourceSetDiscoversProjectFiles(t *testing.T) {
root := t.TempDir()
writeSourceFile(t, filepath.Join(root, "project-b", "session-b.jsonl"), "{}\n")
writeSourceFile(t, filepath.Join(root, "project-a", "session-a.jsonl"), "{}\n")
writeSourceFile(t, filepath.Join(root, "project-a", "nested", "skip.jsonl"), "{}\n")
writeSourceFile(t, filepath.Join(root, "root.jsonl"), "{}\n")
sources := NewDirectoryJSONLSourceSet(AgentQwen, []string{root})
discovered, err := sources.Discover(context.Background())
require.NoError(t, err)
require.Len(t, discovered, 2)
assert.Equal(t, []string{"project-a", "project-b"}, sourceProjects(discovered))
assert.Equal(t, []string{
filepath.Join(root, "project-a", "session-a.jsonl"),
filepath.Join(root, "project-b", "session-b.jsonl"),
}, sourceDisplayPaths(discovered))
found, ok, err := sources.FindSource(context.Background(), FindSourceRequest{
RawSessionID: "session-b",
})
require.NoError(t, err)
require.True(t, ok)
assert.Equal(t, filepath.Join(root, "project-b", "session-b.jsonl"), found.DisplayPath)
}
func TestDirectoryJSONLSourceSetComposesPathFilters(t *testing.T) {
root := t.TempDir()
writeSourceFile(t, filepath.Join(root, "project", "session-keep.jsonl"), "{}\n")
writeSourceFile(t, filepath.Join(root, "project", "ignore.jsonl"), "{}\n")
sources := NewDirectoryJSONLSourceSet(AgentIflow, []string{root},
WithIncludePath(func(root, path string) bool {
return strings.HasPrefix(filepath.Base(path), "session-")
}),
WithProjectHint(func(root, path string) string {
return "custom-" + filepath.Base(filepath.Dir(path))
}),
)
discovered, err := sources.Discover(context.Background())
require.NoError(t, err)
require.Len(t, discovered, 1)
assert.Equal(t, "custom-project", discovered[0].ProjectHint)
assert.Equal(t, filepath.Join(root, "project", "session-keep.jsonl"), discovered[0].DisplayPath)
}
func TestDirectoryJSONLSourceSetClassifiesDeletedProjectFiles(t *testing.T) {
root := t.TempDir()
sources := NewDirectoryJSONLSourceSet(AgentCommandCode, []string{root})
changed, err := sources.SourcesForChangedPath(
context.Background(),
ChangedPathRequest{
Path: filepath.Join(root, "project", "deleted.jsonl"),
EventKind: "remove",
WatchRoot: root,
},
)
require.NoError(t, err)
require.Len(t, changed, 1)
assert.Equal(t, "project", changed[0].ProjectHint)
assert.Equal(t, "project/deleted.jsonl", changed[0].Opaque.(JSONLSource).RelPath)
deep, err := sources.SourcesForChangedPath(
context.Background(),
ChangedPathRequest{
Path: filepath.Join(root, "project", "nested", "ignored.jsonl"),
EventKind: "remove",
WatchRoot: root,
},
)
require.NoError(t, err)
assert.Empty(t, deep)
}