fix: create Codex account config directories
This commit is contained in:
@@ -41,6 +41,9 @@ func (c *Client) Start(ctx context.Context) error {
|
||||
if c.connected {
|
||||
return nil
|
||||
}
|
||||
if e := ensureConfigDir(c.configDir); e != nil {
|
||||
return e
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, "codex", "app-server")
|
||||
cmd.Env = append(os.Environ(), "CODEX_HOME="+c.configDir)
|
||||
out, e := cmd.StdoutPipe()
|
||||
@@ -60,6 +63,13 @@ func (c *Client) Start(ctx context.Context) error {
|
||||
go func() { _ = cmd.Wait(); c.failAll(cmd) }()
|
||||
return nil
|
||||
}
|
||||
|
||||
func ensureConfigDir(dir string) error {
|
||||
if e := os.MkdirAll(dir, 0700); e != nil {
|
||||
return fmt.Errorf("create CODEX_HOME %q: %w", dir, e)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (c *Client) Initialize(ctx context.Context) error {
|
||||
var out any
|
||||
if e := c.Call(ctx, "initialize", map[string]any{"clientInfo": map[string]any{"name": "codex-helper", "title": "Codex Helper", "version": "0.1.0"}, "capabilities": map[string]any{}}, &out); e != nil {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package codex
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEnsureConfigDirCreatesNestedDirectory(t *testing.T) {
|
||||
dir := filepath.Join(t.TempDir(), "accounts", "2", "codex")
|
||||
if err := ensureConfigDir(dir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
info, err := os.Stat(dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !info.IsDir() {
|
||||
t.Fatalf("%s is not a directory", dir)
|
||||
}
|
||||
if got := info.Mode().Perm(); got != 0700 {
|
||||
t.Fatalf("permissions = %o; want 700", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureConfigDirReportsCreationFailure(t *testing.T) {
|
||||
parent := t.TempDir()
|
||||
file := filepath.Join(parent, "not-a-directory")
|
||||
if err := os.WriteFile(file, []byte("x"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dir := filepath.Join(file, "codex")
|
||||
err := ensureConfigDir(dir)
|
||||
if err == nil {
|
||||
t.Fatal("expected directory creation to fail")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "create CODEX_HOME") || !strings.Contains(err.Error(), dir) {
|
||||
t.Fatalf("error = %q; want CODEX_HOME path context", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user