mirror of
https://gh-proxy.org/https://github.com/klinsmaya/multica.git
synced 2026-11-08 17:36:45 +08:00
* fix(test): isolate test home on Windows across config-writing packages
Tests that only redirect HOME still resolve ~/.multica against the real
home on Windows: os.UserHomeDir reads USERPROFILE, not HOME. SaveCLIConfig
then writes test fixtures over a real default-profile config.json.
Reproduced on a Windows host by running `go test ./internal/cli ./cmd/multica`
on an unmodified tree: the real ~/.multica/config.json was replaced with the
test fixture {"token": "mul_owner_pat"}, dropping server_url, app_url and
workspace_id. The running daemon keeps its in-memory config, so the damage
only surfaces on the next restart as an auth failure.
Redirect both home variables process-wide in TestMain for the packages that
resolve ~/.multica (cmd/multica, internal/cli, internal/daemon), and route
per-test home redirects through a redirectTestHome helper that sets HOME and
USERPROFILE together. Per-test t.Setenv overrides still win.
Comparison on the same host, same packages:
without this change: 6 internal/cli + 10 cmd/multica failures, real config overwritten
with this change: 1 + 5 failures (all pre-existing Windows cases), config intact
Co-authored-by: multica-agent <[email protected]>
* fix(test): fail closed when isolating test homes
Co-authored-by: multica-agent <[email protected]>
* test(ghsnapshot): isolate cursor fixture from other packages
Co-authored-by: multica-agent <[email protected]>
---------
Co-authored-by: ZhangRui <[email protected]>
Co-authored-by: multica-agent <[email protected]>
Co-authored-by: Yushen <[email protected]>
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package daemon
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
)
|
|
|
|
func TestProbeAgentCLIsDiscoversCodeArtsDefaultInstallPath(t *testing.T) {
|
|
home := t.TempDir()
|
|
installDir := filepath.Join(home, ".codeartsdoer", "installers")
|
|
if err := os.MkdirAll(installDir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
name := "codearts"
|
|
content := []byte("#!/bin/sh\nexit 0\n")
|
|
if runtime.GOOS == "windows" {
|
|
name = "codearts.cmd"
|
|
content = []byte("@echo off\r\nexit /b 0\r\n")
|
|
}
|
|
executable := filepath.Join(installDir, name)
|
|
if err := os.WriteFile(executable, content, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
origResolve := resolveAgentsViaLoginShell
|
|
t.Cleanup(func() { resolveAgentsViaLoginShell = origResolve })
|
|
resolveAgentsViaLoginShell = func([]string) map[string]string { return map[string]string{} }
|
|
resetShellResolveCacheForTest(t)
|
|
|
|
redirectTestHome(t, home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("PATH", t.TempDir())
|
|
t.Setenv("MULTICA_CODEARTS_PATH", "")
|
|
t.Setenv("MULTICA_CODEARTS_MODEL", "mimo/mimo-v2.5")
|
|
|
|
entry, ok := probeAgentCLIs()["codearts"]
|
|
if !ok {
|
|
t.Fatal("CodeArts was not discovered from its default user install path")
|
|
}
|
|
if filepath.Clean(entry.Path) != filepath.Clean(executable) {
|
|
t.Fatalf("CodeArts path = %q, want %q", entry.Path, executable)
|
|
}
|
|
if entry.Command != "codearts" || entry.Model != "mimo/mimo-v2.5" {
|
|
t.Fatalf("unexpected CodeArts entry: %+v", entry)
|
|
}
|
|
if got := providerDisplayName("codearts"); got != "CodeArts" {
|
|
t.Fatalf("CodeArts display name = %q, want CodeArts", got)
|
|
}
|
|
}
|