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

Function TestRunHandoffSubcommandBuildAndDetailJSON

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

Source from the content-addressed store, hash-verified

359}
360
361func TestRunHandoffSubcommandBuildAndDetailJSON(t *testing.T) {
362 if _, err := exec.LookPath("git"); err != nil {
363 t.Skip("git not available")
364 }
365
366 root := makeMainGitRepo(t, "feature/handoff-main")
367 if err := os.WriteFile(filepath.Join(root, "pkg", "types", "types.go"), []byte("package types\n\ntype Item struct{ Value string }\n"), 0o644); err != nil {
368 t.Fatal(err)
369 }
370 writeMainWatchState(t, root, watch.State{
371 UpdatedAt: time.Now(),
372 FileCount: 5,
373 Importers: map[string][]string{
374 "pkg/types/types.go": {"a/a.go", "b/b.go", "c/c.go", "main.go"},
375 },
376 Imports: map[string][]string{
377 "main.go": {"pkg/types/types.go"},
378 },
379 RecentEvents: []watch.Event{
380 {Time: time.Now().Add(-time.Minute), Op: "WRITE", Path: "pkg/types/types.go", Delta: 2, IsHub: true},
381 },
382 }, false)
383
384 stdout, _ := captureMainStreams(t, func() {
385 runHandoffSubcommand([]string{"--json", "--no-save", root})
386 })
387
388 var artifact handoff.Artifact
389 if err := json.Unmarshal([]byte(stdout), &artifact); err != nil {
390 t.Fatalf("expected handoff JSON output, got error %v with body:\n%s", err, stdout)
391 }
392 if artifact.Branch != "feature/handoff-main" {
393 t.Fatalf("artifact branch = %q, want feature/handoff-main", artifact.Branch)
394 }
395 if len(artifact.Delta.Changed) == 0 || artifact.Delta.Changed[0].Path != "pkg/types/types.go" {
396 t.Fatalf("expected changed type file in artifact, got %+v", artifact.Delta.Changed)
397 }
398 if _, err := os.Stat(handoff.LatestPath(root)); !os.IsNotExist(err) {
399 t.Fatalf("expected --no-save to skip latest artifact write, got err=%v", err)
400 }
401
402 stdout, _ = captureMainStreams(t, func() {
403 runHandoffSubcommand([]string{root})
404 })
405 for _, check := range []string{"# Handoff", "Saved:", "Prefix:", "Delta:", "Metrics:"} {
406 if !strings.Contains(stdout, check) {
407 t.Fatalf("expected %q in handoff output, got:\n%s", check, stdout)
408 }
409 }
410
411 stdout, _ = captureMainStreams(t, func() {
412 runHandoffSubcommand([]string{"--latest", "--detail", "pkg/types/types.go", "--json", root})
413 })
414
415 var detail handoff.FileDetail
416 if err := json.Unmarshal([]byte(stdout), &detail); err != nil {
417 t.Fatalf("expected handoff detail JSON output, got error %v with body:\n%s", err, stdout)
418 }

Callers

nothing calls this directly

Calls 5

LatestPathFunction · 0.92
makeMainGitRepoFunction · 0.85
writeMainWatchStateFunction · 0.85
captureMainStreamsFunction · 0.85
runHandoffSubcommandFunction · 0.85

Tested by

no test coverage detected