(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestHostResolutionHintForNotFound(t *testing.T) { |
| 14 | t.Run("suggests full github URL for GHE shorthand 404", func(t *testing.T) { |
| 15 | t.Setenv("GITHUB_SERVER_URL", "") |
| 16 | t.Setenv("GITHUB_ENTERPRISE_HOST", "ghe.example.com") |
| 17 | t.Setenv("GITHUB_HOST", "") |
| 18 | t.Setenv("GH_HOST", "") |
| 19 | |
| 20 | hint, ok := hostResolutionHintForNotFound( |
| 21 | "githubnext", "agentics", "main", "workflows/daily-repo-status.md", "", errors.New("gh: Not Found (HTTP 404)"), |
| 22 | ) |
| 23 | |
| 24 | require.True(t, ok, "expected hint for GHE shorthand 404") |
| 25 | assert.Contains(t, hint, "resolved on ghe.example.com", "hint should mention resolved host") |
| 26 | assert.Contains(t, hint, "https://github.com/githubnext/agentics/blob/main/workflows/daily-repo-status.md", "hint should include full github.com workflow URL") |
| 27 | }) |
| 28 | |
| 29 | t.Run("does not suggest for github.com host", func(t *testing.T) { |
| 30 | hint, ok := hostResolutionHintForNotFound( |
| 31 | "githubnext", "agentics", "main", "workflows/daily-repo-status.md", "https://github.com", errors.New("gh: Not Found (HTTP 404)"), |
| 32 | ) |
| 33 | assert.False(t, ok, "expected no hint for github.com host") |
| 34 | assert.Empty(t, hint, "expected empty hint for github.com host") |
| 35 | }) |
| 36 | |
| 37 | t.Run("does not suggest for explicit non-github host URL", func(t *testing.T) { |
| 38 | hint, ok := hostResolutionHintForNotFound( |
| 39 | "githubnext", "agentics", "main", "workflows/daily-repo-status.md", "https://ghe.example.com/org/repo", errors.New("gh: Not Found (HTTP 404)"), |
| 40 | ) |
| 41 | assert.False(t, ok, "expected no hint for explicit host") |
| 42 | assert.Empty(t, hint, "expected empty hint for explicit host") |
| 43 | }) |
| 44 | |
| 45 | t.Run("does not suggest for nil or non-404 errors", func(t *testing.T) { |
| 46 | hint, ok := hostResolutionHintForNotFound( |
| 47 | "githubnext", "agentics", "main", "workflows/daily-repo-status.md", "", nil, |
| 48 | ) |
| 49 | assert.False(t, ok, "expected no hint for nil error") |
| 50 | assert.Empty(t, hint, "expected empty hint for nil error") |
| 51 | |
| 52 | t.Setenv("GITHUB_SERVER_URL", "") |
| 53 | t.Setenv("GITHUB_ENTERPRISE_HOST", "ghe.example.com") |
| 54 | t.Setenv("GITHUB_HOST", "") |
| 55 | t.Setenv("GH_HOST", "") |
| 56 | hint, ok = hostResolutionHintForNotFound( |
| 57 | "githubnext", "agentics", "main", "/workflows/daily-repo-status.md", "", errors.New("gh: forbidden (HTTP 403)"), |
| 58 | ) |
| 59 | assert.False(t, ok, "expected no hint for non-404 error") |
| 60 | assert.Empty(t, hint, "expected empty hint for non-404 error") |
| 61 | }) |
| 62 | |
| 63 | t.Run("normalizes leading slash in workflow path", func(t *testing.T) { |
| 64 | t.Setenv("GITHUB_SERVER_URL", "") |
| 65 | t.Setenv("GITHUB_ENTERPRISE_HOST", "ghe.example.com") |
| 66 | t.Setenv("GITHUB_HOST", "") |
| 67 | t.Setenv("GH_HOST", "") |
| 68 | |
| 69 | hint, ok := hostResolutionHintForNotFound( |
| 70 | "githubnext", "agentics", "main", "/workflows/daily-repo-status.md", "", errors.New("HTTP 404"), |
nothing calls this directly
no test coverage detected