返回 DeepSeek-Reasonix
versioned_windows_test.go
根目录 / desktop / cmd / update-helper / versioned_windows_test.go
1 //go:build windows
2
3 package main
4
5 import (
6 "os"
7 "path/filepath"
8 "testing"
9
10 "reasonix/internal/installlayout"
11 "reasonix/internal/repair"
12 )
13
14 func TestPreferVersionedWindowsActivation(t *testing.T) {
15 staging := t.TempDir()
16 if preferVersionedWindowsActivation(staging) {
17 t.Fatal("empty staging must not prefer versioned")
18 }
19 for _, name := range []string{
20 "reasonix-desktop.exe",
21 "reasonix-cli.exe",
22 "reasonix-update-helper.exe",
23 "reasonix-launcher.exe",
24 } {
25 if err := os.WriteFile(filepath.Join(staging, name), []byte(name), 0o700); err != nil {
26 t.Fatal(err)
27 }
28 }
29 if !preferVersionedWindowsActivation(staging) {
30 t.Fatal("complete staging must prefer versioned")
31 }
32 }
33
34 func TestActivateVersionedWindowsFromStaging(t *testing.T) {
35 installDir := t.TempDir()
36 staging := t.TempDir()
37 for _, name := range []string{
38 "reasonix-desktop.exe",
39 "reasonix-cli.exe",
40 "reasonix-update-helper.exe",
41 "reasonix-launcher.exe",
42 "reasonix-guard.exe",
43 } {
44 if err := os.WriteFile(filepath.Join(staging, name), []byte("payload:"+name), 0o700); err != nil {
45 t.Fatal(err)
46 }
47 }
48 // Seed a flat desktop so cleanup is observable.
49 if err := os.WriteFile(filepath.Join(installDir, "reasonix-desktop.exe"), []byte("old"), 0o700); err != nil {
50 t.Fatal(err)
51 }
52 if err := os.WriteFile(filepath.Join(installDir, "reasonix-guard.exe"), []byte("old-guard"), 0o700); err != nil {
53 t.Fatal(err)
54 }
55
56 claimed := &repair.UpdateTransaction{
57 SchemaVersion: 1,
58 ToVersion: "v1.20.0",
59 TargetKind: "file",
60 TargetPath: filepath.Join(installDir, "reasonix-desktop.exe"),
61 CreatedAt: "2026-01-01T00:00:00Z",
62 }
63 if err := activateVersionedWindowsFromStaging(claimed, staging); err != nil {
64 t.Fatal(err)
65 }
66 if !installlayout.HasCurrent(installDir) {
67 t.Fatal("current.json missing")
68 }
69 ptr, err := installlayout.ReadCurrent(installDir)
70 if err != nil || ptr.ActiveVersion != "v1.20.0" {
71 t.Fatalf("pointer=%+v err=%v", ptr, err)
72 }
73 desktop, err := installlayout.ActiveDesktopPath(installDir)
74 if err != nil {
75 t.Fatal(err)
76 }
77 raw, err := os.ReadFile(desktop)
78 if err != nil || string(raw) != "payload:reasonix-desktop.exe" {
79 t.Fatalf("desktop payload = %q err=%v", raw, err)
80 }
81 for _, name := range []string{"reasonix-launcher.exe", "Reasonix.exe", "reasonix-cli.exe"} {
82 if _, err := os.Stat(filepath.Join(installDir, name)); err != nil {
83 t.Fatalf("root entry %s: %v", name, err)
84 }
85 }
86 if _, err := os.Stat(filepath.Join(installDir, "reasonix-desktop.exe")); !os.IsNotExist(err) {
87 t.Fatal("flat desktop should be removed")
88 }
89 if _, err := os.Stat(filepath.Join(installDir, "reasonix-guard.exe")); !os.IsNotExist(err) {
90 t.Fatal("flat guard should be removed")
91 }
92 if prefer := preferRelaunchPath("", installDir); filepath.Base(prefer) != "reasonix-launcher.exe" {
93 t.Fatalf("prefer relaunch = %s", prefer)
94 }
95 }
96
97 func TestInstallStagedWindowsReleaseUnitPrefersVersioned(t *testing.T) {
98 installDir := t.TempDir()
99 staging := t.TempDir()
100 for _, name := range []string{
101 "reasonix-desktop.exe",
102 "reasonix-cli.exe",
103 "reasonix-update-helper.exe",
104 "reasonix-launcher.exe",
105 "reasonix-guard.exe",
106 } {
107 if err := os.WriteFile(filepath.Join(staging, name), []byte("p:"+name), 0o700); err != nil {
108 t.Fatal(err)
109 }
110 }
111 // Minimal claimed unit (versioned path does not need full flat file list).
112 claimed := &repair.UpdateTransaction{
113 SchemaVersion: 1,
114 ToVersion: "v1.20.0",
115 TargetKind: "file",
116 TargetPath: filepath.Join(installDir, "reasonix-desktop.exe"),
117 CreatedAt: "2026-01-01T00:00:00Z",
118 }
119 started, receipts, err := installStagedWindowsReleaseUnit(claimed, staging)
120 if err != nil {
121 t.Fatal(err)
122 }
123 if !started || receipts != nil {
124 t.Fatalf("started=%v receipts=%v want started with nil receipts", started, receipts)
125 }
126 if !installlayout.HasCurrent(installDir) {
127 t.Fatal("versioned activation did not write current.json")
128 }
129 }
130
130 lines GO