ts/coredeno_test.go
Snider 70a6110590 feat: extract core/ts from core/go pkg/coredeno
TypeScript/Deno runtime bridge — Go gRPC server + Deno sidecar.
The seed project that inspired the entire Core framework.

- Module: forge.lthn.ai/core/ts
- Package: ts (renamed from coredeno)
- gRPC bridge: CoreService (Go→Deno) + DenoService (Deno→Go)
- Deno runtime: worker isolation, module loading, permissions
- Proto descriptor retains original path (regenerate with protoc later)

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-06 09:00:25 +00:00

99 lines
2.7 KiB
Go

package ts
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewSidecar_Good(t *testing.T) {
opts := Options{
DenoPath: "echo",
SocketPath: "/tmp/test-core-deno.sock",
}
sc := NewSidecar(opts)
require.NotNil(t, sc)
assert.Equal(t, "echo", sc.opts.DenoPath)
assert.Equal(t, "/tmp/test-core-deno.sock", sc.opts.SocketPath)
}
func TestDefaultSocketPath_Good(t *testing.T) {
path := DefaultSocketPath()
assert.Contains(t, path, "core/deno.sock")
}
func TestSidecar_PermissionFlags_Good(t *testing.T) {
perms := Permissions{
Read: []string{"./data/"},
Write: []string{"./data/config.json"},
Net: []string{"pool.lthn.io:3333"},
Run: []string{"xmrig"},
}
flags := perms.Flags()
assert.Contains(t, flags, "--allow-read=./data/")
assert.Contains(t, flags, "--allow-write=./data/config.json")
assert.Contains(t, flags, "--allow-net=pool.lthn.io:3333")
assert.Contains(t, flags, "--allow-run=xmrig")
}
func TestSidecar_PermissionFlags_Empty(t *testing.T) {
perms := Permissions{}
flags := perms.Flags()
assert.Empty(t, flags)
}
func TestOptions_AppRoot_Good(t *testing.T) {
opts := Options{
DenoPath: "deno",
SocketPath: "/tmp/test.sock",
AppRoot: "/app",
StoreDBPath: "/app/.core/store.db",
}
sc := NewSidecar(opts)
assert.Equal(t, "/app", sc.opts.AppRoot)
assert.Equal(t, "/app/.core/store.db", sc.opts.StoreDBPath)
}
func TestOptions_StoreDBPath_Default_Good(t *testing.T) {
opts := Options{AppRoot: "/app"}
sc := NewSidecar(opts)
assert.Equal(t, "/app/.core/store.db", sc.opts.StoreDBPath,
"StoreDBPath should default to AppRoot/.core/store.db")
}
func TestOptions_SidecarArgs_Good(t *testing.T) {
opts := Options{
DenoPath: "deno",
SidecarArgs: []string{"run", "--allow-env", "main.ts"},
}
sc := NewSidecar(opts)
assert.Equal(t, []string{"run", "--allow-env", "main.ts"}, sc.opts.SidecarArgs)
}
func TestDefaultSocketPath_XDG(t *testing.T) {
orig := os.Getenv("XDG_RUNTIME_DIR")
defer os.Setenv("XDG_RUNTIME_DIR", orig)
os.Setenv("XDG_RUNTIME_DIR", "/run/user/1000")
path := DefaultSocketPath()
assert.Equal(t, "/run/user/1000/core/deno.sock", path)
}
func TestOptions_DenoSocketPath_Default_Good(t *testing.T) {
opts := Options{SocketPath: "/tmp/core/core.sock"}
sc := NewSidecar(opts)
assert.Equal(t, "/tmp/core/deno.sock", sc.opts.DenoSocketPath,
"DenoSocketPath should default to same dir as SocketPath with deno.sock")
}
func TestOptions_DenoSocketPath_Explicit_Good(t *testing.T) {
opts := Options{
SocketPath: "/tmp/core/core.sock",
DenoSocketPath: "/tmp/custom/deno.sock",
}
sc := NewSidecar(opts)
assert.Equal(t, "/tmp/custom/deno.sock", sc.opts.DenoSocketPath,
"Explicit DenoSocketPath should not be overridden")
}