Files
Reims-Go/internal/config/config_test.go
T
NwflowerandClaude Opus 5.5 ce2a0ed813 feat(runtime): rename candidate channel to alpha and build it daily from upstream
- Runtime channel "candidate" is now "alpha"; configs, the --candidate flag
  and SetRuntimeChannel("candidate") still map to alpha.
- ListRemote follows GitHub's Link pagination so stable runtimes are not
  pushed off the first page by daily alphas.
- patches/series.txt is the single patch queue for CI and pack-runtime.ps1;
  pack-runtime takes -Patches and derives allowed changed files from the
  patches (fixes a false "undeclared change" with the coroutine patch).
- build-runtime.yml runs daily: resolves upstream HEAD, skips commits already
  released, applies the queue via apply-patch-series.ps1 (skips patches
  already upstream, stops on conflicts), gates with check-runtime-alpha.ps1,
  publishes an alpha prerelease, keeps the 7 newest alphas, and files issues
  on failure or merged patches. Stable promotion stays manual.
- AGENTS.md and runtime docs updated for the alpha channel.

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

95 lines
2.5 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")
}
}
func TestLegacyCandidateChannelReadsAsAlpha(t *testing.T) {
p := filepath.Join(t.TempDir(), "reims-go.json")
if err := os.WriteFile(p, []byte(`{"data_root":"x","runtime_channel":"candidate"}`), 0o644); err != nil {
t.Fatal(err)
}
cfg, err := Load(p)
if err != nil {
t.Fatal(err)
}
if cfg.RuntimeChannel != "alpha" {
t.Fatalf("runtime_channel = %q, want alpha", cfg.RuntimeChannel)
}
}