kunchenguid--no-mistakes
26f897c1ec
release / release-please (push) Failing after 1m49s
docs / build (push) Failing after 6m34s
release / build-and-upload (arm64, linux) (push) Has been cancelled
release / build-and-upload (arm64, windows) (push) Has been cancelled
release / build-darwin (amd64, darwin) (push) Has been cancelled
release / checksums (push) Has been cancelled
release / finalize (push) Has been cancelled
release / build-darwin (arm64, darwin) (push) Has been cancelled
release / build-and-upload (amd64, linux) (push) Has been cancelled
release / build-and-upload (amd64, windows) (push) Has been cancelled
docs / deploy (push) Has been cancelled
86 行
2.3 KiB
Go
86 行
2.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/kunchenguid/no-mistakes/internal/telemetry"
|
|
)
|
|
|
|
func TestDoctorReportsGateCannotValidateWithoutAgent(t *testing.T) {
|
|
restore := telemetry.SetDefaultForTesting(&telemetryRecorder{})
|
|
defer restore()
|
|
|
|
t.Setenv("NM_HOME", t.TempDir())
|
|
binDir := t.TempDir()
|
|
writeDoctorGitBinary(t, binDir)
|
|
t.Setenv("PATH", binDir)
|
|
|
|
out, err := executeCmd("doctor")
|
|
if err != nil {
|
|
t.Fatalf("doctor failed: %v\n%s", err, out)
|
|
}
|
|
for _, want := range []string{"gate validation", "no runnable agent", "gate cannot validate", "some checks failed"} {
|
|
if !strings.Contains(out, want) {
|
|
t.Errorf("doctor output should contain %q, got:\n%s", want, out)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDoctorAcceptsConfiguredACPBridge(t *testing.T) {
|
|
restore := telemetry.SetDefaultForTesting(&telemetryRecorder{})
|
|
defer restore()
|
|
|
|
nmHome := t.TempDir()
|
|
t.Setenv("NM_HOME", nmHome)
|
|
if err := os.WriteFile(filepath.Join(nmHome, "config.yaml"), []byte("agent: acp:gemini\n"), 0o644); err != nil {
|
|
t.Fatalf("write config: %v", err)
|
|
}
|
|
binDir := t.TempDir()
|
|
writeDoctorGitBinary(t, binDir)
|
|
writeDoctorStubBinary(t, binDir, "acpx")
|
|
t.Setenv("PATH", binDir)
|
|
|
|
out, err := executeCmd("doctor")
|
|
if err != nil {
|
|
t.Fatalf("doctor failed: %v\n%s", err, out)
|
|
}
|
|
for _, want := range []string{"acpx", "gate validation", "acp:gemini is runnable"} {
|
|
if !strings.Contains(out, want) {
|
|
t.Errorf("doctor output should contain %q, got:\n%s", want, out)
|
|
}
|
|
}
|
|
if strings.Contains(out, "some checks failed") {
|
|
t.Errorf("doctor should accept configured ACP bridge, got:\n%s", out)
|
|
}
|
|
}
|
|
|
|
func writeDoctorGitBinary(t *testing.T, dir string) {
|
|
t.Helper()
|
|
name := "git"
|
|
contents := "#!/bin/sh\necho 'git version test'\n"
|
|
if runtime.GOOS == "windows" {
|
|
name = "git.cmd"
|
|
contents = "@echo off\r\necho git version test\r\n"
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, name), []byte(contents), 0o755); err != nil {
|
|
t.Fatalf("write fake git: %v", err)
|
|
}
|
|
}
|
|
|
|
func writeDoctorStubBinary(t *testing.T, dir, base string) {
|
|
t.Helper()
|
|
name := base
|
|
contents := "#!/bin/sh\nexit 0\n"
|
|
if runtime.GOOS == "windows" {
|
|
name += ".cmd"
|
|
contents = "@echo off\r\nexit /b 0\r\n"
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, name), []byte(contents), 0o755); err != nil {
|
|
t.Fatalf("write fake %s: %v", base, err)
|
|
}
|
|
}
|