Files
DeepSeek-Reasonix/internal/config/render_test.go
T
yhhandClaude Opus 4.8 7de6a2474f feat: import Go implementation as v2 kernel (renamed duo → reasonix)
Bring in the finished Go rewrite (developed under the placeholder name
"duo") as the v2 codebase. Code-only import — no upstream git history.

Config- and plugin-driven coding agent: registry core, OpenAI-compatible
providers, builtin tools, MCP (stdio + HTTP) plugins, permission + sandbox,
custom slash commands, @-references, two-model collaboration.

Renamed throughout: duo→reasonix, Duo→Reasonix, DUO→REASONIX — module path,
imports, CLI name, cmd/ dirs, reasonix.toml, .reasonix/commands, and
$REASONIX_* env prefixes. Kept the v2 MIT LICENSE (the Go project had none).

Verified: go build ./... · go vet ./... · go test ./... all green; gofmt clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-05-29 18:13:20 -07:00

75 lines
2.6 KiB
Go

package config
import (
"testing"
"github.com/BurntSushi/toml"
)
// TestRenderTOMLRoundTrips ensures the annotated TOML we emit parses back into
// an equivalent config — i.e. the wizard never writes a file it can't read.
func TestRenderTOMLRoundTrips(t *testing.T) {
orig := Default()
orig.DefaultModel = "mimo-pro"
orig.Language = "zh"
orig.Permissions = PermissionsConfig{
Mode: "deny",
Deny: []string{"bash(rm -rf*)"},
Allow: []string{"bash(go test*)", "read_file"},
}
orig.Plugins = []PluginEntry{
{Name: "example", Command: "reasonix-plugin-example"},
{Name: "stripe", Type: "http", URL: "https://mcp.stripe.com", Headers: map[string]string{"Authorization": "Bearer x"}},
}
mm, _ := orig.Provider("mimo-pro")
mm.BaseURL = "http://localhost:8000/v1"
rendered := RenderTOML(orig)
var got Config
if _, err := toml.Decode(rendered, &got); err != nil {
t.Fatalf("rendered TOML does not parse: %v\n---\n%s", err, rendered)
}
if got.DefaultModel != "mimo-pro" {
t.Errorf("default_model = %q, want mimo-pro", got.DefaultModel)
}
if got.Language != "zh" {
t.Errorf("language = %q, want zh", got.Language)
}
if got.Agent.MaxSteps != orig.Agent.MaxSteps {
t.Errorf("max_steps = %d, want %d", got.Agent.MaxSteps, orig.Agent.MaxSteps)
}
if got.Agent.Temperature != orig.Agent.Temperature {
t.Errorf("temperature = %v, want %v", got.Agent.Temperature, orig.Agent.Temperature)
}
if got.Agent.SystemPrompt != orig.Agent.SystemPrompt {
t.Errorf("system_prompt mismatch:\n got %q\nwant %q", got.Agent.SystemPrompt, orig.Agent.SystemPrompt)
}
if g, _ := got.Provider("mimo-pro"); g == nil || g.BaseURL != "http://localhost:8000/v1" {
t.Errorf("mimo-pro base_url not preserved: %+v", g)
}
if len(got.Providers) != len(orig.Providers) {
t.Errorf("providers count = %d, want %d", len(got.Providers), len(orig.Providers))
}
if got.Permissions.Mode != "deny" {
t.Errorf("permissions.mode = %q, want deny", got.Permissions.Mode)
}
if len(got.Permissions.Deny) != 1 || got.Permissions.Deny[0] != "bash(rm -rf*)" {
t.Errorf("permissions.deny = %v, want [bash(rm -rf*)]", got.Permissions.Deny)
}
if len(got.Permissions.Allow) != 2 {
t.Errorf("permissions.allow = %v, want 2 entries", got.Permissions.Allow)
}
if len(got.Plugins) != 2 {
t.Fatalf("plugins count = %d, want 2", len(got.Plugins))
}
stripe := got.Plugins[1]
if stripe.Name != "stripe" || stripe.Type != "http" || stripe.URL != "https://mcp.stripe.com" {
t.Errorf("http plugin not preserved: %+v", stripe)
}
if stripe.Headers["Authorization"] != "Bearer x" {
t.Errorf("plugin headers not preserved: %v", stripe.Headers)
}
}