| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | func TestActiveConfigTagNamesTheShadowingProjectFile(t *testing.T) { |
| 11 | home := t.TempDir() |
| 12 | t.Setenv("REASONIX_HOME", home) |
| 13 | if err := os.WriteFile(filepath.Join(home, "config.toml"), []byte("default_model = \"a\"\n"), 0o600); err != nil { |
| 14 | t.Fatal(err) |
| 15 | } |
| 16 | work := t.TempDir() |
| 17 | t.Chdir(work) |
| 18 | |
| 19 | if got := activeConfigTag(); !strings.HasSuffix(got, "config.toml") { |
| 20 | t.Fatalf("user-global config should be reported, got %q", got) |
| 21 | } |
| 22 | |
| 23 | local := filepath.Join(work, "reasonix.toml") |
| 24 | if err := os.WriteFile(local, []byte("default_model = \"b\"\n"), 0o600); err != nil { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | if got := activeConfigTag(); !strings.HasSuffix(got, "reasonix.toml") { |
| 28 | t.Fatalf("project config outranks the global one and must be reported, got %q", got) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func TestActiveConfigTagWithoutAnyConfigFile(t *testing.T) { |
| 33 | t.Setenv("REASONIX_HOME", t.TempDir()) |
| 34 | t.Chdir(t.TempDir()) |
| 35 | |
| 36 | if got := activeConfigTag(); !strings.Contains(got, "defaults") { |
| 37 | t.Fatalf("no config file must be stated explicitly, got %q", got) |
| 38 | } |
| 39 | } |
| 40 |