Files
Reims-Go/internal/config/config_test.go
T
NwflowerandClaude Opus 5.5 f6f6bfce34 feat: online runtime install, first-launch data folder picker, source packages
- Runtime: list and fetch runtimes from this repo's GitHub Releases
  (stable by default, candidate on request), with SHA256 check and resume.
  CLI gains `runtime available` and `runtime fetch`; the host page gets an
  online install row and a "receive candidates" switch.
- First launch: pick a data folder (non-system drives first, USB never
  recommended); the choice is recorded in %APPDATA%\reims-go\location.json.
  Existing installs in the default folder are adopted without asking.
- pack-runtime.ps1: also builds the matching source package, records every
  patch with its SHA256 and the channel, and refuses undeclared changes in
  the build trees.
- patches: declare reims-vgpu-cargo-lock.patch (Cargo.lock source lines).
- UI: sidebar and VM page restyle, new design tokens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 04:11:37 -07:00

81 lines
2.1 KiB
Go

package config
import (
"os"
"path/filepath"
"runtime"
"testing"
)
// isolate points the user config dir and the legacy default at temp folders.
func isolate(t *testing.T) (legacy string) {
t.Helper()
cfgHome := t.TempDir()
if runtime.GOOS == "windows" {
t.Setenv("APPDATA", cfgHome)
} else {
t.Setenv("XDG_CONFIG_HOME", cfgHome)
t.Setenv("HOME", cfgHome)
}
t.Setenv("REIMS_GO_DATA_ROOT", "")
legacy = filepath.Join(t.TempDir(), "legacy")
old := legacyDataRoot
legacyDataRoot = func() string { return legacy }
t.Cleanup(func() { legacyDataRoot = old })
return legacy
}
func TestFirstLaunchNeedsSetupUntilAFolderIsChosen(t *testing.T) {
isolate(t)
_, needs, err := Resolve()
if err != nil || !needs {
t.Fatalf("fresh machine: needs=%v err=%v", needs, err)
}
chosen := filepath.Join(t.TempDir(), "Data", "reims-go")
cfg := Default()
cfg.DataRoot = chosen
if err := Save("", cfg); err != nil {
t.Fatal(err)
}
if err := SaveLocation(chosen); err != nil {
t.Fatal(err)
}
got, needs, err := Resolve()
if err != nil || needs || got.DataRoot != chosen {
t.Fatalf("after choosing: root=%q needs=%v err=%v", got.DataRoot, needs, err)
}
if CurrentDataRoot() != chosen {
t.Fatalf("CurrentDataRoot = %q", CurrentDataRoot())
}
}
func TestExistingInstallIsAdoptedWithoutAsking(t *testing.T) {
legacy := isolate(t)
cfg := Default()
cfg.DataRoot = legacy
cfg.ActiveRuntime = "3731afd"
if err := Save(filepath.Join(legacy, "reims-go.json"), cfg); err != nil {
t.Fatal(err)
}
got, needs, err := Resolve()
if err != nil || needs || got.ActiveRuntime != "3731afd" {
t.Fatalf("legacy: %+v needs=%v err=%v", got, needs, err)
}
if root, ok := ReadLocation(); !ok || root != legacy {
t.Fatalf("location not recorded: %q %v", root, ok)
}
}
func TestEnvOverridesEverything(t *testing.T) {
isolate(t)
env := t.TempDir()
t.Setenv("REIMS_GO_DATA_ROOT", env)
cfg, needs, err := Resolve()
if err != nil || needs || cfg.DataRoot != env {
t.Fatalf("env: root=%q needs=%v err=%v", cfg.DataRoot, needs, err)
}
if _, err := os.Stat(LocationPath()); !os.IsNotExist(err) {
t.Fatal("env override must not write the location file")
}
}