Files
zzet--gortex/internal/indexer/mcp_config_excludes_test.go
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

61 lines
2.1 KiB
Go

package indexer
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"github.com/zzet/gortex/internal/config"
"github.com/zzet/gortex/internal/graph"
"github.com/zzet/gortex/internal/parser"
"github.com/zzet/gortex/internal/parser/languages"
)
// TestIndex_MCPConfigUnderAgentDirs verifies the MCP-config-as-graph
// feature reaches its documented .kiro/.claude targets: those dirs are
// Builtin-excluded wholesale, so the indexer must descend them just far
// enough to index MCP server configs — while keeping the surrounding
// agent-state noise (settings.json, skills) out of the graph.
func TestIndex_MCPConfigUnderAgentDirs(t *testing.T) {
dir := t.TempDir()
mustWrite := func(rel, content string) {
p := filepath.Join(dir, rel)
require.NoError(t, os.MkdirAll(filepath.Dir(p), 0o755))
writeFile(t, p, content)
}
// Noise that must stay OUT of the graph.
mustWrite(".claude/settings.json", `{"theme": "dark"}`)
// MCP configs that MUST be indexed despite living under excluded dirs.
mustWrite(".claude/mcp.json", `{"mcpServers": {"claudeone": {"command": "npx", "args": ["-y", "some-pkg"]}}}`)
mustWrite(".kiro/settings/mcp.json", `{"mcpServers": {"kiroone": {"command": "uvx", "args": ["other-pkg"]}}}`)
reg := parser.NewRegistry()
reg.Register(languages.NewMCPConfigExtractor())
reg.Register(languages.NewJSONExtractor()) // settings.json WOULD index if not excluded
cfg := config.Default().Index
cfg.Workers = 2
g := graph.New()
idx := New(g, reg, cfg, zap.NewNop())
_, err := idx.Index(dir)
require.NoError(t, err)
if findKindNamed(g, graph.KindResource, "claudeone") == nil {
t.Error("MCP server 'claudeone' from .claude/mcp.json was not indexed")
}
if findKindNamed(g, graph.KindResource, "kiroone") == nil {
t.Error("MCP server 'kiroone' from .kiro/settings/mcp.json was not indexed")
}
// The agent-state noise must NOT have leaked into the graph.
for _, n := range g.AllNodes() {
if strings.Contains(n.FilePath, "settings.json") {
t.Errorf("agent-state noise leaked into graph: %s (%s)", n.FilePath, n.Kind)
}
}
}