From 511f5eafc6c412d701e1df4fe9179f1c7bc73723 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 2 Oct 2026 03:06:48 +1000 Subject: [PATCH] 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. --- internal/agentexec/harness_runner_test.go | 22 +++++++++++++++++++ .../app/agentworker/task_execution_test.go | 21 ++++++++++++++++++ internal/domain/workflow/steps_test.go | 22 +++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/internal/agentexec/harness_runner_test.go b/internal/agentexec/harness_runner_test.go index fb2c9e3f4..17e106f73 100644 --- a/internal/agentexec/harness_runner_test.go +++ b/internal/agentexec/harness_runner_test.go @@ -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) } diff --git a/internal/app/agentworker/task_execution_test.go b/internal/app/agentworker/task_execution_test.go index 6d390c51d..88ce1c0dc 100644 --- a/internal/app/agentworker/task_execution_test.go +++ b/internal/app/agentworker/task_execution_test.go @@ -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() diff --git a/internal/domain/workflow/steps_test.go b/internal/domain/workflow/steps_test.go index 6ce1fa866..7a3a37959 100644 --- a/internal/domain/workflow/steps_test.go +++ b/internal/domain/workflow/steps_test.go @@ -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{