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
89 lines
3.3 KiB
Go
89 lines
3.3 KiB
Go
package resolver
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/zzet/gortex/internal/graph"
|
|
)
|
|
|
|
func rnPairEdge(g graph.Store, from, to string) *graph.Edge {
|
|
for _, e := range g.GetOutEdges(from) {
|
|
if e.To == to && e.Kind == graph.EdgeReferences && e.Meta != nil {
|
|
if v, _ := e.Meta["via"].(string); v == rnNativePairVia {
|
|
return e
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func TestResolveReactNativeNativePairing_PairsIOSAndAndroid(t *testing.T) {
|
|
g := graph.New()
|
|
rnNativeMethod(g, "ios/Battery.m::getLevel", "objc", "Battery", "getLevel")
|
|
rnNativeMethod(g, "android/Battery.java::getLevel", "java", "Battery", "getLevel")
|
|
|
|
assert.Equal(t, 1, ResolveReactNativeNativePairing(g))
|
|
|
|
fwd := rnPairEdge(g, "ios/Battery.m::getLevel", "android/Battery.java::getLevel")
|
|
require.NotNil(t, fwd, "ios→android pairing edge")
|
|
assert.Equal(t, "Battery", fwd.Meta["rn_module"])
|
|
assert.Equal(t, "getLevel", fwd.Meta["rn_method"])
|
|
assert.Equal(t, "android", fwd.Meta["native_platform"])
|
|
assert.Equal(t, SynthReactNativePair, fwd.Meta[MetaSynthesizedBy])
|
|
assert.Equal(t, graph.OriginASTInferred, fwd.Origin)
|
|
|
|
rev := rnPairEdge(g, "android/Battery.java::getLevel", "ios/Battery.m::getLevel")
|
|
require.NotNil(t, rev, "android→ios pairing edge (bidirectional)")
|
|
assert.Equal(t, "ios", rev.Meta["native_platform"])
|
|
}
|
|
|
|
func TestResolveReactNativeNativePairing_SwiftKotlinPaired(t *testing.T) {
|
|
g := graph.New()
|
|
rnNativeMethod(g, "ios/Battery.swift::getLevel", "swift", "Battery", "getLevel")
|
|
rnNativeMethod(g, "android/Battery.kt::getLevel", "kotlin", "Battery", "getLevel")
|
|
|
|
assert.Equal(t, 1, ResolveReactNativeNativePairing(g))
|
|
assert.NotNil(t, rnPairEdge(g, "ios/Battery.swift::getLevel", "android/Battery.kt::getLevel"))
|
|
}
|
|
|
|
func TestResolveReactNativeNativePairing_NoPairWithinSamePlatform(t *testing.T) {
|
|
g := graph.New()
|
|
// Two iOS implementations of the same method must not pair with each other.
|
|
rnNativeMethod(g, "ios/Battery.m::getLevel", "objc", "Battery", "getLevel")
|
|
rnNativeMethod(g, "ios/Battery2.m::getLevel", "objc", "Battery", "getLevel")
|
|
|
|
assert.Equal(t, 0, ResolveReactNativeNativePairing(g))
|
|
assert.Nil(t, rnPairEdge(g, "ios/Battery.m::getLevel", "ios/Battery2.m::getLevel"))
|
|
}
|
|
|
|
func TestResolveReactNativeNativePairing_NoMetaNoPair(t *testing.T) {
|
|
g := graph.New()
|
|
rnNativeMethod(g, "ios/Battery.m::getLevel", "objc", "Battery", "getLevel")
|
|
// Android side missing rn metadata — nothing to pair against.
|
|
g.AddNode(&graph.Node{ID: "android/Other.java::getLevel", Kind: graph.KindMethod, Name: "getLevel", Language: "java"})
|
|
assert.Equal(t, 0, ResolveReactNativeNativePairing(g))
|
|
}
|
|
|
|
func TestResolveReactNativeNativePairing_Idempotent(t *testing.T) {
|
|
g := graph.New()
|
|
rnNativeMethod(g, "ios/Battery.m::getLevel", "objc", "Battery", "getLevel")
|
|
rnNativeMethod(g, "android/Battery.java::getLevel", "java", "Battery", "getLevel")
|
|
|
|
first := ResolveReactNativeNativePairing(g)
|
|
second := ResolveReactNativeNativePairing(g)
|
|
assert.Equal(t, first, second)
|
|
|
|
count := 0
|
|
for e := range g.EdgesByKind(graph.EdgeReferences) {
|
|
if e != nil && e.Meta != nil {
|
|
if v, _ := e.Meta["via"].(string); v == rnNativePairVia {
|
|
count++
|
|
}
|
|
}
|
|
}
|
|
assert.Equal(t, 2, count, "exactly two pairing edges (one each direction) survive dedup")
|
|
}
|