85c0e735dc
Fix runner bootstrap and auth handling, preserve queued SHAs, make event/job acceptance atomic, fence stale runs, correct retries and prompts, add fake end-to-end coverage, and fix deployment defaults. Co-Authored-By: Claude <noreply@anthropic.com>
48 lines
2.2 KiB
Go
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", 200000)
|
|
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", 200000)
|
|
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", 200000)
|
|
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)
|
|
}
|
|
}
|