返回 DeepSeek-Reasonix
status_test.go
根目录 / internal / desktopinstance / status_test.go
1 package desktopinstance
2
3 import (
4 "encoding/json"
5 "fmt"
6 "path/filepath"
7 "testing"
8 )
9
10 func TestExitCodesPreserveWrappedBlockers(t *testing.T) {
11 for _, tc := range []struct {
12 code Code
13 exit int
14 }{
15 {ConfirmationRequired, 1618}, {Cancelled, 1602}, {UnknownOwner, 1618}, {OtherInstallation, 1618}, {ExitTimeout, 1618}, {StartupFailed, 1603}, {UnsupportedPortableLocation, 1},
16 } {
17 if got := ExitCode(fmt.Errorf("activation: %w", outcome(tc.code, "test"))); got != tc.exit {
18 t.Errorf("%s: got %d", tc.code, got)
19 }
20 }
21 }
22
23 func TestStatusRequiresRendererAndHealthyVisibleWindow(t *testing.T) {
24 s := Status{SchemaVersion: 1, Product: "com.reasonix.desktop", PID: 10, Version: "v1.38.7", Generation: "g", HomeKey: ProfileKey(`C:\Users\Test\reasonix\desktop-shell`), Lifecycle: "ready", Service: "ready", ServicePID: 11, Visible: true, RendererVersion: "v1.38.7", Healthy: true}
25 data, _ := json.Marshal(s)
26 got, err := DecodeStatus(data, 10)
27 if err != nil || !got.Ready("v1.38.7") {
28 t.Fatalf("%+v %v", got, err)
29 }
30 if _, err := DecodeStatus(data, 12); err == nil {
31 t.Fatal("accepted another PID")
32 }
33 s.Healthy = false
34 if s.Ready("") {
35 t.Fatal("accepted unconfirmed frontend")
36 }
37 s.Healthy = true
38 s.RendererVersion = "v1.38.5"
39 if s.Ready("") {
40 t.Fatal("accepted mismatched renderer")
41 }
42 s.RendererVersion = s.Version
43 s.Visible = false
44 if s.Ready("") {
45 t.Fatal("accepted invisible window")
46 }
47 }
48
49 func TestImageRoleExcludesOtherProductsAndInstallations(t *testing.T) {
50 root := t.TempDir()
51 for _, rel := range []string{"versions/v1.38.5/app/Reasonix.exe", "versions/v1.38.5/reasonix-desktop.exe"} {
52 if ImageRole(root, filepath.Join(root, rel)) == "" {
53 t.Fatal(rel)
54 }
55 }
56 for _, rel := range []string{"../Studio/app/Reasonix.exe", "Reasonix Studio.exe", "versions/.staging/app/Reasonix.exe", "versions/v1.38.5/reasonix-cli.exe"} {
57 if ImageRole(root, filepath.Join(root, rel)) != "" {
58 t.Fatal(rel)
59 }
60 }
61 }
62
63 func TestStatusRejectsFutureProtocolAndOversizedMessages(t *testing.T) {
64 if _, err := DecodeStatus(make([]byte, StatusLimit+1), 1); err == nil {
65 t.Fatal("unbounded status")
66 }
67 if _, err := DecodeStatus([]byte(`{"schemaVersion":2}`), 1); err == nil {
68 t.Fatal("future protocol")
69 }
70 if ProfileKey(`C:\Users\TEST\Profile`) != ProfileKey(`c:/users/test/profile`) {
71 t.Fatal("Windows aliases differ")
72 }
73 }
74
74 lines GO