From e04f018b4c22fdd77135fd9ddbc2c671efe2d86d Mon Sep 17 00:00:00 2001 From: Snider Date: Sat, 25 Apr 2026 07:57:29 +0100 Subject: [PATCH] test(agent): add AX-10 unit tests for dispatch/session/sync/tools/content (#169) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Closes tasks.lthn.sh/view.php?id=169 --- pkg/agentic/content_test.go | 15 +++++++++++++++ pkg/agentic/dispatch_test.go | 31 +++++++++++++++++++++++++++++++ pkg/agentic/session_test.go | 18 ++++++++++++++++++ pkg/agentic/sync_test.go | 18 ++++++++++++++++++ pkg/brain/tools_test.go | 26 ++++++++++++++++++++++++++ 5 files changed, 108 insertions(+) diff --git a/pkg/agentic/content_test.go b/pkg/agentic/content_test.go index 68b3ee1..320f5da 100644 --- a/pkg/agentic/content_test.go +++ b/pkg/agentic/content_test.go @@ -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("")) +} diff --git a/pkg/agentic/dispatch_test.go b/pkg/agentic/dispatch_test.go index 0c8ac11..685208c 100644 --- a/pkg/agentic/dispatch_test.go +++ b/pkg/agentic/dispatch_test.go @@ -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) +} diff --git a/pkg/agentic/session_test.go b/pkg/agentic/session_test.go index e6a58a3..fafe7c8 100644 --- a/pkg/agentic/session_test.go +++ b/pkg/agentic/session_test.go @@ -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) +} diff --git a/pkg/agentic/sync_test.go b/pkg/agentic/sync_test.go index 148dc02..31efc4f 100644 --- a/pkg/agentic/sync_test.go +++ b/pkg/agentic/sync_test.go @@ -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)) +} diff --git a/pkg/brain/tools_test.go b/pkg/brain/tools_test.go index a3911c9..aad2259 100644 --- a/pkg/brain/tools_test.go +++ b/pkg/brain/tools_test.go @@ -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) +}