Files
skillshare/internal/server/handler_skillignore_test.go
Willie d1371db7ea fix(audit): keep the skills source when auditing agents only (#412)
* fix(audit): keep the skills source when auditing agents only

`skillshare audit --agents` replaced sourcePath with the agents source
before building auditTUIContext, so the TUI's Skills tab discovered
skills inside the agents directory. The agents-only branches now read
agentsSourcePath themselves and the skills source is left alone.

Also from the #390 review, independent of .skillfollow:

- /api/skillignore reads the source through skillsSource() like the
  other routes (equal in project mode today; consistency only).
- scripts/windows/e2e-file-links.ps1 checked doctor output for a
  "Config:" line that no longer exists and could not match the ~-shortened
  path, so the run always aborted. It now checks status --json
  source.path, as e2e-skillfollow.ps1 does.
- windows-test runs internal/sourcewalk; GOOS=windows vet passes and the
  job on this PR is the first real run.

Refs #404, #407.

* fix(audit): relativize agent names against the agents source

With discovery moved to the agents source, auditInstalled and
auditFiltered still printed the header and computed SkillName against
the skills source, so `audit agents --json` reported names such as
`../agents/helper.md` when the two sources are siblings (Codex review on
#412). auditScanRoot now picks the root per kind for discovery, header,
and relativization; the skills source is kept only for TUI tab switching.

Also drops internal/sourcewalk from windows-test again: the first run on
windows-latest fails TestWalkParity, TestWalkDirParity and
TestSymlinkRoot (callback paths come from the canonical root, so
filepath.Rel against the test's root yields `..\..` chains). Logged on
#344.
2026-10-05 11:29:39 +08:00

62 lines
1.9 KiB
Go

package server
import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
)
func TestHandleGetSkillignore_IncludesLocalFile(t *testing.T) {
s, src := newTestServer(t)
if err := os.WriteFile(filepath.Join(src, ".skillignore.local"), []byte("!feature-radar\n"), 0644); err != nil {
t.Fatalf("seed .skillignore.local: %v", err)
}
rr := httptest.NewRecorder()
s.handler.ServeHTTP(rr, httptest.NewRequest(http.MethodGet, "/api/skillignore", nil))
var resp skillignoreResponse
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
t.Fatalf("decode: %v (body=%s)", err, rr.Body.String())
}
if resp.Local == nil || resp.Local.Raw != "!feature-radar\n" {
t.Fatalf("expected local file contents, got %+v", resp.Local)
}
}
func TestHandleGetSkillignore_NoLocalFile(t *testing.T) {
s, _ := newTestServer(t)
rr := httptest.NewRecorder()
s.handler.ServeHTTP(rr, httptest.NewRequest(http.MethodGet, "/api/skillignore", nil))
var resp skillignoreResponse
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
t.Fatalf("decode: %v (body=%s)", err, rr.Body.String())
}
if resp.Local != nil {
t.Fatalf("expected no local file, got %+v", resp.Local)
}
}
// In project mode the route serves the project skills source; the handler now
// reads it through skillsSource() like the other source-reading routes.
func TestHandleGetSkillignore_ProjectModeUsesProjectSource(t *testing.T) {
s, projectRoot := newTestProjectServerWithExtras(t, nil)
rr := httptest.NewRecorder()
s.handler.ServeHTTP(rr, httptest.NewRequest(http.MethodGet, "/api/skillignore", nil))
var resp skillignoreResponse
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
t.Fatalf("decode: %v (body=%s)", err, rr.Body.String())
}
if !strings.HasPrefix(resp.Path, projectRoot+string(filepath.Separator)) {
t.Fatalf("expected .skillignore under the project source %s, got %s", projectRoot, resp.Path)
}
}