返回 DeepSeek-Reasonix
channel_open_repro_test.go
根目录 / desktop / channel_open_repro_test.go
1 package main
2
3 import (
4 "os"
5 "path/filepath"
6 "testing"
7
8 "reasonix/internal/config"
9 "reasonix/internal/control"
10 )
11
12 // TestOpenChannelSessionGlobalBotAcrossDirs 回归:bot/channel 会话可能位于
13 // 全局 session dir(global scope),而 tab 的 controller 位于项目 dir。
14 // OpenChannelSession* 必须放行跨目录的 channel 会话,否则前端报
15 // 「加载会话历史失败」(session path outside session dir)。
16 func TestOpenChannelSessionGlobalBotAcrossDirs(t *testing.T) {
17 isolateDesktopUserDirs(t)
18 globalDir := config.SessionDir()
19 if err := os.MkdirAll(globalDir, 0o755); err != nil {
20 t.Fatalf("mkdir global: %v", err)
21 }
22 botPath := filepath.Join(globalDir, "bot-abc123.jsonl")
23 if err := os.WriteFile(botPath, []byte(`{"role":"user","content":"from channel"}`+"\n"), 0o644); err != nil {
24 t.Fatalf("write bot session: %v", err)
25 }
26
27 // tab 的 controller 位于"项目"session dir,与全局 bot 会话不同目录。
28 projDir := filepath.Join(globalDir, "..", "project-sessions")
29 if err := os.MkdirAll(projDir, 0o755); err != nil {
30 t.Fatalf("mkdir proj: %v", err)
31 }
32 app := NewApp()
33 ctrl := control.New(control.Options{SessionDir: projDir, SessionPath: filepath.Join(projDir, "active.jsonl"), Label: "test"})
34 app.setTestCtrl(ctrl, "")
35 defer app.activeCtrl().Close()
36
37 if _, err := app.OpenChannelSessionForTab("test", botPath); err != nil {
38 t.Fatalf("open global bot session from project tab: %v", err)
39 }
40 if _, err := app.OpenChannelSessionPageForTab("test", botPath, 60); err != nil {
41 t.Fatalf("open paged global bot session: %v", err)
42 }
43 }
44
44 lines GO