2026-03-24 23:07:02 +00:00
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
|
|
|
|
|
package agentic
|
|
|
|
|
|
|
|
|
|
import (
|
2026-03-26 06:38:02 +00:00
|
|
|
"context"
|
2026-03-24 23:07:02 +00:00
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
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
|
|
|
core "dappco.re/go/core"
|
2026-03-24 23:07:02 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// --- countRunningByModel ---
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestQueue_CountRunningByModel_Good_Empty(t *testing.T) {
|
2026-03-24 23:07:02 +00:00
|
|
|
root := t.TempDir()
|
|
|
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
|
|
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
|
|
|
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{})}
|
2026-03-24 23:07:02 +00:00
|
|
|
assert.Equal(t, 0, s.countRunningByModel("claude:opus"))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestQueue_CountRunningByModel_Good_SkipsNonRunning(t *testing.T) {
|
2026-03-24 23:07:02 +00:00
|
|
|
root := t.TempDir()
|
|
|
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
|
|
|
|
|
|
// Completed workspace — must not be counted
|
2026-03-26 01:39:41 +00:00
|
|
|
ws := core.JoinPath(root, "workspace", "test-ws")
|
2026-03-24 23:07:02 +00:00
|
|
|
require.True(t, fs.EnsureDir(ws).OK)
|
|
|
|
|
require.NoError(t, writeStatus(ws, &WorkspaceStatus{
|
|
|
|
|
Status: "completed",
|
|
|
|
|
Agent: "codex:gpt-5.4",
|
|
|
|
|
PID: 0,
|
|
|
|
|
}))
|
|
|
|
|
|
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
|
|
|
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{})}
|
2026-03-24 23:07:02 +00:00
|
|
|
assert.Equal(t, 0, s.countRunningByModel("codex:gpt-5.4"))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestQueue_CountRunningByModel_Good_SkipsMismatchedModel(t *testing.T) {
|
2026-03-24 23:07:02 +00:00
|
|
|
root := t.TempDir()
|
|
|
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
|
|
2026-03-26 01:39:41 +00:00
|
|
|
ws := core.JoinPath(root, "workspace", "model-ws")
|
2026-03-24 23:07:02 +00:00
|
|
|
require.True(t, fs.EnsureDir(ws).OK)
|
|
|
|
|
require.NoError(t, writeStatus(ws, &WorkspaceStatus{
|
|
|
|
|
Status: "running",
|
|
|
|
|
Agent: "gemini:flash",
|
|
|
|
|
PID: 0,
|
|
|
|
|
}))
|
|
|
|
|
|
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
|
|
|
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{})}
|
2026-03-24 23:07:02 +00:00
|
|
|
// Asking for gemini:pro — must not count gemini:flash
|
|
|
|
|
assert.Equal(t, 0, s.countRunningByModel("gemini:pro"))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestQueue_CountRunningByModel_Good_DeepLayout(t *testing.T) {
|
2026-03-24 23:07:02 +00:00
|
|
|
root := t.TempDir()
|
|
|
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
|
|
|
|
|
|
// Deep layout: workspace/org/repo/task-N/status.json
|
2026-03-26 01:39:41 +00:00
|
|
|
ws := core.JoinPath(root, "workspace", "core", "go-io", "task-1")
|
2026-03-24 23:07:02 +00:00
|
|
|
require.True(t, fs.EnsureDir(ws).OK)
|
|
|
|
|
require.NoError(t, writeStatus(ws, &WorkspaceStatus{
|
|
|
|
|
Status: "completed",
|
|
|
|
|
Agent: "codex:gpt-5.4",
|
|
|
|
|
}))
|
|
|
|
|
|
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
|
|
|
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{})}
|
2026-03-24 23:07:02 +00:00
|
|
|
// Completed, so count is still 0
|
|
|
|
|
assert.Equal(t, 0, s.countRunningByModel("codex:gpt-5.4"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- drainQueue ---
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestQueue_DrainQueue_Good_FrozenReturnsImmediately(t *testing.T) {
|
2026-03-24 23:07:02 +00:00
|
|
|
root := t.TempDir()
|
|
|
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
|
|
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
|
|
|
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}), frozen: true, backoff: make(map[string]time.Time), failCount: make(map[string]int)}
|
2026-03-24 23:07:02 +00:00
|
|
|
// Must not panic and must not block
|
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
|
s.drainQueue()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestQueue_DrainQueue_Good_EmptyWorkspace(t *testing.T) {
|
2026-03-24 23:07:02 +00:00
|
|
|
root := t.TempDir()
|
|
|
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
|
|
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
|
|
|
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}), frozen: false, backoff: make(map[string]time.Time), failCount: make(map[string]int)}
|
2026-03-24 23:07:02 +00:00
|
|
|
// No workspaces — must return without error/panic
|
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
|
s.drainQueue()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Poke ---
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestRunner_Poke_Good_NilChannel(t *testing.T) {
|
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
|
|
|
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}), pokeCh: nil}
|
2026-03-24 23:07:02 +00:00
|
|
|
// Must not panic when pokeCh is nil
|
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
|
s.Poke()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestRunner_Poke_Good_ChannelReceivesSignal(t *testing.T) {
|
2026-03-26 11:19:45 +00:00
|
|
|
// Poke is now a no-op — queue poke is owned by pkg/runner.Service.
|
|
|
|
|
// Verify it does not send to the channel and does not panic.
|
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
|
|
|
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{})}
|
2026-03-24 23:07:02 +00:00
|
|
|
s.pokeCh = make(chan struct{}, 1)
|
|
|
|
|
|
2026-03-26 11:19:45 +00:00
|
|
|
assert.NotPanics(t, func() { s.Poke() })
|
|
|
|
|
assert.Len(t, s.pokeCh, 0, "no-op poke should not enqueue a signal")
|
2026-03-24 23:07:02 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestRunner_Poke_Good_NonBlockingWhenFull(t *testing.T) {
|
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
|
|
|
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{})}
|
2026-03-24 23:07:02 +00:00
|
|
|
s.pokeCh = make(chan struct{}, 1)
|
|
|
|
|
// Pre-fill the channel
|
|
|
|
|
s.pokeCh <- struct{}{}
|
|
|
|
|
|
|
|
|
|
// Second poke must not block or panic
|
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
|
s.Poke()
|
|
|
|
|
})
|
|
|
|
|
assert.Len(t, s.pokeCh, 1, "channel length should remain 1")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- StartRunner ---
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestRunner_StartRunner_Good_CreatesPokeCh(t *testing.T) {
|
2026-03-26 11:19:45 +00:00
|
|
|
// StartRunner is now a no-op — queue drain is owned by pkg/runner.Service.
|
|
|
|
|
// Verify it does not panic and does not set pokeCh.
|
2026-03-24 23:07:02 +00:00
|
|
|
root := t.TempDir()
|
|
|
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
|
t.Setenv("CORE_AGENT_DISPATCH", "")
|
|
|
|
|
|
|
|
|
|
s := NewPrep()
|
|
|
|
|
assert.Nil(t, s.pokeCh)
|
|
|
|
|
|
2026-03-26 11:19:45 +00:00
|
|
|
assert.NotPanics(t, func() { s.StartRunner() })
|
|
|
|
|
assert.Nil(t, s.pokeCh, "no-op StartRunner should not initialise pokeCh")
|
2026-03-24 23:07:02 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestRunner_StartRunner_Good_FrozenByDefault(t *testing.T) {
|
2026-03-26 11:19:45 +00:00
|
|
|
// StartRunner is now a no-op — frozen state is owned by pkg/runner.Service.
|
|
|
|
|
// Verify it does not panic; frozen state is not managed here.
|
2026-03-24 23:07:02 +00:00
|
|
|
root := t.TempDir()
|
|
|
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
|
t.Setenv("CORE_AGENT_DISPATCH", "")
|
|
|
|
|
|
|
|
|
|
s := NewPrep()
|
2026-03-26 11:19:45 +00:00
|
|
|
assert.NotPanics(t, func() { s.StartRunner() })
|
2026-03-24 23:07:02 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestRunner_StartRunner_Good_AutoStartEnvVar(t *testing.T) {
|
2026-03-26 11:19:45 +00:00
|
|
|
// StartRunner is now a no-op — env var handling is in pkg/runner.Service.
|
|
|
|
|
// Verify the no-op does not panic.
|
2026-03-24 23:07:02 +00:00
|
|
|
root := t.TempDir()
|
|
|
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
|
t.Setenv("CORE_AGENT_DISPATCH", "1")
|
|
|
|
|
|
|
|
|
|
s := NewPrep()
|
2026-03-26 11:19:45 +00:00
|
|
|
assert.NotPanics(t, func() { s.StartRunner() })
|
2026-03-24 23:07:02 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 09:31:38 +00:00
|
|
|
// --- Poke Ugly ---
|
|
|
|
|
|
|
|
|
|
func TestRunner_Poke_Ugly(t *testing.T) {
|
|
|
|
|
// Poke on a closed channel — the select with default protects against panic
|
|
|
|
|
// but closing + sending would panic. However, Poke uses non-blocking send,
|
|
|
|
|
// so we test that pokeCh=nil is safe (already tested), and that
|
|
|
|
|
// double-filling is safe (already tested). Here we test rapid multi-poke.
|
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
|
|
|
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{})}
|
2026-03-25 09:31:38 +00:00
|
|
|
s.pokeCh = make(chan struct{}, 1)
|
|
|
|
|
|
|
|
|
|
// Rapid-fire pokes — should all be safe
|
|
|
|
|
for i := 0; i < 100; i++ {
|
|
|
|
|
assert.NotPanics(t, func() { s.Poke() })
|
|
|
|
|
}
|
|
|
|
|
// Channel should have at most 1 signal
|
|
|
|
|
assert.LessOrEqual(t, len(s.pokeCh), 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- StartRunner Bad/Ugly ---
|
|
|
|
|
|
|
|
|
|
func TestRunner_StartRunner_Bad(t *testing.T) {
|
2026-03-26 11:19:45 +00:00
|
|
|
// StartRunner is now a no-op — frozen state and pokeCh are owned by pkg/runner.Service.
|
|
|
|
|
// Verify the no-op does not panic and does not modify state.
|
2026-03-25 09:31:38 +00:00
|
|
|
root := t.TempDir()
|
|
|
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
|
t.Setenv("CORE_AGENT_DISPATCH", "")
|
|
|
|
|
|
|
|
|
|
s := NewPrep()
|
2026-03-26 11:19:45 +00:00
|
|
|
assert.NotPanics(t, func() { s.StartRunner() })
|
|
|
|
|
assert.Nil(t, s.pokeCh, "no-op StartRunner should not create pokeCh")
|
2026-03-25 09:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRunner_StartRunner_Ugly(t *testing.T) {
|
2026-03-26 11:19:45 +00:00
|
|
|
// StartRunner is now a no-op — calling it multiple times must not panic.
|
2026-03-25 09:31:38 +00:00
|
|
|
root := t.TempDir()
|
|
|
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
|
t.Setenv("CORE_AGENT_DISPATCH", "1")
|
|
|
|
|
|
|
|
|
|
s := NewPrep()
|
|
|
|
|
|
2026-03-26 11:19:45 +00:00
|
|
|
// Call twice — both are no-ops, must not panic
|
|
|
|
|
assert.NotPanics(t, func() { s.StartRunner() })
|
|
|
|
|
assert.NotPanics(t, func() { s.StartRunner() })
|
|
|
|
|
assert.Nil(t, s.pokeCh, "no-op StartRunner should not create pokeCh")
|
2026-03-25 09:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 23:07:02 +00:00
|
|
|
// --- DefaultBranch ---
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestPaths_DefaultBranch_Good_DefaultsToMain(t *testing.T) {
|
2026-03-24 23:07:02 +00:00
|
|
|
// Non-git temp dir — git commands fail, fallback is "main"
|
|
|
|
|
dir := t.TempDir()
|
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
|
|
|
branch := testPrep.DefaultBranch(dir)
|
2026-03-24 23:07:02 +00:00
|
|
|
assert.Equal(t, "main", branch)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestPaths_DefaultBranch_Good_RealGitRepo(t *testing.T) {
|
2026-03-24 23:07:02 +00:00
|
|
|
dir := t.TempDir()
|
|
|
|
|
// Init a real git repo with a main branch
|
|
|
|
|
require.NoError(t, runGitInit(dir))
|
|
|
|
|
|
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
|
|
|
branch := testPrep.DefaultBranch(dir)
|
2026-03-24 23:07:02 +00:00
|
|
|
// Any valid branch name — just must not panic or be empty
|
|
|
|
|
assert.NotEmpty(t, branch)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- LocalFs ---
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestPaths_LocalFs_Good_NonNil(t *testing.T) {
|
2026-03-24 23:07:02 +00:00
|
|
|
f := LocalFs()
|
|
|
|
|
assert.NotNil(t, f, "LocalFs should return a non-nil *core.Fs")
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 08:32:08 +00:00
|
|
|
func TestPaths_LocalFs_Good_CanRead(t *testing.T) {
|
2026-03-24 23:07:02 +00:00
|
|
|
dir := t.TempDir()
|
2026-03-26 01:39:41 +00:00
|
|
|
path := core.JoinPath(dir, "hello.txt")
|
2026-03-24 23:07:02 +00:00
|
|
|
require.True(t, fs.Write(path, "hello").OK)
|
|
|
|
|
|
|
|
|
|
f := LocalFs()
|
|
|
|
|
r := f.Read(path)
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
assert.Equal(t, "hello", r.Value.(string))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- helpers ---
|
|
|
|
|
|
test: batch 5 — proc.go GBU + getGitLog + runGoTests + prepWorkspace — 836 tests
New: proc_test.go with 28 tests for all proc.go helpers (runCmd, gitCmd,
gitOutput, processIsRunning, processKill, ensureProcess).
Plus: getGitLog GBU, runGoTests GBU, prepWorkspace Good,
listLocalRepos Ugly, loadRateLimitState Bad, runLoop skips.
AX-7: 501/543 filled (92%), 167/181 functions complete
Coverage: 78.5%, 836 tests
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 10:20:50 +00:00
|
|
|
// --- RunLoop ---
|
|
|
|
|
|
|
|
|
|
func TestRunner_RunLoop_Good(t *testing.T) {
|
|
|
|
|
t.Skip("blocking goroutine — tested indirectly via StartRunner")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRunner_RunLoop_Bad(t *testing.T) {
|
|
|
|
|
t.Skip("blocking goroutine — tested indirectly via StartRunner")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRunner_RunLoop_Ugly(t *testing.T) {
|
|
|
|
|
t.Skip("blocking goroutine — tested indirectly via StartRunner")
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 23:07:02 +00:00
|
|
|
// runGitInit initialises a bare git repo with one commit so branch detection works.
|
|
|
|
|
func runGitInit(dir string) error {
|
|
|
|
|
cmds := [][]string{
|
|
|
|
|
{"git", "init", "-b", "main"},
|
|
|
|
|
{"git", "config", "user.email", "test@test.com"},
|
|
|
|
|
{"git", "config", "user.name", "Test"},
|
|
|
|
|
{"git", "commit", "--allow-empty", "-m", "init"},
|
|
|
|
|
}
|
|
|
|
|
for _, args := range cmds {
|
2026-03-26 06:38:02 +00:00
|
|
|
r := testCore.Process().RunIn(context.Background(), dir, args[0], args[1:]...)
|
|
|
|
|
if !r.OK {
|
|
|
|
|
return core.E("runGitInit", core.Sprintf("cmd %v failed", args), nil)
|
2026-03-24 23:07:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|