@@ -12,9 +12,14 @@ import (
1212 "github.com/fsnotify/fsnotify"
1313)
1414
15+ const (
16+ followImportsWatcherSource = "watcher_import"
17+ followImportsFirstEvent = `{"external_id":"watcher:1","type":"discovery","title":"First","content":"First event.","importance":4}`
18+ )
19+
1520func TestParseFollowImportsOptions (t * testing.T ) {
1621 options , err := parseFollowImportsOptions ([]string {
17- "--source" , "watcher_import" ,
22+ "--source" , followImportsWatcherSource ,
1823 "--input" , "events.jsonl" ,
1924 "--state-file" , "events.offset.json" ,
2025 "--failed-output" , "failed.jsonl" ,
@@ -31,7 +36,7 @@ func TestParseFollowImportsOptions(t *testing.T) {
3136 if err != nil {
3237 t .Fatalf ("parseFollowImportsOptions: %v" , err )
3338 }
34- if got , want := string (options .Source ), "watcher_import" ; got != want {
39+ if got , want := string (options .Source ), followImportsWatcherSource ; got != want {
3540 t .Fatalf ("source mismatch: got %q want %q" , got , want )
3641 }
3742 if got , want := options .InputPath , "events.jsonl" ; got != want {
@@ -55,7 +60,7 @@ func TestParseFollowImportsOptions(t *testing.T) {
5560}
5661
5762func TestParseFollowImportsOptionsRejectsMissingInput (t * testing.T ) {
58- _ , err := parseFollowImportsOptions ([]string {"--source" , "watcher_import" })
63+ _ , err := parseFollowImportsOptions ([]string {"--source" , followImportsWatcherSource })
5964 if err == nil {
6065 t .Fatal ("expected missing input error" )
6166 }
@@ -66,7 +71,7 @@ func TestParseFollowImportsOptionsRejectsMissingInput(t *testing.T) {
6671
6772func TestParseFollowImportsOptionsRejectsInvalidWatchMode (t * testing.T ) {
6873 _ , err := parseFollowImportsOptions ([]string {
69- "--source" , "watcher_import" ,
74+ "--source" , followImportsWatcherSource ,
7075 "--input" , "events.jsonl" ,
7176 "--watch-mode" , "interrupts" ,
7277 })
@@ -182,14 +187,14 @@ func TestAppFollowImportsOnceConsumesOnlyCompleteLinesAndPersistsCheckpoint(t *t
182187
183188 eventsPath := filepath .Join (root , "events.jsonl" )
184189 statePath := filepath .Join (root , "events.offset.json" )
185- first := `{"external_id":"watcher:1","type":"discovery","title":"First","content":"First event.","importance":4}`
190+ first := followImportsFirstEvent
186191 secondPrefix := `{"external_id":"watcher:2","type":"todo","title":"Second"`
187192 if err := os .WriteFile (eventsPath , []byte (first + "\n " + secondPrefix ), 0o644 ); err != nil {
188193 t .Fatalf ("WriteFile events: %v" , err )
189194 }
190195
191196 report , err := instance .FollowImportsOnce (context .Background (), FollowImportsInput {
192- Source : "watcher_import" ,
197+ Source : followImportsWatcherSource ,
193198 InputPath : eventsPath ,
194199 StatePath : statePath ,
195200 CWD : root ,
@@ -234,7 +239,7 @@ func TestAppFollowImportsOnceConsumesOnlyCompleteLinesAndPersistsCheckpoint(t *t
234239 }
235240
236241 report , err = instance .FollowImportsOnce (context .Background (), FollowImportsInput {
237- Source : "watcher_import" ,
242+ Source : followImportsWatcherSource ,
238243 InputPath : eventsPath ,
239244 StatePath : statePath ,
240245 CWD : root ,
@@ -276,7 +281,7 @@ func TestAppFollowImportsOnceUsesCheckpointRecoveryWhenNoNewLinesExist(t *testin
276281 cfg := ingestTestConfig (root )
277282 eventsPath := filepath .Join (root , "events.jsonl" )
278283 statePath := filepath .Join (root , "events.offset.json" )
279- event := `{"external_id":"watcher:1","type":"discovery","title":"First","content":"First event.","importance":4}`
284+ event := followImportsFirstEvent
280285 if err := os .WriteFile (eventsPath , []byte (event + "\n " ), 0o644 ); err != nil {
281286 t .Fatalf ("WriteFile events: %v" , err )
282287 }
@@ -286,7 +291,7 @@ func TestAppFollowImportsOnceUsesCheckpointRecoveryWhenNoNewLinesExist(t *testin
286291 t .Fatalf ("New first instance: %v" , err )
287292 }
288293 report , err := instance .FollowImportsOnce (context .Background (), FollowImportsInput {
289- Source : "watcher_import" ,
294+ Source : followImportsWatcherSource ,
290295 InputPath : eventsPath ,
291296 StatePath : statePath ,
292297 CWD : root ,
@@ -311,7 +316,7 @@ func TestAppFollowImportsOnceUsesCheckpointRecoveryWhenNoNewLinesExist(t *testin
311316 defer func () { _ = instance .Close () }()
312317
313318 report , err = instance .FollowImportsOnce (context .Background (), FollowImportsInput {
314- Source : "watcher_import" ,
319+ Source : followImportsWatcherSource ,
315320 InputPath : eventsPath ,
316321 StatePath : statePath ,
317322 CWD : root ,
@@ -353,12 +358,12 @@ func TestAppFollowImportsOnceResetsOffsetAfterTruncation(t *testing.T) {
353358
354359 eventsPath := filepath .Join (root , "events.jsonl" )
355360 statePath := filepath .Join (root , "events.offset.json" )
356- first := `{"external_id":"watcher:1","type":"discovery","title":"First","content":"First event.","importance":4}`
361+ first := followImportsFirstEvent
357362 if err := os .WriteFile (eventsPath , []byte (first + "\n " ), 0o644 ); err != nil {
358363 t .Fatalf ("WriteFile first events: %v" , err )
359364 }
360365 if _ , err := instance .FollowImportsOnce (context .Background (), FollowImportsInput {
361- Source : "watcher_import" ,
366+ Source : followImportsWatcherSource ,
362367 InputPath : eventsPath ,
363368 StatePath : statePath ,
364369 CWD : root ,
@@ -373,7 +378,7 @@ func TestAppFollowImportsOnceResetsOffsetAfterTruncation(t *testing.T) {
373378 }
374379
375380 report , err := instance .FollowImportsOnce (context .Background (), FollowImportsInput {
376- Source : "watcher_import" ,
381+ Source : followImportsWatcherSource ,
377382 InputPath : eventsPath ,
378383 StatePath : statePath ,
379384 CWD : root ,
@@ -423,7 +428,7 @@ func TestAppFollowImportsOnceWritesBatchScopedFailureExports(t *testing.T) {
423428 }
424429
425430 report , err := instance .FollowImportsOnce (context .Background (), FollowImportsInput {
426- Source : "watcher_import" ,
431+ Source : followImportsWatcherSource ,
427432 InputPath : eventsPath ,
428433 StatePath : statePath ,
429434 CWD : root ,
@@ -506,7 +511,7 @@ func TestAppFollowImportsOnceResetsOffsetWhenFileIsReplacedWithoutShrinking(t *t
506511 }
507512
508513 report , err := instance .FollowImportsOnce (context .Background (), FollowImportsInput {
509- Source : "watcher_import" ,
514+ Source : followImportsWatcherSource ,
510515 InputPath : eventsPath ,
511516 StatePath : statePath ,
512517 CWD : root ,
@@ -524,7 +529,7 @@ func TestAppFollowImportsOnceResetsOffsetWhenFileIsReplacedWithoutShrinking(t *t
524529 }
525530
526531 report , err = instance .FollowImportsOnce (context .Background (), FollowImportsInput {
527- Source : "watcher_import" ,
532+ Source : followImportsWatcherSource ,
528533 InputPath : eventsPath ,
529534 StatePath : statePath ,
530535 CWD : root ,
0 commit comments