MCPcopy Create free account
hub / github.com/codehamr/codehamr / TestCleanupOldSweepsOrphanedTempFiles

Function TestCleanupOldSweepsOrphanedTempFiles

internal/update/update_test.go:456–487  ·  view source on GitHub ↗

TestCleanupOldSweepsOrphanedTempFiles: a Ctrl+C mid-download kills the process before Apply's deferred Remove runs (no signal handler exists that early), stranding a multi-MB .codehamr-update-* partial; each retry uses a fresh random suffix, so only a launch-time sweep ever deletes them. Only STALE

(t *testing.T)

Source from the content-addressed store, hash-verified

454// STALE temps are swept: a fresh one may be another instance's live download.
455// The running binary and unrelated files must survive.
456func TestCleanupOldSweepsOrphanedTempFiles(t *testing.T) {
457 tmpDir := t.TempDir()
458 exec := filepath.Join(tmpDir, "codehamr")
459 unrelated := filepath.Join(tmpDir, "notes.txt")
460 live := filepath.Join(tmpDir, ".codehamr-update-live")
461 orphans := []string{
462 filepath.Join(tmpDir, ".codehamr-update-1111"),
463 filepath.Join(tmpDir, ".codehamr-update-2222"),
464 }
465 for _, p := range append([]string{exec, unrelated, live}, orphans...) {
466 if err := os.WriteFile(p, []byte("x"), 0o755); err != nil {
467 t.Fatal(err)
468 }
469 }
470 stale := time.Now().Add(-2 * orphanSweepAge)
471 for _, p := range orphans {
472 if err := os.Chtimes(p, stale, stale); err != nil {
473 t.Fatal(err)
474 }
475 }
476 CleanupOld(exec)
477 for _, p := range orphans {
478 if _, err := os.Stat(p); !os.IsNotExist(err) {
479 t.Fatalf("stale orphan %s must be swept, stat err: %v", p, err)
480 }
481 }
482 for _, p := range []string{exec, unrelated, live} {
483 if _, err := os.Stat(p); err != nil {
484 t.Fatalf("%s must survive the sweep: %v", p, err)
485 }
486 }
487}
488
489// TestApplyRespectsContextCancel: a cancelled ctx aborts the download and
490// the local exec stays untouched.

Callers

nothing calls this directly

Calls 1

CleanupOldFunction · 0.85

Tested by

no test coverage detected