(t *testing.T)
| 335 | } |
| 336 | |
| 337 | func TestUpdateRun(t *testing.T) { |
| 338 | tests := []struct { |
| 339 | name string |
| 340 | setup func(t *testing.T, dir string) |
| 341 | stubs func(reg *httpmock.Registry) |
| 342 | opts func(ios *iostreams.IOStreams, dir string, reg *httpmock.Registry) *UpdateOptions |
| 343 | verify func(t *testing.T, dir string) |
| 344 | wantErr string |
| 345 | wantStderr string |
| 346 | wantStdout string |
| 347 | }{ |
| 348 | { |
| 349 | name: "scans all agents when no --dir is set", |
| 350 | setup: func(t *testing.T, dir string) { |
| 351 | t.Helper() |
| 352 | t.Setenv("HOME", dir) |
| 353 | t.Setenv("USERPROFILE", dir) |
| 354 | skillDir := filepath.Join(dir, ".agents", "skills", "code-review") |
| 355 | require.NoError(t, os.MkdirAll(skillDir, 0o755)) |
| 356 | require.NoError(t, os.WriteFile(filepath.Join(skillDir, "SKILL.md"), []byte(heredoc.Doc(` |
| 357 | --- |
| 358 | name: code-review |
| 359 | metadata: |
| 360 | github-repo: https://github.com/monalisa/octocat-skills |
| 361 | github-tree-sha: currentsha |
| 362 | github-path: skills/code-review |
| 363 | --- |
| 364 | Installed content |
| 365 | `)), 0o644)) |
| 366 | }, |
| 367 | stubs: func(reg *httpmock.Registry) { |
| 368 | reg.Register( |
| 369 | httpmock.REST("GET", "repos/monalisa/octocat-skills"), |
| 370 | httpmock.StringResponse(`{"id": 1}`)) |
| 371 | reg.Register( |
| 372 | httpmock.REST("GET", "repos/monalisa/octocat-skills/releases/latest"), |
| 373 | httpmock.StringResponse(`{"tag_name": "v1.0.0"}`)) |
| 374 | reg.Register( |
| 375 | httpmock.REST("GET", "repos/monalisa/octocat-skills/git/ref/tags%2Fv1.0.0"), |
| 376 | httpmock.StringResponse(`{"object": {"sha": "commit1", "type": "commit"}}`)) |
| 377 | reg.Register( |
| 378 | httpmock.REST("GET", "repos/monalisa/octocat-skills/git/trees/commit1"), |
| 379 | httpmock.StringResponse(`{"sha": "commit1", "tree": [{"path": "skills/code-review", "type": "tree", "sha": "currentsha"}, {"path": "skills/code-review/SKILL.md", "type": "blob", "sha": "blob1"}, {"path": "skills", "type": "tree", "sha": "treeshaX"}], "truncated": false}`)) |
| 380 | }, |
| 381 | opts: func(ios *iostreams.IOStreams, dir string, reg *httpmock.Registry) *UpdateOptions { |
| 382 | ios.SetStdoutTTY(false) |
| 383 | return &UpdateOptions{ |
| 384 | IO: ios, |
| 385 | Config: func() (gh.Config, error) { return config.NewMockConfig(), nil }, |
| 386 | HttpClient: func() (*http.Client, error) { |
| 387 | return &http.Client{Transport: reg}, nil |
| 388 | }, |
| 389 | GitClient: &git.Client{RepoDir: dir}, |
| 390 | } |
| 391 | }, |
| 392 | wantStderr: "All skills are up to date.", |
| 393 | }, |
| 394 | { |
nothing calls this directly
no test coverage detected