|
1 | 1 | package cmd |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "os" |
4 | 5 | "strings" |
5 | 6 | "testing" |
6 | 7 |
|
@@ -117,3 +118,126 @@ func TestRunCloseCommitCreatesGitCommit(t *testing.T) { |
117 | 118 | t.Fatalf("unexpected commit message %q", lastMessage) |
118 | 119 | } |
119 | 120 | } |
| 121 | + |
| 122 | +func TestRunClosePreservesFilenameWithKoreanTitle(t *testing.T) { |
| 123 | + _, cleanup := setupCommandTestRepo(t) |
| 124 | + defer cleanup() |
| 125 | + |
| 126 | + // Create issue with English title |
| 127 | + if err := runCreate(nil, []string{"Initial English Title"}); err != nil { |
| 128 | + t.Fatalf("runCreate() failed: %v", err) |
| 129 | + } |
| 130 | + |
| 131 | + // Get original filename |
| 132 | + originalPath, _, err := pkg.FindIssueFile("001") |
| 133 | + if err != nil { |
| 134 | + t.Fatalf("failed to find issue: %v", err) |
| 135 | + } |
| 136 | + |
| 137 | + // Edit issue to have Korean title |
| 138 | + issue, _, err := pkg.LoadIssue("001") |
| 139 | + if err != nil { |
| 140 | + t.Fatalf("failed to load issue: %v", err) |
| 141 | + } |
| 142 | + issue.Title = "한글 제목으로 변경" |
| 143 | + content, err := pkg.SerializeIssue(issue) |
| 144 | + if err != nil { |
| 145 | + t.Fatalf("failed to serialize issue: %v", err) |
| 146 | + } |
| 147 | + if err := os.WriteFile(originalPath, []byte(content), 0644); err != nil { |
| 148 | + t.Fatalf("failed to write issue: %v", err) |
| 149 | + } |
| 150 | + |
| 151 | + // Close the issue |
| 152 | + if err := runClose(nil, []string{"001"}); err != nil { |
| 153 | + t.Fatalf("runClose() failed: %v", err) |
| 154 | + } |
| 155 | + |
| 156 | + // Verify issue is in closed directory with original filename |
| 157 | + closedPath, dir, err := pkg.FindIssueFile("001") |
| 158 | + if err != nil { |
| 159 | + t.Fatalf("failed to find closed issue: %v", err) |
| 160 | + } |
| 161 | + if dir != pkg.ClosedDir { |
| 162 | + t.Fatalf("issue should be in closed dir, got %s", dir) |
| 163 | + } |
| 164 | + |
| 165 | + // Verify filename was preserved (contains "initial-english-title") |
| 166 | + if !strings.Contains(closedPath, "initial-english-title") { |
| 167 | + t.Errorf("filename should be preserved, got %s", closedPath) |
| 168 | + } |
| 169 | + |
| 170 | + // Verify no malformed files like "001-.md" were created |
| 171 | + openFiles, _ := pkg.ListIssues(pkg.OpenDir) |
| 172 | + closedFiles, _ := pkg.ListIssues(pkg.ClosedDir) |
| 173 | + |
| 174 | + if len(openFiles) != 0 { |
| 175 | + t.Errorf("open directory should be empty, found %d files", len(openFiles)) |
| 176 | + } |
| 177 | + if len(closedFiles) != 1 { |
| 178 | + t.Errorf("closed directory should have exactly 1 file, found %d", len(closedFiles)) |
| 179 | + } |
| 180 | +} |
| 181 | + |
| 182 | +func TestRunClosePreservesFilenameWhenTitleModified(t *testing.T) { |
| 183 | + _, cleanup := setupCommandTestRepo(t) |
| 184 | + defer cleanup() |
| 185 | + |
| 186 | + // Create issue |
| 187 | + if err := runCreate(nil, []string{"Original Title"}); err != nil { |
| 188 | + t.Fatalf("runCreate() failed: %v", err) |
| 189 | + } |
| 190 | + |
| 191 | + // Get original filename |
| 192 | + originalPath, _, err := pkg.FindIssueFile("001") |
| 193 | + if err != nil { |
| 194 | + t.Fatalf("failed to find issue: %v", err) |
| 195 | + } |
| 196 | + |
| 197 | + // Edit issue to have completely different title |
| 198 | + issue, _, err := pkg.LoadIssue("001") |
| 199 | + if err != nil { |
| 200 | + t.Fatalf("failed to load issue: %v", err) |
| 201 | + } |
| 202 | + issue.Title = "Completely Different Modified Title" |
| 203 | + content, err := pkg.SerializeIssue(issue) |
| 204 | + if err != nil { |
| 205 | + t.Fatalf("failed to serialize issue: %v", err) |
| 206 | + } |
| 207 | + if err := os.WriteFile(originalPath, []byte(content), 0644); err != nil { |
| 208 | + t.Fatalf("failed to write issue: %v", err) |
| 209 | + } |
| 210 | + |
| 211 | + // Close the issue |
| 212 | + if err := runClose(nil, []string{"001"}); err != nil { |
| 213 | + t.Fatalf("runClose() failed: %v", err) |
| 214 | + } |
| 215 | + |
| 216 | + // Verify issue is in closed directory with original filename |
| 217 | + closedPath, dir, err := pkg.FindIssueFile("001") |
| 218 | + if err != nil { |
| 219 | + t.Fatalf("failed to find closed issue: %v", err) |
| 220 | + } |
| 221 | + if dir != pkg.ClosedDir { |
| 222 | + t.Fatalf("issue should be in closed dir, got %s", dir) |
| 223 | + } |
| 224 | + |
| 225 | + // Verify filename was preserved (contains "original-title", not "completely-different") |
| 226 | + if !strings.Contains(closedPath, "original-title") { |
| 227 | + t.Errorf("original filename should be preserved, got %s", closedPath) |
| 228 | + } |
| 229 | + if strings.Contains(closedPath, "completely-different") { |
| 230 | + t.Errorf("filename should not change to modified title, got %s", closedPath) |
| 231 | + } |
| 232 | + |
| 233 | + // Verify no duplicate files were created |
| 234 | + openFiles, _ := pkg.ListIssues(pkg.OpenDir) |
| 235 | + closedFiles, _ := pkg.ListIssues(pkg.ClosedDir) |
| 236 | + |
| 237 | + if len(openFiles) != 0 { |
| 238 | + t.Errorf("open directory should be empty, found %d files", len(openFiles)) |
| 239 | + } |
| 240 | + if len(closedFiles) != 1 { |
| 241 | + t.Errorf("closed directory should have exactly 1 file, found %d", len(closedFiles)) |
| 242 | + } |
| 243 | +} |
0 commit comments