feat: scaffold codespace backend
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package process
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"codespace/internal/util"
|
||||
)
|
||||
|
||||
func TestStatusBeforeStartIsNotRunning(t *testing.T) {
|
||||
m := NewManager("opencode")
|
||||
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("")
|
||||
// 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")
|
||||
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 {}
|
||||
}
|
||||
Reference in New Issue
Block a user