Add German translation; harden paths against unset env vars (#770)
* Add German translation and harden paths against unset env vars Add a German locale to the GUI, tray menu, usage alerts and website home page, and refuse to start when the home folder is unset or relative so nothing is written under the working folder; the pi plugin no longer adopts the user's PI_CODING_AGENT_DIR, and an inherited APPIMAGE no longer selects portable mode. Scripts refuse to run from the wrong folder or empty a shared out folder, and a new internal/testenv sandboxes every test package from the user's real files, which also fixes the Claude picker and Termux installer tests on Windows. * Makefile: know magpie's folder by its go.mod, so paths with spaces work The check compared $(CURDIR) with $(dir $(abspath …)), which make splits on spaces, so a checkout under 'My Projects' or 'John Doe' refused every target. It now reads go.mod relative to the working folder and wants magpie's module there: make -C and a symlinked Makefile work, make -f from another folder still stops before any recipe runs. * i18n: German for the strings main added since, with a parity test 75 strings main added (group order, patterns, slow-start wait, usage caps, RTK savings …) get their German, and two that main dropped go. gui-de.test.cjs checks, as gui-ja does, that de has every zh string with its placeholders and tags, and that the window reads in German when picked or on a German system. * appdir: ignore relative folder variables when reading, keep them for children CheckEnv no longer unsets anything. magpie reads the XDG folders, APPDATA/LOCALAPPDATA and every agent's folder variable through appdir.Getenv/LookupEnv, which pass over a relative value; the environment stays as it is, so the agents magpie starts get the variable as the user set it. That covers what proc.UserPath lends from the login shell too, which is set after main's check and reached the desktop app unchecked. On Windows a path rooted on the current drive (\Users\x, Git Bash's /c/x) counts as usable, and magpie version and help answer without a home, before run makes any folder. * Sandbox the tests main added since internal/wslrun gets testenv's TestMain, and four tests main added that set HOME alone set their home with testenv.SetHome, so on Windows they don't read the runner's profile through USERPROFILE. * agentenv: PI_CONFIG_DIR and OPENCODE_DB take relative names on purpose omp puts $PI_CONFIG_DIR under the home and OpenCode a relative $OPENCODE_DB in its data folder, so neither depends on the working folder: appdir no longer passes them over. * i18n: German for the Library's multi-select and System One's decision API The 19 strings main added since (#791's skill multi-select, the decision API snippets) get their German; the one main replaced (four APIs → five APIs) goes. * appdir: tidy the import into magpie's group; say what Go makes of /c/x The appdir import joins the group of magpie's own imports where a file has one. rooted's comment now says that Go takes a Git Bash path like /c/x as \c\x on the current drive, not C:\x.
This commit is contained in:
@@ -12,12 +12,22 @@
|
||||
import { chromium } from "playwright";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const here = path.dirname(fileURLToPath(import.meta.url));
|
||||
const env = (k, d) => process.env[k] ?? d;
|
||||
const OUT = path.resolve(env("OUT_DIR", "ui-preview-out"));
|
||||
const OUT = path.resolve(process.env.OUT_DIR || "ui-preview-out");
|
||||
// a leak empties OUT, so it must be a folder of its own: not the working
|
||||
// folder, the home, the root or one holding them
|
||||
for (const keep of [process.cwd(), os.homedir(), path.parse(OUT).root]) {
|
||||
const rel = path.relative(OUT, keep);
|
||||
if (rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel))) {
|
||||
console.error(`record: OUT_DIR ${OUT} holds ${keep}; give it a folder of its own`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
const BASE = env("MAGPIE_URL");
|
||||
const LOCALE = env("UI_LOCALE", "zh-CN");
|
||||
const MODEL = env("PLAN_MODEL", "deepseek-flash");
|
||||
|
||||
@@ -8,9 +8,16 @@
|
||||
# env: DEEPSEEK_API_KEY, DIFF_FILE, PR_TITLE, PR_BODY_FILE; PLAYWRIGHT_BROWSERS_PATH
|
||||
# must already point at the installed Chromium, since HOME moves.
|
||||
set -euo pipefail
|
||||
# the home below isolates magpie on Linux only: Windows reads USERPROFILE
|
||||
# and APPDATA, macOS keeps sign-ins in the Keychain
|
||||
[ "$(uname -s)" = Linux ] || { echo "run.sh: Linux only" >&2; exit 1; }
|
||||
src=$(cd "$1" && pwd)
|
||||
mkdir -p "$2"
|
||||
out=$(cd "$2" && pwd)
|
||||
# record.mjs empties the out folder when a secret showed: never one that
|
||||
# holds the source, the home or everything
|
||||
case "$src/" in "${out%/}"/*) echo "run.sh: out folder $out holds the source" >&2; exit 1 ;; esac
|
||||
case "$HOME/" in "${out%/}"/*) echo "run.sh: out folder $out holds the home" >&2; exit 1 ;; esac
|
||||
here=$(cd "$(dirname "$0")" && pwd)
|
||||
work=$(mktemp -d)
|
||||
trap 'kill "${web:-}" 2>/dev/null || true' EXIT
|
||||
|
||||
@@ -32,6 +32,8 @@ jobs:
|
||||
VERSION="$INPUT_VERSION"
|
||||
REF="v$INPUT_VERSION"
|
||||
fi
|
||||
# a newline or quote would add outputs or break the JSON below
|
||||
[[ "$VERSION" =~ ^[0-9][0-9A-Za-z.+-]*$ ]] || { echo "bad version: $VERSION" >&2; exit 1; }
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
echo "ref=$REF" >> $GITHUB_OUTPUT
|
||||
echo "Triggering release for version: $VERSION (ref: $REF)"
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
|
||||
# The recipes (clean's rm -rf too) name paths relative to the working
|
||||
# folder, so they run only in magpie's own, known by its go.mod: run from
|
||||
# another one (make -f path/to/Makefile) they would act there. make -C
|
||||
# works. go.mod is read relative to the working folder, so a path with
|
||||
# spaces (or a symlinked Makefile) changes nothing.
|
||||
ifneq ($(shell sed -n 's/^module //p' go.mod 2>/dev/null),github.com/yetone/magpie)
|
||||
$(error run make in magpie's folder (make -C path/to/magpie), not in $(CURDIR))
|
||||
endif
|
||||
|
||||
# A tag may hold $, ( or `, which the shell lines below would run: the
|
||||
# version keeps only what a version is spelled with.
|
||||
VERSION ?= $(or $(shell git describe --tags --always --dirty 2>/dev/null | tr -cd 'A-Za-z0-9._+-'),dev)
|
||||
LDFLAGS = -s -w -X main.version=$(VERSION)
|
||||
TAGS = production
|
||||
TARGETS = darwin/arm64 darwin/amd64 linux/amd64 linux/arm64 windows/amd64 windows/arm64 android/arm64
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// Run the public command in a fresh process, with only a fake account,
|
||||
@@ -68,7 +69,10 @@ func TestAccountsCachedReading(t *testing.T) {
|
||||
cmd.Env = []string{"MAGPIE_TEST_ACCOUNTS_READING=" + mode, "HOME=" + home, "USERPROFILE=" + home,
|
||||
"XDG_CONFIG_HOME=" + filepath.Dir(config), "XDG_CACHE_HOME=" + filepath.Join(home, ".cache"),
|
||||
"CLAUDE_CONFIG_DIR=" + filepath.Join(home, ".claude"), "CODEX_HOME=" + filepath.Join(home, ".codex"), "PATH=" + home,
|
||||
"SystemRoot=" + os.Getenv("SystemRoot"), "USER=magpie-test", "NO_COLOR=1"}
|
||||
"SystemRoot=" + os.Getenv("SystemRoot"), "USER=magpie-test", "NO_COLOR=1",
|
||||
// so that the binary keeps this home instead of a sandbox of its own
|
||||
testenv.Marker + "=" + os.Getenv(testenv.Marker),
|
||||
"TMP=" + os.Getenv("TMP"), "TEMP=" + os.Getenv("TEMP"), "TMPDIR=" + os.Getenv("TMPDIR")}
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("accounts: %v: %s", err, out)
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
# make passes MAGPIE_ADDR, MAGPIE_DEV_UI, MAGPIE_DEV_BACKEND and
|
||||
# MAGPIE_DEV_CONTROL.
|
||||
set -u
|
||||
cd "$(dirname "$0")/.."
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
|
||||
shell='' backend='' watch='' fsw='' draining=''
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package access
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
@@ -58,7 +59,7 @@ func Clients() []*Agent {
|
||||
// All returns every agent magpie knows about, detected or not.
|
||||
func All() []*Agent {
|
||||
home, _ := os.UserHomeDir()
|
||||
cfg := os.Getenv("XDG_CONFIG_HOME")
|
||||
cfg := appdir.Getenv("XDG_CONFIG_HOME")
|
||||
if cfg == "" {
|
||||
cfg = filepath.Join(home, ".config")
|
||||
}
|
||||
@@ -697,7 +698,7 @@ func mimocodeIn(at place) *Agent {
|
||||
// of the other; OpenCode 1 reads both, the variable's last, so what magpie
|
||||
// writes there wins in either.
|
||||
func openCodeDir(cfg string) string {
|
||||
if d := strings.TrimSpace(os.Getenv("OPENCODE_CONFIG_DIR")); d != "" {
|
||||
if d := strings.TrimSpace(appdir.Getenv("OPENCODE_CONFIG_DIR")); d != "" {
|
||||
if abs, err := filepath.Abs(d); err == nil {
|
||||
return abs
|
||||
}
|
||||
@@ -710,7 +711,7 @@ func openCodeDir(cfg string) string {
|
||||
// to its own config folder.
|
||||
func mimocode(home, cfg string) *Agent {
|
||||
dir := filepath.Join(cfg, "mimocode")
|
||||
if h := os.Getenv("MIMOCODE_HOME"); filepath.IsAbs(h) {
|
||||
if h := appdir.Getenv("MIMOCODE_HOME"); filepath.IsAbs(h) {
|
||||
dir = filepath.Join(h, "config")
|
||||
}
|
||||
return openCodeLike(here(home), "mimocode", "MiMo Code", "mimocode", "mimo",
|
||||
@@ -735,7 +736,7 @@ func piIn(at place) *Agent {
|
||||
// it is not taken; nor this machine's variable for a WSL distro's Pi.
|
||||
func piDir(at place) string {
|
||||
if at.spell == nil {
|
||||
if d := homeDir(at.home, os.Getenv("PI_CODING_AGENT_DIR")); d != "" {
|
||||
if d := homeDir(at.home, appdir.Getenv("PI_CODING_AGENT_DIR")); d != "" {
|
||||
return d
|
||||
}
|
||||
}
|
||||
@@ -856,7 +857,7 @@ func piLike(at place, id, name, dir string) *Agent {
|
||||
func goose(home, cfg string) *Agent {
|
||||
path := filepath.Join(cfg, "goose", "config.yaml")
|
||||
if runtime.GOOS == "windows" {
|
||||
if app := os.Getenv("APPDATA"); app != "" {
|
||||
if app := appdir.Getenv("APPDATA"); app != "" {
|
||||
path = filepath.Join(app, "Block", "goose", "config", "config.yaml")
|
||||
}
|
||||
}
|
||||
@@ -1007,11 +1008,11 @@ func crush(home, cfg string) *Agent {
|
||||
// Crush writes them; magpie's provider stays in path, beside the
|
||||
// library's MCP servers.
|
||||
data := filepath.Join(home, ".local", "share", "crush", "crush.json")
|
||||
if dir := os.Getenv("XDG_DATA_HOME"); dir != "" {
|
||||
if dir := appdir.Getenv("XDG_DATA_HOME"); dir != "" {
|
||||
data = filepath.Join(dir, "crush", "crush.json")
|
||||
}
|
||||
if runtime.GOOS == "windows" {
|
||||
if app := os.Getenv("LOCALAPPDATA"); app != "" {
|
||||
if app := appdir.Getenv("LOCALAPPDATA"); app != "" {
|
||||
path = filepath.Join(app, "crush", "crush.json")
|
||||
}
|
||||
// %LOCALAPPDATA%\crush is Crush's data folder there
|
||||
|
||||
@@ -38,6 +38,7 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
)
|
||||
@@ -52,7 +53,7 @@ func airDir(home, cfg string) string {
|
||||
case "darwin":
|
||||
return filepath.Join(home, "Library", "Application Support", "JetBrains", "Air")
|
||||
case "windows":
|
||||
d := os.Getenv("APPDATA")
|
||||
d := appdir.Getenv("APPDATA")
|
||||
if d == "" {
|
||||
d = filepath.Join(home, "AppData", "Roaming")
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
)
|
||||
@@ -52,7 +52,7 @@ func atomcodeTable(key string) string { return "models." + strconv.Quote(key) }
|
||||
|
||||
func atomcode(home string) *Agent {
|
||||
dir := filepath.Join(home, ".atomcode")
|
||||
if h := os.Getenv("ATOMCODE_HOME"); filepath.IsAbs(h) {
|
||||
if h := appdir.Getenv("ATOMCODE_HOME"); filepath.IsAbs(h) {
|
||||
dir = filepath.Clean(h)
|
||||
}
|
||||
path := filepath.Join(dir, "config.toml")
|
||||
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
)
|
||||
@@ -118,7 +119,7 @@ func claudeDesktop(home string) *Agent {
|
||||
// %APPDATA%\Claude is where Desktop keeps its MCP servers on Windows
|
||||
also := ""
|
||||
if runtime.GOOS == "windows" {
|
||||
if d := os.Getenv("APPDATA"); d != "" {
|
||||
if d := appdir.Getenv("APPDATA"); d != "" {
|
||||
also = filepath.Join(d, "Claude")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
)
|
||||
@@ -53,11 +54,11 @@ import (
|
||||
const clineSlot = "openai-compatible"
|
||||
|
||||
func cline(home string) *Agent {
|
||||
dir := os.Getenv("CLINE_DIR")
|
||||
dir := appdir.Getenv("CLINE_DIR")
|
||||
if dir == "" {
|
||||
dir = filepath.Join(home, ".cline")
|
||||
}
|
||||
data := os.Getenv("CLINE_DATA_DIR")
|
||||
data := appdir.Getenv("CLINE_DATA_DIR")
|
||||
if data == "" {
|
||||
data = filepath.Join(dir, "data")
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The 「接入」 switch keeps an agent on the model it was on, now through
|
||||
@@ -72,7 +73,7 @@ func TestGeminiConnectRoundTrip(t *testing.T) {
|
||||
// first; on no model of its own, a subscription's before the first.
|
||||
func TestConnectPrefersTheSubscription(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
testenv.SetHome(t, home)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
||||
for _, c := range []struct {
|
||||
|
||||
@@ -14,17 +14,17 @@ package agent
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
func devin(home, cfg string) *Agent {
|
||||
dir := filepath.Join(cfg, "devin")
|
||||
if runtime.GOOS == "windows" {
|
||||
if app := os.Getenv("APPDATA"); app != "" {
|
||||
if app := appdir.Getenv("APPDATA"); app != "" {
|
||||
dir = filepath.Join(app, "devin")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import (
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
@@ -1185,7 +1186,7 @@ func dshWriteError(err error) string {
|
||||
|
||||
// dshHome is where dsh keeps its profiles: $DSH_HOME, or ~/.dsh.
|
||||
func dshHome() string {
|
||||
if dir := os.Getenv("DSH_HOME"); dir != "" {
|
||||
if dir := appdir.Getenv("DSH_HOME"); dir != "" {
|
||||
return dir
|
||||
}
|
||||
home, err := os.UserHomeDir()
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// A profile's patch list written in flow style, as dsh's own writers leave
|
||||
@@ -17,7 +18,7 @@ import (
|
||||
// can't edit is named in the error, not as config.yaml.
|
||||
func TestDshFlowPatchList(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
testenv.SetHome(t, home)
|
||||
t.Setenv("DSH_HOME", "")
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
||||
|
||||
@@ -36,6 +36,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
@@ -49,7 +50,7 @@ var hanakoProbe = &http.Client{Timeout: 1500 * time.Millisecond}
|
||||
var hanakoClient = &http.Client{Timeout: 15 * time.Second}
|
||||
|
||||
func hanakoHome(home string) string {
|
||||
dir := os.Getenv("HANA_HOME")
|
||||
dir := appdir.Getenv("HANA_HOME")
|
||||
if dir == "" {
|
||||
return filepath.Join(home, ".hanako")
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The install commands are the vendors' own (#727): the installer their
|
||||
@@ -155,7 +157,7 @@ func TestInstallWithoutNodeStopsWhenTheDownloadFails(t *testing.T) {
|
||||
}))
|
||||
defer bad.Close()
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
testenv.SetHome(t, home)
|
||||
t.Setenv("NVM_DIR", filepath.Join(home, ".nvm"))
|
||||
c := strings.Replace(npmInstall("@earendil-works/pi-coding-agent", "linux", false).Command,
|
||||
"https://raw.githubusercontent.com/nvm-sh/nvm/"+nvmVersion+"/install.sh", bad.URL+"/install.sh", 1)
|
||||
|
||||
@@ -3,33 +3,18 @@ package agent
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/agentenv"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// TestMain gives the package a home of its own. A home an agent is found
|
||||
// through can sit outside HOME — DSH_HOME does — and the package's tests
|
||||
// sandbox HOME alone: left as the developer has it, a test that picks a model
|
||||
// writes it into the real ~/.dsh/profiles, and dsh then refuses every turn
|
||||
// with a model its provider does not list. internal/gateway, internal/provider
|
||||
// and internal/usage isolate themselves the same way.
|
||||
// TestMain gives the package a home of its own (testenv). A home an agent is
|
||||
// found through can sit outside HOME — DSH_HOME does — and the package's
|
||||
// tests sandbox HOME alone: left as the developer has it, a test that picks
|
||||
// a model writes it into the real ~/.dsh/profiles, and dsh then refuses
|
||||
// every turn with a model its provider does not list. internal/gateway,
|
||||
// internal/provider and internal/usage isolate themselves the same way.
|
||||
func TestMain(m *testing.M) {
|
||||
home, _ := os.MkdirTemp("", "magpie-agent-test-")
|
||||
for k, v := range map[string]string{
|
||||
"HOME": home, "USERPROFILE": home,
|
||||
"XDG_CONFIG_HOME": filepath.Join(home, ".config"),
|
||||
"XDG_CACHE_HOME": filepath.Join(home, ".cache"),
|
||||
"XDG_DATA_HOME": filepath.Join(home, ".local", "share"),
|
||||
"APPDATA": filepath.Join(home, "AppData", "Roaming"),
|
||||
"LOCALAPPDATA": filepath.Join(home, "AppData", "Local"),
|
||||
} {
|
||||
os.Setenv(k, v)
|
||||
}
|
||||
for _, k := range agentenv.Vars {
|
||||
os.Unsetenv(k)
|
||||
}
|
||||
// whether Codex's ChatGPT account is out of its allowance is asked of
|
||||
// OpenAI; never from here
|
||||
codexUsedUp = func() bool { return false }
|
||||
@@ -44,7 +29,5 @@ func TestMain(m *testing.M) {
|
||||
// keep the old one, so the test would read back a file nothing had
|
||||
// applied. The Aside tests stand in for it themselves.
|
||||
asideSet = func(string, string) error { return errors.New("aside: no Aside in a test") }
|
||||
code := m.Run()
|
||||
os.RemoveAll(home)
|
||||
os.Exit(code)
|
||||
os.Exit(testenv.Run(m))
|
||||
}
|
||||
|
||||
@@ -16,11 +16,11 @@ package agent
|
||||
// stays.
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"gopkg.in/yaml.v3"
|
||||
@@ -39,7 +39,7 @@ const mcodeUA = "minimax-code"
|
||||
|
||||
// MiniMaxDir is the folder MiniMax Code keeps its config.yaml in.
|
||||
func MiniMaxDir(home string) string {
|
||||
if d := strings.TrimSpace(os.Getenv("MINIMAX_DATA_DIR")); d != "" {
|
||||
if d := strings.TrimSpace(appdir.Getenv("MINIMAX_DATA_DIR")); d != "" {
|
||||
return d
|
||||
}
|
||||
return filepath.Join(home, ".minimax")
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
@@ -95,7 +96,7 @@ var ompProfileName = regexp.MustCompile(`^[a-z0-9][a-z0-9._-]{0,63}$`)
|
||||
// agent there. omp takes that variable as given, without expanding "~".
|
||||
func ompDir(home string) string {
|
||||
root := filepath.Join(home, ".omp")
|
||||
if d := os.Getenv("PI_CONFIG_DIR"); d != "" {
|
||||
if d := appdir.Getenv("PI_CONFIG_DIR"); d != "" {
|
||||
root = filepath.Join(home, d)
|
||||
}
|
||||
p, set := os.LookupEnv("OMP_PROFILE")
|
||||
@@ -105,7 +106,7 @@ func ompDir(home string) string {
|
||||
if p = strings.TrimSpace(p); p != "" && p != "default" && ompProfileName.MatchString(p) && !strings.HasSuffix(p, ".") {
|
||||
return filepath.Join(root, "profiles", p, "agent")
|
||||
}
|
||||
if d := os.Getenv("PI_CODING_AGENT_DIR"); filepath.IsAbs(d) {
|
||||
if d := appdir.Getenv("PI_CODING_AGENT_DIR"); filepath.IsAbs(d) {
|
||||
return filepath.Clean(d)
|
||||
}
|
||||
return filepath.Join(root, "agent")
|
||||
|
||||
@@ -29,13 +29,14 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
)
|
||||
|
||||
// openChamberDir is where OpenChamber keeps its settings.
|
||||
func openChamberDir(home string) string {
|
||||
if d := os.Getenv("OPENCHAMBER_DATA_DIR"); d != "" {
|
||||
if d := appdir.Getenv("OPENCHAMBER_DATA_DIR"); d != "" {
|
||||
if abs, err := filepath.Abs(d); err == nil {
|
||||
return abs
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
)
|
||||
@@ -49,7 +50,7 @@ import (
|
||||
const t3Instance = "providerInstances." + magpieID
|
||||
|
||||
func t3code(home string) *Agent {
|
||||
base := os.Getenv("T3CODE_HOME")
|
||||
base := appdir.Getenv("T3CODE_HOME")
|
||||
if base == "" {
|
||||
base = filepath.Join(home, ".t3")
|
||||
} else if rest, ok := strings.CutPrefix(base, "~"); ok {
|
||||
|
||||
@@ -17,12 +17,12 @@ package agent
|
||||
// Chat's model picker, a model is kept in VS Code's storage, not here.
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
)
|
||||
@@ -46,7 +46,7 @@ func vscode(home, cfg string) *Agent {
|
||||
case "darwin":
|
||||
cfg = filepath.Join(home, "Library", "Application Support")
|
||||
case "windows":
|
||||
cfg = os.Getenv("APPDATA")
|
||||
cfg = appdir.Getenv("APPDATA")
|
||||
if cfg == "" {
|
||||
cfg = filepath.Join(home, "AppData", "Roaming")
|
||||
}
|
||||
|
||||
@@ -22,16 +22,16 @@ package agent
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
)
|
||||
|
||||
func workbuddy(home string) *Agent {
|
||||
dir := os.Getenv("WORKBUDDY_CONFIG_DIR")
|
||||
dir := appdir.Getenv("WORKBUDDY_CONFIG_DIR")
|
||||
if dir == "" {
|
||||
dir = filepath.Join(home, ".workbuddy")
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"time"
|
||||
"unicode/utf16"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
@@ -60,7 +61,7 @@ func (p place) getenv(k string) string {
|
||||
if p.spell != nil {
|
||||
return ""
|
||||
}
|
||||
return os.Getenv(k)
|
||||
return appdir.Getenv(k)
|
||||
}
|
||||
|
||||
// exists is whether there is a file or folder at path, as an agent looks
|
||||
|
||||
@@ -3,11 +3,11 @@ package agent
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
)
|
||||
|
||||
@@ -23,7 +23,7 @@ func zed(home, cfg string) *Agent {
|
||||
case "darwin":
|
||||
cfg = filepath.Join(home, ".config")
|
||||
case "windows":
|
||||
cfg = os.Getenv("APPDATA")
|
||||
cfg = appdir.Getenv("APPDATA")
|
||||
if cfg == "" {
|
||||
cfg = filepath.Join(home, "AppData", "Roaming")
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
func TestZedCredentialCommand(t *testing.T) {
|
||||
@@ -57,7 +59,7 @@ func TestZedAppPath(t *testing.T) {
|
||||
bin := t.TempDir()
|
||||
t.Setenv("PATH", bin)
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
testenv.SetHome(t, home)
|
||||
app := filepath.Join(home, "Applications", "Zed.app")
|
||||
if err := os.MkdirAll(app, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -62,3 +62,14 @@ var Vars = []string{
|
||||
// makes an account or an installation visible that the test didn't make
|
||||
"FACTORY_HOME_OVERRIDE", "WINDSURF_API_SERVER_URL", "ZCODE_CREDENTIAL_SECRET",
|
||||
}
|
||||
|
||||
// NotPaths are the Vars that name no folder or file under the working
|
||||
// folder: a profile's name, a server's address, a secret, or a name its
|
||||
// agent puts under a folder of its own (PI_CONFIG_DIR under the home,
|
||||
// OPENCODE_DB in OpenCode's data folder), which a relative value is meant
|
||||
// for.
|
||||
var NotPaths = map[string]bool{
|
||||
"PI_PROFILE": true, "OMP_PROFILE": true,
|
||||
"WINDSURF_API_SERVER_URL": true, "ZCODE_CREDENTIAL_SECRET": true,
|
||||
"PI_CONFIG_DIR": true, "OPENCODE_DB": true,
|
||||
}
|
||||
|
||||
@@ -90,9 +90,12 @@ func Resolve(exe string) string {
|
||||
|
||||
// Beside is the folder a portable magpie run from exe keeps its data folder
|
||||
// in: the executable's own, the one holding the .app on a Mac, the one
|
||||
// holding the .AppImage on Linux.
|
||||
// holding the .AppImage on Linux. APPIMAGE counts only for the AppImage
|
||||
// magpie runs from (exe under its mount, APPDIR): every program an
|
||||
// AppImage starts inherits both, a magpie started from an AppImage
|
||||
// terminal too.
|
||||
func Beside(exe string) string {
|
||||
if img := os.Getenv("APPIMAGE"); img != "" && runtime.GOOS == "linux" {
|
||||
if img := os.Getenv("APPIMAGE"); img != "" && runtime.GOOS == "linux" && within(exe, os.Getenv("APPDIR")) {
|
||||
return filepath.Dir(img)
|
||||
}
|
||||
dir := filepath.Dir(exe)
|
||||
@@ -105,6 +108,15 @@ func Beside(exe string) string {
|
||||
return dir
|
||||
}
|
||||
|
||||
// within says whether path lies in the absolute folder dir.
|
||||
func within(path, dir string) bool {
|
||||
if !filepath.IsAbs(dir) {
|
||||
return false
|
||||
}
|
||||
rel, err := filepath.Rel(dir, path)
|
||||
return err == nil && rel != ".." && !strings.HasPrefix(rel, ".."+string(filepath.Separator))
|
||||
}
|
||||
|
||||
func absolute(p string) string {
|
||||
if a, err := filepath.Abs(p); err == nil {
|
||||
return a
|
||||
@@ -118,11 +130,10 @@ func Config() string {
|
||||
if p := Portable(); p != "" {
|
||||
return p
|
||||
}
|
||||
if x := os.Getenv("XDG_CONFIG_HOME"); x != "" {
|
||||
if x := os.Getenv("XDG_CONFIG_HOME"); rooted(x) {
|
||||
return filepath.Join(x, "magpie")
|
||||
}
|
||||
home, _ := os.UserHomeDir()
|
||||
return filepath.Join(home, ".config", "magpie")
|
||||
return filepath.Join(mustHome(), ".config", "magpie")
|
||||
}
|
||||
|
||||
// Cache is the folder for what magpie can fetch again (the models.dev
|
||||
@@ -131,11 +142,10 @@ func Cache() string {
|
||||
if p := Portable(); p != "" {
|
||||
return filepath.Join(p, "cache")
|
||||
}
|
||||
if x := os.Getenv("XDG_CACHE_HOME"); x != "" {
|
||||
if x := os.Getenv("XDG_CACHE_HOME"); rooted(x) {
|
||||
return filepath.Join(x, "magpie")
|
||||
}
|
||||
home, _ := os.UserHomeDir()
|
||||
return filepath.Join(home, ".cache", "magpie")
|
||||
return filepath.Join(mustHome(), ".cache", "magpie")
|
||||
}
|
||||
|
||||
// WebView is the folder the Windows webview (WebView2) keeps its profile
|
||||
|
||||
@@ -108,9 +108,15 @@ func TestResolveAppImage(t *testing.T) {
|
||||
img := touch(t, filepath.Join(r, "apps", "Magpie.AppImage"))
|
||||
mkdir(t, filepath.Join(r, "apps", "data"))
|
||||
t.Setenv("APPIMAGE", img)
|
||||
t.Setenv("APPDIR", filepath.Join(r, "mount"))
|
||||
if got, want := Resolve(exe), filepath.Join(r, "apps", "data"); got != want {
|
||||
t.Errorf("AppImage: %q, want %q", got, want)
|
||||
}
|
||||
// inherited from another AppImage (a terminal): magpie isn't in its mount
|
||||
other := touch(t, filepath.Join(r, "bin", "magpie"))
|
||||
if got := Resolve(other); got != "" {
|
||||
t.Errorf("inherited APPIMAGE: %q, want installed", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFolders(t *testing.T) {
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package appdir
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/yetone/magpie/internal/agentenv"
|
||||
)
|
||||
|
||||
// homeVar is the variable Go's os.UserHomeDir reads the home folder from.
|
||||
func homeVar() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
return "USERPROFILE"
|
||||
}
|
||||
return "HOME"
|
||||
}
|
||||
|
||||
// rooted says whether p names the same place whatever the working folder
|
||||
// is: absolute, or on Windows rooted on the current drive, as \Users\x or
|
||||
// /x is. A Git Bash path such as /c/x is one too, though Go takes it as
|
||||
// \c\x on the current drive, not C:\x: it kept that meaning before, and it
|
||||
// still doesn't depend on the working folder.
|
||||
func rooted(p string) bool {
|
||||
if filepath.IsAbs(p) {
|
||||
return true
|
||||
}
|
||||
return runtime.GOOS == "windows" && (strings.HasPrefix(p, `\`) || strings.HasPrefix(p, "/"))
|
||||
}
|
||||
|
||||
// Home is the user's home folder, or an error when its variable is unset,
|
||||
// empty or relative. os.UserHomeDir hands back "" there, which
|
||||
// filepath.Join turns into a path under the folder magpie was started in,
|
||||
// and on Android it falls back to the shared /sdcard.
|
||||
func Home() (string, error) {
|
||||
v := homeVar()
|
||||
switch h := os.Getenv(v); {
|
||||
case h == "":
|
||||
return "", fmt.Errorf("%s is not set: magpie needs the home folder to find its own files and the agents'", v)
|
||||
case !rooted(h):
|
||||
return "", fmt.Errorf("%s is %q, not an absolute path", v, h)
|
||||
default:
|
||||
return h, nil
|
||||
}
|
||||
}
|
||||
|
||||
// mustHome is Home for paths built once main has checked it; reached with
|
||||
// an unusable home anyway (a test made one), it stops rather than write
|
||||
// under the working folder.
|
||||
func mustHome() string {
|
||||
h, err := Home()
|
||||
if err != nil {
|
||||
panic("appdir: " + err.Error())
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
// pathVars are the variables folders and files are built from: the XDG
|
||||
// folders, Windows' application data folders, magpie's own and every
|
||||
// agent's.
|
||||
var pathVars = sync.OnceValue(func() map[string]bool {
|
||||
vs := map[string]bool{}
|
||||
for _, v := range []string{
|
||||
"XDG_CONFIG_HOME", "XDG_CACHE_HOME", "XDG_DATA_HOME", "XDG_STATE_HOME", "XDG_RUNTIME_DIR",
|
||||
"APPDATA", "LOCALAPPDATA",
|
||||
"MAGPIE_BIN_DIR", "OMARCHY_PATH", "OPENCODE_CONFIG",
|
||||
} {
|
||||
vs[v] = true
|
||||
}
|
||||
for _, v := range agentenv.Vars {
|
||||
if !agentenv.NotPaths[v] {
|
||||
vs[v] = true
|
||||
}
|
||||
}
|
||||
return vs
|
||||
})
|
||||
|
||||
// usable says whether a folder variable's value can be built on: rooted,
|
||||
// or starting with ~, which the agents' variables take and which stands for
|
||||
// the home main has checked.
|
||||
func usable(v string) bool {
|
||||
return rooted(v) || strings.HasPrefix(v, "~")
|
||||
}
|
||||
|
||||
// LookupEnv is os.LookupEnv for what magpie itself reads: a folder variable
|
||||
// (pathVars) holding a relative path reads as unset, as the XDG spec asks of
|
||||
// one, so no file of magpie's or an agent's is written under the working
|
||||
// folder. The environment is left as it is: the programs magpie starts get
|
||||
// the variable as the user set it. The variables a login shell lends the
|
||||
// desktop app (proc.UserPath) are read through here too.
|
||||
func LookupEnv(name string) (string, bool) {
|
||||
v, ok := os.LookupEnv(name)
|
||||
if ok && v != "" && pathVars()[name] && !usable(v) {
|
||||
return "", false
|
||||
}
|
||||
return v, ok
|
||||
}
|
||||
|
||||
// Getenv is LookupEnv's value, "" for a variable unset or ignored.
|
||||
func Getenv(name string) string {
|
||||
v, _ := LookupEnv(name)
|
||||
return v
|
||||
}
|
||||
|
||||
// CheckEnv is what main checks before anything is read or written: an
|
||||
// unusable home folder is the error, and ignored names the folder
|
||||
// variables holding a relative path, which LookupEnv passes over.
|
||||
func CheckEnv() (ignored []string, err error) {
|
||||
for v := range pathVars() {
|
||||
if x := os.Getenv(v); x != "" && !usable(x) {
|
||||
ignored = append(ignored, v)
|
||||
}
|
||||
}
|
||||
_, err = Home()
|
||||
return ignored, err
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package appdir
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHomeRefusesEmptyOrRelative(t *testing.T) {
|
||||
v := homeVar()
|
||||
for _, h := range []string{"", "relative/home", "."} {
|
||||
t.Setenv(v, h)
|
||||
if got, err := Home(); err == nil {
|
||||
t.Errorf("%s=%q: Home() = %q, want an error", v, h, got)
|
||||
}
|
||||
if _, err := CheckEnv(); err == nil {
|
||||
t.Errorf("%s=%q: CheckEnv() passed", v, h)
|
||||
}
|
||||
}
|
||||
abs := t.TempDir()
|
||||
t.Setenv(v, abs)
|
||||
if got, err := Home(); err != nil || got != abs {
|
||||
t.Errorf("Home() = %q, %v, want %q", got, err, abs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigNeverRelative(t *testing.T) {
|
||||
t.Setenv("APPIMAGE", "")
|
||||
t.Cleanup(func() { UseExecutable("") })
|
||||
UseExecutable("")
|
||||
home := t.TempDir()
|
||||
t.Setenv(homeVar(), home)
|
||||
t.Setenv("XDG_CONFIG_HOME", "relative/cfg")
|
||||
t.Setenv("XDG_CACHE_HOME", "relative/cache")
|
||||
if got, want := Config(), filepath.Join(home, ".config", "magpie"); got != want {
|
||||
t.Errorf("Config() = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := Cache(), filepath.Join(home, ".cache", "magpie"); got != want {
|
||||
t.Errorf("Cache() = %q, want %q", got, want)
|
||||
}
|
||||
t.Setenv(homeVar(), "")
|
||||
defer func() {
|
||||
if recover() == nil {
|
||||
t.Error("Config() with no home went on instead of stopping")
|
||||
}
|
||||
}()
|
||||
Config()
|
||||
}
|
||||
|
||||
// A relative folder variable reads as unset inside magpie and stays in the
|
||||
// environment for the programs magpie starts; one a login shell lends later
|
||||
// (proc.UserPath sets it with os.Setenv) is read the same way.
|
||||
func TestRelativeFolderVariablesIgnoredNotUnset(t *testing.T) {
|
||||
t.Setenv(homeVar(), t.TempDir())
|
||||
abs := t.TempDir()
|
||||
t.Setenv("XDG_CONFIG_HOME", abs)
|
||||
t.Setenv("XDG_DATA_HOME", "data")
|
||||
t.Setenv("CODEX_HOME", "./codex")
|
||||
t.Setenv("HANA_HOME", "~/.hanako")
|
||||
t.Setenv("PI_PROFILE", "work")
|
||||
t.Setenv("KIMI_SHARE_DIR", "")
|
||||
ignored, err := CheckEnv()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
slices.Sort(ignored)
|
||||
if want := []string{"CODEX_HOME", "XDG_DATA_HOME"}; !slices.Equal(ignored, want) {
|
||||
t.Errorf("ignored %v, want %v", ignored, want)
|
||||
}
|
||||
for v, want := range map[string]string{"XDG_CONFIG_HOME": abs, "HANA_HOME": "~/.hanako", "PI_PROFILE": "work", "XDG_DATA_HOME": "", "CODEX_HOME": ""} {
|
||||
if got := Getenv(v); got != want {
|
||||
t.Errorf("Getenv(%s) = %q, want %q", v, got, want)
|
||||
}
|
||||
}
|
||||
if _, ok := LookupEnv("CODEX_HOME"); ok {
|
||||
t.Error("LookupEnv(CODEX_HOME) says set")
|
||||
}
|
||||
for v, want := range map[string]string{"XDG_DATA_HOME": "data", "CODEX_HOME": "./codex"} {
|
||||
if got := os.Getenv(v); got != want {
|
||||
t.Errorf("the environment's %s = %q, want %q kept for children", v, got, want)
|
||||
}
|
||||
}
|
||||
os.Setenv("CLAUDE_CONFIG_DIR", "claude") // as the shell import would
|
||||
t.Cleanup(func() { os.Unsetenv("CLAUDE_CONFIG_DIR") })
|
||||
if got := Getenv("CLAUDE_CONFIG_DIR"); got != "" {
|
||||
t.Errorf("a relative value lent by the shell read as %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// On Windows a path rooted on the current drive is no working-folder path:
|
||||
// \Users\x and Git Bash's /c/x are kept.
|
||||
func TestRootedOnWindows(t *testing.T) {
|
||||
if runtime.GOOS != "windows" {
|
||||
t.Skip("drive-relative roots are Windows'")
|
||||
}
|
||||
t.Setenv(homeVar(), t.TempDir())
|
||||
for _, v := range []string{`\Users\x\.codex`, "/c/Users/x/.codex"} {
|
||||
t.Setenv("CODEX_HOME", v)
|
||||
if got := Getenv("CODEX_HOME"); got != v {
|
||||
t.Errorf("Getenv(CODEX_HOME) = %q, want %q kept", got, v)
|
||||
}
|
||||
}
|
||||
t.Setenv(homeVar(), `\Users\x`)
|
||||
if _, err := Home(); err != nil {
|
||||
t.Errorf(`a home of \Users\x: %v`, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package appdir
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -6,11 +6,13 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
func TestBootScript(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
testenv.SetHome(t, home)
|
||||
// Spaces, quotes and shell expansions must stay part of the file name.
|
||||
exe := filepath.Join(home, "magpie ' $not_a_variable")
|
||||
out := filepath.Join(home, "args")
|
||||
|
||||
@@ -6,10 +6,12 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
)
|
||||
|
||||
func record() string {
|
||||
dir := os.Getenv("XDG_CONFIG_HOME")
|
||||
dir := appdir.Getenv("XDG_CONFIG_HOME")
|
||||
if dir == "" {
|
||||
home, _ := os.UserHomeDir()
|
||||
dir = filepath.Join(home, ".config")
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package autostart
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -0,0 +1,10 @@
|
||||
package backup
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -771,7 +771,7 @@ func Providers() []string {
|
||||
|
||||
// CodexHome is where Codex CLI keeps its state: $CODEX_HOME, else ~/.codex.
|
||||
func CodexHome() string {
|
||||
if dir := os.Getenv("CODEX_HOME"); dir != "" {
|
||||
if dir := appdir.Getenv("CODEX_HOME"); dir != "" {
|
||||
return dir
|
||||
}
|
||||
home, _ := os.UserHomeDir()
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package catalog
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -0,0 +1,10 @@
|
||||
package claudebridge
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -0,0 +1,10 @@
|
||||
package codexcat
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -0,0 +1,10 @@
|
||||
package davsync
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -0,0 +1,10 @@
|
||||
package edit
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -0,0 +1,10 @@
|
||||
package filememo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -0,0 +1,10 @@
|
||||
package fx
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -7,13 +7,14 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// A key set to serve some of its provider's models only is never a
|
||||
// candidate for another, whatever the routing; it is one for those, and a
|
||||
// key without a list of its own is one for every model, as before (#474).
|
||||
func TestKeyModelsNarrowCandidates(t *testing.T) {
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
testenv.SetHome(t, t.TempDir())
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
for _, mode := range []string{"", provider.Ordered, provider.Rotate, provider.LeastUsed} {
|
||||
p := provider.Provider{ID: "narrow", Name: "Narrow", Chat: "https://example.invalid/v1", Key: "first", Keys: []provider.KeyAccount{{Key: "second"}, {Key: "third"}}, Routing: mode}
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
func TestArrangedKeysAreGatewayCandidates(t *testing.T) {
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
testenv.SetHome(t, t.TempDir())
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
for _, mode := range []string{"", provider.Ordered, provider.Rotate, provider.LeastUsed} {
|
||||
p := provider.Provider{ID: "arrange-routing", Name: "Arrange", Chat: "https://example.invalid/v1", Key: "first", Keys: []provider.KeyAccount{{Key: "second"}, {Key: "third"}, {Key: "off", Off: true}}, Routing: mode}
|
||||
|
||||
@@ -4,13 +4,14 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The trace tells each key's place in its provider's own list, as dragged,
|
||||
// whatever order routing weighed them in, so the live routing view can
|
||||
// seat them in it (#217).
|
||||
func TestWeighedRankIsDraggedOrder(t *testing.T) {
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
testenv.SetHome(t, t.TempDir())
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
for _, mode := range []string{"", provider.Ordered, provider.Rotate, provider.LeastUsed} {
|
||||
p := provider.Provider{ID: "rank" + mode, Name: "Rank", Chat: "https://example.invalid/v1", Key: "first", Keys: []provider.KeyAccount{{Key: "second"}, {Key: "third"}}, Routing: mode}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// resumeHarness runs Claude subscription requests through a script
|
||||
@@ -32,7 +33,7 @@ func newResumeHarness(t *testing.T) *resumeHarness {
|
||||
t.Skip("a shell script stands in for Claude Code")
|
||||
}
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
testenv.SetHome(t, home)
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
||||
t.Setenv("TMPDIR", t.TempDir())
|
||||
config := filepath.Join(home, ".claude")
|
||||
|
||||
@@ -54,6 +54,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
@@ -243,7 +244,7 @@ type bridgeTool struct {
|
||||
}
|
||||
|
||||
func claudeConfigDir() string {
|
||||
if d := os.Getenv("CLAUDE_CONFIG_DIR"); d != "" {
|
||||
if d := appdir.Getenv("CLAUDE_CONFIG_DIR"); d != "" {
|
||||
return d
|
||||
}
|
||||
home, _ := os.UserHomeDir()
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// claudeWorkDirs runs two Claude subscription requests through a script
|
||||
@@ -24,7 +25,7 @@ func claudeWorkDirs(t *testing.T, prepare func(work string)) (dirs []string, wor
|
||||
if err := os.Mkdir(filepath.Join(home, ".git"), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("HOME", home)
|
||||
testenv.SetHome(t, home)
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
||||
t.Setenv("TMPDIR", t.TempDir())
|
||||
work = filepath.Join(os.TempDir(), claudeWorkName())
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// Gemini on a Google sign-in searches by itself, googleSearch, for a
|
||||
@@ -98,7 +99,7 @@ func TestCodeAssistImageModelAsksForImages(t *testing.T) {
|
||||
func TestSmallModelOfGemini(t *testing.T) {
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
testenv.SetHome(t, t.TempDir())
|
||||
p := provider.Provider{ID: "g", Name: "G", Chat: "https://example.invalid/v1", Key: "k",
|
||||
Models: []string{"gemini-pro-agent", "gemini-3.1-pro-low", "gemini-3-flash", "gemini-3.1-flash-lite"}}
|
||||
if err := provider.Save(p); err != nil {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
func TestPublicURL(t *testing.T) {
|
||||
@@ -132,7 +133,7 @@ func TestPublicURLWarningOnce(t *testing.T) {
|
||||
// keyNote does.
|
||||
func TestOpenToAnyone(t *testing.T) {
|
||||
h := t.TempDir()
|
||||
t.Setenv("HOME", h)
|
||||
testenv.SetHome(t, h)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
||||
t.Setenv("XDG_DATA_HOME", filepath.Join(h, ".local"))
|
||||
|
||||
@@ -12,7 +12,11 @@ import (
|
||||
)
|
||||
|
||||
func TestAccountArrangeRouteAndEditorSave(t *testing.T) {
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
// Windows' home: without it the real Claude sign-in is read, and its
|
||||
// models are cached for the tests after this one
|
||||
t.Setenv("USERPROFILE", home)
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
||||
p := provider.Provider{ID: "arrange-test", Name: "Arrange", Chat: "https://example.invalid/v1", Key: "primary", Keys: []provider.KeyAccount{{Key: "second"}}}
|
||||
|
||||
@@ -14344,7 +14344,7 @@ $("#sessQ").onkeydown = (e) => { if (e.key === "Escape" && e.target.value) { e.s
|
||||
// the version, where magpie keeps its files, the gateway's address.
|
||||
|
||||
const THEMES = [["system", "System"], ["light", "Light"], ["dark", "Dark"]];
|
||||
const LOCALES = [["system", "System"], ["en", "English"], ["zh", "中文"], ["ja", "日本語"]];
|
||||
const LOCALES = [["system", "System"], ["en", "English"], ["zh", "中文"], ["ja", "日本語"], ["de", "Deutsch"]];
|
||||
const TRAYS = [["panel", "Quick panel"], ["window", "Main window"]];
|
||||
const CURRENCIES = [["usd", "$ USD"], ["cny", "¥ CNY"]];
|
||||
// The text size is the windows' own zoom, as a browser's Ctrl/Cmd +: the
|
||||
|
||||
+2957
-2
File diff suppressed because it is too large
Load Diff
@@ -49,7 +49,7 @@
|
||||
const u = s.replace(/^git\+/, "").replace(/\.git$/, "");
|
||||
return /^https?:\/\//.test(u) ? u : "";
|
||||
};
|
||||
const lang = () => (document.documentElement.lang || "").startsWith("zh") ? "zh" : "en";
|
||||
const lang = () => (document.documentElement.lang || "en").slice(0, 2);
|
||||
const summary = (l) => l.summary?.[lang()] || l.summary?.en || l.npm?.description || "";
|
||||
const count = (n) => n >= 1e6 ? (n / 1e6).toFixed(n >= 1e7 ? 0 : 1) + "M" : n >= 1e3 ? (n / 1e3).toFixed(n >= 1e4 ? 0 : 1) + "k" : String(n || 0);
|
||||
const entryOf = (pkg) => mine?.plugins?.find((e) => name(e.spec) === pkg);
|
||||
|
||||
@@ -6,11 +6,13 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/fx"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// TestMain keeps the rate off the network: a state read with no rate cached
|
||||
// asks for one behind it (#541), which would otherwise reach the real
|
||||
// endpoint and land in whatever test runs next.
|
||||
// endpoint and land in whatever test runs next. And the tests run in a
|
||||
// home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) {
|
||||
l, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err == nil {
|
||||
@@ -18,5 +20,5 @@ func TestMain(m *testing.M) {
|
||||
l.Close() // refused at once from here on
|
||||
fx.SetRateURL("http://" + addr + "/")
|
||||
}
|
||||
os.Exit(m.Run())
|
||||
os.Exit(testenv.Run(m))
|
||||
}
|
||||
|
||||
@@ -10,13 +10,14 @@ import (
|
||||
"github.com/yetone/magpie/internal/fx"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// Settings shows the local address agents use; the Gateway page advertises
|
||||
// the public URL for its copy buttons and snippets.
|
||||
func TestPublicURLInConsole(t *testing.T) {
|
||||
h := t.TempDir()
|
||||
t.Setenv("HOME", h)
|
||||
testenv.SetHome(t, h)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
||||
t.Setenv("XDG_DATA_HOME", filepath.Join(h, ".local", "share"))
|
||||
@@ -72,7 +73,7 @@ func TestPublicURLInConsole(t *testing.T) {
|
||||
// beyond loopback with nothing shared.
|
||||
func TestGatewayOpenInConsole(t *testing.T) {
|
||||
h := t.TempDir()
|
||||
t.Setenv("HOME", h)
|
||||
testenv.SetHome(t, h)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
||||
t.Setenv("XDG_DATA_HOME", filepath.Join(h, ".local", "share"))
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"math"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
@@ -95,9 +96,50 @@ func alertClockJa(at, now time.Time) string {
|
||||
return fmt.Sprintf("%d月%d日 %s", at.Month(), at.Day(), at.Format("15:04"))
|
||||
}
|
||||
|
||||
// alertWindowDe is a window's name in German; one it doesn't know stays as
|
||||
// the vendor named it.
|
||||
func alertWindowDe(name string) string {
|
||||
if m := hoursName.FindStringSubmatch(name); m != nil {
|
||||
if m[1] == "1" {
|
||||
return "1 Stunde"
|
||||
}
|
||||
return m[1] + " Stunden"
|
||||
}
|
||||
if m := daysName.FindStringSubmatch(name); m != nil {
|
||||
if m[1] == "1" {
|
||||
return "1 Tag"
|
||||
}
|
||||
return m[1] + " Tage"
|
||||
}
|
||||
switch name {
|
||||
case "Weekly":
|
||||
return "Wöchentlich"
|
||||
case "Monthly":
|
||||
return "Monatlich"
|
||||
case "Daily":
|
||||
return "Täglich"
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
// alertClockDe is provider.ResetClock in German.
|
||||
func alertClockDe(at, now time.Time) string {
|
||||
at, now = at.Local(), now.Local()
|
||||
day := func(t time.Time) time.Time { y, m, d := t.Date(); return time.Date(y, m, d, 0, 0, 0, 0, time.Local) }
|
||||
switch days := int(math.Round(day(at).Sub(day(now)).Hours() / 24)); {
|
||||
case days <= 0:
|
||||
return "um " + at.Format("15:04")
|
||||
case days == 1:
|
||||
return "morgen um " + at.Format("15:04")
|
||||
case days < 7:
|
||||
return [...]string{"So.", "Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa."}[at.Weekday()] + " um " + at.Format("15:04")
|
||||
}
|
||||
return at.Format("2.1. um 15:04")
|
||||
}
|
||||
|
||||
// alertText is a usage alert as a notification says it, in the language
|
||||
// (en, zh or ja): the card, and what reached the line. left says a window by
|
||||
// how much of it is left, as the Usage page does when set to.
|
||||
// (en, zh, ja or de): the card, and what reached the line. left says a
|
||||
// window by how much of it is left, as the Usage page does when set to.
|
||||
func alertText(lang string, a provider.QuotaAlert, bal float64, left bool, now time.Time) (title, body string) {
|
||||
title = a.Name
|
||||
if a.User != "" {
|
||||
@@ -105,11 +147,13 @@ func alertText(lang string, a provider.QuotaAlert, bal float64, left bool, now t
|
||||
}
|
||||
if a.Window == "" {
|
||||
line := strconv.FormatFloat(bal, 'f', -1, 64)
|
||||
if lang == "zh" {
|
||||
switch lang {
|
||||
case "zh":
|
||||
return title, fmt.Sprintf("余额已降至 %s(提醒线 %s)", a.Balance, line)
|
||||
}
|
||||
if lang == "ja" {
|
||||
case "ja":
|
||||
return title, fmt.Sprintf("残高が %s まで減りました(通知ライン %s)", a.Balance, line)
|
||||
case "de":
|
||||
return title, fmt.Sprintf("Guthaben auf %s gesunken (Warnschwelle %s)", a.Balance, line)
|
||||
}
|
||||
return title, fmt.Sprintf("Balance down to %s (alert at %s)", a.Balance, line)
|
||||
}
|
||||
@@ -138,6 +182,17 @@ func alertText(lang string, a provider.QuotaAlert, bal float64, left bool, now t
|
||||
}
|
||||
return title, body
|
||||
}
|
||||
if lang == "de" {
|
||||
pct = strings.Replace(pct, ".", ",", 1) // German decimal comma
|
||||
body = fmt.Sprintf("%s: %s verbraucht", alertWindowDe(a.Window), pct)
|
||||
if left {
|
||||
body = fmt.Sprintf("%s: %s übrig", alertWindowDe(a.Window), pct)
|
||||
}
|
||||
if a.ResetsAt != nil {
|
||||
body += ", Zurücksetzung " + alertClockDe(*a.ResetsAt, now)
|
||||
}
|
||||
return title, body
|
||||
}
|
||||
body = fmt.Sprintf("%s: %s used", a.Window, pct)
|
||||
if left {
|
||||
body = fmt.Sprintf("%s: %s left", a.Window, pct)
|
||||
|
||||
@@ -24,6 +24,9 @@ func TestAlertText(t *testing.T) {
|
||||
{"zh", w, true, "Claude Code · a@b.c", "5 小时窗口剩余 17.7%,14:30 重置"},
|
||||
{"en", b, false, "DeepSeek", "Balance down to ¥4.20 (alert at 5)"},
|
||||
{"zh", b, false, "DeepSeek", "余额已降至 ¥4.20(提醒线 5)"},
|
||||
{"de", w, false, "Claude Code · a@b.c", "5 Stunden: 82,3% verbraucht, Zurücksetzung um 14:30"},
|
||||
{"de", w, true, "Claude Code · a@b.c", "5 Stunden: 17,7% übrig, Zurücksetzung um 14:30"},
|
||||
{"de", b, false, "DeepSeek", "Guthaben auf ¥4.20 gesunken (Warnschwelle 5)"},
|
||||
} {
|
||||
title, body := alertText(c.lang, c.a, 5, c.left, now)
|
||||
if title != c.title || body != c.body {
|
||||
@@ -41,4 +44,7 @@ func TestAlertText(t *testing.T) {
|
||||
if _, body := alertText("ja", week, 0, true, now); body != "7 日枠の残り 20%、明日 14:30 にリセット" {
|
||||
t.Errorf("ja left: %q", body)
|
||||
}
|
||||
if _, body := alertText("de", week, 0, false, now); body != "7 Tage: 80% verbraucht, Zurücksetzung morgen um 14:30" {
|
||||
t.Errorf("de tomorrow: %q", body)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -16,7 +17,7 @@ func registerScheme() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data := os.Getenv("XDG_DATA_HOME")
|
||||
data := appdir.Getenv("XDG_DATA_HOME")
|
||||
if data == "" {
|
||||
home, _ := os.UserHomeDir()
|
||||
data = filepath.Join(home, ".local", "share")
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// German, as gui-ja.test.cjs has Japanese: every string the GUI has in
|
||||
// Chinese it has in German, with the same {placeholders} and tags. Picked in
|
||||
// Settings, or the system's language when that is German, the window reads
|
||||
// in German, its <html lang> is de-DE, and Settings offers Deutsch.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
|
||||
test("de has every zh string, with its placeholders and tags", async () => {
|
||||
const src = await fs.readFile(path.join(assets, "i18n.js"), "utf8");
|
||||
const I18N = new Function(src.slice(0, src.indexOf("\n};") + 3) + "; return I18N;")();
|
||||
const zh = Object.keys(I18N.zh), de = I18N.de;
|
||||
assert.deepEqual(zh.filter((k) => !(k in de)), [], "missing in de");
|
||||
assert.deepEqual(Object.keys(de).filter((k) => !(k in I18N.zh)), [], "de only");
|
||||
const marks = (s) => [...s.matchAll(/\{\w+\}|<\/?\w+[^>]*>/g)].map((m) => m[0]).sort();
|
||||
for (const k of zh) {
|
||||
assert.equal(typeof de[k], "string", k);
|
||||
assert.deepEqual(marks(de[k]), marks(k), `de for ${JSON.stringify(k)}`);
|
||||
}
|
||||
});
|
||||
|
||||
function serve(lang) {
|
||||
const settings = { lang, theme: "light" };
|
||||
return async (r) => {
|
||||
const url = new URL(r.request().url());
|
||||
const json = (data) => r.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings });
|
||||
if (url.pathname === "/api/settings") return json(settings);
|
||||
if (url.pathname === "/api/gateway/trace") return url.searchParams.get("wait") ? new Promise(() => {}) : json({ mine: true, now: new Date().toISOString(), seq: 0, totals: {}, routes: [] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
try { await r.fulfill({ body: await fs.readFile(file), contentType }); } catch { await r.fulfill({ status: 404, body: "" }); }
|
||||
};
|
||||
}
|
||||
|
||||
for (const [name, engine] of [["webkit", webkit], ["chromium", chromium]]) {
|
||||
test(`${name}: the window reads in German when picked or the system's`, async () => {
|
||||
const browser = await engine.launch();
|
||||
try {
|
||||
for (const [lang, sys, want] of [["de", "en-US", "de"], ["system", "de-DE", "de"], ["system", "de-AT", "de"], ["system", "en-US", "en"]]) {
|
||||
const page = await (await browser.newContext({ locale: sys, viewport: { width: 1000, height: 760 } })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
await page.route("**/*", serve(lang));
|
||||
await page.goto("http://magpie.test/");
|
||||
await page.waitForFunction(() => typeof locale === "string" && document.documentElement.lang);
|
||||
const got = await page.evaluate(() => ({
|
||||
locale, lang: document.documentElement.lang,
|
||||
nav: [...document.querySelectorAll("button[data-view]")].map((b) => b.textContent.trim()).slice(0, 5),
|
||||
offered: LOCALES.map(([v, l]) => v + ":" + l),
|
||||
}));
|
||||
assert.equal(got.locale, want, `${lang} on ${sys}`);
|
||||
assert.ok(got.offered.includes("de:Deutsch"));
|
||||
if (want === "de") {
|
||||
assert.equal(got.lang, "de-DE");
|
||||
assert.deepEqual(got.nav, ["Agenten", "Anbieter", "Zugangspunkt", "Weiterleitung", "Nutzung"]);
|
||||
}
|
||||
await page.close();
|
||||
}
|
||||
} finally { await browser.close(); }
|
||||
});
|
||||
}
|
||||
@@ -30,16 +30,30 @@ var trayJa = map[string]string{
|
||||
"Restart Now to Update (%d in flight)": "今すぐ再起動してアップデート(%d 件処理中)",
|
||||
}
|
||||
|
||||
// trayDe is the tray menu in German.
|
||||
var trayDe = map[string]string{
|
||||
"Open magpie": "magpie öffnen",
|
||||
"Version %s": "Version %s",
|
||||
"Restart to Update": "Zum Aktualisieren neu starten",
|
||||
"Restart to Update to %s": "Zum Aktualisieren auf %s neu starten",
|
||||
"Quit magpie": "magpie beenden",
|
||||
"Restart Now to Update": "Jetzt neu starten und aktualisieren",
|
||||
"Restart Now to Update (%d in flight)": "Jetzt neu starten und aktualisieren (%d laufend)",
|
||||
}
|
||||
|
||||
// trayWords are the tray menu's translations by language.
|
||||
var trayWords = map[string]map[string]string{"zh": trayZh, "ja": trayJa, "de": trayDe}
|
||||
|
||||
// onLang relabels the tray menu when the Settings page changes the
|
||||
// language; set by the process that has the tray.
|
||||
var onLang func()
|
||||
|
||||
// trayLang is the language the tray menu is in, as the page picks its own:
|
||||
// the setting, or with "system" (or none) the system's, Chinese for any zh,
|
||||
// Japanese for any ja.
|
||||
// Japanese for any ja, German for any de.
|
||||
func trayLang(pref string, system func() string) string {
|
||||
switch pref {
|
||||
case "en", "zh", "ja":
|
||||
case "en", "zh", "ja", "de":
|
||||
return pref
|
||||
}
|
||||
switch sys := strings.ToLower(system()); {
|
||||
@@ -47,13 +61,24 @@ func trayLang(pref string, system func() string) string {
|
||||
return "zh"
|
||||
case strings.HasPrefix(sys, "ja"):
|
||||
return "ja"
|
||||
case strings.HasPrefix(sys, "de"):
|
||||
return "de"
|
||||
}
|
||||
return "en"
|
||||
}
|
||||
|
||||
// notesLang is the language release notes are asked in for lang: there are
|
||||
// no German ones, so German asks for the English.
|
||||
func notesLang(lang string) string {
|
||||
if lang == "de" {
|
||||
return "en"
|
||||
}
|
||||
return lang
|
||||
}
|
||||
|
||||
// trayText is a menu line in the language, English where it has none.
|
||||
func trayText(lang, key string, args ...any) string {
|
||||
if s, ok := map[string]map[string]string{"zh": trayZh, "ja": trayJa}[lang][key]; ok {
|
||||
if s, ok := trayWords[lang][key]; ok {
|
||||
key = s
|
||||
}
|
||||
if len(args) == 0 {
|
||||
|
||||
@@ -29,11 +29,23 @@ func TestTrayMenuLabels(t *testing.T) {
|
||||
{"ja", enSys, "ja"},
|
||||
{"system", func() string { return "ja-JP" }, "ja"},
|
||||
{"", func() string { return "ja_JP.UTF-8" }, "ja"},
|
||||
{"de", enSys, "de"},
|
||||
{"system", func() string { return "de-DE" }, "de"},
|
||||
{"", func() string { return "de_AT.UTF-8" }, "de"},
|
||||
} {
|
||||
if got := trayLang(c.pref, c.sys); got != c.want {
|
||||
t.Errorf("trayLang(%q, %s) = %s, want %s", c.pref, c.sys(), got, c.want)
|
||||
}
|
||||
}
|
||||
de := trayMenuLabels("de", "0.1.500", "0.1.501")
|
||||
if de != (trayLabels{"magpie öffnen", "Version 0.1.500", "Zum Aktualisieren auf 0.1.501 neu starten", "magpie beenden"}) {
|
||||
t.Errorf("de: %+v", de)
|
||||
}
|
||||
for lang, want := range map[string]string{"de": "en", "en": "en", "zh": "zh"} {
|
||||
if got := notesLang(lang); got != want {
|
||||
t.Errorf("notesLang(%q) = %q, want %q", lang, got, want)
|
||||
}
|
||||
}
|
||||
zh := trayMenuLabels("zh", "0.1.500", "")
|
||||
if zh != (trayLabels{"打开 magpie", "版本 0.1.500", "重启以更新", "退出 magpie"}) {
|
||||
t.Errorf("zh: %+v", zh)
|
||||
|
||||
@@ -157,7 +157,7 @@ func (u *updater) run() {
|
||||
lang := u.lang
|
||||
u.mu.Unlock()
|
||||
if lang == "" {
|
||||
lang = trayLang(settings.Load().Lang, systemLang)
|
||||
lang = notesLang(trayLang(settings.Load().Lang, systemLang))
|
||||
}
|
||||
rel, err := update.LatestIn(ctx, lang)
|
||||
u.mu.Lock()
|
||||
|
||||
@@ -217,12 +217,13 @@ func fetchNotes(ctx context.Context, after, upto, lang string) ([]update.Note, e
|
||||
}
|
||||
|
||||
// pageLang is the language a page asks in, its own (?lang=, zh or en), or
|
||||
// without one the app's, as the tray menu has it.
|
||||
// without one the app's, as the tray menu has it, in the languages release
|
||||
// notes come in.
|
||||
func pageLang(r *http.Request) string {
|
||||
if l := askedLang(r); l != "" {
|
||||
return l
|
||||
}
|
||||
return trayLang(settings.Load().Lang, systemLang)
|
||||
return notesLang(trayLang(settings.Load().Lang, systemLang))
|
||||
}
|
||||
|
||||
// askedLang is the language a page names (?lang=): zh for any Chinese, en
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package imagemcp
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -0,0 +1,10 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/tidwall/jsonc"
|
||||
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
)
|
||||
|
||||
@@ -84,7 +85,7 @@ var piGlobalRoots = func() []string {
|
||||
}
|
||||
}
|
||||
if runtime.GOOS == "windows" {
|
||||
if d := os.Getenv("APPDATA"); d != "" {
|
||||
if d := appdir.Getenv("APPDATA"); d != "" {
|
||||
out = append(out, filepath.Join(d, "npm", "node_modules"))
|
||||
}
|
||||
return out
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"gopkg.in/yaml.v3"
|
||||
@@ -523,9 +524,9 @@ func rtkPath() string {
|
||||
}
|
||||
name, dirs := "rtk", []string{filepath.Join(home(), ".local", "bin"), filepath.Join(home(), ".cargo", "bin")}
|
||||
if runtime.GOOS == "windows" {
|
||||
winget := filepath.Join(os.Getenv("LOCALAPPDATA"), "Microsoft", "WinGet")
|
||||
winget := filepath.Join(appdir.Getenv("LOCALAPPDATA"), "Microsoft", "WinGet")
|
||||
name, dirs = "rtk.exe", []string{filepath.Join(winget, "Links"), filepath.Join(home(), ".cargo", "bin")}
|
||||
if os.Getenv("LOCALAPPDATA") != "" {
|
||||
if appdir.Getenv("LOCALAPPDATA") != "" {
|
||||
pkgs, _ := filepath.Glob(filepath.Join(winget, "Packages", "rtk-ai.rtk_*"))
|
||||
dirs = append(dirs, pkgs...)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
)
|
||||
|
||||
// Target is where one agent keeps each of the three: an empty path is
|
||||
@@ -41,7 +42,7 @@ type Target struct {
|
||||
func home() string { h, _ := os.UserHomeDir(); return h }
|
||||
|
||||
func claudeDir() string {
|
||||
if d := os.Getenv("CLAUDE_CONFIG_DIR"); d != "" {
|
||||
if d := appdir.Getenv("CLAUDE_CONFIG_DIR"); d != "" {
|
||||
return d
|
||||
}
|
||||
return filepath.Join(home(), ".claude")
|
||||
@@ -50,14 +51,14 @@ func claudeDir() string {
|
||||
// claudeJSON is where Claude Code keeps its user-wide MCP servers: beside
|
||||
// its folder, or in it when CLAUDE_CONFIG_DIR moves it.
|
||||
func claudeJSON() string {
|
||||
if d := os.Getenv("CLAUDE_CONFIG_DIR"); d != "" {
|
||||
if d := appdir.Getenv("CLAUDE_CONFIG_DIR"); d != "" {
|
||||
return filepath.Join(d, ".claude.json")
|
||||
}
|
||||
return filepath.Join(home(), ".claude.json")
|
||||
}
|
||||
|
||||
func codexDir() string {
|
||||
if d := os.Getenv("CODEX_HOME"); d != "" {
|
||||
if d := appdir.Getenv("CODEX_HOME"); d != "" {
|
||||
return d
|
||||
}
|
||||
return filepath.Join(home(), ".codex")
|
||||
@@ -159,7 +160,7 @@ func targetOf(a *agent.Agent) *Target {
|
||||
t.MCP = &mcpFile{Path: filepath.Join(d, "mcp.json"), Format: fmtCursor}
|
||||
t.Skills = filepath.Join(d, "skills")
|
||||
case "copilot":
|
||||
d := os.Getenv("COPILOT_HOME")
|
||||
d := appdir.Getenv("COPILOT_HOME")
|
||||
if d == "" {
|
||||
d = filepath.Join(h, ".copilot")
|
||||
}
|
||||
@@ -171,7 +172,7 @@ func targetOf(a *agent.Agent) *Target {
|
||||
// Windows too since Crush 0.14; the crush.json magpie edits there is
|
||||
// %LOCALAPPDATA%\crush's, where Crush keeps its own picks and reads
|
||||
// skills but no CRUSH.md
|
||||
cfg := os.Getenv("XDG_CONFIG_HOME")
|
||||
cfg := appdir.Getenv("XDG_CONFIG_HOME")
|
||||
if cfg == "" {
|
||||
cfg = filepath.Join(h, ".config")
|
||||
}
|
||||
@@ -246,7 +247,7 @@ func targetOf(a *agent.Agent) *Target {
|
||||
// Cline's CLI reads its MCP servers from settings/
|
||||
// cline_mcp_settings.json beside providers.json, or
|
||||
// $CLINE_MCP_SETTINGS_PATH (@cline/shared's storage)
|
||||
p := os.Getenv("CLINE_MCP_SETTINGS_PATH")
|
||||
p := appdir.Getenv("CLINE_MCP_SETTINGS_PATH")
|
||||
if p == "" {
|
||||
p = filepath.Join(filepath.Dir(a.Path), "cline_mcp_settings.json")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package mcpauth_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -0,0 +1,10 @@
|
||||
package netproxy
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -108,7 +109,7 @@ func StopClicks() error {
|
||||
// WatchClicks calls click on each click ReportClicks announces, for as long
|
||||
// as magpie runs, reconnecting when Hyprland restarts.
|
||||
func WatchClicks(click func()) {
|
||||
sock := filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "hypr", os.Getenv("HYPRLAND_INSTANCE_SIGNATURE"), ".socket2.sock")
|
||||
sock := filepath.Join(appdir.Getenv("XDG_RUNTIME_DIR"), "hypr", os.Getenv("HYPRLAND_INSTANCE_SIGNATURE"), ".socket2.sock")
|
||||
for {
|
||||
if c, err := net.Dial("unix", sock); err == nil {
|
||||
sc := bufio.NewScanner(c)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package omarchy
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -39,7 +40,7 @@ func Detect() bool {
|
||||
if runtime.GOOS != "linux" || ThemeDir() == "" {
|
||||
return false
|
||||
}
|
||||
if os.Getenv("OMARCHY_PATH") != "" {
|
||||
if appdir.Getenv("OMARCHY_PATH") != "" {
|
||||
return true
|
||||
}
|
||||
home, _ := os.UserHomeDir()
|
||||
@@ -57,7 +58,7 @@ func ThemeDir() string {
|
||||
return d
|
||||
}
|
||||
home, _ := os.UserHomeDir()
|
||||
state := os.Getenv("XDG_STATE_HOME")
|
||||
state := appdir.Getenv("XDG_STATE_HOME")
|
||||
if state == "" {
|
||||
state = filepath.Join(home, ".local", "state")
|
||||
}
|
||||
@@ -351,7 +352,7 @@ func themeFiles(dir string) []string {
|
||||
|
||||
func deskFiles() []string {
|
||||
home, _ := os.UserHomeDir()
|
||||
cfg := os.Getenv("XDG_CONFIG_HOME")
|
||||
cfg := appdir.Getenv("XDG_CONFIG_HOME")
|
||||
if cfg == "" {
|
||||
cfg = filepath.Join(home, ".config")
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -26,7 +27,7 @@ const WidgetID = "usemagpie.magpie"
|
||||
var widgetFiles embed.FS
|
||||
|
||||
func widgetDir() string {
|
||||
cfg := os.Getenv("XDG_CONFIG_HOME")
|
||||
cfg := appdir.Getenv("XDG_CONFIG_HOME")
|
||||
if cfg == "" {
|
||||
home, _ := os.UserHomeDir()
|
||||
cfg = filepath.Join(home, ".config")
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -483,8 +483,11 @@ async function answer(events, { model, stream, res, said }) {
|
||||
// h is what host.js lends: readAuth, changeAuth, keyFor, send, directory.
|
||||
export async function load(h, list) {
|
||||
const home = path.join(h.directory, "pi")
|
||||
// pi keeps its settings and caches here, not in the user's ~/.pi
|
||||
process.env.PI_CODING_AGENT_DIR ??= home
|
||||
// pi keeps its settings and caches here, not in the user's ~/.pi. This
|
||||
// overrides any PI_CODING_AGENT_DIR from the user's shell: with that one,
|
||||
// the auth.json written below would be the user's own pi sign-ins, and
|
||||
// magpie would delete every sign-in it doesn't hold itself.
|
||||
process.env.PI_CODING_AGENT_DIR = home
|
||||
// pi makes it on start; packages write their files into it (pi-antigravity
|
||||
// its accounts) and fail with ENOENT when it isn't there
|
||||
fs.mkdirSync(process.env.PI_CODING_AGENT_DIR, { recursive: true })
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// storeSandbox gives the test its own magpie folders, without the Bun the
|
||||
@@ -20,7 +21,7 @@ import (
|
||||
func storeSandbox(t testing.TB) string {
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
t.Setenv("HOME", dir)
|
||||
testenv.SetHome(t, dir)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(dir, "config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(dir, "cache"))
|
||||
if err := os.MkdirAll(settings.Dir(), 0o700); err != nil {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package proc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -27,7 +27,10 @@ import (
|
||||
// and the app wasn't started with, so that magpie writes an agent's config
|
||||
// into the folder the agent reads, not its default one in the home (atie on
|
||||
// Discord: Pi's models.json went to ~/.pi/agent with PI_CODING_AGENT_DIR set
|
||||
// in the shell). One already in magpie's environment is kept. Those are read
|
||||
// in the shell). One already in magpie's environment is kept. One holding a
|
||||
// relative path is lent to the programs magpie starts all the same, but
|
||||
// magpie itself reads them through appdir.LookupEnv, which passes such a
|
||||
// value over, as it does the ones magpie started with. Those are read
|
||||
// as magpie starts (the library is synced into the agents at once), so the
|
||||
// answer is waited for, but no more than shellWait: a slow profile mustn't
|
||||
// hold the window up, and what it says later is still taken.
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/windows/registry"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
)
|
||||
|
||||
// UserPath has nothing to do on Windows: an app started from the Start menu
|
||||
@@ -18,11 +20,11 @@ func UserPath() {}
|
||||
func UserBinDirs() []string {
|
||||
home, _ := os.UserHomeDir()
|
||||
known := []string{
|
||||
filepath.Join(os.Getenv("APPDATA"), "npm"),
|
||||
filepath.Join(appdir.Getenv("APPDATA"), "npm"),
|
||||
filepath.Join(home, ".local", "bin"),
|
||||
filepath.Join(home, ".bun", "bin"),
|
||||
filepath.Join(os.Getenv("LOCALAPPDATA"), "Volta", "bin"),
|
||||
filepath.Join(os.Getenv("LOCALAPPDATA"), "pnpm"),
|
||||
filepath.Join(appdir.Getenv("LOCALAPPDATA"), "Volta", "bin"),
|
||||
filepath.Join(appdir.Getenv("LOCALAPPDATA"), "pnpm"),
|
||||
}
|
||||
var have []string
|
||||
for _, d := range known {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package profile
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// The tests run in a home of their own, never the user's real files.
|
||||
func TestMain(m *testing.M) { testenv.Main(m) }
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/plugin"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
@@ -359,7 +360,7 @@ type claudeCredentialLocation struct {
|
||||
// claudeCredentialsPath is Claude Code's credentials file, where it keeps
|
||||
// its sign-in off the Mac's keychain.
|
||||
func claudeCredentialsPath() string {
|
||||
dir := os.Getenv("CLAUDE_CONFIG_DIR")
|
||||
dir := appdir.Getenv("CLAUDE_CONFIG_DIR")
|
||||
if dir == "" {
|
||||
home, _ := os.UserHomeDir()
|
||||
dir = filepath.Join(home, ".claude")
|
||||
@@ -659,7 +660,7 @@ func refreshFailed(status int, agent, msg string) error {
|
||||
func Accounts() []Provider {
|
||||
rememberLogins(false)
|
||||
home, _ := os.UserHomeDir()
|
||||
cfg := os.Getenv("XDG_CONFIG_HOME")
|
||||
cfg := appdir.Getenv("XDG_CONFIG_HOME")
|
||||
if cfg == "" {
|
||||
cfg = filepath.Join(home, ".config")
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
func TestAccountOrderValidation(t *testing.T) {
|
||||
@@ -21,7 +23,7 @@ func TestAccountOrderValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAccountOrderKeysAllRoutingModes(t *testing.T) {
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
testenv.SetHome(t, t.TempDir())
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
||||
for _, mode := range []string{"", Ordered, Rotate, LeastUsed} {
|
||||
|
||||
@@ -15,11 +15,13 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
)
|
||||
|
||||
// copilotConfigDir is where the Copilot editors keep their sign-in.
|
||||
func copilotConfigDir() string {
|
||||
if cfg := os.Getenv("XDG_CONFIG_HOME"); cfg != "" {
|
||||
if cfg := appdir.Getenv("XDG_CONFIG_HOME"); cfg != "" {
|
||||
return cfg
|
||||
}
|
||||
home, _ := os.UserHomeDir()
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/tidwall/jsonc"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -45,7 +46,7 @@ type copilotCLIUser struct {
|
||||
|
||||
// copilotCLIHome is where the CLI keeps its settings.
|
||||
func copilotCLIHome() string {
|
||||
if h := os.Getenv("COPILOT_HOME"); h != "" {
|
||||
if h := appdir.Getenv("COPILOT_HOME"); h != "" {
|
||||
return h
|
||||
}
|
||||
home, _ := os.UserHomeDir()
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// wbCard is a WorkBuddy card as the built-in and its plugin both make it:
|
||||
@@ -30,7 +32,7 @@ func dailyOf(t *testing.T, qs []SubscriptionQuota, user string) *DailyCredits {
|
||||
// an error and a reading kept from before count nothing, and the days
|
||||
// come back with the card, oldest first (#568).
|
||||
func TestDailyCredits(t *testing.T) {
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
testenv.SetHome(t, t.TempDir())
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
day := func(d, h int) time.Time { return time.Date(2026, 10, d, h, 0, 0, 0, time.Local) }
|
||||
steps := []struct {
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
@@ -286,7 +287,7 @@ func CursorClientVersion() string {
|
||||
home, _ := os.UserHomeDir()
|
||||
dirs := []string{filepath.Join(home, ".local", "share", "cursor-agent", "versions")}
|
||||
if runtime.GOOS == "windows" {
|
||||
dirs = append(dirs, filepath.Join(os.Getenv("LOCALAPPDATA"), "cursor-agent", "versions"))
|
||||
dirs = append(dirs, filepath.Join(appdir.Getenv("LOCALAPPDATA"), "cursor-agent", "versions"))
|
||||
}
|
||||
for _, dir := range dirs {
|
||||
es, _ := os.ReadDir(dir)
|
||||
@@ -308,7 +309,7 @@ func cursorAuthFile() string {
|
||||
home, _ := os.UserHomeDir()
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
dir := os.Getenv("APPDATA")
|
||||
dir := appdir.Getenv("APPDATA")
|
||||
if dir == "" {
|
||||
dir = filepath.Join(home, "AppData", "Roaming")
|
||||
}
|
||||
@@ -316,7 +317,7 @@ func cursorAuthFile() string {
|
||||
case "darwin":
|
||||
return filepath.Join(home, ".cursor", "auth.json")
|
||||
}
|
||||
dir := os.Getenv("XDG_CONFIG_HOME")
|
||||
dir := appdir.Getenv("XDG_CONFIG_HOME")
|
||||
if dir == "" {
|
||||
dir = filepath.Join(home, ".config")
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
)
|
||||
|
||||
// cursorBase is Cursor's API; a var so tests can point it elsewhere.
|
||||
@@ -60,7 +62,7 @@ func cursorAuthPath() string {
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
dir := os.Getenv("APPDATA")
|
||||
dir := appdir.Getenv("APPDATA")
|
||||
if dir == "" {
|
||||
dir = filepath.Join(home, "AppData", "Roaming")
|
||||
}
|
||||
@@ -68,7 +70,7 @@ func cursorAuthPath() string {
|
||||
case "darwin":
|
||||
return filepath.Join(home, ".cursor", "auth.json")
|
||||
}
|
||||
dir := os.Getenv("XDG_CONFIG_HOME")
|
||||
dir := appdir.Getenv("XDG_CONFIG_HOME")
|
||||
if dir == "" {
|
||||
dir = filepath.Join(home, ".config")
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
|
||||
toml "github.com/pelletier/go-toml/v2"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
)
|
||||
|
||||
@@ -51,11 +52,11 @@ var DevinExecutable = func() string {
|
||||
// DevinCredentialsPath is where the CLI keeps its sign-in.
|
||||
func DevinCredentialsPath() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
if app := os.Getenv("APPDATA"); app != "" {
|
||||
if app := appdir.Getenv("APPDATA"); app != "" {
|
||||
return filepath.Join(app, "devin", "credentials.toml")
|
||||
}
|
||||
}
|
||||
base := os.Getenv("XDG_DATA_HOME")
|
||||
base := appdir.Getenv("XDG_DATA_HOME")
|
||||
if base == "" {
|
||||
home, _ := os.UserHomeDir()
|
||||
base = filepath.Join(home, ".local", "share")
|
||||
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
@@ -44,7 +45,7 @@ import (
|
||||
var GrokExecutable = func() string {
|
||||
home, _ := os.UserHomeDir()
|
||||
path := append(filepath.SplitList(os.Getenv("PATH")), registryPath()...)
|
||||
for _, c := range grokCandidates(runtime.GOOS, home, GrokHome(), os.Getenv("GROK_BIN_DIR"), path) {
|
||||
for _, c := range grokCandidates(runtime.GOOS, home, GrokHome(), appdir.Getenv("GROK_BIN_DIR"), path) {
|
||||
if isFile(c.path) && (c.own || isGrokBuild(c.path)) {
|
||||
return c.path
|
||||
}
|
||||
@@ -120,7 +121,7 @@ func isGrokBuild(path string) bool {
|
||||
|
||||
// GrokHome is where the CLI keeps its sign-in and settings.
|
||||
func GrokHome() string {
|
||||
if h := os.Getenv("GROK_HOME"); h != "" {
|
||||
if h := appdir.Getenv("GROK_HOME"); h != "" {
|
||||
return h
|
||||
}
|
||||
home, _ := os.UserHomeDir()
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
@@ -78,7 +79,7 @@ func installGrokBuild(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
downloads := filepath.Join(home, ".grok", "downloads")
|
||||
bin := os.Getenv("GROK_BIN_DIR")
|
||||
bin := appdir.Getenv("GROK_BIN_DIR")
|
||||
if bin == "" {
|
||||
bin = filepath.Join(home, ".grok", "bin")
|
||||
}
|
||||
|
||||
@@ -6,10 +6,12 @@ import (
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
)
|
||||
|
||||
func codexConfigPath() string {
|
||||
dir := os.Getenv("CODEX_HOME")
|
||||
dir := appdir.Getenv("CODEX_HOME")
|
||||
if dir == "" {
|
||||
home, _ := os.UserHomeDir()
|
||||
dir = filepath.Join(home, ".codex")
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/tidwall/jsonc"
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/plugin"
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
@@ -401,7 +402,7 @@ func fileExists(p string) bool {
|
||||
}
|
||||
|
||||
func claudeSettingsPath() string {
|
||||
if dir := os.Getenv("CLAUDE_CONFIG_DIR"); dir != "" {
|
||||
if dir := appdir.Getenv("CLAUDE_CONFIG_DIR"); dir != "" {
|
||||
return filepath.Join(dir, "settings.json")
|
||||
}
|
||||
home, _ := os.UserHomeDir()
|
||||
|
||||
@@ -39,6 +39,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
@@ -68,7 +69,7 @@ var kiroCLIDB = func() string {
|
||||
home, _ := os.UserHomeDir()
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
dir := os.Getenv("APPDATA")
|
||||
dir := appdir.Getenv("APPDATA")
|
||||
if dir == "" {
|
||||
dir = filepath.Join(home, "AppData", "Roaming")
|
||||
}
|
||||
|
||||
@@ -5,37 +5,18 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/agentenv"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// TestMain keeps the package's tests off the Kiro sign-ins of whoever runs
|
||||
// them: Accounts() reads them, and asks Kiro who the account is. It also
|
||||
// gives the package a home of its own, so what a test leaves behind it —
|
||||
// a CLI's answer kept by refresh after the test is over — never lands in
|
||||
// the runner's magpie, nor in APPDATA on Windows.
|
||||
// gives the package a home of its own (testenv), so what a test leaves
|
||||
// behind it — a CLI's answer kept by refresh after the test is over —
|
||||
// never lands in the runner's magpie, nor in APPDATA on Windows.
|
||||
func TestMain(m *testing.M) {
|
||||
dir, _ := os.MkdirTemp("", "magpie-kiro")
|
||||
home := filepath.Join(dir, "home")
|
||||
os.MkdirAll(home, 0o755)
|
||||
for k, v := range map[string]string{
|
||||
"HOME": home, "USERPROFILE": home,
|
||||
"XDG_CONFIG_HOME": filepath.Join(home, ".config"),
|
||||
"XDG_CACHE_HOME": filepath.Join(home, ".cache"),
|
||||
"XDG_DATA_HOME": filepath.Join(home, ".local", "share"),
|
||||
"APPDATA": filepath.Join(home, "AppData", "Roaming"),
|
||||
"LOCALAPPDATA": filepath.Join(home, "AppData", "Local"),
|
||||
} {
|
||||
os.Setenv(k, v)
|
||||
}
|
||||
// Accounts here read what an agent keeps on this machine: a variable left
|
||||
// in the shell would point a test at the runner's real one (#522).
|
||||
for _, k := range agentenv.Vars {
|
||||
os.Unsetenv(k)
|
||||
}
|
||||
kiroCLIDB = func() string { return filepath.Join(dir, "kiro-cli", "data.sqlite3") }
|
||||
kiroIDEDir = func() string { return filepath.Join(dir, "sso") }
|
||||
askKiroIdentity = func(string, string) (string, string) { return "", "" }
|
||||
code := m.Run()
|
||||
os.RemoveAll(dir)
|
||||
os.Exit(code)
|
||||
os.Exit(testenv.RunIn(m, func(home string) {
|
||||
kiroCLIDB = func() string { return filepath.Join(home, "kiro-test", "kiro-cli", "data.sqlite3") }
|
||||
kiroIDEDir = func() string { return filepath.Join(home, "kiro-test", "sso") }
|
||||
askKiroIdentity = func(string, string) (string, string) { return "", "" }
|
||||
}))
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user