agent/pkg/messages/messages_test.go

63 lines
2 KiB
Go
Raw Permalink Normal View History

// SPDX-License-Identifier: EUPL-1.2
package messages
import (
"testing"
core "dappco.re/go/core"
"github.com/stretchr/testify/assert"
)
feat: AX v0.8.0 upgrade — Core features + quality gates AX Quality Gates (RFC-025): - Eliminate os/exec from all test + production code (12+ files) - Eliminate encoding/json from all test files (15 files, 66 occurrences) - Eliminate os from all test files except TestMain (Go runtime contract) - Eliminate path/filepath, net/url from all files - String concat: 39 violations replaced with core.Concat() - Test naming AX-7: 264 test functions renamed across all 6 packages - Example test 1:1 coverage complete Core Features Adopted: - Task Composition: agent.completion pipeline (QA → PR → Verify → Ingest → Poke) - PerformAsync: completion pipeline runs with WaitGroup + progress tracking - Config: agents.yaml loaded once, feature flags (auto-qa/pr/merge/ingest) - Named Locks: c.Lock("drain") for queue serialisation - Registry: workspace state with cross-package QUERY access - QUERY: c.QUERY(WorkspaceQuery{Status: "running"}) for cross-service queries - Action descriptions: 25+ Actions self-documenting - Data mounts: prompts/tasks/flows/personas/workspaces via c.Data() - Content Actions: agentic.prompt/task/flow/persona callable via IPC - Drive endpoints: forge + brain registered with tokens - Drive REST helpers: DriveGet/DrivePost/DriveDo for Drive-aware HTTP - HandleIPCEvents: auto-discovered by WithService (no manual wiring) - Entitlement: frozen-queue gate on write Actions - CLI dispatch: workspace dispatch wired to real dispatch method - CLI: --quiet/-q and --debug/-d global flags - CLI: banner, version, check (with service/action/command counts), env - main.go: minimal — 5 services + c.Run(), no os import - cmd tests: 84.2% coverage (was 0%) Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 06:38:02 +00:00
// TestMessages_AllSatisfyMessage_Good verifies every message type can be
// used as a core.Message (which is `any`). Compile-time + runtime check.
func TestMessages_AllSatisfyMessage_Good(t *testing.T) {
msgs := []core.Message{
AgentStarted{Agent: "codex", Repo: "go-io", Workspace: "core/go-io/task-5"},
AgentCompleted{Agent: "codex", Repo: "go-io", Workspace: "core/go-io/task-5", Status: "completed"},
QAResult{Workspace: "core/go-io/task-5", Repo: "go-io", Passed: true},
PRCreated{Repo: "go-io", Branch: "agent/fix", PRURL: "https://forge.lthn.ai/core/go-io/pulls/1", PRNum: 1},
PRMerged{Repo: "go-io", PRURL: "https://forge.lthn.ai/core/go-io/pulls/1", PRNum: 1},
WorkspacePushed{Repo: "go-io", Branch: "agent/fix", Org: "core"},
PRNeedsReview{Repo: "go-io", PRNum: 1, Reason: "merge conflict"},
QueueDrained{Completed: 3},
PokeQueue{},
RateLimitDetected{Pool: "codex", Duration: "30m"},
HarvestComplete{Repo: "go-io", Branch: "agent/fix", Files: 5},
HarvestRejected{Repo: "go-io", Branch: "agent/fix", Reason: "binary detected"},
InboxMessage{New: 1, Total: 3},
}
assert.Len(t, msgs, 13, "expected 13 message types")
for _, msg := range msgs {
assert.NotNil(t, msg)
}
}
feat: AX v0.8.0 upgrade — Core features + quality gates AX Quality Gates (RFC-025): - Eliminate os/exec from all test + production code (12+ files) - Eliminate encoding/json from all test files (15 files, 66 occurrences) - Eliminate os from all test files except TestMain (Go runtime contract) - Eliminate path/filepath, net/url from all files - String concat: 39 violations replaced with core.Concat() - Test naming AX-7: 264 test functions renamed across all 6 packages - Example test 1:1 coverage complete Core Features Adopted: - Task Composition: agent.completion pipeline (QA → PR → Verify → Ingest → Poke) - PerformAsync: completion pipeline runs with WaitGroup + progress tracking - Config: agents.yaml loaded once, feature flags (auto-qa/pr/merge/ingest) - Named Locks: c.Lock("drain") for queue serialisation - Registry: workspace state with cross-package QUERY access - QUERY: c.QUERY(WorkspaceQuery{Status: "running"}) for cross-service queries - Action descriptions: 25+ Actions self-documenting - Data mounts: prompts/tasks/flows/personas/workspaces via c.Data() - Content Actions: agentic.prompt/task/flow/persona callable via IPC - Drive endpoints: forge + brain registered with tokens - Drive REST helpers: DriveGet/DrivePost/DriveDo for Drive-aware HTTP - HandleIPCEvents: auto-discovered by WithService (no manual wiring) - Entitlement: frozen-queue gate on write Actions - CLI dispatch: workspace dispatch wired to real dispatch method - CLI: --quiet/-q and --debug/-d global flags - CLI: banner, version, check (with service/action/command counts), env - main.go: minimal — 5 services + c.Run(), no os import - cmd tests: 84.2% coverage (was 0%) Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 06:38:02 +00:00
// TestMessages_TypeSwitch_Good verifies the IPC dispatch pattern works.
func TestMessages_TypeSwitch_Good(t *testing.T) {
var msg core.Message = AgentCompleted{
Agent: "codex",
Repo: "go-io",
Workspace: "core/go-io/task-5",
Status: "completed",
}
handled := false
switch ev := msg.(type) {
case AgentCompleted:
assert.Equal(t, "codex", ev.Agent)
assert.Equal(t, "go-io", ev.Repo)
assert.Equal(t, "completed", ev.Status)
handled = true
}
assert.True(t, handled)
}
feat: AX v0.8.0 upgrade — Core features + quality gates AX Quality Gates (RFC-025): - Eliminate os/exec from all test + production code (12+ files) - Eliminate encoding/json from all test files (15 files, 66 occurrences) - Eliminate os from all test files except TestMain (Go runtime contract) - Eliminate path/filepath, net/url from all files - String concat: 39 violations replaced with core.Concat() - Test naming AX-7: 264 test functions renamed across all 6 packages - Example test 1:1 coverage complete Core Features Adopted: - Task Composition: agent.completion pipeline (QA → PR → Verify → Ingest → Poke) - PerformAsync: completion pipeline runs with WaitGroup + progress tracking - Config: agents.yaml loaded once, feature flags (auto-qa/pr/merge/ingest) - Named Locks: c.Lock("drain") for queue serialisation - Registry: workspace state with cross-package QUERY access - QUERY: c.QUERY(WorkspaceQuery{Status: "running"}) for cross-service queries - Action descriptions: 25+ Actions self-documenting - Data mounts: prompts/tasks/flows/personas/workspaces via c.Data() - Content Actions: agentic.prompt/task/flow/persona callable via IPC - Drive endpoints: forge + brain registered with tokens - Drive REST helpers: DriveGet/DrivePost/DriveDo for Drive-aware HTTP - HandleIPCEvents: auto-discovered by WithService (no manual wiring) - Entitlement: frozen-queue gate on write Actions - CLI dispatch: workspace dispatch wired to real dispatch method - CLI: --quiet/-q and --debug/-d global flags - CLI: banner, version, check (with service/action/command counts), env - main.go: minimal — 5 services + c.Run(), no os import - cmd tests: 84.2% coverage (was 0%) Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 06:38:02 +00:00
// TestMessages_EmptySignal_Good verifies zero-field messages work as signals.
func TestMessages_EmptySignal_Good(t *testing.T) {
var msg core.Message = PokeQueue{}
_, ok := msg.(PokeQueue)
assert.True(t, ok)
}