fix(36): compile token scope catalog once in pier boot coverage warning

This commit is contained in:
Jakub Zych
2026-11-25 01:29:28 +01:00
parent 0b90f757bc
commit 51b60b94b8
4 changed files with 109 additions and 22 deletions

View File

@@ -319,4 +319,45 @@ func TestUncoveredBackendWriteToolsWarning(t *testing.T) {
t.Fatalf("expected 0 warning lines for user-guarded write tool, got %d:\n%s", got, buf.String())
}
})
t.Run("warns_on_invalid_token_scope_catalog_without_misleading_tool_warnings", func(t *testing.T) {
buf := captureLogs(t)
app := pierAppWith(t, map[string]string{"mcp.yaml": "enabled: false\n"}, &acmeGuard{})
plugin := warningScopedPlugin{
warningBackendPlugin: warningBackendPlugin{
id: "acme.badscope",
mountMW: true,
registerMW: true,
perms: []pact.Permission{
{Code: "acme.badscope.manage", Tab: "Bad", Label: "Manage"},
},
tools: []pact.MCPTool{
{
Name: "badscope_create_item", Title: "Create item", Description: "Create item.",
Method: http.MethodPost, Path: "/acme-badscope/items/{id}", Input: warningTestInput{},
Permissions: []string{"acme.badscope.manage"},
},
},
},
scopes: []pact.TokenScope{
{
Name: "INVALID SCOPE", Label: "Bad", Description: "Invalid scope name",
Permissions: []string{"acme.badscope.*"}, Methods: allMethods,
},
},
}
host, err := mountPier(t, app, []party.Plugin{plugin})
if err != nil {
t.Fatalf("mountPier must not fail boot: %v", err)
}
t.Cleanup(func() { _ = host.pier.Close() })
logs := buf.String()
if got := countWarningLines(logs); got != 0 {
t.Fatalf("expected 0 misleading per-plugin uncovered-tool warnings on catalog error, got %d:\n%s", got, logs)
}
if !strings.Contains(logs, "could not compile token scope catalog") {
t.Fatalf("expected catalog compile warning in logs:\n%s", logs)
}
})
}