agent/pkg/agentic/queue_test.go
Snider f83c753277 feat(v0.8.0): full AX migration — ServiceRuntime, Actions, quality gates, transport
go-process:
- Register factory, Result lifecycle, 5 named Action handlers
- Start/Run/StartWithOptions/RunWithOptions all return core.Result
- core.ID() replaces fmt.Sprintf, core.As replaces errors.As

core/agent:
- PrepSubsystem + monitor.Subsystem + setup.Service embed ServiceRuntime[T]
- 22 named Actions + agent.completion Task pipeline in OnStartup
- ChannelNotifier removed — all IPC via c.ACTION(messages.X{})
- proc.go: all methods via s.Core().Process(), returns core.Result
- status.go: WriteAtomic + JSONMarshalString
- paths.go: Fs.NewUnrestricted() replaces unsafe.Pointer
- transport.go: ONE net/http file — HTTPGet/HTTPPost/HTTPDo/MCP transport
- All disallowed imports eliminated from source files (13 quality gates)
- String concat eliminated — core.Concat() throughout
- 1:1 _test.go + _example_test.go for every source file
- Reference docs synced from core/go v0.8.0
- RFC-025 updated with net/http, net/url, io/fs quality gates
- lib.go: io/fs eliminated via Data.ListNames, Array[T].Deduplicate

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 01:27:46 +00:00

86 lines
3 KiB
Go

// SPDX-License-Identifier: EUPL-1.2
package agentic
import (
core "dappco.re/go/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"path/filepath"
"testing"
)
func TestQueue_BaseAgent_Ugly_Empty(t *testing.T) {
assert.Equal(t, "", baseAgent(""))
}
func TestQueue_BaseAgent_Ugly_MultipleColons(t *testing.T) {
// SplitN with N=2 should only split on first colon
assert.Equal(t, "claude", baseAgent("claude:opus:extra"))
}
func TestDispatchConfig_Good_Defaults(t *testing.T) {
// loadAgentsConfig falls back to defaults when no config file exists
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}), codePath: t.TempDir()}
t.Setenv("CORE_WORKSPACE", t.TempDir())
cfg := s.loadAgentsConfig()
assert.Equal(t, "claude", cfg.Dispatch.DefaultAgent)
assert.Equal(t, "coding", cfg.Dispatch.DefaultTemplate)
assert.Equal(t, 1, cfg.Concurrency["claude"].Total)
assert.Equal(t, 3, cfg.Concurrency["gemini"].Total)
}
func TestQueue_CanDispatchAgent_Good_NoConfig(t *testing.T) {
// With no running workspaces and default config, should be able to dispatch
root := t.TempDir()
t.Setenv("CORE_WORKSPACE", root)
require.True(t, fs.EnsureDir(filepath.Join(root, "workspace")).OK)
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}), codePath: t.TempDir()}
assert.True(t, s.canDispatchAgent("gemini"))
}
func TestQueue_CanDispatchAgent_Good_UnknownAgent(t *testing.T) {
// Unknown agent has no limit, so always allowed
root := t.TempDir()
t.Setenv("CORE_WORKSPACE", root)
require.True(t, fs.EnsureDir(filepath.Join(root, "workspace")).OK)
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}), codePath: t.TempDir()}
assert.True(t, s.canDispatchAgent("unknown-agent"))
}
func TestQueue_CountRunningByAgent_Good_EmptyWorkspace(t *testing.T) {
root := t.TempDir()
t.Setenv("CORE_WORKSPACE", root)
require.True(t, fs.EnsureDir(filepath.Join(root, "workspace")).OK)
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{})}
assert.Equal(t, 0, s.countRunningByAgent("gemini"))
assert.Equal(t, 0, s.countRunningByAgent("claude"))
}
func TestQueue_CountRunningByAgent_Good_NoRunning(t *testing.T) {
root := t.TempDir()
t.Setenv("CORE_WORKSPACE", root)
// Create a workspace with completed status under workspace/
ws := filepath.Join(root, "workspace", "test-ws")
require.True(t, fs.EnsureDir(ws).OK)
require.NoError(t, writeStatus(ws, &WorkspaceStatus{
Status: "completed",
Agent: "gemini",
PID: 0,
}))
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{})}
assert.Equal(t, 0, s.countRunningByAgent("gemini"))
}
func TestQueue_DelayForAgent_Good_NoConfig(t *testing.T) {
// With no config, delay should be 0
t.Setenv("CORE_WORKSPACE", t.TempDir())
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}), codePath: t.TempDir()}
assert.Equal(t, 0, int(s.delayForAgent("gemini").Seconds()))
}