test(agent): add AX-10 unit tests for dispatch/session/sync/tools/content (#169)

Append-only — no existing tests modified.

- dispatch_test.go: TestDispatch_agentCommand_{Good,Bad,Ugly}
- session_test.go: TestSession_normaliseSessionAgentType_{Good,Bad,Ugly}
- sync_test.go: TestSync_syncBackoffSchedule_{Good,Bad,Ugly}
- tools_test.go: TestTools_RememberInput_{Bad,Ugly} (Good was pre-existing)
- content_test.go: TestContent_contentSchemaType_{Good,Bad,Ugly}

gofmt clean. Test verification deferred (private dappco.re/go/* deps
missing go.sum entries with GOWORK=off — would resolve under workspace).

Co-authored-by: Codex <noreply@openai.com>
Closes tasks.lthn.sh/view.php?id=169
This commit is contained in:
Snider 2026-04-25 07:57:29 +01:00
parent 91551dec9b
commit e04f018b4c
5 changed files with 108 additions and 0 deletions

View file

@ -324,3 +324,18 @@ func TestContent_HandleContentSchemaGenerate_Ugly(t *testing.T) {
))
assert.False(t, result.OK)
}
func TestContent_contentSchemaType_Good(t *testing.T) {
assert.Equal(t, "BlogPosting", contentSchemaType("article"))
assert.Equal(t, "FAQPage", contentSchemaType("faq"))
assert.Equal(t, "HowTo", contentSchemaType("how-to"))
}
func TestContent_contentSchemaType_Bad(t *testing.T) {
assert.Empty(t, contentSchemaType("press-release"))
}
func TestContent_contentSchemaType_Ugly(t *testing.T) {
assert.Equal(t, "TechArticle", contentSchemaType(" TECH-ARTICLE "))
assert.Empty(t, contentSchemaType(""))
}

View file

@ -610,3 +610,34 @@ func TestDispatch_ContainerCommand_Bad(t *testing.T) {
// Good: tested in queue_test.go
// Bad: tested in queue_test.go
// Ugly: see queue_extra_test.go
// --- agentCommand AX-10 ---
func TestDispatch_agentCommand_Good(t *testing.T) {
command, args, err := agentCommand("codex:gpt-5.4-mini", "Implement AX-10 unit tests for Mantis #169")
require.NoError(t, err)
assert.Equal(t, "codex", command)
assert.Equal(t, []string{
"exec",
"--dangerously-bypass-approvals-and-sandbox",
"-o", "../.meta/agent-codex.log",
"--model", "gpt-5.4-mini",
"Implement AX-10 unit tests for Mantis #169",
}, args)
}
func TestDispatch_agentCommand_Bad(t *testing.T) {
command, args, err := agentCommand("mantis", "Investigate a failing dispatch")
require.Error(t, err)
assert.Contains(t, err.Error(), "unknown agent: mantis")
assert.Empty(t, command)
assert.Nil(t, args)
}
func TestDispatch_agentCommand_Ugly(t *testing.T) {
command, args, err := agentCommand("", "Investigate a failing dispatch")
require.Error(t, err)
assert.Contains(t, err.Error(), "unknown agent")
assert.Empty(t, command)
assert.Nil(t, args)
}

View file

@ -566,3 +566,21 @@ func TestSession_HandleSessionReplay_Ugly_MissingSession(t *testing.T) {
))
assert.False(t, result.OK)
}
func TestSession_normaliseSessionAgentType_Good(t *testing.T) {
agentType, ok := normaliseSessionAgentType(" CLAUDE:Sonnet ")
require.True(t, ok)
assert.Equal(t, "sonnet", agentType)
}
func TestSession_normaliseSessionAgentType_Bad(t *testing.T) {
agentType, ok := normaliseSessionAgentType("codex")
assert.False(t, ok)
assert.Empty(t, agentType)
}
func TestSession_normaliseSessionAgentType_Ugly(t *testing.T) {
agentType, ok := normaliseSessionAgentType(" ")
assert.False(t, ok)
assert.Empty(t, agentType)
}

View file

@ -669,3 +669,21 @@ func TestSync_HandleSyncPush_Ugly_RespectsBackoffWindow(t *testing.T) {
require.Len(t, queued, 1)
assert.Equal(t, 3, queued[0].Attempts)
}
func TestSync_syncBackoffSchedule_Good(t *testing.T) {
assert.Equal(t, time.Second, syncBackoffSchedule(1))
assert.Equal(t, 5*time.Second, syncBackoffSchedule(2))
assert.Equal(t, 15*time.Second, syncBackoffSchedule(3))
assert.Equal(t, 60*time.Second, syncBackoffSchedule(4))
}
func TestSync_syncBackoffSchedule_Bad(t *testing.T) {
assert.Equal(t, time.Duration(0), syncBackoffSchedule(-1))
assert.Equal(t, time.Duration(0), syncBackoffSchedule(-42))
}
func TestSync_syncBackoffSchedule_Ugly(t *testing.T) {
assert.Equal(t, time.Duration(0), syncBackoffSchedule(0))
assert.Equal(t, 5*time.Minute, syncBackoffSchedule(5))
assert.Equal(t, 5*time.Minute, syncBackoffSchedule(999))
}

View file

@ -5,6 +5,7 @@ package brain
import (
"testing"
core "dappco.re/go/core"
"github.com/stretchr/testify/assert"
)
@ -29,3 +30,28 @@ func TestTools_Memory_Good(t *testing.T) {
assert.Equal(t, "2026-04-01T00:00:00Z", memory.DeletedAt)
}
func TestTools_RememberInput_Bad(t *testing.T) {
var input RememberInput
result := core.JSONUnmarshalString(`{"content":"Use core.Env for paths","type":42}`, &input)
assert.False(t, result.OK)
}
func TestTools_RememberInput_Ugly(t *testing.T) {
input := RememberInput{
Content: "Keep zero-value memory metadata intact",
Type: "observation",
Tags: nil,
Confidence: 0,
ExpiresIn: 0,
}
var output RememberInput
roundTrip(t, input, &output)
assert.Equal(t, input.Content, output.Content)
assert.Equal(t, input.Type, output.Type)
assert.Nil(t, output.Tags)
assert.Zero(t, output.Confidence)
assert.Zero(t, output.ExpiresIn)
}