Files
magpie/internal/gui/library_market_test.go
T
yetone b7a926e9aa library, gui: a market search one source of which didn't answer says which, over what the rest found, not a failed search; a 503 is asked once more (#1589, Ti800)
Ti800 searched the Library's Discover for "prototype" and saw the amber
error "couldn't search skills.sh: www.skills.sh answered 503 Service
Unavailable" over two results. The cause was neither a stale request
(fetchMarket already drops an answer whose seq is old, results and error
alike) nor an error left over from an earlier search: MarketSkills matches
skills.sh's most-installed list (front page, cached) and magpie's picks
itself, then asks skills.sh's search. The search answered 503; the two
cards were the most-installed list's matches, and the handler sent both
the list and the search's error, which the page drew as a failed search.

- library: the search's failure is a SearchError naming its source
  (skills.sh, the MCP Registry); get() asks once more after a 503, after
  a one-second pause (one extra try, nothing else retried).
- gui: /api/library/market/{skills,servers} add failed and cause beside
  error. With results, the page says in a muted line with an amber dot
  that skills.sh's search (or the MCP Registry) didn't answer and why, and
  that these are only the matches among magpie's picks and the most
  installed (or magpie's featured servers). With no results the error bar
  is as before. Strings in zh, zh-TW, ja, de.

Siblings: the MCP market has the same shape (featured + registry) and gets
the same notice. The Plugins page's npm search already shows its error in
the "On npm" section only, beside the market's own list, keyed by query.

Tests:
- internal/library TestSkillsSearch503 (httptest fake skills.sh): 503 then
  200 gives the search's results and no error; 503 every time gives the
  popular match and a SearchError for skills.sh, searched exactly twice.
  With the retry taken out it fails: "after one 503:
  [mattpocock/skills/prototype] couldn't search skills.sh: … 503 …, 1
  searches".
- internal/gui TestMarketOfNamesTheFailedSource.
- gui tests market-partial.test.cjs: the reporter's case (two results +
  skills.sh 503), nothing found (error kept), an older search's 503
  answered 1.2s after a newer search's results (nothing changes), and the
  MCP Registry case; Chromium and WebKit, en/zh/zh-TW/ja/de, 520px wide:
  10/10. With the new branch disabled, 5/5 Chromium fail with "the partial
  list is shown as a failed search". market-*.test.cjs and
  library-discover-jump: 114/114.
- go test ./internal/library ./internal/gui, gofmt -l, GOOS=linux and
  GOOS=windows go vet -tags nogui on both packages; full suite in the
  push record.
Not tried against the real skills.sh (it answers 200 now); the fake
answers 503 as the report's text says.
2026-10-11 20:10:05 +08:00

28 lines
933 B
Go

package gui
import (
"errors"
"fmt"
"testing"
"github.com/yetone/magpie/internal/library"
)
// A market search one source of which didn't answer tells the page which
// source and why, apart from the whole error, for it to say the list is
// short rather than that the search failed (#1589); any other error is the
// error alone.
func TestMarketOfNamesTheFailedSource(t *testing.T) {
err := fmt.Errorf("x: %w", &library.SearchError{Source: "skills.sh", Err: errors.New("www.skills.sh answered 503 Service Unavailable")})
m := marketOf([]int{1}, err)
if m.Failed != "skills.sh" || m.Cause != "www.skills.sh answered 503 Service Unavailable" || m.Error != err.Error() {
t.Fatalf("%+v", m)
}
if m := marketOf([]int{}, errors.New("disk full")); m.Failed != "" || m.Cause != "" || m.Error != "disk full" {
t.Fatalf("%+v", m)
}
if m := marketOf([]int{}, nil); m.Failed != "" || m.Error != "" {
t.Fatalf("%+v", m)
}
}