Files
archie/internal/tools/classification_test.go
T
sam 766c09d477 refactor(tools): delete unreachable dispatch/gating engine
DispatchSequential, DispatchConcurrent, ClassifyEntry and their
supporting types (dispatch.go) have zero non-test callers; the live
tool path is agentexec/toolset.go's BuildToolSetFrom. Removes the
dead engine and its tests, and updates the PRD status table that
referenced it (tools-core-1).
2026-09-15 10:19:39 +10:00

140 lines
3.4 KiB
Go

package tools
import (
"encoding/json"
"testing"
)
func TestToolClassificationIsIdempotent(t *testing.T) {
t.Run("zero value is not idempotent", func(t *testing.T) {
var c ToolClassification
if c.IsIdempotent() {
t.Error("zero classification should not be idempotent")
}
})
t.Run("explicit idempotent flag", func(t *testing.T) {
if !ClassIdempotent.IsIdempotent() {
t.Error("ClassIdempotent should be idempotent")
}
})
t.Run("idempotent is not mutating", func(t *testing.T) {
if ClassIdempotent.IsMutating() {
t.Error("idempotent should not be mutating")
}
})
}
func TestToolClassificationIsMutating(t *testing.T) {
t.Run("zero value is not mutating", func(t *testing.T) {
var c ToolClassification
if c.IsMutating() {
t.Error("zero classification should not be mutating")
}
})
t.Run("explicit mutating flag", func(t *testing.T) {
if !ClassMutating.IsMutating() {
t.Error("ClassMutating should be mutating")
}
})
t.Run("mutating is not idempotent", func(t *testing.T) {
if ClassMutating.IsIdempotent() {
t.Error("mutating should not be idempotent")
}
})
}
func TestToolClassificationCombined(t *testing.T) {
c := ClassIdempotent | ClassMutating
if !c.IsIdempotent() {
t.Error("combined should be idempotent")
}
if !c.IsMutating() {
t.Error("combined should be mutating")
}
}
func TestToolClassificationIsApprovalRequired(t *testing.T) {
t.Run("zero value does not require approval", func(t *testing.T) {
var c ToolClassification
if c.IsApprovalRequired() {
t.Error("zero classification should not require approval")
}
})
t.Run("explicit approval flag", func(t *testing.T) {
if !RequiresApproval.IsApprovalRequired() {
t.Error("RequiresApproval should require approval")
}
})
t.Run("approval is independent of idempotent", func(t *testing.T) {
c := ClassIdempotent | RequiresApproval
if !c.IsApprovalRequired() {
t.Error("idempotent + approval should require approval")
}
if !c.IsIdempotent() {
t.Error("idempotent + approval should still be idempotent")
}
})
t.Run("approval is independent of mutating", func(t *testing.T) {
c := ClassMutating | RequiresApproval
if !c.IsApprovalRequired() {
t.Error("mutating + approval should require approval")
}
if !c.IsMutating() {
t.Error("mutating + approval should still be mutating")
}
})
}
func TestToolClassificationString(t *testing.T) {
tests := []struct {
c ToolClassification
want string
}{
{0, "default"},
{ClassIdempotent, "idempotent"},
{ClassMutating, "mutating"},
{ClassIdempotent | ClassMutating, "idempotent|mutating"},
{RequiresApproval, "requires_approval"},
{ClassMutating | RequiresApproval, "mutating|requires_approval"},
{ToolClassification(8), "unknown"},
}
for _, tt := range tests {
got := tt.c.String()
if got != tt.want {
t.Errorf("String() = %q, want %q", got, tt.want)
}
}
}
func TestClassificationJSONRoundTrip(t *testing.T) {
e := ToolEntry{
Name: "classified",
Toolset: "test",
Description: "A classified tool",
Handler: noopHandler,
Classification: ClassIdempotent,
}
data, err := json.Marshal(e)
if err != nil {
t.Fatalf("marshal: %v", err)
}
var decoded ToolEntry
if err := json.Unmarshal(data, &decoded); err != nil {
t.Fatalf("unmarshal: %v", err)
}
if decoded.Classification != ClassIdempotent {
t.Errorf("Classification = %v after round-trip, want idempotent", decoded.Classification)
}
}