refactor(watch): extract testable maybeBackfillExistingArchives helper

Co-authored-by: Belphemur <197810+Belphemur@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-07-03 15:45:35 +00:00
committed by GitHub
co-authored by Belphemur
parent 1d981be21b
commit d7782fdb25
2 changed files with 17 additions and 10 deletions
@@ -181,11 +181,11 @@ func TestWatchCommandBackfillFlagDefaultsToFalse(t *testing.T) {
assert.Equal(t, "bool", flag.Value.Type())
}
func TestBackfillExistingArchivesOnlyInvokedWhenRequested(t *testing.T) {
func TestMaybeBackfillExistingArchivesOnlyInvokedWhenRequested(t *testing.T) {
root := t.TempDir()
require.NoError(t, os.WriteFile(filepath.Join(root, "chapter1.cbz"), []byte("data"), 0o644))
runBackfill := func(backfill bool) []string {
runBackfill := func(enabled bool) []string {
var found []string
var mu sync.Mutex
process := func(path string) {
@@ -193,11 +193,9 @@ func TestBackfillExistingArchivesOnlyInvokedWhenRequested(t *testing.T) {
defer mu.Unlock()
found = append(found, path)
}
// Mirrors the gating logic in WatchCommand: backfillExistingArchives
// must only run when the --backfill flag is set.
if backfill {
backfillExistingArchives(root, process)
}
// This is the exact same gating call WatchCommand makes based on the
// --backfill flag value.
maybeBackfillExistingArchives(enabled, root, process)
return found
}