2026-03-30 00:54:20 +00:00
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
2026-03-30 00:19:43 +00:00
|
|
|
|
test: add comprehensive unit tests for forge/, gitea/, git/, agentci/
Phase 1 test coverage for the three 0% packages plus agentci/ improvement:
- git/ (0% -> 79.5%): RepoStatus methods, status parsing with real temp
repos, multi-repo parallel status, Push/Pull error paths, ahead/behind
with bare remote, context cancellation, GitError, IsNonFastForward,
service DirtyRepos/AheadRepos filtering
- forge/ (0% -> 91.2%): All SDK wrapper functions tested via httptest mock
server — client creation, repos, issues, PRs, labels, webhooks, orgs,
meta, config resolution, SetPRDraft raw HTTP endpoint
- gitea/ (0% -> 89.2%): All SDK wrapper functions tested via httptest mock
server — client creation, repos, issues, PRs, meta, config resolution
- agentci/ (56% -> 94.5%): Clotho DeterminePlan all code paths, security
helpers (SanitizePath, EscapeShellArg, SecureSSHCommand, MaskToken)
Key findings documented in FINDINGS.md:
- Forgejo SDK validates token via HTTP on NewClient()
- SDK route patterns differ from public API docs (/org/ vs /orgs/)
- Gitea SDK requires auth token for GitHub mirror creation
- Config resolution priority verified: config file < env vars < flags
Co-Authored-By: Charon <developers@lethean.io>
2026-02-20 00:59:46 +00:00
|
|
|
package forge
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestClient_GetPRMeta_Good(t *testing.T) {
|
|
|
|
|
client, srv := newTestClient(t)
|
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
|
|
meta, err := client.GetPRMeta("test-org", "org-repo", 1)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, "PR 1", meta.Title)
|
|
|
|
|
assert.Equal(t, "open", meta.State)
|
|
|
|
|
assert.Equal(t, "feature", meta.Branch)
|
|
|
|
|
assert.Equal(t, "main", meta.BaseBranch)
|
|
|
|
|
assert.Equal(t, "author", meta.Author)
|
|
|
|
|
assert.Contains(t, meta.Labels, "enhancement")
|
|
|
|
|
assert.Contains(t, meta.Assignees, "dev1")
|
|
|
|
|
assert.False(t, meta.IsMerged)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 06:37:20 +00:00
|
|
|
func TestClient_GetPRMeta_Bad_ServerError_Good(t *testing.T) {
|
test: add comprehensive unit tests for forge/, gitea/, git/, agentci/
Phase 1 test coverage for the three 0% packages plus agentci/ improvement:
- git/ (0% -> 79.5%): RepoStatus methods, status parsing with real temp
repos, multi-repo parallel status, Push/Pull error paths, ahead/behind
with bare remote, context cancellation, GitError, IsNonFastForward,
service DirtyRepos/AheadRepos filtering
- forge/ (0% -> 91.2%): All SDK wrapper functions tested via httptest mock
server — client creation, repos, issues, PRs, labels, webhooks, orgs,
meta, config resolution, SetPRDraft raw HTTP endpoint
- gitea/ (0% -> 89.2%): All SDK wrapper functions tested via httptest mock
server — client creation, repos, issues, PRs, meta, config resolution
- agentci/ (56% -> 94.5%): Clotho DeterminePlan all code paths, security
helpers (SanitizePath, EscapeShellArg, SecureSSHCommand, MaskToken)
Key findings documented in FINDINGS.md:
- Forgejo SDK validates token via HTTP on NewClient()
- SDK route patterns differ from public API docs (/org/ vs /orgs/)
- Gitea SDK requires auth token for GitHub mirror creation
- Config resolution priority verified: config file < env vars < flags
Co-Authored-By: Charon <developers@lethean.io>
2026-02-20 00:59:46 +00:00
|
|
|
client, srv := newErrorServer(t)
|
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
|
|
_, err := client.GetPRMeta("test-org", "org-repo", 1)
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
assert.Contains(t, err.Error(), "failed to get PR metadata")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestClient_GetCommentBodies_Good(t *testing.T) {
|
|
|
|
|
client, srv := newTestClient(t)
|
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
|
|
comments, err := client.GetCommentBodies("test-org", "org-repo", 1)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.Len(t, comments, 2)
|
|
|
|
|
assert.Equal(t, "comment 1", comments[0].Body)
|
|
|
|
|
assert.Equal(t, "user1", comments[0].Author)
|
|
|
|
|
assert.Equal(t, "comment 2", comments[1].Body)
|
|
|
|
|
assert.Equal(t, "user2", comments[1].Author)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 06:37:20 +00:00
|
|
|
func TestClient_GetCommentBodies_Bad_ServerError_Good(t *testing.T) {
|
test: add comprehensive unit tests for forge/, gitea/, git/, agentci/
Phase 1 test coverage for the three 0% packages plus agentci/ improvement:
- git/ (0% -> 79.5%): RepoStatus methods, status parsing with real temp
repos, multi-repo parallel status, Push/Pull error paths, ahead/behind
with bare remote, context cancellation, GitError, IsNonFastForward,
service DirtyRepos/AheadRepos filtering
- forge/ (0% -> 91.2%): All SDK wrapper functions tested via httptest mock
server — client creation, repos, issues, PRs, labels, webhooks, orgs,
meta, config resolution, SetPRDraft raw HTTP endpoint
- gitea/ (0% -> 89.2%): All SDK wrapper functions tested via httptest mock
server — client creation, repos, issues, PRs, meta, config resolution
- agentci/ (56% -> 94.5%): Clotho DeterminePlan all code paths, security
helpers (SanitizePath, EscapeShellArg, SecureSSHCommand, MaskToken)
Key findings documented in FINDINGS.md:
- Forgejo SDK validates token via HTTP on NewClient()
- SDK route patterns differ from public API docs (/org/ vs /orgs/)
- Gitea SDK requires auth token for GitHub mirror creation
- Config resolution priority verified: config file < env vars < flags
Co-Authored-By: Charon <developers@lethean.io>
2026-02-20 00:59:46 +00:00
|
|
|
client, srv := newErrorServer(t)
|
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
|
|
_, err := client.GetCommentBodies("test-org", "org-repo", 1)
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
assert.Contains(t, err.Error(), "failed to get PR comments")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestClient_GetIssueBody_Good(t *testing.T) {
|
|
|
|
|
client, srv := newTestClient(t)
|
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
|
|
body, err := client.GetIssueBody("test-org", "org-repo", 1)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, "First issue body", body)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 06:37:20 +00:00
|
|
|
func TestClient_GetIssueBody_Bad_ServerError_Good(t *testing.T) {
|
test: add comprehensive unit tests for forge/, gitea/, git/, agentci/
Phase 1 test coverage for the three 0% packages plus agentci/ improvement:
- git/ (0% -> 79.5%): RepoStatus methods, status parsing with real temp
repos, multi-repo parallel status, Push/Pull error paths, ahead/behind
with bare remote, context cancellation, GitError, IsNonFastForward,
service DirtyRepos/AheadRepos filtering
- forge/ (0% -> 91.2%): All SDK wrapper functions tested via httptest mock
server — client creation, repos, issues, PRs, labels, webhooks, orgs,
meta, config resolution, SetPRDraft raw HTTP endpoint
- gitea/ (0% -> 89.2%): All SDK wrapper functions tested via httptest mock
server — client creation, repos, issues, PRs, meta, config resolution
- agentci/ (56% -> 94.5%): Clotho DeterminePlan all code paths, security
helpers (SanitizePath, EscapeShellArg, SecureSSHCommand, MaskToken)
Key findings documented in FINDINGS.md:
- Forgejo SDK validates token via HTTP on NewClient()
- SDK route patterns differ from public API docs (/org/ vs /orgs/)
- Gitea SDK requires auth token for GitHub mirror creation
- Config resolution priority verified: config file < env vars < flags
Co-Authored-By: Charon <developers@lethean.io>
2026-02-20 00:59:46 +00:00
|
|
|
client, srv := newErrorServer(t)
|
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
|
|
_, err := client.GetIssueBody("test-org", "org-repo", 1)
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
assert.Contains(t, err.Error(), "failed to get issue body")
|
|
|
|
|
}
|