test(agentexec): make seeded git repos independent of host signing config

The temp-repo fixtures in agentexec, domain/workflow and agentworker seeded
a repository and committed without disabling gpg signing, so a host with
commit.gpgsign=true and an agent-only SSH signing key failed those tests at
the fixture's own git call ("Couldn't get agent socket?").

Each producer now writes commit.gpgsign=false into the temporary repository's
own config, which also covers commits made inside the seeded repo by a
subprocess (the fake harness). A regression test per package pins the
fixture's hermeticity under a hostile global git config.
This commit is contained in:
sam committed 2026-10-02 03:06:48 +10:00
1 parent 20b4595a95
commit 6bf24d73db
3 files changed
+65

No files matched your search

+22
View File
@@ -77,6 +77,27 @@ func runGit(t *testing.T, dir string, args ...string) {
}
}
// hostileSigningConfig writes a global git config that makes every commit
// fail unless the fixture disables signing in the repository's own config.
func hostileSigningConfig(t *testing.T) string {
t.Helper()
path := filepath.Join(t.TempDir(), "hostile.gitconfig")
const cfg = "[user]\n\tname = Hostile\n\temail = hostile@example.com\n\tsigningkey = /nonexistent/signing-key\n[gpg]\n\tformat = ssh\n[commit]\n\tgpgsign = true\n"
if err := os.WriteFile(path, []byte(cfg), 0o600); err != nil {
t.Fatal(err)
}
return path
}
// TestFixtureSeedsARepositoryThatIgnoresHostSigningConfig pins the fixture's
// hermeticity: it must not depend on the developer's global git identity or a
// signing agent.
func TestFixtureSeedsARepositoryThatIgnoresHostSigningConfig(t *testing.T) {
t.Setenv("GIT_CONFIG_GLOBAL", hostileSigningConfig(t))
t.Setenv("GIT_CONFIG_NOSYSTEM", "1")
newFixture(t, "edit")
}
type fixture struct {
workspace string
log string
@@ -87,6 +108,7 @@ func newFixture(t *testing.T, scenario string) *fixture {
t.Helper()
ws := t.TempDir()
runGit(t, ws, "init", "-q")
runGit(t, ws, "config", "commit.gpgsign", "false")
if err := os.WriteFile(filepath.Join(ws, "widget_test.go"), []byte("package widget\n"), 0o600); err != nil {
t.Fatal(err)
}
@@ -338,6 +338,7 @@ func newLocalRemote(t *testing.T, owner, repo string) string {
run(seed, "init", "-b", "main")
run(seed, "config", "user.name", "seeder")
run(seed, "config", "user.email", "seed@example.com")
run(seed, "config", "commit.gpgsign", "false")
if err := os.WriteFile(filepath.Join(seed, "README.md"), []byte("seed\n"), 0o644); err != nil {
t.Fatal(err)
}
@@ -347,6 +348,26 @@ func newLocalRemote(t *testing.T, owner, repo string) string {
return host
}
// hostileSigningConfig writes a global git config that makes every commit
// fail unless the fixture disables signing in the repository's own config.
func hostileSigningConfig(t *testing.T) string {
t.Helper()
path := filepath.Join(t.TempDir(), "hostile.gitconfig")
const cfg = "[user]\n\tname = Hostile\n\temail = hostile@example.com\n\tsigningkey = /nonexistent/signing-key\n[gpg]\n\tformat = ssh\n[commit]\n\tgpgsign = true\n"
if err := os.WriteFile(path, []byte(cfg), 0o600); err != nil {
t.Fatal(err)
}
return path
}
// TestNewLocalRemoteIgnoresHostSigningConfig pins the fixture's hermeticity:
// it must not depend on the developer's global git identity or a signing agent.
func TestNewLocalRemoteIgnoresHostSigningConfig(t *testing.T) {
t.Setenv("GIT_CONFIG_GLOBAL", hostileSigningConfig(t))
t.Setenv("GIT_CONFIG_NOSYSTEM", "1")
newLocalRemote(t, "acme", "todo")
}
func startEmbeddedTaskRPCServer(t *testing.T) *server.Server {
t.Helper()
srv := natssrv.RunRandClientPortServer()
+22
View File
@@ -35,6 +35,7 @@ func gitRepoWithOriginRef(t *testing.T, base string) string {
runGit(t, dir, "init", "-b", base)
runGit(t, dir, "config", "user.name", "archie-bot")
runGit(t, dir, "config", "user.email", "archie-bot@example.com")
runGit(t, dir, "config", "commit.gpgsign", "false")
if err := os.WriteFile(filepath.Join(dir, "README.md"), []byte("seed\n"), 0o644); err != nil {
t.Fatal(err)
}
@@ -44,6 +45,27 @@ func gitRepoWithOriginRef(t *testing.T, base string) string {
return dir
}
// hostileSigningConfig writes a global git config that makes every commit
// fail unless the fixture disables signing in the repository's own config.
func hostileSigningConfig(t *testing.T) string {
t.Helper()
path := filepath.Join(t.TempDir(), "hostile.gitconfig")
const cfg = "[user]\n\tname = Hostile\n\temail = hostile@example.com\n\tsigningkey = /nonexistent/signing-key\n[gpg]\n\tformat = ssh\n[commit]\n\tgpgsign = true\n"
if err := os.WriteFile(path, []byte(cfg), 0o600); err != nil {
t.Fatal(err)
}
return path
}
// TestGitRepoWithOriginRefIgnoresHostSigningConfig pins the fixture's
// hermeticity: it must not depend on the developer's global git identity or a
// signing agent.
func TestGitRepoWithOriginRefIgnoresHostSigningConfig(t *testing.T) {
t.Setenv("GIT_CONFIG_GLOBAL", hostileSigningConfig(t))
t.Setenv("GIT_CONFIG_NOSYSTEM", "1")
gitRepoWithOriginRef(t, "main")
}
func newYaegiGateTaskContext(t *testing.T, dir string) *TaskContext {
t.Helper()
return &TaskContext{