83 lines
3.0 KiB
Go
83 lines
3.0 KiB
Go
package domain
|
|
|
|
import "testing"
|
|
|
|
func TestProjectConfigValidate(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
cfg ProjectConfig
|
|
wantErr bool
|
|
}{
|
|
{"empty ok", ProjectConfig{}, false},
|
|
{"good agent config", ProjectConfig{AgentConfig: AgentConfig{Model: "m", Permissions: PermissionModeAuto}}, false},
|
|
{"bad permission", ProjectConfig{AgentConfig: AgentConfig{Permissions: "yolo"}}, true},
|
|
{"good session prefix", ProjectConfig{SessionPrefix: "ao"}, false},
|
|
{"session prefix with slash", ProjectConfig{SessionPrefix: "ao/project"}, true},
|
|
{"session prefix with backslash", ProjectConfig{SessionPrefix: `ao\project`}, true},
|
|
{"session prefix traversal component", ProjectConfig{SessionPrefix: ".."}, true},
|
|
{"good role override", ProjectConfig{Worker: RoleOverride{Harness: HarnessCodex}}, false},
|
|
{"unknown role harness", ProjectConfig{Orchestrator: RoleOverride{Harness: "nope"}}, true},
|
|
{"bad role agent config", ProjectConfig{Worker: RoleOverride{AgentConfig: AgentConfig{Permissions: "nope"}}}, true},
|
|
{"good symlinks", ProjectConfig{Symlinks: []string{".env", "configs/dev.toml"}}, false},
|
|
{"symlink absolute path", ProjectConfig{Symlinks: []string{"/etc/passwd"}}, true},
|
|
{"symlink parent escape", ProjectConfig{Symlinks: []string{"../escape"}}, true},
|
|
{"symlink embedded parent", ProjectConfig{Symlinks: []string{"a/../../b"}}, true},
|
|
{"symlink bare ..", ProjectConfig{Symlinks: []string{".."}}, true},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if err := tt.cfg.Validate(); (err != nil) != tt.wantErr {
|
|
t.Fatalf("Validate() err = %v, wantErr = %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestDefaultProjectConfig(t *testing.T) {
|
|
def := DefaultProjectConfig()
|
|
|
|
// The one documented non-empty default.
|
|
if def.DefaultBranch != "main" {
|
|
t.Fatalf("default DefaultBranch = %q, want main", def.DefaultBranch)
|
|
}
|
|
|
|
// Every other field defaults to its zero value: clearing the documented
|
|
// default must leave the config completely empty.
|
|
def.DefaultBranch = ""
|
|
if !def.IsZero() {
|
|
t.Fatalf("default config has unexpected non-zero fields: %#v", def)
|
|
}
|
|
}
|
|
|
|
func TestProjectConfigWithDefaults(t *testing.T) {
|
|
// An unset config gets the documented defaults.
|
|
got := (ProjectConfig{}).WithDefaults()
|
|
if got.DefaultBranch != DefaultBranchName {
|
|
t.Fatalf("WithDefaults = %#v, want branch=main", got)
|
|
}
|
|
|
|
// Set fields are preserved, not overwritten.
|
|
got = (ProjectConfig{
|
|
DefaultBranch: "develop",
|
|
AgentConfig: AgentConfig{Model: "m"},
|
|
}).WithDefaults()
|
|
if got.DefaultBranch != "develop" {
|
|
t.Fatalf("WithDefaults overwrote set fields: %#v", got)
|
|
}
|
|
if got.AgentConfig.Model != "m" {
|
|
t.Fatalf("WithDefaults dropped a set field: %#v", got.AgentConfig)
|
|
}
|
|
}
|
|
|
|
func TestProjectConfigIsZero(t *testing.T) {
|
|
if !(ProjectConfig{}).IsZero() {
|
|
t.Fatal("empty config should be zero")
|
|
}
|
|
if (ProjectConfig{DefaultBranch: "main"}).IsZero() {
|
|
t.Fatal("populated config should not be zero")
|
|
}
|
|
if (ProjectConfig{Env: map[string]string{"A": "b"}}).IsZero() {
|
|
t.Fatal("config with env should not be zero")
|
|
}
|
|
}
|