mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
Upkeep: CI, flaky tests, dead code and the coding agents page. - test: tests never run git on the repo they're run from. A git that runs the tests (a hook, git rebase --exec) sets GIT_DIR and friends, and the tests' plain git followed them into the real repo's config. Every test's git now runs through internal/stubtest (Git, GitEnv, NoGitRepo), the structure test enforces it, and the whole suite passes with GIT_DIR pointing at a decoy repo that stays untouched. - ci: two test jobs instead of three: Linux in America/Los_Angeles (DST) and macOS in UTC, with lint on both, since golangci-lint checks only the runner's OS's files. - test(e2e): accept Codex 0.167's wording for an API-key login. - test: internal/safefile's swap-after-look branch is tested on purpose through a seam, so its coverage no longer depends on a race (97.7% every run). - test(fetch): TestRetryUnanswered's "no answer" comes from a listener that keeps its port, so a parallel test's server can no longer take the freed port and answer in its place (Linux reuses ports at once). - refactor(proxy): the test-only policy.decide and policy.byRequest move to the tests; the proxy already judges a host from one read of the rules (rulesFor). - docs(agents): "Pasting images" moves down the coding agents page, before History, and its run of paragraphs becomes commands and lists, every fact and anchor kept. Gate and coverage pass on each commit; e2e `network` and `project` pass on Linux (251 passed, 4 macOS-only skips). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
75 lines
2.8 KiB
Go
75 lines
2.8 KiB
Go
package stubtest
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
// GitEnv takes out git's variables that pick a repo, its files or its
|
|
// config, and keeps the rest.
|
|
func TestGitEnv(t *testing.T) {
|
|
env := []string{
|
|
"HOME=/h", "GIT_DIR=/r/.git", "GIT_WORK_TREE=/r", "GIT_INDEX_FILE=/r/.git/index", "GIT_COMMON_DIR=/r/.git",
|
|
"GIT_OBJECT_DIRECTORY=/r/.git/objects", "GIT_ALTERNATE_OBJECT_DIRECTORIES=/o", "GIT_NAMESPACE=n",
|
|
"GIT_CONFIG=/c", "GIT_CONFIG_PARAMETERS='core.bare'='true'", "GIT_CONFIG_COUNT=1", "GIT_CONFIG_KEY_0=k",
|
|
"GIT_CONFIG_VALUE_0=v", "GIT_CONFIG_GLOBAL=/g", "GIT_AUTHOR_NAME=a", "PATH=/bin",
|
|
}
|
|
if got, want := GitEnv(env), []string{"HOME=/h", "GIT_AUTHOR_NAME=a", "PATH=/bin"}; !slices.Equal(got, want) {
|
|
t.Errorf("GitEnv = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
// Git works on the repo its arguments name, never the one GIT_DIR names
|
|
// for the git that ran the tests, and reads no config but the repo's;
|
|
// NoGitRepo takes the same variables out of the test's environment, for
|
|
// what it runs, until the test ends.
|
|
func TestGit(t *testing.T) {
|
|
if _, err := exec.LookPath("git"); err != nil {
|
|
t.Skip("no git")
|
|
}
|
|
decoy, mine := t.TempDir(), t.TempDir()
|
|
if out, err := Git(t.Context(), "init", "-q", decoy).CombinedOutput(); err != nil {
|
|
t.Fatalf("git init: %v\n%s", err, out)
|
|
}
|
|
config := filepath.Join(decoy, ".git", "config")
|
|
was, err := os.ReadFile(config) //nolint:gosec // the test's own
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Setenv("GIT_DIR", filepath.Join(decoy, ".git"))
|
|
t.Setenv("GIT_CONFIG_PARAMETERS", "'core.bare'='true'")
|
|
global := filepath.Join(decoy, "global")
|
|
if err := os.WriteFile(global, []byte("[decoy]\n\tk = global\n"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Setenv("GIT_CONFIG_GLOBAL", global)
|
|
for _, args := range [][]string{{"init", "-q"}, {"config", "core.fsmonitor", "/nowhere"}} {
|
|
if out, err := Git(t.Context(), append([]string{"-C", mine}, args...)...).CombinedOutput(); err != nil {
|
|
t.Fatalf("git %v: %v\n%s", args, err, out)
|
|
}
|
|
}
|
|
if now, err := os.ReadFile(config); err != nil || string(now) != string(was) { //nolint:gosec // the test's own
|
|
t.Errorf("the decoy's config changed:\n%s", now)
|
|
}
|
|
if out, _ := Git(t.Context(), "-C", mine, "config", "decoy.k").Output(); len(out) != 0 {
|
|
t.Errorf("read the global config GIT_CONFIG_GLOBAL named: %q", out)
|
|
}
|
|
if out, err := Git(t.Context(), "-C", mine, "config", "core.fsmonitor").Output(); err != nil || string(out) != "/nowhere\n" {
|
|
t.Errorf("the test's repo: core.fsmonitor %q, %v", out, err)
|
|
}
|
|
t.Run("NoGitRepo", func(t *testing.T) {
|
|
NoGitRepo(t)
|
|
for _, k := range []string{"GIT_DIR", "GIT_CONFIG_PARAMETERS", "GIT_CONFIG_GLOBAL"} {
|
|
if v, ok := os.LookupEnv(k); ok {
|
|
t.Errorf("%s=%s", k, v)
|
|
}
|
|
}
|
|
})
|
|
if v := os.Getenv("GIT_DIR"); v != filepath.Join(decoy, ".git") {
|
|
t.Errorf("GIT_DIR after NoGitRepo's test: %q", v)
|
|
}
|
|
}
|