Closes #52 — unblocks parallax#3 dispatch labeling, which needs to both discover a repo's label set and attach labels to an issue by name (the CAD pipeline doesn't track Gitea's internal numeric label IDs). - gitea.Client: ListLabels, AddIssueLabels (additive POST, matches Gitea's own semantics — no delete-then-post needed); extend the existing Label struct with Color for label_list's output. - tools.LabelList (read-only, allowlisted): lists a repo's labels. - tools.IssueLabel (allowlisted): resolves label names to IDs via ListLabels, so callers pass names (the primary interface) instead of hunting for numeric IDs; also accepts label_ids for callers that already have them. An unknown name fails closed, naming exactly which label wasn't found. - Bump TestRegisteredToolCount 39 -> 41 in the same commit (this project was bitten today by a locked count going stale silently). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package tools_test
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"git.d-ma.be/mathias/gitea-mcp/internal/allowlist"
|
|
"git.d-ma.be/mathias/gitea-mcp/internal/gitea"
|
|
"git.d-ma.be/mathias/gitea-mcp/internal/tools"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestLabelListTool(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
assert.Equal(t, http.MethodGet, r.Method)
|
|
assert.Equal(t, "/api/v1/repos/mathias/infra/labels", r.URL.Path)
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_, _ = w.Write([]byte(`[
|
|
{"id":1,"name":"bug","color":"ee0701"},
|
|
{"id":2,"name":"enhancement","color":"84b6eb"}
|
|
]`))
|
|
}))
|
|
defer srv.Close()
|
|
|
|
tool := tools.NewLabelList(gitea.NewClient(srv.URL, "tok"), allowlist.New([]string{"mathias"}))
|
|
out, err := tool.Call(context.Background(), json.RawMessage(`{"owner":"mathias","repo":"infra"}`))
|
|
require.NoError(t, err)
|
|
assert.Contains(t, string(out), `"id":1`)
|
|
assert.Contains(t, string(out), `"name":"bug"`)
|
|
assert.Contains(t, string(out), `"color":"ee0701"`)
|
|
assert.Contains(t, string(out), `"name":"enhancement"`)
|
|
}
|
|
|
|
func TestLabelListAllowlistRejects(t *testing.T) {
|
|
tool := tools.NewLabelList(gitea.NewClient("http://unused", ""), allowlist.New([]string{"mathias"}))
|
|
_, err := tool.Call(context.Background(), json.RawMessage(`{"owner":"evil","repo":"x"}`))
|
|
require.Error(t, err)
|
|
}
|