MCPcopy Create free account
hub / github.com/driangle/taskmd / TestEngine_ConflictRemote

Function TestEngine_ConflictRemote

apps/cli/internal/sync/engine_test.go:234–289  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

232}
233
234func TestEngine_ConflictRemote(t *testing.T) {
235 sourceName := "test-conflict-remote"
236 defer cleanupRegistry(sourceName)
237
238 setupMockSource(sourceName, []ExternalTask{
239 {ExternalID: "EXT-1", Title: "A task", Status: "open"},
240 })
241
242 dir := t.TempDir()
243 outputDir := filepath.Join(dir, "tasks")
244
245 engine := &Engine{ConfigDir: dir, ConflictStrategy: ConflictRemote}
246 srcCfg := SourceConfig{
247 Name: sourceName,
248 OutputDir: outputDir,
249 FieldMap: FieldMap{Status: map[string]string{"open": "pending"}},
250 }
251
252 // First sync creates the file
253 result1, err := engine.RunSync(srcCfg)
254 if err != nil {
255 t.Fatalf("first sync error: %v", err)
256 }
257 filePath := result1.Created[0].FilePath
258
259 // Modify the local file
260 data, err := os.ReadFile(filePath)
261 if err != nil {
262 t.Fatalf("failed to read file: %v", err)
263 }
264 modified := strings.Replace(string(data), "pending", "in-progress", 1)
265 if err := os.WriteFile(filePath, []byte(modified), 0644); err != nil {
266 t.Fatalf("failed to modify file: %v", err)
267 }
268
269 // Second sync with ConflictRemote — should overwrite local
270 result2, err := engine.RunSync(srcCfg)
271 if err != nil {
272 t.Fatalf("second sync error: %v", err)
273 }
274 if len(result2.Conflicts) != 0 {
275 t.Errorf("expected 0 conflicts, got %d", len(result2.Conflicts))
276 }
277 if len(result2.Updated) != 1 {
278 t.Errorf("expected 1 updated, got %d", len(result2.Updated))
279 }
280
281 // Verify file was overwritten with remote content
282 content, err := os.ReadFile(filePath)
283 if err != nil {
284 t.Fatalf("failed to read file: %v", err)
285 }
286 if strings.Contains(string(content), "in-progress") {
287 t.Error("expected local changes to be overwritten")
288 }
289}
290
291func TestEngine_ConflictLocal(t *testing.T) {

Callers

nothing calls this directly

Calls 4

RunSyncMethod · 0.95
cleanupRegistryFunction · 0.85
setupMockSourceFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected