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 (
|
|
|
|
|
"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"
|
|
|
|
|
)
|
|
|
|
|
|
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
|
|
|
// --- Log ---
|
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 TestLog_New_Good(t *testing.T) {
|
refactor: AX audit fixes — no direct strings/fmt, full type names
Direct strings import removed from: data.go, error.go, fs.go
→ uses Split, SplitN, TrimPrefix, TrimSuffix, HasPrefix, Replace, Contains, Join
Direct fmt import removed from: fs.go
→ uses Print() from utils.go
fmt.Errorf in panic recovery → NewError(fmt.Sprint("panic: ", r))
Abbreviated type names renamed:
ConfigOpts → ConfigOptions
LogOpts → LogOptions
RotationLogOpts → RotationLogOptions
embed.go keeps strings import (strings.NewReader, strings.Builder).
error.go keeps fmt import (fmt.Sprint for panic values).
232 tests, 77.8% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 13:47:23 +00:00
|
|
|
l := NewLog(LogOptions{Level: LevelInfo})
|
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, l)
|
|
|
|
|
}
|
|
|
|
|
|
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 TestLog_AllLevels_Good(t *testing.T) {
|
refactor: AX audit fixes — no direct strings/fmt, full type names
Direct strings import removed from: data.go, error.go, fs.go
→ uses Split, SplitN, TrimPrefix, TrimSuffix, HasPrefix, Replace, Contains, Join
Direct fmt import removed from: fs.go
→ uses Print() from utils.go
fmt.Errorf in panic recovery → NewError(fmt.Sprint("panic: ", r))
Abbreviated type names renamed:
ConfigOpts → ConfigOptions
LogOpts → LogOptions
RotationLogOpts → RotationLogOptions
embed.go keeps strings import (strings.NewReader, strings.Builder).
error.go keeps fmt import (fmt.Sprint for panic values).
232 tests, 77.8% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 13:47:23 +00:00
|
|
|
l := NewLog(LogOptions{Level: LevelDebug})
|
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
|
|
|
l.Debug("debug")
|
|
|
|
|
l.Info("info")
|
|
|
|
|
l.Warn("warn")
|
|
|
|
|
l.Error("error")
|
|
|
|
|
l.Security("security event")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLog_LevelFiltering_Good(t *testing.T) {
|
|
|
|
|
// At Error level, Debug/Info/Warn should be suppressed (no panic)
|
refactor: AX audit fixes — no direct strings/fmt, full type names
Direct strings import removed from: data.go, error.go, fs.go
→ uses Split, SplitN, TrimPrefix, TrimSuffix, HasPrefix, Replace, Contains, Join
Direct fmt import removed from: fs.go
→ uses Print() from utils.go
fmt.Errorf in panic recovery → NewError(fmt.Sprint("panic: ", r))
Abbreviated type names renamed:
ConfigOpts → ConfigOptions
LogOpts → LogOptions
RotationLogOpts → RotationLogOptions
embed.go keeps strings import (strings.NewReader, strings.Builder).
error.go keeps fmt import (fmt.Sprint for panic values).
232 tests, 77.8% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 13:47:23 +00:00
|
|
|
l := NewLog(LogOptions{Level: LevelError})
|
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
|
|
|
l.Debug("suppressed")
|
|
|
|
|
l.Info("suppressed")
|
|
|
|
|
l.Warn("suppressed")
|
|
|
|
|
l.Error("visible")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLog_SetLevel_Good(t *testing.T) {
|
refactor: AX audit fixes — no direct strings/fmt, full type names
Direct strings import removed from: data.go, error.go, fs.go
→ uses Split, SplitN, TrimPrefix, TrimSuffix, HasPrefix, Replace, Contains, Join
Direct fmt import removed from: fs.go
→ uses Print() from utils.go
fmt.Errorf in panic recovery → NewError(fmt.Sprint("panic: ", r))
Abbreviated type names renamed:
ConfigOpts → ConfigOptions
LogOpts → LogOptions
RotationLogOpts → RotationLogOptions
embed.go keeps strings import (strings.NewReader, strings.Builder).
error.go keeps fmt import (fmt.Sprint for panic values).
232 tests, 77.8% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 13:47:23 +00:00
|
|
|
l := NewLog(LogOptions{Level: LevelInfo})
|
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
|
|
|
l.SetLevel(LevelDebug)
|
|
|
|
|
assert.Equal(t, LevelDebug, l.Level())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLog_SetRedactKeys_Good(t *testing.T) {
|
refactor: AX audit fixes — no direct strings/fmt, full type names
Direct strings import removed from: data.go, error.go, fs.go
→ uses Split, SplitN, TrimPrefix, TrimSuffix, HasPrefix, Replace, Contains, Join
Direct fmt import removed from: fs.go
→ uses Print() from utils.go
fmt.Errorf in panic recovery → NewError(fmt.Sprint("panic: ", r))
Abbreviated type names renamed:
ConfigOpts → ConfigOptions
LogOpts → LogOptions
RotationLogOpts → RotationLogOptions
embed.go keeps strings import (strings.NewReader, strings.Builder).
error.go keeps fmt import (fmt.Sprint for panic values).
232 tests, 77.8% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 13:47:23 +00:00
|
|
|
l := NewLog(LogOptions{Level: LevelInfo})
|
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
|
|
|
l.SetRedactKeys("password", "token")
|
|
|
|
|
// Redacted keys should mask values in output
|
|
|
|
|
l.Info("login", "password", "secret123", "user", "admin")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLog_LevelString_Good(t *testing.T) {
|
|
|
|
|
assert.Equal(t, "debug", LevelDebug.String())
|
|
|
|
|
assert.Equal(t, "info", LevelInfo.String())
|
|
|
|
|
assert.Equal(t, "warn", LevelWarn.String())
|
|
|
|
|
assert.Equal(t, "error", LevelError.String())
|
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 TestLog_CoreLog_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
|
|
|
assert.NotNil(t, c.Log())
|
|
|
|
|
}
|
|
|
|
|
|
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 TestLog_ErrorSink_Good(t *testing.T) {
|
refactor: AX audit fixes — no direct strings/fmt, full type names
Direct strings import removed from: data.go, error.go, fs.go
→ uses Split, SplitN, TrimPrefix, TrimSuffix, HasPrefix, Replace, Contains, Join
Direct fmt import removed from: fs.go
→ uses Print() from utils.go
fmt.Errorf in panic recovery → NewError(fmt.Sprint("panic: ", r))
Abbreviated type names renamed:
ConfigOpts → ConfigOptions
LogOpts → LogOptions
RotationLogOpts → RotationLogOptions
embed.go keeps strings import (strings.NewReader, strings.Builder).
error.go keeps fmt import (fmt.Sprint for panic values).
232 tests, 77.8% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 13:47:23 +00:00
|
|
|
l := NewLog(LogOptions{Level: LevelInfo})
|
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
|
|
|
var sink ErrorSink = l
|
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
|
|
|
sink.Error("test")
|
|
|
|
|
sink.Warn("test")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Default Logger ---
|
|
|
|
|
|
|
|
|
|
func TestLog_Default_Good(t *testing.T) {
|
|
|
|
|
d := Default()
|
|
|
|
|
assert.NotNil(t, d)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLog_SetDefault_Good(t *testing.T) {
|
|
|
|
|
original := Default()
|
|
|
|
|
defer SetDefault(original)
|
|
|
|
|
|
refactor: AX audit fixes — no direct strings/fmt, full type names
Direct strings import removed from: data.go, error.go, fs.go
→ uses Split, SplitN, TrimPrefix, TrimSuffix, HasPrefix, Replace, Contains, Join
Direct fmt import removed from: fs.go
→ uses Print() from utils.go
fmt.Errorf in panic recovery → NewError(fmt.Sprint("panic: ", r))
Abbreviated type names renamed:
ConfigOpts → ConfigOptions
LogOpts → LogOptions
RotationLogOpts → RotationLogOptions
embed.go keeps strings import (strings.NewReader, strings.Builder).
error.go keeps fmt import (fmt.Sprint for panic values).
232 tests, 77.8% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 13:47:23 +00:00
|
|
|
custom := NewLog(LogOptions{Level: LevelDebug})
|
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
|
|
|
SetDefault(custom)
|
|
|
|
|
assert.Equal(t, custom, Default())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLog_PackageLevelFunctions_Good(t *testing.T) {
|
|
|
|
|
// Package-level log functions use the default logger
|
|
|
|
|
Debug("debug msg")
|
|
|
|
|
Info("info msg")
|
|
|
|
|
Warn("warn msg")
|
|
|
|
|
Error("error msg")
|
|
|
|
|
Security("security msg")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLog_PackageSetLevel_Good(t *testing.T) {
|
|
|
|
|
original := Default()
|
|
|
|
|
defer SetDefault(original)
|
|
|
|
|
|
|
|
|
|
SetLevel(LevelDebug)
|
|
|
|
|
SetRedactKeys("secret")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLog_Username_Good(t *testing.T) {
|
|
|
|
|
u := Username()
|
|
|
|
|
assert.NotEmpty(t, u)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- LogErr ---
|
|
|
|
|
|
feat: implement RFC plans 1-5 — Registry[T], Action/Task, Process, primitives
Plans 1-5 complete for core/go scope. 456 tests, 84.4% coverage, 100% AX-7 naming.
Critical bugs (Plan 1):
- P4-3+P7-3: ACTION broadcast calls all handlers with panic recovery
- P7-2+P7-4: RunE() with defer ServiceShutdown, Run() delegates
- P3-1: Startable/Stoppable return Result (breaking, clean)
- P9-1: Zero os/exec — App.Find() rewritten with os.Stat+PATH
- I3: Embed() removed, I15: New() comment fixed
- I9: CommandLifecycle removed → Command.Managed field
Registry[T] (Plan 2):
- Universal thread-safe named collection with 3 lock modes
- All 5 registries migrated: services, commands, drive, data, lock
- Insertion order preserved (fixes P4-1)
- c.RegistryOf("name") cross-cutting accessor
Action/Task system (Plan 3):
- Action type with Run()/Exists(), ActionHandler signature
- c.Action("name") dual-purpose accessor (register/invoke)
- TaskDef with Steps — sequential chain, async dispatch, previous-input piping
- Panic recovery on all Action execution
- broadcast() internal, ACTION() sugar
Process primitive (Plan 4):
- c.Process() returns Action sugar — Run/RunIn/RunWithEnv/Start/Kill/Exists
- No deps added — delegates to c.Action("process.*")
- Permission-by-registration: no handler = no capability
Missing primitives (Plan 5):
- core.ID() — atomic counter + crypto/rand suffix
- ValidateName() / SanitisePath() — reusable validation
- Fs.WriteAtomic() — write-to-temp-then-rename
- Fs.NewUnrestricted() / Fs.Root() — legitimate sandbox bypass
- AX-7: 456/456 tests renamed to TestFile_Function_{Good,Bad,Ugly}
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 15:18:25 +00:00
|
|
|
func TestLog_LogErr_Good(t *testing.T) {
|
refactor: AX audit fixes — no direct strings/fmt, full type names
Direct strings import removed from: data.go, error.go, fs.go
→ uses Split, SplitN, TrimPrefix, TrimSuffix, HasPrefix, Replace, Contains, Join
Direct fmt import removed from: fs.go
→ uses Print() from utils.go
fmt.Errorf in panic recovery → NewError(fmt.Sprint("panic: ", r))
Abbreviated type names renamed:
ConfigOpts → ConfigOptions
LogOpts → LogOptions
RotationLogOpts → RotationLogOptions
embed.go keeps strings import (strings.NewReader, strings.Builder).
error.go keeps fmt import (fmt.Sprint for panic values).
232 tests, 77.8% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 13:47:23 +00:00
|
|
|
l := NewLog(LogOptions{Level: LevelInfo})
|
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
|
|
|
le := NewLogErr(l)
|
|
|
|
|
assert.NotNil(t, le)
|
|
|
|
|
|
fix: AX audit round 5 — full naming, Result returns throughout
Renames (via GoLand refactor):
- Option.K → Key, Option.V → Value
- Err.Op → Operation, Err.Msg → Message, Err.Err → Error
- CrashSystem.OS → OperatingSystem, Arch → Architecture
- TaskID → TaskIdentifier, TaskWithID → TaskWithIdentifier
- Ipc → IPC, BaseDir → BaseDirectory
- ServiceRuntime.Opts → Options
Return type changes:
- Options.Get, Config.Get → Result (was (any, bool))
- Embed.ReadDir → Result (was ([]fs.DirEntry, error))
- Translator.Translate, I18n.Translate → Result (was string)
Rule 6:
- data.go: propagate opts.Get failure, typed error for bad fs.FS
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 16:32:43 +00:00
|
|
|
err := E("test.Operation", "something broke", nil)
|
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
|
|
|
le.Log(err)
|
|
|
|
|
}
|
|
|
|
|
|
feat: implement RFC plans 1-5 — Registry[T], Action/Task, Process, primitives
Plans 1-5 complete for core/go scope. 456 tests, 84.4% coverage, 100% AX-7 naming.
Critical bugs (Plan 1):
- P4-3+P7-3: ACTION broadcast calls all handlers with panic recovery
- P7-2+P7-4: RunE() with defer ServiceShutdown, Run() delegates
- P3-1: Startable/Stoppable return Result (breaking, clean)
- P9-1: Zero os/exec — App.Find() rewritten with os.Stat+PATH
- I3: Embed() removed, I15: New() comment fixed
- I9: CommandLifecycle removed → Command.Managed field
Registry[T] (Plan 2):
- Universal thread-safe named collection with 3 lock modes
- All 5 registries migrated: services, commands, drive, data, lock
- Insertion order preserved (fixes P4-1)
- c.RegistryOf("name") cross-cutting accessor
Action/Task system (Plan 3):
- Action type with Run()/Exists(), ActionHandler signature
- c.Action("name") dual-purpose accessor (register/invoke)
- TaskDef with Steps — sequential chain, async dispatch, previous-input piping
- Panic recovery on all Action execution
- broadcast() internal, ACTION() sugar
Process primitive (Plan 4):
- c.Process() returns Action sugar — Run/RunIn/RunWithEnv/Start/Kill/Exists
- No deps added — delegates to c.Action("process.*")
- Permission-by-registration: no handler = no capability
Missing primitives (Plan 5):
- core.ID() — atomic counter + crypto/rand suffix
- ValidateName() / SanitisePath() — reusable validation
- Fs.WriteAtomic() — write-to-temp-then-rename
- Fs.NewUnrestricted() / Fs.Root() — legitimate sandbox bypass
- AX-7: 456/456 tests renamed to TestFile_Function_{Good,Bad,Ugly}
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 15:18:25 +00:00
|
|
|
func TestLog_LogErr_Nil_Good(t *testing.T) {
|
refactor: AX audit fixes — no direct strings/fmt, full type names
Direct strings import removed from: data.go, error.go, fs.go
→ uses Split, SplitN, TrimPrefix, TrimSuffix, HasPrefix, Replace, Contains, Join
Direct fmt import removed from: fs.go
→ uses Print() from utils.go
fmt.Errorf in panic recovery → NewError(fmt.Sprint("panic: ", r))
Abbreviated type names renamed:
ConfigOpts → ConfigOptions
LogOpts → LogOptions
RotationLogOpts → RotationLogOptions
embed.go keeps strings import (strings.NewReader, strings.Builder).
error.go keeps fmt import (fmt.Sprint for panic values).
232 tests, 77.8% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 13:47:23 +00:00
|
|
|
l := NewLog(LogOptions{Level: LevelInfo})
|
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
|
|
|
le := NewLogErr(l)
|
|
|
|
|
le.Log(nil) // should not panic
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 15:36:33 +00:00
|
|
|
// --- LogPanic ---
|
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: implement RFC plans 1-5 — Registry[T], Action/Task, Process, primitives
Plans 1-5 complete for core/go scope. 456 tests, 84.4% coverage, 100% AX-7 naming.
Critical bugs (Plan 1):
- P4-3+P7-3: ACTION broadcast calls all handlers with panic recovery
- P7-2+P7-4: RunE() with defer ServiceShutdown, Run() delegates
- P3-1: Startable/Stoppable return Result (breaking, clean)
- P9-1: Zero os/exec — App.Find() rewritten with os.Stat+PATH
- I3: Embed() removed, I15: New() comment fixed
- I9: CommandLifecycle removed → Command.Managed field
Registry[T] (Plan 2):
- Universal thread-safe named collection with 3 lock modes
- All 5 registries migrated: services, commands, drive, data, lock
- Insertion order preserved (fixes P4-1)
- c.RegistryOf("name") cross-cutting accessor
Action/Task system (Plan 3):
- Action type with Run()/Exists(), ActionHandler signature
- c.Action("name") dual-purpose accessor (register/invoke)
- TaskDef with Steps — sequential chain, async dispatch, previous-input piping
- Panic recovery on all Action execution
- broadcast() internal, ACTION() sugar
Process primitive (Plan 4):
- c.Process() returns Action sugar — Run/RunIn/RunWithEnv/Start/Kill/Exists
- No deps added — delegates to c.Action("process.*")
- Permission-by-registration: no handler = no capability
Missing primitives (Plan 5):
- core.ID() — atomic counter + crypto/rand suffix
- ValidateName() / SanitisePath() — reusable validation
- Fs.WriteAtomic() — write-to-temp-then-rename
- Fs.NewUnrestricted() / Fs.Root() — legitimate sandbox bypass
- AX-7: 456/456 tests renamed to TestFile_Function_{Good,Bad,Ugly}
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 15:18:25 +00:00
|
|
|
func TestLog_LogPanic_Good(t *testing.T) {
|
refactor: AX audit fixes — no direct strings/fmt, full type names
Direct strings import removed from: data.go, error.go, fs.go
→ uses Split, SplitN, TrimPrefix, TrimSuffix, HasPrefix, Replace, Contains, Join
Direct fmt import removed from: fs.go
→ uses Print() from utils.go
fmt.Errorf in panic recovery → NewError(fmt.Sprint("panic: ", r))
Abbreviated type names renamed:
ConfigOpts → ConfigOptions
LogOpts → LogOptions
RotationLogOpts → RotationLogOptions
embed.go keeps strings import (strings.NewReader, strings.Builder).
error.go keeps fmt import (fmt.Sprint for panic values).
232 tests, 77.8% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 13:47:23 +00:00
|
|
|
l := NewLog(LogOptions{Level: LevelInfo})
|
2026-03-20 15:36:33 +00:00
|
|
|
lp := NewLogPanic(l)
|
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.NotNil(t, lp)
|
|
|
|
|
}
|
|
|
|
|
|
feat: implement RFC plans 1-5 — Registry[T], Action/Task, Process, primitives
Plans 1-5 complete for core/go scope. 456 tests, 84.4% coverage, 100% AX-7 naming.
Critical bugs (Plan 1):
- P4-3+P7-3: ACTION broadcast calls all handlers with panic recovery
- P7-2+P7-4: RunE() with defer ServiceShutdown, Run() delegates
- P3-1: Startable/Stoppable return Result (breaking, clean)
- P9-1: Zero os/exec — App.Find() rewritten with os.Stat+PATH
- I3: Embed() removed, I15: New() comment fixed
- I9: CommandLifecycle removed → Command.Managed field
Registry[T] (Plan 2):
- Universal thread-safe named collection with 3 lock modes
- All 5 registries migrated: services, commands, drive, data, lock
- Insertion order preserved (fixes P4-1)
- c.RegistryOf("name") cross-cutting accessor
Action/Task system (Plan 3):
- Action type with Run()/Exists(), ActionHandler signature
- c.Action("name") dual-purpose accessor (register/invoke)
- TaskDef with Steps — sequential chain, async dispatch, previous-input piping
- Panic recovery on all Action execution
- broadcast() internal, ACTION() sugar
Process primitive (Plan 4):
- c.Process() returns Action sugar — Run/RunIn/RunWithEnv/Start/Kill/Exists
- No deps added — delegates to c.Action("process.*")
- Permission-by-registration: no handler = no capability
Missing primitives (Plan 5):
- core.ID() — atomic counter + crypto/rand suffix
- ValidateName() / SanitisePath() — reusable validation
- Fs.WriteAtomic() — write-to-temp-then-rename
- Fs.NewUnrestricted() / Fs.Root() — legitimate sandbox bypass
- AX-7: 456/456 tests renamed to TestFile_Function_{Good,Bad,Ugly}
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 15:18:25 +00:00
|
|
|
func TestLog_LogPanic_Recover_Good(t *testing.T) {
|
refactor: AX audit fixes — no direct strings/fmt, full type names
Direct strings import removed from: data.go, error.go, fs.go
→ uses Split, SplitN, TrimPrefix, TrimSuffix, HasPrefix, Replace, Contains, Join
Direct fmt import removed from: fs.go
→ uses Print() from utils.go
fmt.Errorf in panic recovery → NewError(fmt.Sprint("panic: ", r))
Abbreviated type names renamed:
ConfigOpts → ConfigOptions
LogOpts → LogOptions
RotationLogOpts → RotationLogOptions
embed.go keeps strings import (strings.NewReader, strings.Builder).
error.go keeps fmt import (fmt.Sprint for panic values).
232 tests, 77.8% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 13:47:23 +00:00
|
|
|
l := NewLog(LogOptions{Level: LevelInfo})
|
2026-03-20 15:36:33 +00:00
|
|
|
lp := NewLogPanic(l)
|
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.NotPanics(t, func() {
|
|
|
|
|
defer lp.Recover()
|
|
|
|
|
panic("caught")
|
|
|
|
|
})
|
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 12:10:41 +00:00
|
|
|
|
|
|
|
|
// --- SetOutput ---
|
|
|
|
|
|
|
|
|
|
func TestLog_SetOutput_Good(t *testing.T) {
|
refactor: AX audit fixes — no direct strings/fmt, full type names
Direct strings import removed from: data.go, error.go, fs.go
→ uses Split, SplitN, TrimPrefix, TrimSuffix, HasPrefix, Replace, Contains, Join
Direct fmt import removed from: fs.go
→ uses Print() from utils.go
fmt.Errorf in panic recovery → NewError(fmt.Sprint("panic: ", r))
Abbreviated type names renamed:
ConfigOpts → ConfigOptions
LogOpts → LogOptions
RotationLogOpts → RotationLogOptions
embed.go keeps strings import (strings.NewReader, strings.Builder).
error.go keeps fmt import (fmt.Sprint for panic values).
232 tests, 77.8% coverage.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-20 13:47:23 +00:00
|
|
|
l := NewLog(LogOptions{Level: LevelInfo})
|
2026-03-25 19:23:11 +00:00
|
|
|
l.SetOutput(NewBuilder())
|
2026-03-20 12:10:41 +00:00
|
|
|
l.Info("redirected")
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
// --- Log suppression by level ---
|
|
|
|
|
|
|
|
|
|
func TestLog_Quiet_Suppresses_Ugly(t *testing.T) {
|
|
|
|
|
l := NewLog(LogOptions{Level: LevelQuiet})
|
|
|
|
|
// These should not panic even though nothing is logged
|
|
|
|
|
l.Debug("suppressed")
|
|
|
|
|
l.Info("suppressed")
|
|
|
|
|
l.Warn("suppressed")
|
|
|
|
|
l.Error("suppressed")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLog_ErrorLevel_Suppresses_Ugly(t *testing.T) {
|
|
|
|
|
l := NewLog(LogOptions{Level: LevelError})
|
|
|
|
|
l.Debug("suppressed") // below threshold
|
|
|
|
|
l.Info("suppressed") // below threshold
|
|
|
|
|
l.Warn("suppressed") // below threshold
|
|
|
|
|
l.Error("visible") // at threshold
|
|
|
|
|
}
|