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

69 lines
2.2 KiB
Go

package graph
import (
"testing"
"time"
)
// TestProxyNodeID_RoundTrip asserts the origin-namespaced id composes and
// decomposes, and that a remote whose repo prefix collides with a local
// prefix still yields a distinct (non-aliasing) proxy id.
func TestProxyNodeID_RoundTrip(t *testing.T) {
remoteID := "gortex/internal/daemon/router.go::Router"
pid := ProxyNodeID("r2", remoteID)
if !IsProxyID(pid) {
t.Fatalf("%q should be a proxy id", pid)
}
if got := ProxyOriginSlug(pid); got != "r2" {
t.Errorf("origin slug = %q, want r2", got)
}
if got := ProxyRemoteID(pid); got != remoteID {
t.Errorf("remote id = %q, want %q", got, remoteID)
}
// A local node with the same native id is never a proxy id, so no
// alias is possible even on a shared prefix.
if IsProxyID(remoteID) {
t.Error("a local native id must not be mistaken for a proxy id")
}
if ProxyNodeID("r3", remoteID) == pid {
t.Error("the same remote symbol under two slugs must yield distinct proxy ids")
}
}
// TestIsProxyNode asserts proxy detection keys on the struct fields, not
// the id shape, and never confuses a stdlib stub.
func TestIsProxyNode(t *testing.T) {
proxy := &Node{ID: ProxyNodeID("r2", "x/y.go::Z"), Origin: "remote:r2", Stub: true, FetchedAt: time.Now()}
if !IsProxyNode(proxy) {
t.Error("a Stub+Origin node is a proxy node")
}
local := &Node{ID: "x/y.go::Z"}
if IsProxyNode(local) {
t.Error("a local node is not a proxy node")
}
// Stub without Origin (some other stub convention) is not a proxy.
if IsProxyNode(&Node{Stub: true}) {
t.Error("Stub alone is not a proxy node")
}
if IsProxyNode(nil) {
t.Error("nil is not a proxy node")
}
// IsStub (the string predicate) must not match a proxy id.
if IsStub(proxy.ID) {
t.Error("IsStub must not recognise a proxy id")
}
}
// TestProxyHelpers_NonProxyInputs asserts the accessors are safe on
// non-proxy ids.
func TestProxyHelpers_NonProxyInputs(t *testing.T) {
for _, id := range []string{"", "x/y.go::Z", "remote:nosep", "stdlib::fmt"} {
if IsProxyID(id) {
t.Errorf("%q should not be a proxy id", id)
}
if ProxyOriginSlug(id) != "" || ProxyRemoteID(id) != "" {
t.Errorf("accessors should be empty for non-proxy id %q", id)
}
}
}