feat: restructure Core as unified struct with DTO pattern
Complete architectural overhaul of pkg/core:
- All subsystem types renamed to idiomatic Go (no stutter)
- Core struct: App, Embed, Fs, Config, ErrPan, ErrLog, Cli, Service, Lock, Ipc, I18n
- Exports consolidated in core.go, contracts/options in contract.go
- Service() unified get/register: c.Service(), c.Service("name"), c.Service("name", svc)
- Lock() named mutex map: c.Lock("srv"), c.Lock("ipc")
- Error system: Err/ErrLog/ErrPan + Log/LogErr/LogPan (shared ErrSink interface)
- CoreCommand with optional description (i18n resolves from command path)
- Tests moved to tests/ directory (black-box package core_test)
- Removed: ServiceFor/MustServiceFor, global instance, Display/Workspace/Crypt interfaces
- New files: app.go, fs.go, ipc.go, lock.go, i18n.go, task.go, runtime.go, contract.go
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-18 09:12:29 +00:00
|
|
|
package core_test
|
|
|
|
|
|
2026-01-30 09:02:16 +00:00
|
|
|
|
|
|
|
|
import (
|
feat: restructure Core as unified struct with DTO pattern
Complete architectural overhaul of pkg/core:
- All subsystem types renamed to idiomatic Go (no stutter)
- Core struct: App, Embed, Fs, Config, ErrPan, ErrLog, Cli, Service, Lock, Ipc, I18n
- Exports consolidated in core.go, contracts/options in contract.go
- Service() unified get/register: c.Service(), c.Service("name"), c.Service("name", svc)
- Lock() named mutex map: c.Lock("srv"), c.Lock("ipc")
- Error system: Err/ErrLog/ErrPan + Log/LogErr/LogPan (shared ErrSink interface)
- CoreCommand with optional description (i18n resolves from command path)
- Tests moved to tests/ directory (black-box package core_test)
- Removed: ServiceFor/MustServiceFor, global instance, Display/Workspace/Crypt interfaces
- New files: app.go, fs.go, ipc.go, lock.go, i18n.go, task.go, runtime.go, contract.go
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-18 09:12:29 +00:00
|
|
|
. "forge.lthn.ai/core/go/pkg/core"
|
2026-01-30 09:02:16 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type MockServiceWithIPC struct {
|
|
|
|
|
MockService
|
|
|
|
|
handled bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *MockServiceWithIPC) HandleIPCEvents(c *Core, msg Message) error {
|
|
|
|
|
m.handled = true
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCore_WithService_IPC(t *testing.T) {
|
|
|
|
|
svc := &MockServiceWithIPC{MockService: MockService{Name: "ipc-service"}}
|
|
|
|
|
factory := func(c *Core) (any, error) {
|
|
|
|
|
return svc, nil
|
|
|
|
|
}
|
|
|
|
|
c, err := New(WithService(factory))
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
// Trigger ACTION to verify handler was registered
|
|
|
|
|
err = c.ACTION(nil)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.True(t, svc.handled)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCore_ACTION_Bad(t *testing.T) {
|
|
|
|
|
c, err := New()
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
errHandler := func(c *Core, msg Message) error {
|
|
|
|
|
return assert.AnError
|
|
|
|
|
}
|
|
|
|
|
c.RegisterAction(errHandler)
|
|
|
|
|
err = c.ACTION(nil)
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
assert.Contains(t, err.Error(), assert.AnError.Error())
|
|
|
|
|
}
|