返回 DeepSeek-Reasonix
path_identity_migration_test.go
根目录 / internal / sessioncatalog / path_identity_migration_test.go
1 package sessioncatalog
2
3 import (
4 "context"
5 "path/filepath"
6 "testing"
7
8 "reasonix/internal/projectiondb"
9 )
10
11 func TestPathIdentityMigrationsInvalidateLegacyProjectionForAuthoritativeRebuild(t *testing.T) {
12 ctx := context.Background()
13 path := filepath.Join(t.TempDir(), "catalog.sqlite")
14 handle, err := projectiondb.Open(ctx, projectiondb.OpenOptions{
15 Path: path, MemoryName: "session-catalog-v8-test", Migrations: sessionMigrations()[:8], RequireDisk: true,
16 })
17 if err != nil {
18 t.Fatal(err)
19 }
20 for _, statement := range []string{
21 `INSERT INTO catalog_directories(path,scope) VALUES('/Sessions','global')`,
22 `INSERT INTO catalog_projects(scope,title) VALUES('global','Global')`,
23 `INSERT INTO catalog_sessions(path,directory,scope,topic_id) VALUES('/Sessions/Mixed.jsonl','/Sessions','global','topic')`,
24 `INSERT INTO catalog_topics(scope,topic_id) VALUES('global','topic')`,
25 `INSERT INTO catalog_folded_topics(scope,topic_id) VALUES('global','folded')`,
26 } {
27 if _, err := handle.DB.ExecContext(ctx, statement); err != nil {
28 _ = handle.DB.Close()
29 t.Fatal(err)
30 }
31 }
32 if err := handle.DB.Close(); err != nil {
33 t.Fatal(err)
34 }
35
36 catalog, err := Open(ctx, Options{Path: path, DisableRepair: true})
37 if err != nil {
38 t.Fatal(err)
39 }
40 t.Cleanup(func() { _ = catalog.Close(context.Background()) })
41 for _, table := range []string{"catalog_directories", "catalog_projects", "catalog_sessions", "catalog_topics", "catalog_folded_topics"} {
42 var rows int
43 if err := catalog.db.QueryRowContext(ctx, `SELECT COUNT(*) FROM `+table).Scan(&rows); err != nil {
44 t.Fatal(err)
45 }
46 if rows != 0 {
47 t.Fatalf("%s rows after v9 migration = %d, want clean disposable projection", table, rows)
48 }
49 }
50 }
51
52 func TestMigrationV10InvalidatesPublishedV9Projection(t *testing.T) {
53 ctx := context.Background()
54 path := filepath.Join(t.TempDir(), "catalog.sqlite")
55 handle, err := projectiondb.Open(ctx, projectiondb.OpenOptions{
56 Path: path, MemoryName: "session-catalog-v9-test", Migrations: sessionMigrations()[:9], RequireDisk: true,
57 })
58 if err != nil {
59 t.Fatal(err)
60 }
61 for _, statement := range []string{
62 `INSERT INTO catalog_directories(path,path_key,scope) VALUES('/Sessions','/sessions','global')`,
63 `INSERT INTO catalog_projects(scope,title) VALUES('global','Global')`,
64 `INSERT INTO catalog_sessions(path,path_key,directory,directory_key,scope,topic_id) VALUES('/Sessions/Mixed.jsonl','/sessions/mixed.jsonl','/Sessions','/sessions','global','topic')`,
65 `INSERT INTO catalog_topics(scope,topic_id) VALUES('global','topic')`,
66 `INSERT INTO catalog_folded_topics(scope,topic_id) VALUES('global','folded')`,
67 } {
68 if _, err := handle.DB.ExecContext(ctx, statement); err != nil {
69 _ = handle.DB.Close()
70 t.Fatal(err)
71 }
72 }
73 if err := handle.DB.Close(); err != nil {
74 t.Fatal(err)
75 }
76
77 catalog, err := Open(ctx, Options{Path: path, DisableRepair: true})
78 if err != nil {
79 t.Fatal(err)
80 }
81 t.Cleanup(func() { _ = catalog.Close(context.Background()) })
82 for _, table := range []string{"catalog_directories", "catalog_projects", "catalog_sessions", "catalog_topics", "catalog_folded_topics"} {
83 var rows int
84 if err := catalog.db.QueryRowContext(ctx, `SELECT COUNT(*) FROM `+table).Scan(&rows); err != nil {
85 t.Fatal(err)
86 }
87 if rows != 0 {
88 t.Fatalf("%s rows after v10 migration = %d, want clean disposable projection", table, rows)
89 }
90 }
91 }
92
92 lines GO