返回 DeepSeek-Reasonix
schema_compat_test.go
根目录 / internal / sessioninbox / schema_compat_test.go
1 package sessioninbox
2
3 import (
4 "encoding/json"
5 "errors"
6 "os"
7 "path/filepath"
8 "testing"
9
10 "reasonix/internal/store"
11 )
12
13 func TestPreviousInboxReaderPausesSchemaThree(t *testing.T) {
14 const previousSchema = 2
15 if SchemaVersion <= previousSchema {
16 t.Fatalf("inbox schema %d is not newer than previous reader %d", SchemaVersion, previousSchema)
17 }
18 session := filepath.Join(t.TempDir(), "s.jsonl")
19 s, err := Open(session, Limits{})
20 if err != nil {
21 t.Fatal(err)
22 }
23 defer s.Close()
24 if s.Snapshot().SchemaVersion != SchemaVersion {
25 t.Fatalf("schema = %d, want %d", s.Snapshot().SchemaVersion, SchemaVersion)
26 }
27 if !(s.Snapshot().SchemaVersion > previousSchema) {
28 t.Fatal("previous inbox reader would not pause schema 3")
29 }
30 }
31
32 func TestInboxNewerSchemaIsReadonlyPaused(t *testing.T) {
33 session := filepath.Join(t.TempDir(), "s.jsonl")
34 inboxDir := store.SessionInboxDir(session)
35 if err := os.MkdirAll(inboxDir, 0o700); err != nil {
36 t.Fatal(err)
37 }
38 body, err := json.Marshal(manifest{SchemaVersion: SchemaVersion + 1, Items: []InboxItemMeta{}})
39 if err != nil {
40 t.Fatal(err)
41 }
42 if err := os.WriteFile(filepath.Join(inboxDir, manifestName), body, 0o600); err != nil {
43 t.Fatal(err)
44 }
45 s, err := Open(session, Limits{})
46 if err != nil {
47 t.Fatal(err)
48 }
49 defer s.Close()
50 snap := s.Snapshot()
51 if !snap.Paused || !snap.Readonly || snap.SchemaVersion != SchemaVersion+1 {
52 t.Fatalf("newer schema snapshot = %+v, want readonly pause", snap)
53 }
54 if _, err := s.Enqueue(EnqueueRequest{Envelope: PromptEnvelope{SubmitText: "nope"}}); !errors.Is(err, ErrSchemaReadonly) {
55 t.Fatalf("enqueue newer schema = %v, want %v", err, ErrSchemaReadonly)
56 }
57 }
58
58 lines GO