mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
feat(ui): check only the selected skills on the Updates tab (#965)
After a full check, a skill whose remote did not answer shows "Check failed". The only ways to look at it again were to check everything once more, which with many skills takes a while and re-runs the ones that already answered, or to update it without knowing whether an update exists (#963). Ticking rows on the Skills Updates tab now offers "Check N selected". It checks those tracked repos and skills only, and every other row keeps the result it had. GET /api/check/stream takes the names to limit the check to, as GET /api/update/stream already does. The action is not offered for agents: the dashboard check does not cover them, so it would report each one as failed. Closes #963 Release-As: 0.30.13
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"skillshare/internal/check"
|
||||
"skillshare/internal/install"
|
||||
@@ -27,12 +28,32 @@ type skillCheckResult struct {
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// checkNames reads the names query param (comma-separated): the tracked repos
|
||||
// and skills a check is limited to. Without it, nil: everything is checked.
|
||||
func checkNames(r *http.Request) map[string]bool {
|
||||
param := r.URL.Query().Get("names")
|
||||
if param == "" {
|
||||
return nil
|
||||
}
|
||||
only := map[string]bool{}
|
||||
for name := range strings.SplitSeq(param, ",") {
|
||||
if name = strings.TrimSpace(name); name != "" {
|
||||
only[name] = true
|
||||
}
|
||||
}
|
||||
return only
|
||||
}
|
||||
|
||||
// planSkillCheck plans the update check of every installed skill outside a
|
||||
// followed checkout. It takes s.mu.RLock, so the caller must not hold s.mu.
|
||||
func (s *Server) planSkillCheck(sourceDir, projectRoot string, walk sourcewalk.Options) *check.Resolution {
|
||||
// followed checkout, or of those in only when it is not nil. It takes
|
||||
// s.mu.RLock, so the caller must not hold s.mu.
|
||||
func (s *Server) planSkillCheck(sourceDir, projectRoot string, walk sourcewalk.Options, only map[string]bool) *check.Resolution {
|
||||
names, _ := install.GetUpdatableSkills(sourceDir)
|
||||
var skills []check.Skill
|
||||
for _, name := range names {
|
||||
if only != nil && !only[name] {
|
||||
continue
|
||||
}
|
||||
if followedCheckout(filepath.Join(sourceDir, name), walk.Follow) != "" {
|
||||
continue
|
||||
}
|
||||
@@ -80,7 +101,7 @@ func (s *Server) handleCheck(w http.ResponseWriter, r *http.Request) {
|
||||
s.mu.RUnlock()
|
||||
|
||||
repos, linked := dashboardRepos(sourceDir, walk)
|
||||
plan := s.planSkillCheck(sourceDir, projectRoot, walk)
|
||||
plan := s.planSkillCheck(sourceDir, projectRoot, walk, nil)
|
||||
|
||||
var repoResults []repoCheckResult
|
||||
for _, repo := range repos {
|
||||
|
||||
@@ -137,3 +137,33 @@ func TestHandleCheckStream_EventSequence(t *testing.T) {
|
||||
t.Errorf("skills:\n got %+v\nwant %+v", payload.Skills, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleCheckStream_NamesLimitTheCheck(t *testing.T) {
|
||||
s, src := newTestServer(t)
|
||||
checktest.Seed(t, t.TempDir(), src)
|
||||
addTrackedRepoWithBrokenIndex(t, src, "_team")
|
||||
addTrackedRepoWithBrokenIndex(t, src, "_other")
|
||||
s.reloadSkillsStore()
|
||||
|
||||
rr := httptest.NewRecorder()
|
||||
s.handleCheckStream(rr, httptest.NewRequest(http.MethodGet, "/api/check/stream?names=_team,changed", nil))
|
||||
|
||||
blocks := strings.Split(strings.TrimSpace(rr.Body.String()), "\n\n")
|
||||
if len(blocks) < 3 {
|
||||
t.Fatalf("expected at least discovering, start and done, got %q", rr.Body.String())
|
||||
}
|
||||
if want := "event: start\ndata: " + `{"repos":1,"sources":1,"total":2}`; blocks[1] != want {
|
||||
t.Errorf("second event = %q, want %q", blocks[1], want)
|
||||
}
|
||||
_, done, ok := strings.Cut(blocks[len(blocks)-1], "event: done\ndata: ")
|
||||
if !ok {
|
||||
t.Fatalf("last event = %q, want done", blocks[len(blocks)-1])
|
||||
}
|
||||
payload := decodeCheckPayload(t, done)
|
||||
if len(payload.TrackedRepos) != 1 || payload.TrackedRepos[0].Name != "_team" {
|
||||
t.Errorf("tracked repos = %+v, want only _team", payload.TrackedRepos)
|
||||
}
|
||||
if len(payload.Skills) != 1 || payload.Skills[0].Name != "changed" {
|
||||
t.Errorf("skills = %+v, want only changed", payload.Skills)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -19,6 +20,9 @@ import (
|
||||
//
|
||||
// "total" counts actual work units (repos + remote URL groups), NOT individual skills.
|
||||
// This ensures the progress bar advances evenly — one tick per network call.
|
||||
//
|
||||
// Query params: names (comma-separated) limits the check to those tracked repos
|
||||
// and skills; the events then cover only them.
|
||||
func (s *Server) handleCheckStream(w http.ResponseWriter, r *http.Request) {
|
||||
safeSend, ok := initSSE(w)
|
||||
if !ok {
|
||||
@@ -38,9 +42,13 @@ func (s *Server) handleCheckStream(w http.ResponseWriter, r *http.Request) {
|
||||
// Immediate feedback before the potentially slow discovery walk.
|
||||
safeSend("discovering", map[string]string{"phase": "scanning source directory"})
|
||||
|
||||
only := checkNames(r)
|
||||
repos, linked := dashboardRepos(sourceDir, walk)
|
||||
if only != nil {
|
||||
repos = slices.DeleteFunc(repos, func(repo string) bool { return !only[repo] })
|
||||
}
|
||||
// Group skills by remote (fast, local only).
|
||||
plan := s.planSkillCheck(sourceDir, projectRoot, walk)
|
||||
plan := s.planSkillCheck(sourceDir, projectRoot, walk, only)
|
||||
|
||||
// Total = repos + URL groups (the actual network-bound work units).
|
||||
total := len(repos) + plan.Remotes()
|
||||
|
||||
@@ -38,9 +38,13 @@ export const installApi = {
|
||||
onProgress: (checked: number) => void,
|
||||
onDone: (data: CheckResult) => void,
|
||||
onError: (err: Error) => void,
|
||||
/** Tracked repos and skills to check; every one of them when omitted. */
|
||||
names?: string[],
|
||||
): EventSource =>
|
||||
createSSEStream(
|
||||
BASE + '/check/stream',
|
||||
BASE +
|
||||
'/check/stream' +
|
||||
(names?.length ? `?${new URLSearchParams({ names: names.join(',') })}` : ''),
|
||||
{
|
||||
discovering: () => onDiscovering(),
|
||||
start: (d) => onStart(d.total),
|
||||
|
||||
@@ -949,6 +949,7 @@
|
||||
"update.empty.title": "Keine aktualisierbaren Skills",
|
||||
"update.empty.agentsTitle": "Keine aktualisierbaren Agents",
|
||||
"update.empty.agentsDescription": "Von GitHub oder aus einem getrackten Repo installierte Agents lassen sich hier aktualisieren.",
|
||||
"update.header.checkSelected": "Ausgewählte prüfen ({count})",
|
||||
"update.header.updateSelected": "Ausgewählte aktualisieren ({count})",
|
||||
"update.status.blocked": "Blockiert",
|
||||
"update.status.failed": "Fehlgeschlagen",
|
||||
|
||||
@@ -871,6 +871,7 @@
|
||||
"update.empty.title": "No updatable skills",
|
||||
"update.empty.agentsTitle": "No updatable agents",
|
||||
"update.empty.agentsDescription": "Agents installed from GitHub or a tracked repo can be updated here.",
|
||||
"update.header.checkSelected": "Check {count} selected",
|
||||
"update.header.updateSelected": "Update {count} selected",
|
||||
"update.status.blocked": "Blocked",
|
||||
"update.status.failed": "Failed",
|
||||
|
||||
@@ -949,6 +949,7 @@
|
||||
"update.empty.title": "Sin skills actualizables",
|
||||
"update.empty.agentsTitle": "Sin agents actualizables",
|
||||
"update.empty.agentsDescription": "Los agents instalados desde GitHub o un repo rastreado se pueden actualizar aquí.",
|
||||
"update.header.checkSelected": "Comprobar seleccionados ({count})",
|
||||
"update.header.updateSelected": "Actualizar seleccionados ({count})",
|
||||
"update.status.blocked": "Bloqueado",
|
||||
"update.status.failed": "Fallido",
|
||||
|
||||
@@ -949,6 +949,7 @@
|
||||
"update.empty.title": "هیچ اسکیل قابل بهروزرسانی وجود ندارد",
|
||||
"update.empty.agentsTitle": "هیچ ایجنت قابل بهروزرسانی وجود ندارد",
|
||||
"update.empty.agentsDescription": "ایجنتهایی که از GitHub یا یک مخزن ردیابیشده نصب شدهاند را میتوان اینجا بهروزرسانی کرد.",
|
||||
"update.header.checkSelected": "بررسی انتخابشدهها ({count})",
|
||||
"update.header.updateSelected": "بهروزرسانی انتخابشدهها ({count})",
|
||||
"update.status.blocked": "مسدود شده",
|
||||
"update.status.failed": "ناموفق",
|
||||
|
||||
@@ -949,6 +949,7 @@
|
||||
"update.empty.title": "Aucun skill pouvant être mis à jour",
|
||||
"update.empty.agentsTitle": "Aucun agent pouvant être mis à jour",
|
||||
"update.empty.agentsDescription": "Les agents installés depuis GitHub ou un dépôt suivi peuvent être mis à jour ici.",
|
||||
"update.header.checkSelected": "Vérifier la sélection ({count})",
|
||||
"update.header.updateSelected": "Mettre à jour la sélection ({count})",
|
||||
"update.status.blocked": "Bloqué",
|
||||
"update.status.failed": "Échec",
|
||||
|
||||
@@ -949,6 +949,7 @@
|
||||
"update.empty.title": "Tidak ada skill yang dapat diperbarui",
|
||||
"update.empty.agentsTitle": "Tidak ada agent yang dapat diperbarui",
|
||||
"update.empty.agentsDescription": "Agent yang dipasang dari GitHub atau repo terlacak dapat diperbarui di sini.",
|
||||
"update.header.checkSelected": "Periksa Terpilih ({count})",
|
||||
"update.header.updateSelected": "Perbarui Terpilih ({count})",
|
||||
"update.status.blocked": "Diblokir",
|
||||
"update.status.failed": "Gagal",
|
||||
|
||||
@@ -949,6 +949,7 @@
|
||||
"update.empty.title": "更新可能なスキルがありません",
|
||||
"update.empty.agentsTitle": "更新可能なエージェントがありません",
|
||||
"update.empty.agentsDescription": "GitHub や追跡中のリポジトリからインストールしたエージェントはここで更新できます。",
|
||||
"update.header.checkSelected": "選択した項目を確認({count})",
|
||||
"update.header.updateSelected": "選択した項目を更新({count})",
|
||||
"update.status.blocked": "ブロック済み",
|
||||
"update.status.failed": "失敗",
|
||||
|
||||
@@ -949,6 +949,7 @@
|
||||
"update.empty.title": "업데이트 가능한 skills 없음",
|
||||
"update.empty.agentsTitle": "업데이트 가능한 agents 없음",
|
||||
"update.empty.agentsDescription": "GitHub 또는 추적 중인 저장소에서 설치한 agents는 여기에서 업데이트할 수 있습니다.",
|
||||
"update.header.checkSelected": "선택 항목 확인 ({count})",
|
||||
"update.header.updateSelected": "선택 항목 업데이트 ({count})",
|
||||
"update.status.blocked": "차단됨",
|
||||
"update.status.failed": "실패",
|
||||
|
||||
@@ -949,6 +949,7 @@
|
||||
"update.empty.title": "Nenhuma skill atualizável",
|
||||
"update.empty.agentsTitle": "Nenhum agent atualizável",
|
||||
"update.empty.agentsDescription": "Agents instalados do GitHub ou de um repo rastreado podem ser atualizados aqui.",
|
||||
"update.header.checkSelected": "Verificar Selecionados ({count})",
|
||||
"update.header.updateSelected": "Atualizar Selecionados ({count})",
|
||||
"update.status.blocked": "Bloqueado",
|
||||
"update.status.failed": "Falhou",
|
||||
|
||||
@@ -949,6 +949,7 @@
|
||||
"update.empty.title": "没有可更新的 skill",
|
||||
"update.empty.agentsTitle": "没有可更新的 agent",
|
||||
"update.empty.agentsDescription": "从 GitHub 或追踪仓库安装的 agent 可在这里更新。",
|
||||
"update.header.checkSelected": "检查所选({count})",
|
||||
"update.header.updateSelected": "更新所选({count})",
|
||||
"update.status.blocked": "已拦截",
|
||||
"update.status.failed": "失败",
|
||||
|
||||
@@ -949,6 +949,7 @@
|
||||
"update.empty.title": "沒有可更新的 skills",
|
||||
"update.empty.agentsTitle": "沒有可更新的 agents",
|
||||
"update.empty.agentsDescription": "從 GitHub 或追蹤中的 repo 安裝的 agents 可以在這裡更新。",
|
||||
"update.header.checkSelected": "檢查已選取({count})",
|
||||
"update.header.updateSelected": "更新已選取({count})",
|
||||
"update.status.blocked": "已封鎖",
|
||||
"update.status.failed": "失敗",
|
||||
|
||||
+49
-32
@@ -306,37 +306,43 @@ export default function UpdatePage({ kind }: { kind: Kind }) {
|
||||
[updatable, setStatuses, queryClient],
|
||||
);
|
||||
|
||||
const runCheck = useCallback(() => {
|
||||
esRef.current?.close();
|
||||
setChecking(true);
|
||||
setPruned(0);
|
||||
setRun(new Map());
|
||||
setFinished(false);
|
||||
setStatuses((prev) => {
|
||||
const next = new Map(prev);
|
||||
for (const item of updatable) next.set(checkKey(item), { status: 'checking' });
|
||||
return next;
|
||||
});
|
||||
esRef.current = api.checkStream(
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
(result) => {
|
||||
applyCheckResult(result);
|
||||
setChecking(false);
|
||||
},
|
||||
(err) => {
|
||||
toast(err.message, 'error');
|
||||
setStatuses((prev) => {
|
||||
const next = new Map(prev);
|
||||
const checkedAt = new Date().toISOString();
|
||||
for (const item of updatable) next.set(checkKey(item), { status: 'error', checkedAt });
|
||||
return next;
|
||||
});
|
||||
setChecking(false);
|
||||
},
|
||||
);
|
||||
}, [updatable, applyCheckResult, setStatuses, toast]);
|
||||
// Checks the given units, leaving every other result as it is; all of them when omitted.
|
||||
const runCheck = useCallback(
|
||||
(only?: UpdateUnit[]) => {
|
||||
const items = only ? only.flatMap((u) => u.items) : updatable;
|
||||
esRef.current?.close();
|
||||
setChecking(true);
|
||||
setPruned(0);
|
||||
setRun(new Map());
|
||||
setFinished(false);
|
||||
setStatuses((prev) => {
|
||||
const next = new Map(prev);
|
||||
for (const item of items) next.set(checkKey(item), { status: 'checking' });
|
||||
return next;
|
||||
});
|
||||
esRef.current = api.checkStream(
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
(result) => {
|
||||
applyCheckResult(result);
|
||||
setChecking(false);
|
||||
},
|
||||
(err) => {
|
||||
toast(err.message, 'error');
|
||||
setStatuses((prev) => {
|
||||
const next = new Map(prev);
|
||||
const checkedAt = new Date().toISOString();
|
||||
for (const item of items) next.set(checkKey(item), { status: 'error', checkedAt });
|
||||
return next;
|
||||
});
|
||||
setChecking(false);
|
||||
},
|
||||
only?.map((u) => u.name),
|
||||
);
|
||||
},
|
||||
[updatable, applyCheckResult, setStatuses, toast],
|
||||
);
|
||||
|
||||
/* -- Update -- */
|
||||
|
||||
@@ -810,10 +816,21 @@ export default function UpdatePage({ kind }: { kind: Kind }) {
|
||||
onChange={setForce}
|
||||
disabled={busy}
|
||||
/>
|
||||
<Button variant="secondary" loading={checking} disabled={running} onClick={runCheck}>
|
||||
<Button
|
||||
variant="secondary"
|
||||
loading={checking}
|
||||
disabled={running}
|
||||
onClick={() => runCheck()}
|
||||
>
|
||||
<RefreshCw size={15} />
|
||||
{t(lastChecked ? 'update.tab.checkAgain' : 'update.tab.checkNow')}
|
||||
</Button>
|
||||
{/* The check does not cover agents, so only skills can be checked by selection. */}
|
||||
{kind === 'skill' && shown.length > 0 && (
|
||||
<Button variant="secondary" disabled={busy} onClick={() => runCheck(shown)}>
|
||||
{t('update.header.checkSelected', { count: shown.length })}
|
||||
</Button>
|
||||
)}
|
||||
{shown.length > 0 && (
|
||||
<Button
|
||||
variant="secondary"
|
||||
|
||||
Reference in New Issue
Block a user