kenn-io--agentsview
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
84 行
2.7 KiB
Go
84 行
2.7 KiB
Go
package parser
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// countWorkspaceManifestReads swaps the workspace-manifest seam with a counter
|
|
// for the duration of the test and returns a pointer to the call count.
|
|
func countWorkspaceManifestReads(t *testing.T) *int {
|
|
t.Helper()
|
|
var calls int
|
|
orig := readVSCodeWorkspaceManifest
|
|
readVSCodeWorkspaceManifest = func(dir string) string {
|
|
calls++
|
|
return orig(dir)
|
|
}
|
|
t.Cleanup(func() { readVSCodeWorkspaceManifest = orig })
|
|
return &calls
|
|
}
|
|
|
|
func writeWorkspaceManifestSessions(t *testing.T, root string, ids ...string) {
|
|
t.Helper()
|
|
hashDir := filepath.Join(root, "workspaceStorage", "ws-hash")
|
|
chatDir := filepath.Join(hashDir, "chatSessions")
|
|
writeSourceFile(t, filepath.Join(hashDir, "workspace.json"),
|
|
`{"folder":"file:///Users/alice/code/myproj"}`)
|
|
for _, id := range ids {
|
|
writeSourceFile(t, filepath.Join(chatDir, id+".jsonl"),
|
|
vscodeCopilotProviderJSONL(id, "hi"))
|
|
}
|
|
}
|
|
|
|
// TestVSCodeCopilotDiscoverReadsWorkspaceManifestOncePerDir guards against
|
|
// re-reading workspace.json for every discovered session. The manifest depends
|
|
// only on the workspace hash dir, so reading it per source made discovery scale
|
|
// with session count.
|
|
func TestVSCodeCopilotDiscoverReadsWorkspaceManifestOncePerDir(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeWorkspaceManifestSessions(t, root, "s1", "s2", "s3")
|
|
|
|
calls := countWorkspaceManifestReads(t)
|
|
provider, ok := NewProvider(AgentVSCodeCopilot, ProviderConfig{
|
|
Roots: []string{root}, Machine: "local",
|
|
})
|
|
require.True(t, ok)
|
|
|
|
srcs, err := provider.Discover(context.Background())
|
|
require.NoError(t, err)
|
|
require.Len(t, srcs, 3)
|
|
for _, s := range srcs {
|
|
assert.Equal(t, "myproj", s.ProjectHint)
|
|
}
|
|
assert.Equal(t, 1, *calls,
|
|
"workspace.json should be read once per workspace dir, not per session")
|
|
}
|
|
|
|
// TestPositronDiscoverReadsWorkspaceManifestOncePerDir is the Positron
|
|
// counterpart: Positron reuses the VSCode workspaceStorage layout and the same
|
|
// manifest reader, and had the same per-source rebuild.
|
|
func TestPositronDiscoverReadsWorkspaceManifestOncePerDir(t *testing.T) {
|
|
root := t.TempDir()
|
|
writeWorkspaceManifestSessions(t, root, "s1", "s2", "s3")
|
|
|
|
calls := countWorkspaceManifestReads(t)
|
|
provider, ok := NewProvider(AgentPositron, ProviderConfig{
|
|
Roots: []string{root}, Machine: "local",
|
|
})
|
|
require.True(t, ok)
|
|
|
|
srcs, err := provider.Discover(context.Background())
|
|
require.NoError(t, err)
|
|
require.Len(t, srcs, 3)
|
|
for _, s := range srcs {
|
|
assert.Equal(t, "myproj", s.ProjectHint)
|
|
}
|
|
assert.Equal(t, 1, *calls,
|
|
"workspace.json should be read once per workspace dir, not per session")
|
|
}
|