2026-02-05 11:16:23 +00:00
|
|
|
package workspace
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"testing"
|
|
|
|
|
|
refactor: strip 25 extracted packages, slim to foundation (#5)
## Summary
- Remove 25 packages extracted to domain repos (go-crypt, go-ai, go-devops, go-scm, go-netops)
- Make crypt service registration optional in CLI framework
- core/go is now a pure foundation library (~24K LOC, 17 packages)
## Remaining packages
cache, cli, config, framework, help, i18n, io, lab, log, plugin, process, ratelimit, repos, session, webview, workspace, ws
Co-authored-by: Claude <developers@lethean.io>
Reviewed-on: https://forge.lthn.ai/core/go/pulls/5
Co-authored-by: Charon <charon@lthn.ai>
Co-committed-by: Charon <charon@lthn.ai>
2026-02-16 15:37:06 +00:00
|
|
|
"forge.lthn.ai/core/go-crypt/crypt/openpgp"
|
refactor: strip to pure package library (#3)
- Fix remaining 187 pkg/ files referencing core/cli → core/go
- Move SDK library code from internal/cmd/sdk/ → pkg/sdk/ (new package)
- Create pkg/rag/helpers.go with convenience functions from internal/cmd/rag/
- Fix pkg/mcp/tools_rag.go to use pkg/rag instead of internal/cmd/rag
- Fix pkg/build/buildcmd/cmd_sdk.go and pkg/release/sdk.go to use pkg/sdk
- Remove all non-library content: main.go, internal/, cmd/, docker/,
scripts/, tasks/, tools/, .core/, .forgejo/, .woodpecker/, Taskfile.yml
- Run go mod tidy to trim unused dependencies
core/go is now a pure Go package suite (library only).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Claude <developers@lethean.io>
Reviewed-on: https://forge.lthn.ai/core/go/pulls/3
2026-02-16 14:23:45 +00:00
|
|
|
core "forge.lthn.ai/core/go/pkg/framework/core"
|
2026-02-05 11:16:23 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestWorkspace(t *testing.T) {
|
|
|
|
|
// Setup core with crypt service
|
|
|
|
|
c, _ := core.New(
|
|
|
|
|
core.WithName("crypt", openpgp.New),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
tempHome, _ := os.MkdirTemp("", "core-test-home")
|
|
|
|
|
defer os.RemoveAll(tempHome)
|
|
|
|
|
|
|
|
|
|
// Mock os.UserHomeDir by setting HOME env
|
|
|
|
|
oldHome := os.Getenv("HOME")
|
|
|
|
|
os.Setenv("HOME", tempHome)
|
|
|
|
|
defer os.Setenv("HOME", oldHome)
|
|
|
|
|
|
|
|
|
|
s_any, err := New(c)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
s := s_any.(*Service)
|
|
|
|
|
|
|
|
|
|
// Test CreateWorkspace
|
|
|
|
|
id, err := s.CreateWorkspace("test-user", "pass123")
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.NotEmpty(t, id)
|
|
|
|
|
|
|
|
|
|
wsPath := filepath.Join(tempHome, ".core", "workspaces", id)
|
|
|
|
|
assert.DirExists(t, wsPath)
|
|
|
|
|
assert.DirExists(t, filepath.Join(wsPath, "keys"))
|
|
|
|
|
assert.FileExists(t, filepath.Join(wsPath, "keys", "private.key"))
|
|
|
|
|
|
|
|
|
|
// Test SwitchWorkspace
|
|
|
|
|
err = s.SwitchWorkspace(id)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, id, s.activeWorkspace)
|
|
|
|
|
|
|
|
|
|
// Test File operations
|
|
|
|
|
filename := "secret.txt"
|
|
|
|
|
content := "top secret info"
|
|
|
|
|
err = s.WorkspaceFileSet(filename, content)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
got, err := s.WorkspaceFileGet(filename)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, content, got)
|
|
|
|
|
}
|