Files
zzet--gortex/internal/resolver/framework_synth_test.go
T
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

100 lines
3.4 KiB
Go

package resolver
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zzet/gortex/internal/graph"
)
func TestStampSynthesized(t *testing.T) {
e := &graph.Edge{From: "a", To: "b", Kind: graph.EdgeCalls}
StampSynthesized(e, SynthEventChannel)
assert.Equal(t, SynthEventChannel, e.Meta[MetaSynthesizedBy])
assert.Equal(t, ProvenanceHeuristic, e.Meta[MetaProvenance])
// Does not clobber an explicit provenance already set.
e2 := &graph.Edge{From: "a", To: "b", Kind: graph.EdgeCalls, Meta: map[string]any{MetaProvenance: "verified"}}
StampSynthesized(e2, SynthGRPCStub)
assert.Equal(t, "verified", e2.Meta[MetaProvenance])
assert.Equal(t, SynthGRPCStub, e2.Meta[MetaSynthesizedBy])
UnstampSynthesized(e)
_, hasBy := e.Meta[MetaSynthesizedBy]
_, hasProv := e.Meta[MetaProvenance]
assert.False(t, hasBy)
assert.False(t, hasProv)
// nil-safe.
StampSynthesized(nil, SynthGRPCStub)
UnstampSynthesized(nil)
}
func TestStampSynthesizedTyped(t *testing.T) {
// The typed-tier stamp records ProvenanceFramework, not Heuristic.
e := &graph.Edge{From: "a", To: "b", Kind: graph.EdgeCalls}
StampSynthesizedTyped(e, SynthEventChannel)
assert.Equal(t, SynthEventChannel, e.Meta[MetaSynthesizedBy])
assert.Equal(t, ProvenanceFramework, e.Meta[MetaProvenance])
// The two provenance tiers are distinct values so analyze
// kind=synthesizers can separate them from one MetaProvenance read.
assert.NotEqual(t, ProvenanceHeuristic, ProvenanceFramework)
// Confidence tiers carry the documented values.
assert.Equal(t, 0.85, ConfidenceTyped)
assert.Equal(t, 0.6, ConfidenceHeuristic)
// UnstampSynthesized clears the typed provenance too.
UnstampSynthesized(e)
_, hasBy := e.Meta[MetaSynthesizedBy]
_, hasProv := e.Meta[MetaProvenance]
assert.False(t, hasBy)
assert.False(t, hasProv)
// nil-safe.
StampSynthesizedTyped(nil, SynthGRPCStub)
}
func TestRunFrameworkSynthesizers_Report(t *testing.T) {
b := newEventChannelTestGraph()
b.emit("p.go::p", "eventemitter", "e", "p.go", 1)
b.listen("c.go::c", "eventemitter", "e", "c.go", 1)
rep := RunFrameworkSynthesizers(b.g)
assert.Equal(t, 1, rep.Total, "the one event-channel pair is the only synthesized edge")
byName := map[string]int{}
for _, p := range rep.Per {
byName[p.Name] = p.Edges
}
// Every registered synthesizer reports a row, even at zero.
require.Contains(t, byName, SynthGRPCStub)
require.Contains(t, byName, SynthTemporalStub)
require.Contains(t, byName, SynthEventChannel)
require.Contains(t, byName, SynthStoreFactory)
require.Contains(t, byName, SynthReduxThunk)
require.Contains(t, byName, SynthObjectRegistry)
require.Contains(t, byName, SynthRTKQuery)
require.Contains(t, byName, SynthVuexDispatch)
require.Contains(t, byName, SynthCelery)
require.Contains(t, byName, SynthSpringEvent)
require.Contains(t, byName, SynthMediatR)
require.Contains(t, byName, SynthSidekiq)
require.Contains(t, byName, SynthLaravelEvent)
require.Contains(t, byName, SynthFnPointerDispatch)
require.Contains(t, byName, SynthGoFrameRoute)
require.Contains(t, byName, SynthExpressResolve)
assert.Equal(t, 0, byName[SynthGRPCStub])
assert.Equal(t, 0, byName[SynthTemporalStub])
assert.Equal(t, 1, byName[SynthEventChannel])
}
func TestRunFrameworkSynthesizers_NilGraph(t *testing.T) {
rep := RunFrameworkSynthesizers(nil)
assert.Equal(t, 0, rep.Total)
assert.Nil(t, rep.Per)
}