This repository has been archived on 2026-07-17. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
gitea-codex/internal/runner/runner_test.go
T
Space-Banane f19b271642
ci / test (pull_request) Successful in 1m54s
ci / publish (pull_request) Has been skipped
feat. rebuild service in Go
Rebuild the Gitea Codex review bot from the product contract with a Go HTTP service, durable SQL queue, typed Gitea client, isolated runner, and deployment updates.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-12 21:51:01 +02:00

48 lines
2.2 KiB
Go

package runner
import (
"strings"
"testing"
"gitea-codex-bot/internal/config"
"gitea-codex-bot/internal/domain"
)
func samplePR() domain.PullRequestContext {
return domain.PullRequestContext{Repo: "acme/repo", PRNumber: 1, BaseRef: "main", BaseSHA: strings.Repeat("b", 40), HeadRef: "feature", HeadSHA: strings.Repeat("a", 40), CloneURL: "https://gitea.test/acme/repo.git", BaseCloneURL: "https://gitea.test/acme/repo.git", HTMLURL: "https://gitea.test/pulls/1"}
}
func TestScriptChecksExactHeadAndBase(t *testing.T) {
r := NewDockerRunner(config.Settings{GiteaBotUsername: "bot", GiteaToken: "token", OpenAIReviewModel: "model", CodexAuthMode: "api_key"})
script := r.script(samplePR(), "review prompt", "BEGIN_nonce", "END_nonce")
for _, fragment := range []string{"git checkout --detach", "git rev-parse HEAD", "fetch --no-tags origin 'feature'", "fetch --no-tags origin '" + strings.Repeat("b", 40) + "'", "BEGIN_nonce", "END_nonce", "--output-schema", "-o /tmp/result.json"} {
if !strings.Contains(script, fragment) {
t.Fatalf("script missing %q: %s", fragment, script)
}
}
if strings.Contains(script, "; ;") {
t.Fatalf("script contains an empty shell command: %s", script)
}
if strings.Contains(script, "|| true") {
t.Fatalf("runner must fail when Codex fails")
}
}
func TestForkScriptUsesUpstreamBaseRemote(t *testing.T) {
pr := samplePR()
pr.BaseCloneURL = "https://gitea.test/base/repo.git"
r := NewDockerRunner(config.Settings{GiteaBotUsername: "bot", GiteaToken: "token", OpenAIReviewModel: "model", CodexAuthMode: "api_key"})
script := r.script(pr, "prompt", "BEGIN", "END")
if !strings.Contains(script, "git remote add upstream") || !strings.Contains(script, "fetch --no-tags upstream") {
t.Fatalf("fork base remote was not configured: %s", script)
}
}
func TestChatGPTScriptWritesAuthFile(t *testing.T) {
r := NewDockerRunner(config.Settings{GiteaBotUsername: "bot", GiteaToken: "token", OpenAIReviewModel: "model", CodexAuthMode: "chatgpt"})
script := r.script(samplePR(), "prompt", "BEGIN", "END")
if !strings.Contains(script, "CODEX_AUTH_JSON_B64") || !strings.Contains(script, "chmod 600 /root/.codex/auth.json") {
t.Fatalf("chatgpt auth setup missing: %s", script)
}
}