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 (
|
2026-03-20 14:37:06 +00:00
|
|
|
"io/fs"
|
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
|
|
|
"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"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// --- Fs (Sandboxed Filesystem) ---
|
|
|
|
|
|
|
|
|
|
func TestFs_WriteRead_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
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
|
|
|
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "test.txt")
|
2026-03-20 14:37:06 +00:00
|
|
|
assert.True(t, c.Fs().Write(path, "hello core").OK)
|
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 14:37:06 +00:00
|
|
|
r := c.Fs().Read(path)
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
assert.Equal(t, "hello core", r.Value.(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 TestFs_Read_Bad(t *testing.T) {
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-20 14:37:06 +00:00
|
|
|
r := c.Fs().Read("/nonexistent/path/to/file.txt")
|
|
|
|
|
assert.False(t, r.OK)
|
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 TestFs_EnsureDir_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "sub", "dir")
|
2026-03-20 14:37:06 +00:00
|
|
|
assert.True(t, c.Fs().EnsureDir(path).OK)
|
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.True(t, c.Fs().IsDir(path))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_IsDir_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
|
|
|
dir := t.TempDir()
|
|
|
|
|
assert.True(t, c.Fs().IsDir(dir))
|
2026-03-25 18:58:16 +00:00
|
|
|
assert.False(t, c.Fs().IsDir(Path(dir, "nonexistent")))
|
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.False(t, c.Fs().IsDir(""))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_IsFile_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "test.txt")
|
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
|
|
|
c.Fs().Write(path, "data")
|
|
|
|
|
assert.True(t, c.Fs().IsFile(path))
|
2026-03-20 14:37:06 +00:00
|
|
|
assert.False(t, c.Fs().IsFile(dir))
|
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.False(t, c.Fs().IsFile(""))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_Exists_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "exists.txt")
|
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
|
|
|
c.Fs().Write(path, "yes")
|
|
|
|
|
assert.True(t, c.Fs().Exists(path))
|
|
|
|
|
assert.True(t, c.Fs().Exists(dir))
|
2026-03-25 18:58:16 +00:00
|
|
|
assert.False(t, c.Fs().Exists(Path(dir, "nope")))
|
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 TestFs_List_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
c.Fs().Write(Path(dir, "a.txt"), "a")
|
|
|
|
|
c.Fs().Write(Path(dir, "b.txt"), "b")
|
2026-03-20 14:37:06 +00:00
|
|
|
r := c.Fs().List(dir)
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
assert.Len(t, r.Value.([]fs.DirEntry), 2)
|
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 TestFs_Stat_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "stat.txt")
|
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
|
|
|
c.Fs().Write(path, "data")
|
2026-03-20 14:37:06 +00:00
|
|
|
r := c.Fs().Stat(path)
|
|
|
|
|
assert.True(t, r.OK)
|
2026-03-25 19:23:11 +00:00
|
|
|
assert.Equal(t, "stat.txt", r.Value.(fs.FileInfo).Name())
|
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 TestFs_Open_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "open.txt")
|
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
|
|
|
c.Fs().Write(path, "content")
|
2026-03-20 14:37:06 +00:00
|
|
|
r := c.Fs().Open(path)
|
|
|
|
|
assert.True(t, r.OK)
|
feat: eliminate io import — add ReadAll, WriteAll, CloseStream primitives
New primitives:
- core.ReadAll(reader) — reads all from any reader, closes, returns Result
- core.WriteAll(writer, content) — writes to any writer, closes, returns Result
- core.CloseStream(v) — closes any value implementing io.Closer
Replaced all io.ReadCloser/io.WriteCloser/io.ReadAll type assertions
in fs_test.go and data_test.go with Core primitives.
"io" import is now zero across all test files. 558 tests, 84.5% coverage.
Remaining stdlib imports (all legitimate test infrastructure):
testing, fmt, context, time, sync, embed, io/fs, bytes, gzip, base64
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 19:30:45 +00:00
|
|
|
CloseStream(r.Value)
|
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 TestFs_Create_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "sub", "created.txt")
|
2026-03-20 14:37:06 +00:00
|
|
|
r := c.Fs().Create(path)
|
|
|
|
|
assert.True(t, r.OK)
|
feat: eliminate io import — add ReadAll, WriteAll, CloseStream primitives
New primitives:
- core.ReadAll(reader) — reads all from any reader, closes, returns Result
- core.WriteAll(writer, content) — writes to any writer, closes, returns Result
- core.CloseStream(v) — closes any value implementing io.Closer
Replaced all io.ReadCloser/io.WriteCloser/io.ReadAll type assertions
in fs_test.go and data_test.go with Core primitives.
"io" import is now zero across all test files. 558 tests, 84.5% coverage.
Remaining stdlib imports (all legitimate test infrastructure):
testing, fmt, context, time, sync, embed, io/fs, bytes, gzip, base64
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 19:30:45 +00:00
|
|
|
WriteAll(r.Value, "hello")
|
2026-03-20 14:37:06 +00:00
|
|
|
rr := c.Fs().Read(path)
|
|
|
|
|
assert.Equal(t, "hello", rr.Value.(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 TestFs_Append_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "append.txt")
|
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
|
|
|
c.Fs().Write(path, "first")
|
2026-03-20 14:37:06 +00:00
|
|
|
r := c.Fs().Append(path)
|
|
|
|
|
assert.True(t, r.OK)
|
feat: eliminate io import — add ReadAll, WriteAll, CloseStream primitives
New primitives:
- core.ReadAll(reader) — reads all from any reader, closes, returns Result
- core.WriteAll(writer, content) — writes to any writer, closes, returns Result
- core.CloseStream(v) — closes any value implementing io.Closer
Replaced all io.ReadCloser/io.WriteCloser/io.ReadAll type assertions
in fs_test.go and data_test.go with Core primitives.
"io" import is now zero across all test files. 558 tests, 84.5% coverage.
Remaining stdlib imports (all legitimate test infrastructure):
testing, fmt, context, time, sync, embed, io/fs, bytes, gzip, base64
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 19:30:45 +00:00
|
|
|
WriteAll(r.Value, " second")
|
2026-03-20 14:37:06 +00:00
|
|
|
rr := c.Fs().Read(path)
|
|
|
|
|
assert.Equal(t, "first second", rr.Value.(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 TestFs_ReadStream_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "stream.txt")
|
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
|
|
|
c.Fs().Write(path, "streamed")
|
2026-03-20 14:37:06 +00:00
|
|
|
r := c.Fs().ReadStream(path)
|
|
|
|
|
assert.True(t, r.OK)
|
feat: eliminate io import — add ReadAll, WriteAll, CloseStream primitives
New primitives:
- core.ReadAll(reader) — reads all from any reader, closes, returns Result
- core.WriteAll(writer, content) — writes to any writer, closes, returns Result
- core.CloseStream(v) — closes any value implementing io.Closer
Replaced all io.ReadCloser/io.WriteCloser/io.ReadAll type assertions
in fs_test.go and data_test.go with Core primitives.
"io" import is now zero across all test files. 558 tests, 84.5% coverage.
Remaining stdlib imports (all legitimate test infrastructure):
testing, fmt, context, time, sync, embed, io/fs, bytes, gzip, base64
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 19:30:45 +00:00
|
|
|
CloseStream(r.Value)
|
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 TestFs_WriteStream_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "sub", "ws.txt")
|
2026-03-20 14:37:06 +00:00
|
|
|
r := c.Fs().WriteStream(path)
|
|
|
|
|
assert.True(t, r.OK)
|
feat: eliminate io import — add ReadAll, WriteAll, CloseStream primitives
New primitives:
- core.ReadAll(reader) — reads all from any reader, closes, returns Result
- core.WriteAll(writer, content) — writes to any writer, closes, returns Result
- core.CloseStream(v) — closes any value implementing io.Closer
Replaced all io.ReadCloser/io.WriteCloser/io.ReadAll type assertions
in fs_test.go and data_test.go with Core primitives.
"io" import is now zero across all test files. 558 tests, 84.5% coverage.
Remaining stdlib imports (all legitimate test infrastructure):
testing, fmt, context, time, sync, embed, io/fs, bytes, gzip, base64
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 19:30:45 +00:00
|
|
|
WriteAll(r.Value, "stream")
|
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 TestFs_Delete_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "delete.txt")
|
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
|
|
|
c.Fs().Write(path, "gone")
|
2026-03-20 14:37:06 +00:00
|
|
|
assert.True(t, c.Fs().Delete(path).OK)
|
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.False(t, c.Fs().Exists(path))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_DeleteAll_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
sub := Path(dir, "deep", "nested")
|
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
|
|
|
c.Fs().EnsureDir(sub)
|
2026-03-25 18:58:16 +00:00
|
|
|
c.Fs().Write(Path(sub, "file.txt"), "data")
|
|
|
|
|
assert.True(t, c.Fs().DeleteAll(Path(dir, "deep")).OK)
|
|
|
|
|
assert.False(t, c.Fs().Exists(Path(dir, "deep")))
|
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 TestFs_Rename_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
old := Path(dir, "old.txt")
|
|
|
|
|
nw := Path(dir, "new.txt")
|
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
|
|
|
c.Fs().Write(old, "data")
|
2026-03-20 14:37:06 +00:00
|
|
|
assert.True(t, c.Fs().Rename(old, nw).OK)
|
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.False(t, c.Fs().Exists(old))
|
2026-03-20 14:37:06 +00:00
|
|
|
assert.True(t, c.Fs().Exists(nw))
|
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 TestFs_WriteMode_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "secret.txt")
|
2026-03-20 14:37:06 +00:00
|
|
|
assert.True(t, c.Fs().WriteMode(path, "secret", 0600).OK)
|
|
|
|
|
r := c.Fs().Stat(path)
|
|
|
|
|
assert.True(t, r.OK)
|
2026-03-25 19:23:11 +00:00
|
|
|
assert.Equal(t, "secret.txt", r.Value.(fs.FileInfo).Name())
|
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: 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
|
|
|
|
|
|
|
|
// --- Zero Value ---
|
|
|
|
|
|
|
|
|
|
func TestFs_ZeroValue_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
zeroFs := &Fs{}
|
|
|
|
|
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "zero.txt")
|
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
|
|
|
assert.True(t, zeroFs.Write(path, "zero value works").OK)
|
|
|
|
|
r := zeroFs.Read(path)
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
assert.Equal(t, "zero value works", r.Value.(string))
|
|
|
|
|
assert.True(t, zeroFs.IsFile(path))
|
|
|
|
|
assert.True(t, zeroFs.Exists(path))
|
|
|
|
|
assert.True(t, zeroFs.IsDir(dir))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_ZeroValue_List_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
zeroFs := &Fs{}
|
|
|
|
|
|
2026-03-25 19:23:11 +00:00
|
|
|
(&Fs{}).New("/").Write(Path(dir, "a.txt"), "a")
|
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
|
|
|
r := zeroFs.List(dir)
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
entries := r.Value.([]fs.DirEntry)
|
|
|
|
|
assert.Len(t, entries, 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_Exists_NotFound_Bad(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
|
|
|
assert.False(t, c.Fs().Exists("/nonexistent/path/xyz"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Fs path/validatePath edge cases ---
|
|
|
|
|
|
|
|
|
|
func TestFs_Read_EmptyPath_Ugly(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
|
|
|
r := c.Fs().Read("")
|
|
|
|
|
assert.False(t, r.OK)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_Write_EmptyPath_Ugly(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
|
|
|
r := c.Fs().Write("", "data")
|
|
|
|
|
assert.False(t, r.OK)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_Delete_Protected_Ugly(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
|
|
|
r := c.Fs().Delete("/")
|
|
|
|
|
assert.False(t, r.OK)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_DeleteAll_Protected_Ugly(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
|
|
|
r := c.Fs().DeleteAll("/")
|
|
|
|
|
assert.False(t, r.OK)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_ReadStream_WriteStream_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-24 21:50:05 +00:00
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "stream.txt")
|
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.Fs().Write(path, "streamed")
|
|
|
|
|
|
|
|
|
|
r := c.Fs().ReadStream(path)
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
|
|
|
|
|
w := c.Fs().WriteStream(path)
|
|
|
|
|
assert.True(t, w.OK)
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
// --- WriteAtomic ---
|
|
|
|
|
|
|
|
|
|
func TestFs_WriteAtomic_Good(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "status.json")
|
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
|
|
|
r := c.Fs().WriteAtomic(path, `{"status":"completed"}`)
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
|
|
|
|
|
read := c.Fs().Read(path)
|
|
|
|
|
assert.True(t, read.OK)
|
|
|
|
|
assert.Equal(t, `{"status":"completed"}`, read.Value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_WriteAtomic_Good_Overwrite(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "data.txt")
|
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
|
|
|
c.Fs().WriteAtomic(path, "first")
|
|
|
|
|
c.Fs().WriteAtomic(path, "second")
|
|
|
|
|
|
|
|
|
|
read := c.Fs().Read(path)
|
|
|
|
|
assert.Equal(t, "second", read.Value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_WriteAtomic_Bad_ReadOnlyDir(t *testing.T) {
|
|
|
|
|
// Write to a non-existent root that can't be created
|
|
|
|
|
m := (&Fs{}).New("/proc/nonexistent")
|
|
|
|
|
r := m.WriteAtomic("file.txt", "data")
|
|
|
|
|
assert.False(t, r.OK, "WriteAtomic must fail when parent dir cannot be created")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_WriteAtomic_Ugly_NoTempFileLeftOver(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "clean.txt")
|
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
|
|
|
c.Fs().WriteAtomic(path, "content")
|
|
|
|
|
|
|
|
|
|
// Check no .tmp files remain
|
2026-03-25 19:23:11 +00:00
|
|
|
lr := c.Fs().List(dir)
|
|
|
|
|
entries, _ := lr.Value.([]fs.DirEntry)
|
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
|
|
|
for _, e := range entries {
|
|
|
|
|
assert.False(t, Contains(e.Name(), ".tmp."), "temp file should not remain after successful atomic write")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_WriteAtomic_Good_CreatesParentDir(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
c := New()
|
2026-03-25 18:58:16 +00:00
|
|
|
path := Path(dir, "sub", "dir", "file.txt")
|
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
|
|
|
r := c.Fs().WriteAtomic(path, "nested")
|
|
|
|
|
assert.True(t, r.OK)
|
|
|
|
|
|
|
|
|
|
read := c.Fs().Read(path)
|
|
|
|
|
assert.Equal(t, "nested", read.Value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- NewUnrestricted ---
|
|
|
|
|
|
|
|
|
|
func TestFs_NewUnrestricted_Good(t *testing.T) {
|
|
|
|
|
sandboxed := (&Fs{}).New(t.TempDir())
|
|
|
|
|
unrestricted := sandboxed.NewUnrestricted()
|
|
|
|
|
assert.Equal(t, "/", unrestricted.Root())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_NewUnrestricted_Good_CanReadOutsideSandbox(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-25 18:58:16 +00:00
|
|
|
outside := Path(dir, "outside.txt")
|
2026-03-25 19:23:11 +00:00
|
|
|
(&Fs{}).New("/").Write(outside, "hello")
|
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
|
|
|
|
2026-03-25 18:58:16 +00:00
|
|
|
sandboxed := (&Fs{}).New(Path(dir, "sandbox"))
|
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
|
|
|
unrestricted := sandboxed.NewUnrestricted()
|
|
|
|
|
|
|
|
|
|
r := unrestricted.Read(outside)
|
|
|
|
|
assert.True(t, r.OK, "unrestricted Fs must read paths outside the original sandbox")
|
|
|
|
|
assert.Equal(t, "hello", r.Value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_NewUnrestricted_Ugly_OriginalStaysSandboxed(t *testing.T) {
|
|
|
|
|
dir := t.TempDir()
|
2026-03-25 18:58:16 +00:00
|
|
|
sandbox := Path(dir, "sandbox")
|
2026-03-25 19:23:11 +00:00
|
|
|
(&Fs{}).New("/").EnsureDir(sandbox)
|
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
|
|
|
|
|
|
|
|
sandboxed := (&Fs{}).New(sandbox)
|
|
|
|
|
_ = sandboxed.NewUnrestricted() // getting unrestricted doesn't affect original
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, sandbox, sandboxed.Root(), "original Fs must remain sandboxed")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Root ---
|
|
|
|
|
|
|
|
|
|
func TestFs_Root_Good(t *testing.T) {
|
|
|
|
|
m := (&Fs{}).New("/home/agent")
|
|
|
|
|
assert.Equal(t, "/home/agent", m.Root())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFs_Root_Good_Default(t *testing.T) {
|
|
|
|
|
m := (&Fs{}).New("")
|
|
|
|
|
assert.Equal(t, "/", m.Root())
|
|
|
|
|
}
|