返回 DeepSeek-Reasonix
shell_repair_guidance_test.go
根目录 / desktop / shell_repair_guidance_test.go
1 package main
2
3 import (
4 "strings"
5 "testing"
6 )
7
8 func TestShellRepairGuidancePerPlatform(t *testing.T) {
9 if got := shellRepairGuidanceForGOOS("windows"); got != nil {
10 t.Fatalf("Windows guidance = %+v, want nil because its install action owns repair", got)
11 }
12 if got := shellRepairGuidanceForGOOS("darwin"); got != nil {
13 t.Fatalf("macOS shell guidance = %+v, want nil because zsh/sh are native fallbacks", got)
14 }
15 if got := gitRepairGuidanceForGOOS("darwin"); got == nil || got.Manager != "homebrew" || got.Command != "brew install git" {
16 t.Fatalf("macOS Git guidance = %+v, want copy-only Homebrew Git command", got)
17 }
18 }
19
20 func TestLinuxShellRepairGuidanceUsesAllowlistedCommandsWithoutSudo(t *testing.T) {
21 tests := []struct {
22 name string
23 osRelease string
24 manager string
25 command string
26 }{
27 {"ubuntu", "ID=ubuntu\nID_LIKE=debian\n", "apt", "apt-get install bash"},
28 {"fedora-like", "ID=custom\nID_LIKE=\"rhel fedora\"\n", "dnf", "dnf install bash"},
29 {"arch", "ID=arch\n", "pacman", "pacman -S bash"},
30 {"opensuse", "ID='opensuse'\nID_LIKE=\"suse\"\n", "zypper", "zypper install bash"},
31 {"alpine", "ID=alpine\n", "apk", "apk add bash"},
32 }
33 for _, test := range tests {
34 t.Run(test.name, func(t *testing.T) {
35 got := linuxShellRepairGuidance([]byte(test.osRelease))
36 if got.Manager != test.manager || got.Command != test.command {
37 t.Fatalf("guidance = %+v, want manager=%q command=%q", got, test.manager, test.command)
38 }
39 if strings.Contains(strings.ToLower(got.Command), "sudo") {
40 t.Fatalf("copy-only repair command must not prescribe sudo: %q", got.Command)
41 }
42 })
43 }
44 }
45
46 func TestLinuxGitRepairGuidanceUsesAllowlistedCommandsWithoutSudo(t *testing.T) {
47 got := linuxGitRepairGuidance([]byte("ID=ubuntu\nID_LIKE=debian\n"))
48 if got.Manager != "apt" || got.Command != "apt-get install git" {
49 t.Fatalf("Git guidance = %+v, want apt Git command", got)
50 }
51 if strings.Contains(strings.ToLower(got.Command), "sudo") {
52 t.Fatalf("copy-only Git command must not prescribe sudo: %q", got.Command)
53 }
54 }
55
56 func TestLinuxShellRepairGuidanceDoesNotInterpolateOSRelease(t *testing.T) {
57 got := linuxShellRepairGuidance([]byte("ID=unknown; touch /tmp/not-allowed\n"))
58 if got.Manager != "system" || got.Command != "" {
59 t.Fatalf("unknown distribution guidance = %+v, want generic no-command fallback", got)
60 }
61 }
62
62 lines GO