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]>
58 lines
2.1 KiB
Go
58 lines
2.1 KiB
Go
package stubtest
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// gitRepoVar reports whether k is one of git's variables that pick a repo, its files or its
|
|
// config: GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, GIT_COMMON_DIR, GIT_OBJECT_DIRECTORY,
|
|
// GIT_ALTERNATE_OBJECT_DIRECTORIES, GIT_NAMESPACE and GIT_CONFIG*. A git that runs the tests sets
|
|
// some of them, such as a hook's or git rebase --exec's, and a test's git that kept them would
|
|
// work on that repo, the checkout itself, instead of the test's own.
|
|
func gitRepoVar(k string) bool {
|
|
switch k {
|
|
case "GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_COMMON_DIR", "GIT_OBJECT_DIRECTORY",
|
|
"GIT_ALTERNATE_OBJECT_DIRECTORIES", "GIT_NAMESPACE":
|
|
return true
|
|
}
|
|
return strings.HasPrefix(k, "GIT_CONFIG")
|
|
}
|
|
|
|
// GitEnv is env without git's variables that pick a repo, its files or its config, so git run
|
|
// with it works on the repo its arguments or its folder name.
|
|
func GitEnv(env []string) []string {
|
|
var out []string
|
|
for _, kv := range env {
|
|
if k, _, _ := strings.Cut(kv, "="); !gitRepoVar(k) {
|
|
out = append(out, kv)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// Git is plain git, as a test runs it on a repo of its own: in the test's environment without
|
|
// GitEnv's variables, whatever git ran the tests, and with no config but the repo's own (no
|
|
// global or system file). Every test's git runs through it, which the structure test checks.
|
|
func Git(ctx context.Context, args ...string) *exec.Cmd {
|
|
cmd := exec.CommandContext(ctx, "git", args...) //nolint:gosec // a test's own git, on its own repo
|
|
cmd.Env = append(GitEnv(os.Environ()), "GIT_CONFIG_GLOBAL="+os.DevNull, "GIT_CONFIG_NOSYSTEM=1")
|
|
return cmd
|
|
}
|
|
|
|
// NoGitRepo takes GitEnv's variables out of the test's own environment until t ends, for what
|
|
// the test runs that runs git itself, such as a stub or a script. New calls it. Like t.Setenv,
|
|
// it's not for a parallel test.
|
|
func NoGitRepo(t testing.TB) {
|
|
t.Helper()
|
|
for _, kv := range os.Environ() {
|
|
if k, _, _ := strings.Cut(kv, "="); gitRepoVar(k) {
|
|
t.Setenv(k, "") // restored when t ends
|
|
_ = os.Unsetenv(k) //nolint:forbidigo // a test's own environment, restored by t.Setenv's cleanup
|
|
}
|
|
}
|
|
}
|