Commit 080259c
committed
fix(tests): isolate test databases to prevent production data loss
CRITICAL BUG FIX: Tests were using production database and deleting all data
The root cause was in storage_test.go line 26:
defer os.RemoveAll(os.ExpandEnv("$HOME/.local/share/codeme"))
This caused complete data loss when running 'go test ./...'. Tests would:
1. Use OpenDB() which opened the PRODUCTION database
2. Execute DELETE FROM heartbeats to "clean up"
3. Delete the entire production database directory on exit
Changes made to prevent this:
- Created OpenDBWithPath() to allow custom database location
- Added shared setupTestDB() helper in testhelper_test.go
- Updated all test files to use isolated temporary databases via t.TempDir()
- Removed dangerous os.RemoveAll() calls
- Removed unnecessary DELETE cleanup (temp dirs auto-cleanup)
Tests now use completely isolated databases that are automatically
cleaned up by Go's testing framework. Production database is never
touched during tests.
Verified:
- All tests pass with isolated databases
- Production database remains intact after running tests
- No data loss occurs when running go test ./...1 parent e8225f7 commit 080259c
File tree
6 files changed
+41
-61
lines changed- core
6 files changed
+41
-61
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 10 | + | |
14 | 11 | | |
15 | 12 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | 13 | | |
20 | 14 | | |
21 | 15 | | |
| |||
106 | 100 | | |
107 | 101 | | |
108 | 102 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | 103 | | |
113 | 104 | | |
114 | 105 | | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
| 106 | + | |
119 | 107 | | |
120 | 108 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | 109 | | |
125 | 110 | | |
126 | 111 | | |
| |||
176 | 161 | | |
177 | 162 | | |
178 | 163 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | 164 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 104 | + | |
108 | 105 | | |
109 | 106 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | 107 | | |
114 | 108 | | |
115 | 109 | | |
| |||
188 | 182 | | |
189 | 183 | | |
190 | 184 | | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | 185 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
75 | 86 | | |
76 | 87 | | |
77 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 8 | + | |
13 | 9 | | |
14 | 10 | | |
15 | 11 | | |
16 | 12 | | |
17 | | - | |
| 13 | + | |
18 | 14 | | |
19 | 15 | | |
20 | 16 | | |
21 | 17 | | |
22 | 18 | | |
23 | 19 | | |
24 | | - | |
| 20 | + | |
25 | 21 | | |
26 | | - | |
27 | 22 | | |
28 | 23 | | |
29 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
| 8 | + | |
12 | 9 | | |
13 | 10 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | 11 | | |
18 | 12 | | |
19 | 13 | | |
| |||
77 | 71 | | |
78 | 72 | | |
79 | 73 | | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | 74 | | |
84 | 75 | | |
85 | 76 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 77 | + | |
90 | 78 | | |
91 | 79 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | 80 | | |
96 | | - | |
| 81 | + | |
97 | 82 | | |
98 | 83 | | |
99 | 84 | | |
| |||
122 | 107 | | |
123 | 108 | | |
124 | 109 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | 110 | | |
0 commit comments