(t *testing.T)
| 289 | } |
| 290 | |
| 291 | func TestEngine_ConflictLocal(t *testing.T) { |
| 292 | sourceName := "test-conflict-local" |
| 293 | defer cleanupRegistry(sourceName) |
| 294 | |
| 295 | setupMockSource(sourceName, []ExternalTask{ |
| 296 | {ExternalID: "EXT-1", Title: "A task", Status: "open"}, |
| 297 | }) |
| 298 | |
| 299 | dir := t.TempDir() |
| 300 | outputDir := filepath.Join(dir, "tasks") |
| 301 | |
| 302 | engine := &Engine{ConfigDir: dir, ConflictStrategy: ConflictLocal} |
| 303 | srcCfg := SourceConfig{ |
| 304 | Name: sourceName, |
| 305 | OutputDir: outputDir, |
| 306 | FieldMap: FieldMap{Status: map[string]string{"open": "pending"}}, |
| 307 | } |
| 308 | |
| 309 | // First sync creates the file |
| 310 | result1, err := engine.RunSync(srcCfg) |
| 311 | if err != nil { |
| 312 | t.Fatalf("first sync error: %v", err) |
| 313 | } |
| 314 | filePath := result1.Created[0].FilePath |
| 315 | |
| 316 | // Modify the local file |
| 317 | data, err := os.ReadFile(filePath) |
| 318 | if err != nil { |
| 319 | t.Fatalf("failed to read file: %v", err) |
| 320 | } |
| 321 | modified := strings.Replace(string(data), "pending", "in-progress", 1) |
| 322 | if err := os.WriteFile(filePath, []byte(modified), 0644); err != nil { |
| 323 | t.Fatalf("failed to modify file: %v", err) |
| 324 | } |
| 325 | |
| 326 | // Second sync with ConflictLocal — should keep local, update state |
| 327 | result2, err := engine.RunSync(srcCfg) |
| 328 | if err != nil { |
| 329 | t.Fatalf("second sync error: %v", err) |
| 330 | } |
| 331 | if len(result2.Conflicts) != 0 { |
| 332 | t.Errorf("expected 0 conflicts, got %d", len(result2.Conflicts)) |
| 333 | } |
| 334 | if len(result2.Updated) != 1 { |
| 335 | t.Errorf("expected 1 updated, got %d", len(result2.Updated)) |
| 336 | } |
| 337 | |
| 338 | // Verify local changes are preserved |
| 339 | content, err := os.ReadFile(filePath) |
| 340 | if err != nil { |
| 341 | t.Fatalf("failed to read file: %v", err) |
| 342 | } |
| 343 | if !strings.Contains(string(content), "in-progress") { |
| 344 | t.Error("expected local changes to be preserved") |
| 345 | } |
| 346 | |
| 347 | // Third sync — should skip (state is now up to date) |
| 348 | result3, err := engine.RunSync(srcCfg) |
nothing calls this directly
no test coverage detected