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
63 lines
2.0 KiB
Go
63 lines
2.0 KiB
Go
package mcp
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/zzet/gortex/internal/telemetry"
|
|
)
|
|
|
|
// TestTelemetryRecorderWiredIntoDispatch verifies that a tool call routed
|
|
// through wrapToolHandler records a consent-gated mcp_tool_call counter named
|
|
// by the tool, and nothing else.
|
|
func TestTelemetryRecorderWiredIntoDispatch(t *testing.T) {
|
|
s := fastPathTestServer(t)
|
|
store := telemetry.NewStore(t.TempDir())
|
|
s.SetTelemetryRecorder(telemetry.NewRecorder(telemetry.Consent{Enabled: true}, store))
|
|
|
|
callWrapped(t, s, echoHandler, "search_symbols")
|
|
callWrapped(t, s, echoHandler, "search_symbols")
|
|
callWrapped(t, s, echoHandler, "find_usages")
|
|
s.FlushTelemetry()
|
|
|
|
days, err := store.Days()
|
|
if err != nil || len(days) != 1 {
|
|
t.Fatalf("expected one day of telemetry, got days=%v err=%v", days, err)
|
|
}
|
|
roll, err := store.Load(days[0])
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if roll.Counts["mcp_tool_call:search_symbols"] != 2 {
|
|
t.Errorf("search_symbols count = %d, want 2", roll.Counts["mcp_tool_call:search_symbols"])
|
|
}
|
|
if roll.Counts["mcp_tool_call:find_usages"] != 1 {
|
|
t.Errorf("find_usages count = %d, want 1", roll.Counts["mcp_tool_call:find_usages"])
|
|
}
|
|
}
|
|
|
|
// TestTelemetryDispatchDisabledRecordsNothing verifies that with consent off,
|
|
// dispatch records nothing and never creates the telemetry directory.
|
|
func TestTelemetryDispatchDisabledRecordsNothing(t *testing.T) {
|
|
s := fastPathTestServer(t)
|
|
store := telemetry.NewStore(t.TempDir())
|
|
s.SetTelemetryRecorder(telemetry.NewRecorder(telemetry.Consent{Enabled: false}, store))
|
|
|
|
callWrapped(t, s, echoHandler, "search_symbols")
|
|
s.FlushTelemetry()
|
|
|
|
if days, _ := store.Days(); len(days) != 0 {
|
|
t.Errorf("disabled telemetry wrote days %v", days)
|
|
}
|
|
}
|
|
|
|
// TestTelemetryDispatchNoRecorder verifies dispatch is unaffected when no
|
|
// recorder is installed (the default).
|
|
func TestTelemetryDispatchNoRecorder(t *testing.T) {
|
|
s := fastPathTestServer(t)
|
|
// No SetTelemetryRecorder — s.recorder is nil.
|
|
res := callWrapped(t, s, echoHandler, "search_symbols")
|
|
if res == nil {
|
|
t.Fatal("dispatch with nil recorder returned no result")
|
|
}
|
|
}
|