返回 DeepSeek-Reasonix
import_history_identity_test.go
根目录 / internal / session / import_history_identity_test.go
1 package session
2
3 import (
4 "os"
5 "path/filepath"
6 "testing"
7 )
8
9 func TestImportWithoutRecoveryIdentityPublishesReadableHistory(t *testing.T) {
10 source, _, runtime := newSourceService(t, "old-archive")
11 appendCompletedTurn(t, runtime, "turn", "historical-answer")
12 bundle := filepath.Join(t.TempDir(), "bundle")
13 if err := source.Export(t.Context(), runtime.Ref(), bundle); err != nil {
14 t.Fatal(err)
15 }
16 if err := os.Remove(filepath.Join(bundle, storageIdentityName)); err != nil {
17 t.Fatal(err)
18 }
19 for _, id := range []string{"old-archive", "remapped-archive"} {
20 t.Run(id, func(t *testing.T) {
21 target, err := NewService("desktop", NewFilesystemPersistence(t.TempDir()))
22 if err != nil {
23 t.Fatal(err)
24 }
25 t.Cleanup(func() { _ = target.Shutdown(t.Context()) })
26 ref, err := target.ImportWithHeader(t.Context(), bundle, CreateOptions{SessionID: id, CWD: filepath.Clean("/workspace"), Origin: SessionOriginCanonicalImport})
27 if err != nil {
28 t.Fatal(err)
29 }
30 shape, err := target.Query().HistoryShape(t.Context(), ref)
31 if err != nil || len(shape.Positions) != 1 {
32 t.Fatalf("imported history unavailable before runtime: %+v %v", shape, err)
33 }
34 page := windowReady(t, target.Query(), ref, HistoryWindowRequest{Anchor: "newest", Limit: 10})
35 if len(page.Messages) != 1 || page.Messages[0].MessageID != "historical-answer" {
36 t.Fatalf("imported message changed: %+v", page)
37 }
38 if _, live := target.Runtime(ref); live {
39 t.Fatal("history read started a runtime")
40 }
41 if _, err := os.Stat(filepath.Join(bundle, storageIdentityName)); !os.IsNotExist(err) {
42 t.Fatalf("import modified the old archive: %v", err)
43 }
44 })
45 }
46 }
47
47 lines GO