feat: add Wine Z: path prefix for Windows platform on Linux host
CI / build (push) Successful in 1m44s

- Add winePath helper that prepends Z: when platform is windows on Linux
- Thread platform through buildModPath, buildAutoArgs, and Start()
- Apply Z: prefix to -config=, -mod=, -profiles=, and %command% binary paths
- Add tests for winePath, buildAutoArgs, and buildModPath with platform param
- Fix formatting across services package with gofmt
- Include all prior bug fixes from this branch
This commit is contained in:
MrFastwind
2026-07-24 03:57:51 +02:00
parent 41c1390972
commit 6f3175ac9a
18 changed files with 219 additions and 75 deletions
@@ -294,7 +294,7 @@ func TestBuildModPath_MultipleMods(t *testing.T) {
{Name: "DisabledMod", Enabled: false},
})
got := pm.buildModPath(ml.ID)
got := pm.buildModPath(ml.ID, "")
if !strings.HasPrefix(got, "-mod=") {
t.Errorf("expected -mod= prefix, got %q", got)
}
@@ -321,7 +321,7 @@ func TestBuildModPath_EmptyModlist(t *testing.T) {
pm := NewProcessManager(dir, modsDir, filepath.Join(dir, "cfg"), filepath.Join(dir, "profiles"), sm, mm, cm, streamer)
got := pm.buildModPath("nonexistent-id")
got := pm.buildModPath("nonexistent-id", "")
if got != "" {
t.Errorf("buildModPath(nonexistent) = %q, want empty", got)
}
@@ -338,8 +338,8 @@ func TestWriteUserconfigFiles(t *testing.T) {
pm := NewProcessManager(dir, modsDir, filepath.Join(dir, "cfg"), filepath.Join(dir, "profiles"), sm, mm, cm, streamer)
s := &models.ServerSettings{
CBASettings: "force = 1",
AILevelPresets: "preset1",
CBASettings: "force = 1",
AILevelPresets: "preset1",
DifficultyPresets: "difficulty_normal",
}
@@ -396,6 +396,142 @@ func TestWriteUserconfigFiles_EmptyContent(t *testing.T) {
}
}
func TestWinePath(t *testing.T) {
tests := []struct {
name string
path string
platform string
want string
}{
{"linux platform returns as-is", "/server/cfg/test.cfg", "linux", "/server/cfg/test.cfg"},
{"empty platform returns as-is", "/server/cfg/test.cfg", "", "/server/cfg/test.cfg"},
{"windows platform on linux adds prefix", "/server/cfg/test.cfg", "windows", "Z:/server/cfg/test.cfg"},
{"empty path linux", "", "linux", ""},
{"empty path windows", "", "windows", "Z:"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := winePath(tt.path, tt.platform)
if got != tt.want {
t.Errorf("winePath(%q, %q) = %q, want %q", tt.path, tt.platform, got, tt.want)
}
})
}
}
func TestBuildAutoArgs_WindowsPlatform(t *testing.T) {
dir := t.TempDir()
cfgDir := filepath.Join(dir, "cfg")
profilesDir := filepath.Join(dir, "profiles")
modsDir := filepath.Join(dir, "mods")
sm := NewSettingsManager(dir)
mm := NewModlistManager(filepath.Join(dir, "modlists"))
cm := NewConfigManager(cfgDir)
streamer := NewLogStreamer()
pm := NewProcessManager(dir, modsDir, cfgDir, profilesDir, sm, mm, cm, streamer)
s := &models.ServerSettings{
Platform: "windows",
ActiveConfig: "server_config",
IPPort: "0.0.0.0:2302",
}
args := pm.buildAutoArgs(s)
foundConfig := false
foundProfiles := false
for _, a := range args {
if strings.HasPrefix(a, "-config=Z:") && strings.HasSuffix(a, "server_config.cfg") {
foundConfig = true
}
if strings.HasPrefix(a, "-profiles=Z:") {
foundProfiles = true
}
}
if !foundConfig {
t.Errorf("expected -config=Z:...server_config.cfg in args, got %v", args)
}
if !foundProfiles {
t.Errorf("expected -profiles=Z:... in args, got %v", args)
}
}
func TestBuildAutoArgs_LinuxPlatform(t *testing.T) {
dir := t.TempDir()
cfgDir := filepath.Join(dir, "cfg")
profilesDir := filepath.Join(dir, "profiles")
modsDir := filepath.Join(dir, "mods")
sm := NewSettingsManager(dir)
mm := NewModlistManager(filepath.Join(dir, "modlists"))
cm := NewConfigManager(cfgDir)
streamer := NewLogStreamer()
pm := NewProcessManager(dir, modsDir, cfgDir, profilesDir, sm, mm, cm, streamer)
s := &models.ServerSettings{
Platform: "linux",
ActiveConfig: "server_config",
IPPort: "0.0.0.0:2302",
}
args := pm.buildAutoArgs(s)
for _, a := range args {
if strings.HasPrefix(a, "-config=Z:") {
t.Errorf("unexpected Z: prefix in args: %v", a)
}
}
}
func TestBuildModPath_WindowsPlatform(t *testing.T) {
dir := t.TempDir()
modsDir := filepath.Join(dir, "mods")
os.MkdirAll(filepath.Join(modsDir, "@CBA_A3"), 0755)
sm := NewSettingsManager(dir)
mm := NewModlistManager(filepath.Join(dir, "modlists"))
cm := NewConfigManager(filepath.Join(dir, "cfg"))
streamer := NewLogStreamer()
pm := NewProcessManager(dir, modsDir, filepath.Join(dir, "cfg"), filepath.Join(dir, "profiles"), sm, mm, cm, streamer)
ml, _ := mm.Create("Test List")
mm.Update(ml.ID, "Test List", []models.ModEntry{
{Name: "CBA_A3", Enabled: true},
})
got := pm.buildModPath(ml.ID, "windows")
if !strings.HasPrefix(got, "-mod=Z:") {
t.Errorf("expected -mod=Z: prefix, got %q", got)
}
}
func TestBuildModPath_LinuxPlatform(t *testing.T) {
dir := t.TempDir()
modsDir := filepath.Join(dir, "mods")
os.MkdirAll(filepath.Join(modsDir, "@CBA_A3"), 0755)
sm := NewSettingsManager(dir)
mm := NewModlistManager(filepath.Join(dir, "modlists"))
cm := NewConfigManager(filepath.Join(dir, "cfg"))
streamer := NewLogStreamer()
pm := NewProcessManager(dir, modsDir, filepath.Join(dir, "cfg"), filepath.Join(dir, "profiles"), sm, mm, cm, streamer)
ml, _ := mm.Create("Test List")
mm.Update(ml.ID, "Test List", []models.ModEntry{
{Name: "CBA_A3", Enabled: true},
})
got := pm.buildModPath(ml.ID, "linux")
if strings.Contains(got, "Z:") {
t.Errorf("unexpected Z: prefix in args: %q", got)
}
}
func TestStartAndStopWithStub(t *testing.T) {
dir := t.TempDir()
serverfileDir := filepath.Join(dir, "server")