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
47 lines
1.8 KiB
Go
47 lines
1.8 KiB
Go
package indexer
|
|
|
|
import (
|
|
"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"
|
|
)
|
|
|
|
func TestContentLinkEdgeBudget(t *testing.T) {
|
|
require.Equal(t, 2000, contentLinkEdgeBudget(0))
|
|
require.Equal(t, 2000, contentLinkEdgeBudget(10000), "10% (1000) is below the 2000 floor")
|
|
require.Equal(t, 5000, contentLinkEdgeBudget(50000), "10% of live edges above the floor")
|
|
}
|
|
|
|
func TestLinkContentToCode(t *testing.T) {
|
|
g := graph.New()
|
|
g.AddBatch([]*graph.Node{
|
|
{ID: "pkg/order.go::ProcessOrder", Kind: graph.KindFunction, Name: "ProcessOrder", FilePath: "pkg/order.go"},
|
|
{ID: "deck.pptx::doc:slide-1", Kind: graph.KindDoc, FilePath: "deck.pptx",
|
|
Meta: map[string]any{"data_class": "content", "asset_kind": "slide",
|
|
"section_text": "This deck explains why ProcessOrder validates inventory before charging."}},
|
|
// Markdown prose has no data_class — it must NOT be linked by the content pass.
|
|
{ID: "README.md::doc:intro", Kind: graph.KindDoc, FilePath: "README.md",
|
|
Meta: map[string]any{"asset_kind": "markdown_section", "section_text": "ProcessOrder is the core."}},
|
|
}, nil)
|
|
|
|
idx := New(g, parser.NewRegistry(), config.Default().Index, zap.NewNop())
|
|
idx.linkContentToCode()
|
|
|
|
var motivates []*graph.Edge
|
|
for _, e := range g.AllEdges() {
|
|
if e.Kind == graph.EdgeMotivates {
|
|
motivates = append(motivates, e)
|
|
}
|
|
}
|
|
require.Len(t, motivates, 1, "the content chunk links; markdown prose (no data_class) does not")
|
|
require.Equal(t, "deck.pptx::doc:slide-1", motivates[0].From)
|
|
require.Equal(t, "pkg/order.go::ProcessOrder", motivates[0].To)
|
|
require.Equal(t, graph.OriginTextMatched, motivates[0].Origin)
|
|
require.Equal(t, "lexical", motivates[0].Meta["signal"])
|
|
}
|