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

94 lines
4.3 KiB
Go

package mcp
import (
"context"
"strings"
"testing"
"github.com/mark3labs/mcp-go/mcp"
"github.com/stretchr/testify/require"
)
// providerMatrixMarker is the 13-provider enumeration — the single-home
// marker for the LLM-provider matrix. It must appear in the guide and NOWHERE
// in the installed CLAUDE.md sections (asserted by the single-home gate).
const providerMatrixMarker = "`local` / `anthropic` / `openai` / `azure` / `ollama` / `claudecli` / `codex` / `copilot` / `cursor` / `opencode` / `gemini` / `bedrock` / `deepseek`"
// formatDeepDiveMarker is a phrase unique to the wire-format deep-dive in the
// server instructions (sharedParamLegend). It is the single-home marker for
// "format lives only in the instructions" — asserted absent from the guide
// here and from the CLAUDE.md sections in the agents package.
const formatDeepDiveMarker = "compact tabular text, lossy"
// TestGuideText_TopicsAndContent verifies each relocated reference block is
// reachable through GuideText, both in the full render and section-addressed.
func TestGuideText_TopicsAndContent(t *testing.T) {
full := GuideText("")
require.Contains(t, full, "# Gortex Guide")
require.Contains(t, full, providerMatrixMarker, "provider matrix must live in the guide")
require.Contains(t, full, "Overlay sessions", "capabilities catalog must live in the guide")
require.Contains(t, full, "compress_bodies", "token-economy content must live in the guide")
require.Contains(t, full, "gortex://report", "resources list must live in the guide")
// Section addressing returns just that section.
require.Contains(t, GuideText("providers"), providerMatrixMarker)
require.NotContains(t, GuideText("providers"), "Overlay sessions",
"a section address must return only its section")
require.Contains(t, GuideText("capabilities"), "Speculative execution")
require.Contains(t, GuideText("resources"), "gortex://guide")
// The analyze / search_ast sections point at the single-source catalog
// (kind:"help" / detector:"help" / gortex://schema) rather than re-inlining
// it — the grouped summary + a pointer, not the full per-kind text.
analyze := GuideText("analyze")
require.Contains(t, analyze, "dead_code")
require.Contains(t, analyze, `kind:"help"`)
require.NotContains(t, analyze, analyzeCatalogText(),
"the guide points at the analyze catalog; it must not re-inline the full per-kind text")
searchAST := GuideText("search_ast")
require.Contains(t, searchAST, "detector")
require.Contains(t, searchAST, `detector:"help"`)
// Aliases resolve.
require.Equal(t, GuideText("llm"), GuideText("providers"))
require.Equal(t, GuideText("features"), GuideText("capabilities"))
// Unknown topic degrades to the full guide (still useful, names topics).
unknown := GuideText("does-not-exist")
require.Contains(t, unknown, "# Gortex Guide")
require.Contains(t, unknown, providerMatrixMarker)
}
// TestGuideText_FormatDeepDiveStaysInInstructions enforces that the wire-
// FORMAT deep-dive is NOT re-inlined into the guide — it lives once in the
// server instructions (sharedParamLegend). The guide only points at it.
func TestGuideText_FormatDeepDiveStaysInInstructions(t *testing.T) {
require.Contains(t, sharedParamLegend, formatDeepDiveMarker,
"the wire-format deep-dive must live in the server instructions")
require.NotContains(t, GuideText(""), formatDeepDiveMarker,
"the guide must point at the server-instructions format legend, not repeat it")
}
// TestGuideResource_ReturnsContent drives the MCP resource handlers.
func TestGuideResource_ReturnsContent(t *testing.T) {
s := &Server{}
got, err := s.handleResourceGuide(context.Background(), mcp.ReadResourceRequest{
Params: mcp.ReadResourceParams{URI: "gortex://guide"},
})
require.NoError(t, err)
require.Len(t, got, 1)
trc, ok := got[0].(mcp.TextResourceContents)
require.True(t, ok)
require.Contains(t, trc.Text, providerMatrixMarker)
sec, err := s.handleResourceGuideSection(context.Background(), mcp.ReadResourceRequest{
Params: mcp.ReadResourceParams{URI: "gortex://guide/capabilities"},
})
require.NoError(t, err)
require.Len(t, sec, 1)
secText := sec[0].(mcp.TextResourceContents).Text
require.Contains(t, secText, "Speculative execution")
require.False(t, strings.Contains(secText, providerMatrixMarker),
"the capabilities section must not carry the provider matrix")
}