package runtime import ( "os" "path/filepath" "strings" "testing" "github.com/Nwflower/reims-go/internal/config" ) func TestBuildChildEnvRedirectsTemp(t *testing.T) { root := t.TempDir() cfg := &config.Config{DataRoot: root} rt := Installed{ Dir: filepath.Join(root, "runtimes", "3731afd"), } t.Setenv("TEMP", `C:\Users\中文用户\AppData\Local\Temp`) t.Setenv("TMP", `C:\Users\中文用户\AppData\Local\Temp`) t.Setenv("TMPDIR", `C:\Users\中文用户\AppData\Local\Temp`) env := BuildChildEnv(cfg, rt) wantTmp := cfg.TempDir() if info, err := os.Stat(wantTmp); err != nil || !info.IsDir() { t.Fatalf("expected TempDir %q to exist: err=%v", wantTmp, err) } counts := map[string]int{} values := map[string]string{} for _, kv := range env { idx := strings.IndexByte(kv, '=') if idx <= 0 { continue } k := strings.ToUpper(kv[:idx]) v := kv[idx+1:] if k == "TEMP" || k == "TMP" || k == "TMPDIR" { counts[k]++ values[k] = v } } for _, key := range []string{"TEMP", "TMP", "TMPDIR"} { if counts[key] != 1 { t.Errorf("%s appeared %d times in child env, want 1", key, counts[key]) } if values[key] != wantTmp { t.Errorf("%s = %q, want %q", key, values[key], wantTmp) } } }