@@ -2,6 +2,8 @@ package main
22
33import (
44 "bytes"
5+ "os"
6+ "path/filepath"
57 "strings"
68 "testing"
79)
@@ -187,3 +189,40 @@ func stubPrimeHasGitRemote(hasRemote bool) func() {
187189 primeHasGitRemote = original
188190 }
189191}
192+
193+ func TestPrimeGlobalFallback (t * testing.T ) {
194+ // Create a temp directory to act as config dir
195+ tmpDir := t .TempDir ()
196+ beadsConfigDir := filepath .Join (tmpDir , "beads" )
197+ if err := os .MkdirAll (beadsConfigDir , 0755 ); err != nil {
198+ t .Fatalf ("mkdir: %v" , err )
199+ }
200+
201+ content := "# Global PRIME override\n Custom instructions here.\n "
202+ if err := os .WriteFile (filepath .Join (beadsConfigDir , "PRIME.md" ), []byte (content ), 0644 ); err != nil {
203+ t .Fatalf ("write PRIME.md: %v" , err )
204+ }
205+
206+ // Call the helper that resolves the global prime path
207+ got := resolveGlobalPrimePath (tmpDir )
208+ if got == "" {
209+ t .Fatal ("resolveGlobalPrimePath returned empty, want path to global PRIME.md" )
210+ }
211+
212+ data , err := os .ReadFile (got )
213+ if err != nil {
214+ t .Fatalf ("ReadFile(%s): %v" , got , err )
215+ }
216+ if string (data ) != content {
217+ t .Errorf ("content = %q, want %q" , string (data ), content )
218+ }
219+ }
220+
221+ func TestPrimeGlobalFallback_Missing (t * testing.T ) {
222+ // When no global PRIME.md exists, should return empty string
223+ tmpDir := t .TempDir ()
224+ got := resolveGlobalPrimePath (tmpDir )
225+ if got != "" {
226+ t .Errorf ("resolveGlobalPrimePath = %q, want empty for missing file" , got )
227+ }
228+ }
0 commit comments