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

Function TestBuildWriteRead

handoff/handoff_test.go:33–162  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31}
32
33func TestBuildWriteRead(t *testing.T) {
34 root := t.TempDir()
35
36 runCmd(t, root, "git", "init")
37
38 if err := os.WriteFile(filepath.Join(root, "a.go"), []byte("package main\n\nfunc A() {}\n"), 0644); err != nil {
39 t.Fatal(err)
40 }
41 if err := os.WriteFile(filepath.Join(root, "b.go"), []byte("package main\n\nfunc B() {}\n"), 0644); err != nil {
42 t.Fatal(err)
43 }
44 if err := os.WriteFile(filepath.Join(root, "go.mod"), []byte("module example\n\ngo 1.24\n"), 0644); err != nil {
45 t.Fatal(err)
46 }
47
48 runCmd(t, root, "git", "add", ".")
49 runCmd(t, root, "git", "-c", "user.name=Test", "-c", "user.email=test@example.com", "commit", "-m", "init")
50
51 // Local modification to show up in handoff changed files.
52 if err := os.WriteFile(filepath.Join(root, "a.go"), []byte("package main\n\nfunc A() int { return 1 }\n"), 0644); err != nil {
53 t.Fatal(err)
54 }
55 if err := os.WriteFile(filepath.Join(root, "go.mod"), []byte("module example\n\ngo 1.25\n"), 0644); err != nil {
56 t.Fatal(err)
57 }
58 // Noise file should not be included in changed files handoff output.
59 if err := os.WriteFile(filepath.Join(root, "firebase-debug.log"), []byte("debug noise\n"), 0644); err != nil {
60 t.Fatal(err)
61 }
62 // Binary noise file (no extension) should also be excluded.
63 if err := os.WriteFile(filepath.Join(root, "codemap-dev"), []byte{0xCA, 0xFE, 0xBA, 0xBE, 0x00}, 0755); err != nil {
64 t.Fatal(err)
65 }
66
67 state := &watch.State{
68 Importers: map[string][]string{
69 "a.go": {"x.go", "y.go", "z.go"},
70 },
71 RecentEvents: []watch.Event{
72 {
73 Time: time.Now().Add(-20 * time.Minute),
74 Op: "WRITE",
75 Path: "a.go",
76 Delta: 3,
77 IsHub: true,
78 },
79 },
80 }
81
82 artifact, err := Build(root, BuildOptions{
83 BaseRef: "HEAD",
84 Since: time.Hour,
85 State: state,
86 })
87 if err != nil {
88 t.Fatalf("Build failed: %v", err)
89 }
90

Callers

nothing calls this directly

Calls 8

runCmdFunction · 0.85
BuildFunction · 0.85
WriteLatestFunction · 0.85
PrefixPathFunction · 0.85
DeltaPathFunction · 0.85
MetricsPathFunction · 0.85
ReadLatestFunction · 0.85
containsFunction · 0.70

Tested by

no test coverage detected