| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "github.com/BurntSushi/toml" |
| 10 | ) |
| 11 | |
| 12 | func TestLegacyAnchorSafetyGateIsDecodeOnly(t *testing.T) { |
| 13 | cfg := Default() |
| 14 | cfg.Agent.LegacyAnchorSafetyGate = true |
| 15 | rendered := RenderTOML(cfg) |
| 16 | if strings.Contains(rendered, "legacy_anchor_safety_gate") { |
| 17 | t.Fatalf("retired legacy anchor safety switch was rendered:\n%s", rendered) |
| 18 | } |
| 19 | var decoded Config |
| 20 | if _, err := toml.Decode(rendered, &decoded); err != nil { |
| 21 | t.Fatalf("decode rendered config: %v", err) |
| 22 | } |
| 23 | if decoded.Agent.LegacyAnchorSafetyGate { |
| 24 | t.Fatal("retired legacy anchor safety switch survived a current config render") |
| 25 | } |
| 26 | if project := RenderTOMLForScope(cfg, RenderScopeProject); strings.Contains(project, "legacy_anchor_safety_gate") { |
| 27 | t.Fatalf("project config exposed user-global anchor safety switch:\n%s", project) |
| 28 | } |
| 29 | |
| 30 | var explicit Config |
| 31 | if _, err := toml.Decode("[agent]\nlegacy_anchor_safety_gate = true\n", &explicit); err != nil { |
| 32 | t.Fatalf("decode explicit switch: %v", err) |
| 33 | } |
| 34 | if !explicit.Agent.LegacyAnchorSafetyGate { |
| 35 | t.Fatal("old TOML switch no longer decodes for compatibility") |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func TestProjectCannotOverrideLegacyAnchorSafetyGate(t *testing.T) { |
| 40 | isolateUserConfigHome(t) |
| 41 | root := t.TempDir() |
| 42 | if err := os.WriteFile(filepath.Join(root, "reasonix.toml"), []byte("[agent]\nlegacy_anchor_safety_gate = true\n"), 0o600); err != nil { |
| 43 | t.Fatal(err) |
| 44 | } |
| 45 | cfg, err := LoadForRootReadOnly(root) |
| 46 | if err != nil { |
| 47 | t.Fatalf("LoadForRootReadOnly: %v", err) |
| 48 | } |
| 49 | if cfg.Agent.LegacyAnchorSafetyGate { |
| 50 | t.Fatal("project config weakened the user-global anchor safety policy") |
| 51 | } |
| 52 | } |
| 53 |