返回 DeepSeek-Reasonix
attachment_owner_test.go
根目录 / internal / control / attachment_owner_test.go
1 package control
2
3 import (
4 "context"
5 "path/filepath"
6 "testing"
7
8 "reasonix/internal/agent"
9 "reasonix/internal/event"
10 "reasonix/internal/session"
11 "reasonix/internal/tool"
12 )
13
14 func TestAttachmentStoreFollowsLatePublishedSessionOwner(t *testing.T) {
15 root := t.TempDir()
16 service, err := session.NewService("desktop", session.NewFilesystemPersistence(filepath.Join(root, "by-id")))
17 if err != nil {
18 t.Fatal(err)
19 }
20 t.Cleanup(func() { _ = service.CloseAll(context.Background()) })
21 newAgent := func() *agent.Agent {
22 return agent.New(nil, tool.NewRegistry(), agent.NewSession("sys"), agent.Options{}, event.Discard)
23 }
24 exec := newAgent()
25 opts := Options{WorkspaceRoot: root, SessionDir: filepath.Join(root, "legacy-sessions"), SessionService: service, Executor: exec, Runner: exec}
26 c := newOwnedTestController(t, opts)
27 ref, err := c.BindFreshSession(t.Context(), "late-owner")
28 if err != nil {
29 t.Fatal(err)
30 }
31 runtime, ok := service.Runtime(ref)
32 if !ok {
33 t.Fatal("session was not published")
34 }
35 if got, want := c.attachmentService().Store().Root(), runtime.Session().ContentStore().Root(); got != want {
36 t.Fatalf("attachment store=%s, session store=%s", got, want)
37 }
38 draft, err := c.StageImage(t.Context(), "rebuild.png", "image/png", "data:image/png;base64,"+tinyPNG)
39 if err != nil {
40 t.Fatal(err)
41 }
42 if err := runtime.Session().ContentStore().Verify(t.Context(), draft.Ref.Content); err != nil {
43 t.Fatalf("original is not in the session content graph: %v", err)
44 }
45 opts.SessionRuntime, opts.ExclusiveSession = runtime, true
46 opts.Executor = newAgent()
47 opts.Runner = opts.Executor
48 next := newOwnedTestController(t, opts)
49 if err := ActivateSessionAPIReplacement(c, next); err != nil {
50 t.Fatal(err)
51 }
52 rebound, err := next.RebindDraftImage(t.Context(), draft.ID)
53 if err != nil || rebound.ID == draft.ID {
54 t.Fatalf("rebind=%+v err=%v", rebound, err)
55 }
56 if _, _, err := next.ReadDraftImage(t.Context(), rebound.ID); err != nil {
57 t.Fatal(err)
58 }
59 }
60
60 lines GO