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
|
|
|
package core_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2026-03-20 21:00:48 +00:00
|
|
|
. "dappco.re/go/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
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// --- ServiceRuntime ---
|
|
|
|
|
|
|
|
|
|
type testOpts struct {
|
|
|
|
|
URL string
|
|
|
|
|
Timeout int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestServiceRuntime_Good(t *testing.T) {
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
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 := testOpts{URL: "https://api.lthn.ai", Timeout: 30}
|
|
|
|
|
rt := NewServiceRuntime(c, opts)
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, c, rt.Core())
|
2026-03-20 16:00:41 +00:00
|
|
|
assert.Equal(t, opts, rt.Options())
|
|
|
|
|
assert.Equal(t, "https://api.lthn.ai", rt.Options().URL)
|
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
|
|
|
assert.NotNil(t, rt.Config())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- NewWithFactories ---
|
|
|
|
|
|
|
|
|
|
func TestNewWithFactories_Good(t *testing.T) {
|
2026-03-20 13:30:22 +00:00
|
|
|
r := NewWithFactories(nil, map[string]ServiceFactory{
|
|
|
|
|
"svc1": func() Result { return Result{Value: Service{}, OK: true} },
|
|
|
|
|
"svc2": func() Result { return Result{Value: Service{}, OK: true} },
|
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
|
|
|
})
|
2026-03-20 13:30:22 +00:00
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
rt := r.Value.(*Runtime)
|
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
|
|
|
assert.NotNil(t, rt.Core)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 13:30:22 +00:00
|
|
|
func TestNewWithFactories_NilFactory_Good(t *testing.T) {
|
|
|
|
|
r := NewWithFactories(nil, map[string]ServiceFactory{
|
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
|
|
|
"bad": nil,
|
|
|
|
|
})
|
2026-03-20 13:30:22 +00:00
|
|
|
assert.True(t, r.OK) // nil factories skipped
|
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 TestNewRuntime_Good(t *testing.T) {
|
2026-03-20 13:30:22 +00:00
|
|
|
r := NewRuntime(nil)
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRuntime_ServiceName_Good(t *testing.T) {
|
|
|
|
|
r := NewRuntime(nil)
|
|
|
|
|
rt := r.Value.(*Runtime)
|
|
|
|
|
assert.Equal(t, "Core", rt.ServiceName())
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Lifecycle via Runtime ---
|
|
|
|
|
|
|
|
|
|
func TestRuntime_Lifecycle_Good(t *testing.T) {
|
2026-03-20 13:30:22 +00:00
|
|
|
started := false
|
|
|
|
|
r := NewWithFactories(nil, map[string]ServiceFactory{
|
|
|
|
|
"test": func() Result {
|
|
|
|
|
return Result{Value: Service{
|
|
|
|
|
OnStart: func() Result { started = true; return Result{OK: true} },
|
|
|
|
|
}, OK: true}
|
|
|
|
|
},
|
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
|
|
|
})
|
2026-03-20 13:30:22 +00:00
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
rt := r.Value.(*Runtime)
|
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
|
|
|
|
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
|
|
|
result := rt.ServiceStartup(context.Background(), nil)
|
|
|
|
|
assert.True(t, result.OK)
|
2026-03-20 13:30:22 +00:00
|
|
|
assert.True(t, started)
|
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
|
|
|
}
|
feat: inline tests + Fs zero-value fix + coverage 76.9% → 82.3%
Move all tests from tests/ to package root for proper coverage.
Fix Fs zero-value: path() and validatePath() default empty root
to "/" so &Fs{} works without New().
New tests: PathGlob, PathIsAbs, CleanPath, Cli.SetOutput,
ServiceShutdown, Core.Context, Fs zero-value, Fs protected
delete, Command lifecycle with implementation, error formatting
branches, PerformAsync completion/no-handler/after-shutdown,
Extract with templates, Embed path traversal.
Coverage: 76.9% → 82.3% (23 test files).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 13:30:01 +00:00
|
|
|
|
|
|
|
|
func TestRuntime_ServiceShutdown_Good(t *testing.T) {
|
|
|
|
|
stopped := false
|
|
|
|
|
r := NewWithFactories(nil, map[string]ServiceFactory{
|
|
|
|
|
"test": func() Result {
|
|
|
|
|
return Result{Value: Service{
|
|
|
|
|
OnStart: func() Result { return Result{OK: true} },
|
|
|
|
|
OnStop: func() Result { stopped = true; return Result{OK: true} },
|
|
|
|
|
}, OK: true}
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
rt := r.Value.(*Runtime)
|
|
|
|
|
|
|
|
|
|
rt.ServiceStartup(context.Background(), nil)
|
|
|
|
|
result := rt.ServiceShutdown(context.Background())
|
|
|
|
|
assert.True(t, result.OK)
|
|
|
|
|
assert.True(t, stopped)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRuntime_ServiceShutdown_NilCore_Good(t *testing.T) {
|
|
|
|
|
rt := &Runtime{}
|
|
|
|
|
result := rt.ServiceShutdown(context.Background())
|
|
|
|
|
assert.True(t, result.OK)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCore_ServiceShutdown_Good(t *testing.T) {
|
|
|
|
|
stopped := false
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
feat: inline tests + Fs zero-value fix + coverage 76.9% → 82.3%
Move all tests from tests/ to package root for proper coverage.
Fix Fs zero-value: path() and validatePath() default empty root
to "/" so &Fs{} works without New().
New tests: PathGlob, PathIsAbs, CleanPath, Cli.SetOutput,
ServiceShutdown, Core.Context, Fs zero-value, Fs protected
delete, Command lifecycle with implementation, error formatting
branches, PerformAsync completion/no-handler/after-shutdown,
Extract with templates, Embed path traversal.
Coverage: 76.9% → 82.3% (23 test files).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 13:30:01 +00:00
|
|
|
c.Service("test", Service{
|
|
|
|
|
OnStart: func() Result { return Result{OK: true} },
|
|
|
|
|
OnStop: func() Result { stopped = true; return Result{OK: true} },
|
|
|
|
|
})
|
|
|
|
|
c.ServiceStartup(context.Background(), nil)
|
|
|
|
|
result := c.ServiceShutdown(context.Background())
|
|
|
|
|
assert.True(t, result.OK)
|
|
|
|
|
assert.True(t, stopped)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCore_Context_Good(t *testing.T) {
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
feat: inline tests + Fs zero-value fix + coverage 76.9% → 82.3%
Move all tests from tests/ to package root for proper coverage.
Fix Fs zero-value: path() and validatePath() default empty root
to "/" so &Fs{} works without New().
New tests: PathGlob, PathIsAbs, CleanPath, Cli.SetOutput,
ServiceShutdown, Core.Context, Fs zero-value, Fs protected
delete, Command lifecycle with implementation, error formatting
branches, PerformAsync completion/no-handler/after-shutdown,
Extract with templates, Embed path traversal.
Coverage: 76.9% → 82.3% (23 test files).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 13:30:01 +00:00
|
|
|
c.ServiceStartup(context.Background(), nil)
|
|
|
|
|
assert.NotNil(t, c.Context())
|
|
|
|
|
c.ServiceShutdown(context.Background())
|
|
|
|
|
}
|