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"
|
|
|
|
|
|
|
|
|
|
forgejo "codeberg.org/mvdkleijn/forgejo-sdk/forgejo/v2"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestClient_ListOrgRepos_Good(t *testing.T) {
|
|
|
|
|
client, srv := newTestClient(t)
|
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
|
|
repos, err := client.ListOrgRepos("test-org")
|
|
|
|
|
require.NoError(t, err)
|
2026-04-01 05:11:34 +00:00
|
|
|
require.Len(t, repos, 2)
|
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
|
|
|
assert.Equal(t, "org-repo", repos[0].Name)
|
2026-04-01 05:11:34 +00:00
|
|
|
assert.Equal(t, "second-repo", repos[1].Name)
|
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
|
|
|
}
|
|
|
|
|
|
2026-03-30 06:37:20 +00:00
|
|
|
func TestClient_ListOrgRepos_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.ListOrgRepos("test-org")
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
assert.Contains(t, err.Error(), "failed to list org repos")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestClient_ListUserRepos_Good(t *testing.T) {
|
|
|
|
|
client, srv := newTestClient(t)
|
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
|
|
repos, err := client.ListUserRepos()
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.Len(t, repos, 2)
|
|
|
|
|
assert.Equal(t, "repo-a", repos[0].Name)
|
|
|
|
|
assert.Equal(t, "repo-b", repos[1].Name)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 06:37:20 +00:00
|
|
|
func TestClient_ListUserRepos_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.ListUserRepos()
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
assert.Contains(t, err.Error(), "failed to list user repos")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestClient_GetRepo_Good(t *testing.T) {
|
|
|
|
|
client, srv := newTestClient(t)
|
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
|
|
repo, err := client.GetRepo("test-org", "org-repo")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.Equal(t, "org-repo", repo.Name)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 06:37:20 +00:00
|
|
|
func TestClient_GetRepo_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.GetRepo("test-org", "org-repo")
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
assert.Contains(t, err.Error(), "failed to get repo")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestClient_CreateOrgRepo_Good(t *testing.T) {
|
|
|
|
|
client, srv := newTestClient(t)
|
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
|
|
repo, err := client.CreateOrgRepo("test-org", forgejo.CreateRepoOption{
|
|
|
|
|
Name: "new-repo",
|
|
|
|
|
Description: "A new repository",
|
|
|
|
|
})
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.NotNil(t, repo)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 06:37:20 +00:00
|
|
|
func TestClient_CreateOrgRepo_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.CreateOrgRepo("test-org", forgejo.CreateRepoOption{
|
|
|
|
|
Name: "new-repo",
|
|
|
|
|
})
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
assert.Contains(t, err.Error(), "failed to create org repo")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestClient_DeleteRepo_Good(t *testing.T) {
|
|
|
|
|
client, srv := newTestClient(t)
|
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
|
|
err := client.DeleteRepo("test-org", "org-repo")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 06:37:20 +00:00
|
|
|
func TestClient_DeleteRepo_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.DeleteRepo("test-org", "org-repo")
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
assert.Contains(t, err.Error(), "failed to delete repo")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestClient_MigrateRepo_Good(t *testing.T) {
|
|
|
|
|
client, srv := newTestClient(t)
|
|
|
|
|
defer srv.Close()
|
|
|
|
|
|
|
|
|
|
repo, err := client.MigrateRepo(forgejo.MigrateRepoOption{
|
|
|
|
|
RepoName: "migrated-repo",
|
|
|
|
|
RepoOwner: "test-user",
|
|
|
|
|
CloneAddr: "https://github.com/example/repo.git",
|
|
|
|
|
})
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
assert.NotNil(t, repo)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 06:37:20 +00:00
|
|
|
func TestClient_MigrateRepo_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.MigrateRepo(forgejo.MigrateRepoOption{
|
|
|
|
|
RepoName: "migrated-repo",
|
|
|
|
|
RepoOwner: "test-user",
|
|
|
|
|
CloneAddr: "https://github.com/example/repo.git",
|
|
|
|
|
})
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
assert.Contains(t, err.Error(), "failed to migrate repo")
|
|
|
|
|
}
|