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 (
|
|
|
|
|
"testing"
|
|
|
|
|
|
test: rewrite test suite for AX primitives API
164 tests, 41.3% coverage. Tests written against the public API only
(external test package, no _test.go in pkg/core/).
Covers: New(Options), Data, Drive, Config, Service, Error, IPC,
Fs, Cli, Lock, Array, Log, App, Runtime, Task.
Fixes: NewCommand now inits flagset, New() wires Cli root command.
Old tests removed — they referenced With*, RegisterService, and
other patterns that no longer exist.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 08:42:38 +00:00
|
|
|
. "forge.lthn.ai/core/go/pkg/core"
|
2026-01-30 09:02:16 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
test: rewrite test suite for AX primitives API
164 tests, 41.3% coverage. Tests written against the public API only
(external test package, no _test.go in pkg/core/).
Covers: New(Options), Data, Drive, Config, Service, Error, IPC,
Fs, Cli, Lock, Array, Log, App, Runtime, Task.
Fixes: NewCommand now inits flagset, New() wires Cli root command.
Old tests removed — they referenced With*, RegisterService, and
other patterns that no longer exist.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 08:42:38 +00:00
|
|
|
// --- New ---
|
2026-01-30 09:02:16 +00:00
|
|
|
|
test: rewrite test suite for AX primitives API
164 tests, 41.3% coverage. Tests written against the public API only
(external test package, no _test.go in pkg/core/).
Covers: New(Options), Data, Drive, Config, Service, Error, IPC,
Fs, Cli, Lock, Array, Log, App, Runtime, Task.
Fixes: NewCommand now inits flagset, New() wires Cli root command.
Old tests removed — they referenced With*, RegisterService, and
other patterns that no longer exist.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 08:42:38 +00:00
|
|
|
func TestNew_Good(t *testing.T) {
|
|
|
|
|
c := New()
|
2026-01-30 09:02:16 +00:00
|
|
|
assert.NotNil(t, c)
|
|
|
|
|
}
|
|
|
|
|
|
test: rewrite test suite for AX primitives API
164 tests, 41.3% coverage. Tests written against the public API only
(external test package, no _test.go in pkg/core/).
Covers: New(Options), Data, Drive, Config, Service, Error, IPC,
Fs, Cli, Lock, Array, Log, App, Runtime, Task.
Fixes: NewCommand now inits flagset, New() wires Cli root command.
Old tests removed — they referenced With*, RegisterService, and
other patterns that no longer exist.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 08:42:38 +00:00
|
|
|
func TestNew_WithOptions_Good(t *testing.T) {
|
|
|
|
|
c := New(Options{{K: "name", V: "myapp"}})
|
|
|
|
|
assert.NotNil(t, c)
|
|
|
|
|
assert.Equal(t, "myapp", c.App().Name)
|
2026-01-30 09:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
test: rewrite test suite for AX primitives API
164 tests, 41.3% coverage. Tests written against the public API only
(external test package, no _test.go in pkg/core/).
Covers: New(Options), Data, Drive, Config, Service, Error, IPC,
Fs, Cli, Lock, Array, Log, App, Runtime, Task.
Fixes: NewCommand now inits flagset, New() wires Cli root command.
Old tests removed — they referenced With*, RegisterService, and
other patterns that no longer exist.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 08:42:38 +00:00
|
|
|
func TestNew_WithOptions_Bad(t *testing.T) {
|
|
|
|
|
// Empty options — should still create a valid Core
|
|
|
|
|
c := New(Options{})
|
|
|
|
|
assert.NotNil(t, c)
|
2026-01-30 09:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
test: rewrite test suite for AX primitives API
164 tests, 41.3% coverage. Tests written against the public API only
(external test package, no _test.go in pkg/core/).
Covers: New(Options), Data, Drive, Config, Service, Error, IPC,
Fs, Cli, Lock, Array, Log, App, Runtime, Task.
Fixes: NewCommand now inits flagset, New() wires Cli root command.
Old tests removed — they referenced With*, RegisterService, and
other patterns that no longer exist.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 08:42:38 +00:00
|
|
|
// --- Accessors ---
|
|
|
|
|
|
|
|
|
|
func TestAccessors_Good(t *testing.T) {
|
|
|
|
|
c := New()
|
|
|
|
|
assert.NotNil(t, c.App())
|
|
|
|
|
assert.NotNil(t, c.Data())
|
|
|
|
|
assert.NotNil(t, c.Drive())
|
|
|
|
|
assert.NotNil(t, c.Fs())
|
|
|
|
|
assert.NotNil(t, c.Config())
|
|
|
|
|
assert.NotNil(t, c.Error())
|
|
|
|
|
assert.NotNil(t, c.Log())
|
|
|
|
|
assert.NotNil(t, c.Cli())
|
|
|
|
|
assert.NotNil(t, c.IPC())
|
|
|
|
|
assert.NotNil(t, c.I18n())
|
2026-01-30 09:02:16 +00:00
|
|
|
assert.Equal(t, c, c.Core())
|
|
|
|
|
}
|
|
|
|
|
|
test: rewrite test suite for AX primitives API
164 tests, 41.3% coverage. Tests written against the public API only
(external test package, no _test.go in pkg/core/).
Covers: New(Options), Data, Drive, Config, Service, Error, IPC,
Fs, Cli, Lock, Array, Log, App, Runtime, Task.
Fixes: NewCommand now inits flagset, New() wires Cli root command.
Old tests removed — they referenced With*, RegisterService, and
other patterns that no longer exist.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 08:42:38 +00:00
|
|
|
func TestOptions_Accessor_Good(t *testing.T) {
|
|
|
|
|
c := New(Options{
|
|
|
|
|
{K: "name", V: "testapp"},
|
|
|
|
|
{K: "port", V: 8080},
|
|
|
|
|
{K: "debug", V: true},
|
2026-02-05 11:00:49 +00:00
|
|
|
})
|
test: rewrite test suite for AX primitives API
164 tests, 41.3% coverage. Tests written against the public API only
(external test package, no _test.go in pkg/core/).
Covers: New(Options), Data, Drive, Config, Service, Error, IPC,
Fs, Cli, Lock, Array, Log, App, Runtime, Task.
Fixes: NewCommand now inits flagset, New() wires Cli root command.
Old tests removed — they referenced With*, RegisterService, and
other patterns that no longer exist.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 08:42:38 +00:00
|
|
|
opts := c.Options()
|
|
|
|
|
assert.NotNil(t, opts)
|
|
|
|
|
assert.Equal(t, "testapp", opts.String("name"))
|
|
|
|
|
assert.Equal(t, 8080, opts.Int("port"))
|
|
|
|
|
assert.True(t, opts.Bool("debug"))
|
2026-01-30 09:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
test: rewrite test suite for AX primitives API
164 tests, 41.3% coverage. Tests written against the public API only
(external test package, no _test.go in pkg/core/).
Covers: New(Options), Data, Drive, Config, Service, Error, IPC,
Fs, Cli, Lock, Array, Log, App, Runtime, Task.
Fixes: NewCommand now inits flagset, New() wires Cli root command.
Old tests removed — they referenced With*, RegisterService, and
other patterns that no longer exist.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 08:42:38 +00:00
|
|
|
func TestOptions_Accessor_Nil(t *testing.T) {
|
|
|
|
|
c := New()
|
|
|
|
|
// No options passed — Options() returns nil
|
|
|
|
|
assert.Nil(t, c.Options())
|
2026-02-01 16:03:44 +00:00
|
|
|
}
|
test: 200 tests, 50.2% coverage — Data, I18n, Fs, Log, Embed, Runtime
New tests: Data List/ListNames/Extract, I18n with mock Translator,
Fs full surface (EnsureDir, IsDir, IsFile, Exists, List, Stat, Open,
Create, Append, ReadStream, WriteStream, Delete, DeleteAll, Rename),
Log all levels + Security + Username + Default + LogErr + LogPan,
Embed ScanAssets + GeneratePack + MountEmbed, Runtime ServiceName,
Core LogError/LogWarn/Must helpers.
Fixes: NewCommand inits flagset, New() wires Cli root command + app.
Remaining 0% (excluding CLI/App): compress, getAllFiles (internal),
Reports/appendReport (needs ErrorPanic filePath), SetOutput (trivial).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 10:49:33 +00:00
|
|
|
|
|
|
|
|
// --- Core Error/Log Helpers ---
|
|
|
|
|
|
|
|
|
|
func TestCore_LogError_Good(t *testing.T) {
|
|
|
|
|
c := New()
|
|
|
|
|
cause := assert.AnError
|
feat: IPC, task, lifecycle all return Result
Action, Query, QueryAll, Perform → Result
QueryHandler, TaskHandler → func returning Result
RegisterAction/RegisterActions → handler returns Result
ServiceStartup, ServiceShutdown → Result
LogError, LogWarn → Result
ACTION, QUERY, QUERYALL, PERFORM aliases → Result
Tests updated to match new signatures.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 13:59:45 +00:00
|
|
|
r := c.LogError(cause, "test.Op", "something broke")
|
|
|
|
|
assert.False(t, r.OK)
|
|
|
|
|
err, ok := r.Value.(error)
|
|
|
|
|
assert.True(t, ok)
|
test: 200 tests, 50.2% coverage — Data, I18n, Fs, Log, Embed, Runtime
New tests: Data List/ListNames/Extract, I18n with mock Translator,
Fs full surface (EnsureDir, IsDir, IsFile, Exists, List, Stat, Open,
Create, Append, ReadStream, WriteStream, Delete, DeleteAll, Rename),
Log all levels + Security + Username + Default + LogErr + LogPan,
Embed ScanAssets + GeneratePack + MountEmbed, Runtime ServiceName,
Core LogError/LogWarn/Must helpers.
Fixes: NewCommand inits flagset, New() wires Cli root command + app.
Remaining 0% (excluding CLI/App): compress, getAllFiles (internal),
Reports/appendReport (needs ErrorPanic filePath), SetOutput (trivial).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 10:49:33 +00:00
|
|
|
assert.ErrorIs(t, err, cause)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCore_LogWarn_Good(t *testing.T) {
|
|
|
|
|
c := New()
|
feat: IPC, task, lifecycle all return Result
Action, Query, QueryAll, Perform → Result
QueryHandler, TaskHandler → func returning Result
RegisterAction/RegisterActions → handler returns Result
ServiceStartup, ServiceShutdown → Result
LogError, LogWarn → Result
ACTION, QUERY, QUERYALL, PERFORM aliases → Result
Tests updated to match new signatures.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 13:59:45 +00:00
|
|
|
r := c.LogWarn(assert.AnError, "test.Op", "heads up")
|
|
|
|
|
assert.False(t, r.OK)
|
|
|
|
|
_, ok := r.Value.(error)
|
|
|
|
|
assert.True(t, ok)
|
test: 200 tests, 50.2% coverage — Data, I18n, Fs, Log, Embed, Runtime
New tests: Data List/ListNames/Extract, I18n with mock Translator,
Fs full surface (EnsureDir, IsDir, IsFile, Exists, List, Stat, Open,
Create, Append, ReadStream, WriteStream, Delete, DeleteAll, Rename),
Log all levels + Security + Username + Default + LogErr + LogPan,
Embed ScanAssets + GeneratePack + MountEmbed, Runtime ServiceName,
Core LogError/LogWarn/Must helpers.
Fixes: NewCommand inits flagset, New() wires Cli root command + app.
Remaining 0% (excluding CLI/App): compress, getAllFiles (internal),
Reports/appendReport (needs ErrorPanic filePath), SetOutput (trivial).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 10:49:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCore_Must_Ugly(t *testing.T) {
|
|
|
|
|
c := New()
|
|
|
|
|
assert.Panics(t, func() {
|
|
|
|
|
c.Must(assert.AnError, "test.Op", "fatal")
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCore_Must_Nil_Good(t *testing.T) {
|
|
|
|
|
c := New()
|
|
|
|
|
assert.NotPanics(t, func() {
|
|
|
|
|
c.Must(nil, "test.Op", "no error")
|
|
|
|
|
})
|
|
|
|
|
}
|