MCPcopy Create free account
hub / github.com/JordanCoin/codemap / TestRunWatchModeRunDaemonAndWatchStart

Function TestRunWatchModeRunDaemonAndWatchStart

main_more_test.go:427–513  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

425}
426
427func TestRunWatchModeRunDaemonAndWatchStart(t *testing.T) {
428 t.Run("watch mode prints summary after interrupt", func(t *testing.T) {
429 fake := &fakeWatchProcess{
430 fileCount: 7,
431 events: []watch.Event{
432 {Path: "main.go", Op: "WRITE"},
433 {Path: "pkg/types.go", Op: "CREATE"},
434 },
435 }
436 withMainRuntimeStubs(
437 t,
438 func(root string, verbose bool) (watchProcess, error) { return fake, nil },
439 func(c chan<- os.Signal, sig ...os.Signal) { c <- os.Interrupt },
440 nil,
441 nil,
442 nil,
443 nil,
444 nil,
445 )
446
447 stdout, _ := captureMainStreams(t, func() { runWatchMode(t.TempDir(), false) })
448 for _, check := range []string{"codemap watch - Live code graph daemon", "Watching:", "Press Ctrl+C to stop", "Session summary:", "Files tracked: 7", "Events logged: 2"} {
449 if !strings.Contains(stdout, check) {
450 t.Fatalf("expected %q in watch mode output, got:\n%s", check, stdout)
451 }
452 }
453 if !fake.started || !fake.stopped {
454 t.Fatalf("expected fake watch process to start and stop, got %+v", fake)
455 }
456 })
457
458 t.Run("daemon writes and removes pid around lifecycle", func(t *testing.T) {
459 fake := &fakeWatchProcess{}
460 root := t.TempDir()
461 withMainRuntimeStubs(
462 t,
463 func(root string, verbose bool) (watchProcess, error) { return fake, nil },
464 func(c chan<- os.Signal, sig ...os.Signal) { c <- syscall.SIGTERM },
465 nil,
466 nil,
467 nil,
468 nil,
469 nil,
470 )
471
472 runDaemon(root)
473 if !fake.started || !fake.stopped {
474 t.Fatalf("expected fake daemon to start and stop, got %+v", fake)
475 }
476 if _, err := os.Stat(filepath.Join(root, ".codemap", "watch.pid")); !os.IsNotExist(err) {
477 t.Fatalf("expected pid file to be removed after daemon stops, got err=%v", err)
478 }
479 })
480
481 t.Run("watch start shells out to daemon entrypoint", func(t *testing.T) {
482 root := t.TempDir()
483 var gotName string
484 var gotArgs []string

Callers

nothing calls this directly

Calls 5

withMainRuntimeStubsFunction · 0.85
captureMainStreamsFunction · 0.85
runWatchModeFunction · 0.85
runDaemonFunction · 0.85
runWatchSubcommandFunction · 0.85

Tested by

no test coverage detected