tinyrelayfile
tinyrelay/internal/daemon/mcp_docs_test.go/

internal/daemon/mcp_docs_test.go raw
1package daemon
2
3import (
4 "context"
5 "net/http"
6 "net/http/httptest"
7 "os"
8 "regexp"
9 "strings"
10 "testing"
11)
12
13func TestLLMSDocumentsRegisteredToolsAndRoutes(t *testing.T) {
14 app, tenant := testTenant(t)
15 for _, prefix := range []string{"", "/r/main"} {
16 t.Run(prefix, func(t *testing.T) {
17 response := httptest.NewRecorder()
18 app.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "http://relay.test"+prefix+"/llms.txt?v=docs", nil))
19 if response.Code != http.StatusOK {
20 t.Fatalf("llms.txt status: %d", response.Code)
21 }
22 body := response.Body.String()
23 words := map[string]bool{}
24 for _, word := range regexp.MustCompile(`[a-z_]+`).FindAllString(body, -1) {
25 words[word] = true
26 }
27 for _, tool := range tenant.mcp.Tools.Tools() {
28 if !words[tool.Name] {
29 t.Errorf("registered tool %q is missing from llms.txt", tool.Name)
30 }
31 }
32 for _, path := range []string{"/mcp", "/chat", "/social", "/account", "/approvals", "/files", "/wiki"} {
33 if !strings.Contains(body, "http://relay.test"+prefix+path) {
34 t.Errorf("missing tenant-aware route %s", path)
35 }
36 }
37 if strings.Contains(body, "?v=docs") {
38 t.Error("cache-busting query leaked into documentation URLs")
39 }
40 links := regexp.MustCompile(`https://github.com/FelineStateMachine/tinyrelay/blob/main/(docs/[a-z-]+\.md)`).FindAllStringSubmatch(body, -1)
41 if len(links) < 8 {
42 t.Errorf("expected feature guides, got %d documentation links", len(links))
43 }
44 for _, link := range links {
45 if _, err := os.Stat("../../" + link[1]); err != nil {
46 t.Errorf("broken guide link %s: %v", link[1], err)
47 }
48 }
49 })
50 }
51}
52
53func TestLLMSKeepsPrivatePresentationOutOfPublicGuide(t *testing.T) {
54 app, tenant := testTenant(t)
55 policy := tenant.Policy()
56 policy.Features.Grasp = true
57 policy.Features.Grasp08 = true
58 policy.Reads = "members"
59 policy.Name, policy.Description = "secret-name", "secret-description"
60 if err := tenant.applyPolicy(context.Background(), policy); err != nil {
61 t.Fatal(err)
62 }
63 response := httptest.NewRecorder()
64 app.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "http://relay.test/llms.txt", nil))
65 body := response.Body.String()
66 if response.Code != http.StatusOK || strings.Contains(body, "secret-name") || strings.Contains(body, "secret-description") {
67 t.Fatalf("private guide status=%d body=%s", response.Code, body)
68 }
69}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs