Files
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

63 lines
1.9 KiB
Go

package resolver
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zzet/gortex/internal/graph"
)
func sqlFnNode(g graph.Store, id, name string) {
g.AddNode(&graph.Node{ID: id, Kind: graph.KindFunction, Name: name, FilePath: "schema.sql", Language: "sql"})
}
func sqlCaller(g graph.Store, callerID, fn string) *graph.Edge {
g.AddNode(&graph.Node{ID: callerID, Kind: graph.KindFunction, Name: lastSeg(callerID), FilePath: "app.ts", Language: "typescript"})
e := &graph.Edge{
From: callerID, To: "unresolved::sqlfn::" + fn, Kind: graph.EdgeCalls,
FilePath: "app.ts", Line: 2, Meta: map[string]any{"via": sqlCallsiteVia, "sql_function": fn},
}
g.AddEdge(e)
return e
}
func TestResolveSQLCallsites_Lands(t *testing.T) {
g := graph.New()
e := sqlCaller(g, "app.ts::load", "get_user_stats")
sqlFnNode(g, "schema.sql::get_user_stats", "get_user_stats")
n := ResolveSQLCallsites(g)
assert.Equal(t, 1, n)
assert.Equal(t, "schema.sql::get_user_stats", e.To)
assert.Equal(t, graph.OriginASTInferred, e.Origin)
assert.Equal(t, SynthSQLCallsite, e.Meta[MetaSynthesizedBy])
require.Len(t, g.GetInEdges("schema.sql::get_user_stats"), 1)
}
func TestResolveSQLCallsites_AmbiguousStaysPlaceholder(t *testing.T) {
g := graph.New()
e := sqlCaller(g, "app.ts::load", "calc")
sqlFnNode(g, "a.sql::calc", "calc")
sqlFnNode(g, "b.sql::calc", "calc")
assert.Equal(t, 0, ResolveSQLCallsites(g))
assert.Equal(t, "unresolved::sqlfn::calc", e.To, "ambiguous SQL function stays unresolved")
}
func TestResolveSQLCallsites_NoSQLFunction(t *testing.T) {
g := graph.New()
sqlCaller(g, "app.ts::load", "ghost")
assert.Equal(t, 0, ResolveSQLCallsites(g))
}
func TestResolveSQLCallsites_Idempotent(t *testing.T) {
g := graph.New()
sqlCaller(g, "app.ts::load", "fn")
sqlFnNode(g, "schema.sql::fn", "fn")
first := ResolveSQLCallsites(g)
second := ResolveSQLCallsites(g)
assert.Equal(t, first, second)
assert.Equal(t, 1, second)
}