Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions internal/harness/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ var (
validAgentName = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)
validModelName = regexp.MustCompile(`^[a-zA-Z0-9_.@-]+$`)
validPluginName = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)
// validRoleName mirrors mintcore.RolePattern — duplicated to avoid coupling harness→mintcore.
validRoleName = regexp.MustCompile(`^[a-z][a-z0-9_-]*$`)
validSlugName = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_-]*$`)
envVarRef = regexp.MustCompile(`\$\{([^}]+)\}`)
)

Expand Down Expand Up @@ -193,6 +196,8 @@ type Harness struct {
Agent string `yaml:"agent"`
Doc string `yaml:"doc,omitempty"` // source-repo-only; not resolved at runtime, used by lint-agent-docs
Description string `yaml:"description,omitempty"`
Role string `yaml:"role,omitempty"`
Slug string `yaml:"slug,omitempty"`
Image string `yaml:"image,omitempty"`
Policy string `yaml:"policy,omitempty"`
Skills []string `yaml:"skills,omitempty"`
Expand Down Expand Up @@ -248,6 +253,17 @@ func (h *Harness) Validate() error {
if h.Model != "" && !validModelName.MatchString(h.Model) {
return fmt.Errorf("model %q contains invalid characters (allowed: a-z, A-Z, 0-9, _, -, ., @)", h.Model)
}
if h.Role != "" {
Comment thread
ggallen marked this conversation as resolved.
Resolved
if !validRoleName.MatchString(h.Role) {
return fmt.Errorf("role %q contains invalid characters (allowed: a-z, 0-9, _, -; must start with a lowercase letter)", h.Role)
}
if strings.Contains(h.Role, "--") {
return fmt.Errorf("role %q must not contain double hyphens", h.Role)
}
Comment thread
ggallen marked this conversation as resolved.
Resolved
}
if h.Slug != "" && !validSlugName.MatchString(h.Slug) {
return fmt.Errorf("slug %q contains invalid characters (allowed: a-z, A-Z, 0-9, _, -; must start with a letter or digit)", h.Slug)
}
for i, p := range h.Plugins {
pluginBase := filepath.Base(p)
if !validPluginName.MatchString(pluginBase) {
Expand Down
71 changes: 71 additions & 0 deletions internal/harness/harness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,3 +1073,74 @@ func TestMatchingAllowedPrefix(t *testing.T) {
assert.Equal(t, "https://Example.Com/Skills/", h2.MatchingAllowedPrefix("https://example.com/skills/test.md"))
})
}

// --- Role and slug field tests ---

func TestLoad_RoleAndSlug(t *testing.T) {
content := `
agent: agents/triage.md
role: triage
slug: fullsend-ai-triage
`
dir := t.TempDir()
path := filepath.Join(dir, "triage.yaml")
require.NoError(t, os.WriteFile(path, []byte(content), 0o644))

h, err := Load(path)
require.NoError(t, err)
assert.Equal(t, "triage", h.Role)
assert.Equal(t, "fullsend-ai-triage", h.Slug)
}

func TestLoad_RoleAndSlugAbsent(t *testing.T) {
content := `
agent: agents/test.md
`
dir := t.TempDir()
path := filepath.Join(dir, "test.yaml")
require.NoError(t, os.WriteFile(path, []byte(content), 0o644))

h, err := Load(path)
require.NoError(t, err)
assert.Empty(t, h.Role)
assert.Empty(t, h.Slug)
}

func TestValidate_RoleValid(t *testing.T) {
for _, role := range []string{"triage", "code-reviewer", "bug_triage", "a"} {
h := &Harness{Agent: "agents/test.md", Role: role}
require.NoError(t, h.Validate(), "role %q should be valid", role)
}
}

func TestValidate_RoleInvalid(t *testing.T) {
for _, role := range []string{"Triage", "1role", "role!"} {
h := &Harness{Agent: "agents/test.md", Role: role}
err := h.Validate()
require.Error(t, err, "role %q should be invalid", role)
assert.Contains(t, err.Error(), "contains invalid characters")
}
}

func TestValidate_RoleDoubleHyphen(t *testing.T) {
h := &Harness{Agent: "agents/test.md", Role: "my--role"}
err := h.Validate()
require.Error(t, err)
assert.Contains(t, err.Error(), "double hyphens")
}

func TestValidate_SlugValid(t *testing.T) {
for _, slug := range []string{"fullsend-ai-triage", "Custom_App", "a1"} {
h := &Harness{Agent: "agents/test.md", Slug: slug}
require.NoError(t, h.Validate(), "slug %q should be valid", slug)
}
}

func TestValidate_SlugInvalid(t *testing.T) {
for _, slug := range []string{"-slug", "slug!name", "my slug"} {
h := &Harness{Agent: "agents/test.md", Slug: slug}
err := h.Validate()
require.Error(t, err, "slug %q should be invalid", slug)
assert.Contains(t, err.Error(), "slug")
}
}
Loading