mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
* feat(audit): show unfollowed source links in Markdown and the TUI When a followed source link could not be read, only text output (and JSON's warnings/incomplete fields) said so. A Markdown report looked like a full scan, and the TUI covered the warnings printed before it opened, so a partial scan read as complete there. Item 25 of #746 asks for incomplete status to stay visible in human reports, including under --min-severity. Markdown now ends its summary with a "Source links not followed" section, led by an "Incomplete scan" line when a link could not be read. The TUI summary line starts with the count in the warning colour. JSON and SARIF are unchanged. * feat(ui): mark a partial audit scan on the dashboard The audit API dropped the source-link warnings the scan collected, so the dashboard showed a scan that skipped an unreadable followed link as complete. Item 25 of #746 asks for incomplete status to stay visible in every human report, the dashboard included. GET /api/audit and the stream's done event now carry warnings and incomplete with the same meaning as `audit --format json`, and the Audit page shows the count beside the Skills/Agents tabs. * feat(ui): stop calling an incomplete audit scan all clear After a scan that skipped an unreadable followed source link, the Audit page still toasted "no dangerous content" and the Dashboard's Quick Scan toasted "All clear", while the home page showed nothing, so a partial scan still read as a clean one there. Both toasts now warn that the scan is incomplete, and the home page's "Needs attention" list gets a row linking to the Audit page. One helper words the note for the Audit page label, both toasts and the row. --------- Co-authored-by: sim <sim@example.invalid>
166 lines
6.3 KiB
Go
166 lines
6.3 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestHandleListSkills_SourceLinkWarnings(t *testing.T) {
|
|
for _, project := range []bool{false, true} {
|
|
t.Run(fmt.Sprintf("project=%t", project), func(t *testing.T) {
|
|
s, source := newUpdateFollowServer(t, project, true)
|
|
addSkill(t, source, "healthy")
|
|
if err := os.Symlink(filepath.Join(t.TempDir(), "missing"), filepath.Join(source, "gone")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
rr := httptest.NewRecorder()
|
|
s.handleListSkills(rr, httptest.NewRequest(http.MethodGet, "/api/resources", nil))
|
|
var resp struct {
|
|
Resources []skillItem `json:"resources"`
|
|
Warnings []string `json:"sourceLinkWarnings"`
|
|
}
|
|
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(resp.Resources) != 1 || resp.Resources[0].Name != "healthy" {
|
|
t.Fatalf("healthy inventory lost: %s", rr.Body.String())
|
|
}
|
|
if len(resp.Warnings) != 1 || !strings.Contains(resp.Warnings[0], "source link gone not followed: target is missing") {
|
|
t.Fatalf("missing warning: %s", rr.Body.String())
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestHandleGetSkill_FollowedLinkRootFiles(t *testing.T) {
|
|
for _, project := range []bool{false, true} {
|
|
for _, enabled := range []bool{false, true} {
|
|
t.Run(fmt.Sprintf("project=%t/follow=%t", project, enabled), func(t *testing.T) {
|
|
s, source := newUpdateFollowServer(t, project, enabled)
|
|
checkout := t.TempDir()
|
|
if err := os.MkdirAll(filepath.Join(checkout, "assets"), 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for name, content := range map[string]string{"SKILL.md": "# Linked root skill\n", "assets/notes.txt": "attachment\n"} {
|
|
if err := os.WriteFile(filepath.Join(checkout, name), []byte(content), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
link := filepath.Join(source, "_dev-skills")
|
|
if err := os.Symlink(checkout, link); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
rr := httptest.NewRecorder()
|
|
req := httptest.NewRequest(http.MethodGet, "/api/resources/_dev-skills", nil)
|
|
req.SetPathValue("name", "_dev-skills")
|
|
s.handleGetSkill(rr, req)
|
|
if !enabled {
|
|
if rr.Code != http.StatusNotFound {
|
|
t.Fatalf("disabled link discovered: %d %s", rr.Code, rr.Body.String())
|
|
}
|
|
return
|
|
}
|
|
var resp struct {
|
|
Resource skillItem `json:"resource"`
|
|
Files []string `json:"files"`
|
|
Content string `json:"skillMdContent"`
|
|
}
|
|
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if rr.Code != http.StatusOK || !slices.Equal(resp.Files, []string{"SKILL.md", "assets/notes.txt"}) {
|
|
t.Fatalf("root-of-link files missing: %d %s", rr.Code, rr.Body.String())
|
|
}
|
|
if resp.Resource.SourcePath != link || resp.Resource.RelPath != "_dev-skills" || resp.Content != "# Linked root skill\n" {
|
|
t.Fatalf("logical skill response changed: %+v", resp)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSetTargetsRefusesNestedSkillLink(t *testing.T) {
|
|
for _, project := range []bool{false, true} {
|
|
for _, batch := range []bool{false, true} {
|
|
t.Run(fmt.Sprintf("project=%t/batch=%t", project, batch), func(t *testing.T) {
|
|
s, source := newUpdateFollowServer(t, project, true)
|
|
checkout := t.TempDir()
|
|
addSkill(t, checkout, "healthy")
|
|
if err := os.Mkdir(filepath.Join(checkout, "linked-file"), 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
outside := filepath.Join(t.TempDir(), "outside.md")
|
|
original := "---\nname: linked-file\n---\nOutside content\n"
|
|
if err := os.WriteFile(outside, []byte(original), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Symlink(outside, filepath.Join(checkout, "linked-file", "SKILL.md")); err != nil {
|
|
t.Skip(err)
|
|
}
|
|
if err := os.Symlink(checkout, filepath.Join(source, "linked-source")); err != nil {
|
|
t.Skip(err)
|
|
}
|
|
rr := httptest.NewRecorder()
|
|
if batch {
|
|
s.handleBatchSetTargets(rr, httptest.NewRequest(http.MethodPost, "/api/skills/batch/targets", strings.NewReader(`{"folder":"*","target":"claude"}`)))
|
|
var resp batchSetTargetsResponse
|
|
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if rr.Code != http.StatusOK || resp.Updated != 1 || len(resp.Errors) != 1 || !strings.Contains(resp.Errors[0], "is a link") {
|
|
t.Fatalf("batch refusal missing: %d %s", rr.Code, rr.Body.String())
|
|
}
|
|
} else {
|
|
req := httptest.NewRequest(http.MethodPatch, "/api/resources/linked-source__linked-file/targets", strings.NewReader(`{"target":"claude"}`))
|
|
req.SetPathValue("name", "linked-source__linked-file")
|
|
s.handleSetSkillTargets(rr, req)
|
|
if rr.Code != http.StatusBadRequest || !strings.Contains(rr.Body.String(), "is a link") {
|
|
t.Fatalf("single refusal missing: %d %s", rr.Code, rr.Body.String())
|
|
}
|
|
rr = httptest.NewRecorder()
|
|
req = httptest.NewRequest(http.MethodPatch, "/api/resources/linked-source__healthy/targets", strings.NewReader(`{"target":"claude"}`))
|
|
req.SetPathValue("name", "linked-source__healthy")
|
|
s.handleSetSkillTargets(rr, req)
|
|
if rr.Code != http.StatusOK {
|
|
t.Fatalf("healthy skill failed: %d %s", rr.Code, rr.Body.String())
|
|
}
|
|
}
|
|
if got, err := os.ReadFile(outside); err != nil || string(got) != original {
|
|
t.Fatalf("outside file changed: %q, %v", got, err)
|
|
}
|
|
got, err := os.ReadFile(filepath.Join(checkout, "healthy", "SKILL.md"))
|
|
if err != nil || !strings.Contains(string(got), "- claude") {
|
|
t.Fatalf("healthy targets missing: %q, %v", got, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestHandleAuditAll_ReportsUnfollowedSourceLink(t *testing.T) {
|
|
s, source := newUpdateFollowServer(t, false, true)
|
|
addSkill(t, source, "healthy")
|
|
if err := os.Symlink(filepath.Join(t.TempDir(), "missing"), filepath.Join(source, "gone")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
rr := httptest.NewRecorder()
|
|
s.handleAuditAll(rr, httptest.NewRequest(http.MethodGet, "/api/audit", nil))
|
|
var resp struct {
|
|
Warnings []string `json:"warnings"`
|
|
Incomplete bool `json:"incomplete"`
|
|
}
|
|
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !resp.Incomplete || len(resp.Warnings) != 1 || !strings.Contains(resp.Warnings[0], "source link gone not followed: target is missing") {
|
|
t.Fatalf("partial scan reported as complete: %s", rr.Body.String())
|
|
}
|
|
}
|