55 lines
2.2 KiB
Go
55 lines
2.2 KiB
Go
//go:build integration
|
|
|
|
package builder
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestReplay310 is the replay of novox/hq issue 310, written with only what the build agent had before its
|
|
// fix, so mesh-lab's prover can lay it over the commit before: a pull request whose branch holds no
|
|
// merge-check.sh, into a main that holds one. Before the fix the check read the head's tree alone, found no
|
|
// script, and answered the repository's layer a warning — none of its tests run, and the forge took it.
|
|
// After it, main's script judges the change: with no artifact store to read the facts from here, the check
|
|
// goes on to run it and says it cannot, and never answers the warning.
|
|
func TestReplay310(t *testing.T) {
|
|
origin := t.TempDir()
|
|
git := func(args ...string) string {
|
|
t.Helper()
|
|
cmd := exec.Command("git", args...)
|
|
cmd.Dir = origin
|
|
cmd.Env = append(os.Environ(), "GIT_AUTHOR_NAME=t", "GIT_AUTHOR_EMAIL=t@example.org",
|
|
"GIT_COMMITTER_NAME=t", "GIT_COMMITTER_EMAIL=t@example.org")
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("git %v: %v\n%s", args, err, out)
|
|
}
|
|
return strings.TrimSpace(string(out))
|
|
}
|
|
git("init", "--quiet", "-b", "main")
|
|
if err := os.WriteFile(filepath.Join(origin, CheckScript), []byte("echo 'FAIL: the suite'; exit 1\n"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
git("add", "-A")
|
|
git("commit", "--quiet", "-m", "main holds its check")
|
|
git("checkout", "--quiet", "-b", "change")
|
|
git("rm", "--quiet", CheckScript)
|
|
git("commit", "--quiet", "-m", "the change holds none")
|
|
head := git("rev-parse", "HEAD")
|
|
git("checkout", "--quiet", "main")
|
|
|
|
v, err := Check(t.Context(), Command, CheckSpec{ID: "replay-310", Repository: origin, Ref: head, Owner: "novox",
|
|
Repo: "mesh-media-catalog", Number: 11, Base: "main"}, t.TempDir(), "", GitCredential{}, nil)
|
|
if err == nil && (v.Repo == nil || v.Repo.Verdict != "fail") {
|
|
t.Fatalf("a pull request without main's %s was answered %+v: none of its tests ran, and main's script "+
|
|
"did not judge it", CheckScript, v.Repo)
|
|
}
|
|
if err != nil && !strings.Contains(err.Error(), "artifact store") {
|
|
t.Fatalf("the check stopped before main's script could run: %v", err)
|
|
}
|
|
}
|