This repository has been archived on 2026-07-17. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
codespace/internal/process/manager_test.go
T
tao.chen 2597d0d60c feat(backend): add opencode ACP (Agent Client Protocol) client
Adds a minimal but real ACP stack for the opencode process:

- pkg/config: process.args default ["acp"] (opencodeCommand still "opencode")
- internal/process: NewManager(command, args) — exec.Command uses args
- internal/acp (new): NDJSON transport + JSON-RPC client over the existing
  process stdio. Implements initialize / session/new / session/prompt /
  session/cancel. Serves fs/read_text_file and fs/write_text_file from the
  workspace's fs.FileSystem. terminal/* requests get MethodNotFound.
- internal/service/acp_service: per-workspace Client + mutex; starts the
  process on first prompt; transparently re-init on restart.
- internal/api/acp_handler: GET /acp/status, GET /acp/history,
  POST /acp/prompt, POST /acp/cancel.
- internal/model/acp: API DTOs.
- internal/acp/client_test: NDJSON split-lines, request/response correlation,
  notification dispatch, agent-initiated request handling (fs + terminal).

Existing process WS endpoint and Shell subsystem are unchanged.

Conversation: 019f354c-a51b-7ec3-83ad-c647e9b50b19
2026-07-06 11:03:59 +08:00

62 lines
1.4 KiB
Go

package process
import (
"os"
"testing"
"codespace/internal/util"
)
func TestStatusBeforeStartIsNotRunning(t *testing.T) {
m := NewManager("opencode", nil)
s := m.Status("ws1")
if s.Running {
t.Error("expected Running=false before start")
}
if s.PID != 0 {
t.Errorf("expected PID=0, got %d", s.PID)
}
}
func TestStartRejectsDuplicateRunningSession(t *testing.T) {
m := NewManager("", nil)
// Override command for testing using the test binary itself.
m.command = os.Args[0]
m.args = []string{"-test.run=TestHelperProcess", "--"}
// Set env so the helper process enters its blocking select loop.
t.Setenv("CODESPACE_HELPER_PROCESS", "1")
root := t.TempDir()
if err := m.Start("ws1", root); err != nil {
t.Fatalf("first Start: %v", err)
}
defer m.Stop("ws1")
err := m.Start("ws1", root)
if err == nil {
t.Fatal("expected error on duplicate start")
}
if code := util.CodeOf(err); code != util.CodeConflict {
t.Errorf("expected conflict error, got %v", err)
}
}
func TestStopMissingSessionIsNotFound(t *testing.T) {
m := NewManager("opencode", nil)
err := m.Stop("nonexistent")
if err == nil {
t.Fatal("expected error stopping missing session")
}
if code := util.CodeOf(err); code != util.CodeNotFound {
t.Errorf("expected not_found error, got %v", err)
}
}
func TestHelperProcess(t *testing.T) {
if os.Getenv("CODESPACE_HELPER_PROCESS") != "1" {
return
}
select {}
}