返回 DeepSeek-Reasonix
session_trash_sidecars_test.go
根目录 / desktop / session_trash_sidecars_test.go
1 package main
2
3 import (
4 "os"
5 "path/filepath"
6 "testing"
7
8 "reasonix/internal/store"
9 )
10
11 func TestDeleteSessionFileMovesLegacyCleanupEvidenceSidecars(t *testing.T) {
12 dir := t.TempDir()
13 sessionPath := filepath.Join(dir, "session.jsonl")
14 if err := os.WriteFile(sessionPath, []byte("data"), 0o644); err != nil {
15 t.Fatal(err)
16 }
17 active := writeSessionDurableSidecars(t, sessionPath)
18 if err := deleteSessionFile(dir, sessionPath); err != nil {
19 t.Fatal(err)
20 }
21 assertSessionSidecarsMissing(t, active)
22 assertSessionSidecarsPresent(t, trashedSessionDurableSidecars(dir))
23 }
24
25 func writeSessionDurableSidecars(t *testing.T, sessionPath string) []string {
26 t.Helper()
27 paths := []string{
28 store.SessionTurnEventLog(sessionPath),
29 store.SessionTurnEventLogDamaged(sessionPath),
30 store.SessionTranscriptProjection(sessionPath),
31 store.SessionContext(sessionPath),
32 }
33 for _, path := range paths {
34 if err := os.WriteFile(path, []byte(`{"fixture":true}`+"\n"), 0o644); err != nil {
35 t.Fatal(err)
36 }
37 }
38 return paths
39 }
40
41 func trashedSessionDurableSidecars(dir string) []string {
42 root := filepath.Join(dir, sessionTrashDir, "session.jsonl")
43 return []string{
44 filepath.Join(root, "session.turns.jsonl"),
45 filepath.Join(root, "session.turns.jsonl.damaged"),
46 filepath.Join(root, "session.transcript-projection.json"),
47 filepath.Join(root, "session.context.json"),
48 }
49 }
50
51 func assertSessionSidecarsMissing(t *testing.T, paths []string) {
52 t.Helper()
53 for _, path := range paths {
54 if _, err := os.Stat(path); !os.IsNotExist(err) {
55 t.Errorf("session durable sidecar should be removed from active sessions: %s", path)
56 }
57 }
58 }
59
60 func assertSessionSidecarsPresent(t *testing.T, paths []string) {
61 t.Helper()
62 for _, path := range paths {
63 if _, err := os.Stat(path); err != nil {
64 t.Fatalf("session durable sidecar should be in trash: %s: %v", path, err)
65 }
66 }
67 }
68
68 lines GO