fix(ax): make core-agent bootstrap testable
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
bf3aae5766
commit
07942b5d27
4 changed files with 96 additions and 1 deletions
|
|
@ -12,6 +12,15 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
newCoreAgent().Run()
|
||||
}
|
||||
|
||||
// newCoreAgent builds the Core app with services and CLI commands wired for startup.
|
||||
//
|
||||
// c := newCoreAgent()
|
||||
// core.Println(c.App().Name) // "core-agent"
|
||||
// core.Println(c.App().Version) // "dev" or linked version
|
||||
func newCoreAgent() *core.Core {
|
||||
c := core.New(
|
||||
core.WithOption("name", "core-agent"),
|
||||
core.WithService(agentic.ProcessRegister),
|
||||
|
|
@ -29,7 +38,7 @@ func main() {
|
|||
|
||||
registerAppCommands(c)
|
||||
|
||||
c.Run()
|
||||
return c
|
||||
}
|
||||
|
||||
// appVersion resolves the build version injected at link time.
|
||||
|
|
|
|||
|
|
@ -4,6 +4,21 @@ package main
|
|||
|
||||
import core "dappco.re/go/core"
|
||||
|
||||
func Example_newCoreAgent() {
|
||||
oldVersion := version
|
||||
version = "0.15.0"
|
||||
defer func() { version = oldVersion }()
|
||||
|
||||
c := newCoreAgent()
|
||||
core.Println(c.App().Name)
|
||||
core.Println(c.App().Version)
|
||||
core.Println(len(c.Commands()) >= 3)
|
||||
// Output:
|
||||
// core-agent
|
||||
// 0.15.0
|
||||
// true
|
||||
}
|
||||
|
||||
func Example_appVersion() {
|
||||
oldVersion := version
|
||||
version = "0.15.0"
|
||||
|
|
|
|||
69
cmd/core-agent/main_test.go
Normal file
69
cmd/core-agent/main_test.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"dappco.re/go/agent/pkg/agentic"
|
||||
"dappco.re/go/agent/pkg/brain"
|
||||
"dappco.re/go/agent/pkg/monitor"
|
||||
"dappco.re/go/agent/pkg/runner"
|
||||
"dappco.re/go/core"
|
||||
"forge.lthn.ai/core/mcp/pkg/mcp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func withVersion(t *testing.T, value string) {
|
||||
t.Helper()
|
||||
oldVersion := version
|
||||
version = value
|
||||
t.Cleanup(func() { version = oldVersion })
|
||||
}
|
||||
|
||||
func TestMain_NewCoreAgent_Good_RegistersRuntime(t *testing.T) {
|
||||
withVersion(t, "0.15.0")
|
||||
|
||||
c := newCoreAgent()
|
||||
|
||||
assert.Equal(t, "core-agent", c.App().Name)
|
||||
assert.Equal(t, "0.15.0", c.App().Version)
|
||||
assert.Contains(t, c.Services(), "process")
|
||||
assert.Contains(t, c.Services(), "agentic")
|
||||
assert.Contains(t, c.Services(), "runner")
|
||||
assert.Contains(t, c.Services(), "monitor")
|
||||
assert.Contains(t, c.Services(), "brain")
|
||||
assert.Contains(t, c.Services(), "mcp")
|
||||
assert.Contains(t, c.Commands(), "version")
|
||||
assert.Contains(t, c.Commands(), "check")
|
||||
assert.Contains(t, c.Commands(), "env")
|
||||
assert.Contains(t, c.Actions(), "process.run")
|
||||
|
||||
_, ok := core.ServiceFor[*agentic.PrepSubsystem](c, "agentic")
|
||||
assert.True(t, ok)
|
||||
_, ok = core.ServiceFor[*runner.Service](c, "runner")
|
||||
assert.True(t, ok)
|
||||
_, ok = core.ServiceFor[*monitor.Subsystem](c, "monitor")
|
||||
assert.True(t, ok)
|
||||
_, ok = core.ServiceFor[*brain.DirectSubsystem](c, "brain")
|
||||
assert.True(t, ok)
|
||||
_, ok = core.ServiceFor[*mcp.Service](c, "mcp")
|
||||
assert.True(t, ok)
|
||||
}
|
||||
|
||||
func TestMain_NewCoreAgent_Good_BannerUsesVersion(t *testing.T) {
|
||||
withVersion(t, "0.15.0")
|
||||
|
||||
c := newCoreAgent()
|
||||
|
||||
assert.Equal(t, "core-agent 0.15.0 — agentic orchestration for the Core ecosystem", c.Cli().Banner())
|
||||
}
|
||||
|
||||
func TestMain_NewCoreAgent_Ugly_DevVersionFallback(t *testing.T) {
|
||||
withVersion(t, "")
|
||||
|
||||
c := newCoreAgent()
|
||||
|
||||
assert.Equal(t, "dev", c.App().Version)
|
||||
assert.Equal(t, "core-agent dev — agentic orchestration for the Core ecosystem", c.Cli().Banner())
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
package lib
|
||||
|
||||
import (
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue