Files
zzet--gortex/internal/resolver/expo_module_bridge_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

64 lines
2.2 KiB
Go

package resolver
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zzet/gortex/internal/graph"
)
func expoNativeNode(g graph.Store, id, lang, module, method string) {
g.AddNode(&graph.Node{
ID: id, Kind: graph.KindMethod, Name: lastSeg(id),
FilePath: id, StartLine: 1, Language: lang,
Meta: map[string]any{"expo_module": module, "expo_method": method},
})
}
// expoJSCall adds a JS caller plus the rn.native placeholder edge a
// requireNativeModule('mod').method() call produces.
func expoJSCall(g graph.Store, callerID, module, method string) {
g.AddNode(&graph.Node{ID: callerID, Kind: graph.KindFunction, Name: lastSeg(callerID), FilePath: "app.ts", Language: "typescript"})
g.AddEdge(&graph.Edge{
From: callerID, To: "unresolved::rn::" + module + "::" + method,
Kind: graph.EdgeCalls, FilePath: "app.ts", Line: 4,
Meta: map[string]any{"via": rnNativeVia, "rn_module": module, "rn_method": method},
})
}
func expoBridgeEdge(g graph.Store, from, to string) *graph.Edge {
for _, e := range g.GetOutEdges(from) {
if e.To == to && e.Kind == graph.EdgeCalls && e.Meta != nil {
if v, _ := e.Meta["via"].(string); v == expoBridgeVia {
return e
}
}
}
return nil
}
func TestResolveExpoModuleBridge_Pairs(t *testing.T) {
g := graph.New()
expoJSCall(g, "app.ts::useMath", "Math", "add")
expoNativeNode(g, "ios/MathModule.swift::expo:Math:add", "swift", "Math", "add")
expoNativeNode(g, "android/MathModule.kt::expo:Math:add", "kotlin", "Math", "add")
n := ResolveExpoModuleBridge(g)
assert.Equal(t, 2, n, "JS call bridges to both the Swift and Kotlin Expo impls")
sw := expoBridgeEdge(g, "app.ts::useMath", "ios/MathModule.swift::expo:Math:add")
require.NotNil(t, sw)
assert.Equal(t, SynthExpoModules, sw.Meta[MetaSynthesizedBy])
assert.Equal(t, "swift", sw.Meta["native_language"])
require.NotNil(t, expoBridgeEdge(g, "app.ts::useMath", "android/MathModule.kt::expo:Math:add"))
}
func TestResolveExpoModuleBridge_NoMatch(t *testing.T) {
g := graph.New()
expoJSCall(g, "app.ts::useMath", "Math", "add")
expoNativeNode(g, "ios/Other.swift::expo:Other:sub", "swift", "Other", "sub")
assert.Equal(t, 0, ResolveExpoModuleBridge(g))
}