mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
fix: address code review findings
- Fix data race: read agentsSource inside RLock in handleDiffStream - Validate kind param in handleSync (reject invalid values) - Add test for symlink-points-elsewhere agent diff case - Always show KindBadge on DiffItemRow (default to 'skill')
This commit is contained in:
@@ -56,6 +56,36 @@ func TestComputeAgentTargetDiff_LocalFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeAgentTargetDiff_SymlinkPointsElsewhere(t *testing.T) {
|
||||
sourceDir := t.TempDir()
|
||||
otherDir := t.TempDir()
|
||||
targetDir := t.TempDir()
|
||||
|
||||
srcFile := filepath.Join(sourceDir, "agent.md")
|
||||
os.WriteFile(srcFile, []byte("# Agent"), 0644)
|
||||
otherFile := filepath.Join(otherDir, "agent.md")
|
||||
os.WriteFile(otherFile, []byte("# Other"), 0644)
|
||||
|
||||
// Symlink points to otherFile, not srcFile
|
||||
os.Symlink(otherFile, filepath.Join(targetDir, "agent.md"))
|
||||
|
||||
agents := []resource.DiscoveredResource{
|
||||
{FlatName: "agent.md", AbsPath: srcFile, RelPath: "agent.md"},
|
||||
}
|
||||
|
||||
items := computeAgentTargetDiff(targetDir, agents)
|
||||
|
||||
if len(items) != 1 {
|
||||
t.Fatalf("expected 1 item, got %d", len(items))
|
||||
}
|
||||
if items[0].Action != "update" {
|
||||
t.Errorf("expected action 'update', got %q", items[0].Action)
|
||||
}
|
||||
if items[0].Reason != "symlink points elsewhere" {
|
||||
t.Errorf("expected reason 'symlink points elsewhere', got %q", items[0].Reason)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeAgentTargetDiff_InSync(t *testing.T) {
|
||||
sourceDir := t.TempDir()
|
||||
targetDir := t.TempDir()
|
||||
|
||||
@@ -29,6 +29,7 @@ func (s *Server) handleDiffStream(w http.ResponseWriter, r *http.Request) {
|
||||
// Snapshot config under RLock, then release before slow I/O.
|
||||
s.mu.RLock()
|
||||
source := s.cfg.Source
|
||||
agentsSource := s.agentsSource()
|
||||
globalMode := s.cfg.Mode
|
||||
targets := s.cloneTargets()
|
||||
s.mu.RUnlock()
|
||||
@@ -68,7 +69,6 @@ func (s *Server) handleDiffStream(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Agent diffs — discover agents and compute per-target diffs
|
||||
agentsSource := s.agentsSource()
|
||||
var agents []resource.DiscoveredResource
|
||||
if agentsSource != "" {
|
||||
discovered, _ := resource.AgentKind{}.Discover(agentsSource)
|
||||
|
||||
@@ -57,6 +57,11 @@ func (s *Server) handleSync(w http.ResponseWriter, r *http.Request) {
|
||||
// Default to non-dry-run, non-force, empty kind (both)
|
||||
}
|
||||
|
||||
if body.Kind != "" && body.Kind != "skill" && body.Kind != "agent" {
|
||||
writeError(w, http.StatusBadRequest, "invalid kind: must be 'skill', 'agent', or empty")
|
||||
return
|
||||
}
|
||||
|
||||
globalMode := s.cfg.Mode
|
||||
if globalMode == "" {
|
||||
globalMode = "merge"
|
||||
|
||||
@@ -573,7 +573,7 @@ function DiffItemRow({ item }: { item: { action: string; skill: string; reason?:
|
||||
<div className="flex items-center gap-2 text-base py-0.5">
|
||||
<ActionBadge action={item.action} />
|
||||
<ArrowRight size={12} className="text-muted-dark shrink-0" />
|
||||
{item.kind && <KindBadge kind={item.kind} />}
|
||||
<KindBadge kind={item.kind ?? 'skill'} />
|
||||
<span className="font-mono text-pencil-light text-sm truncate">
|
||||
{item.skill}
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user