COMFY_DIR alone manages ComfyUI: derive the launch command from the standard venv layout
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -190,3 +192,50 @@ func TestWatchIdleRespectsBusyGPU(t *testing.T) {
|
||||
t.Fatal("process was stopped while the GPU was busy")
|
||||
}
|
||||
}
|
||||
|
||||
func TestComfyLayoutAndDefaultCommand(t *testing.T) {
|
||||
// Nested layout (ComfyUI/main.py under dir) wins.
|
||||
dir := t.TempDir()
|
||||
nested := filepath.Join(dir, "ComfyUI", "main.py")
|
||||
if err := os.MkdirAll(filepath.Dir(nested), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(nested, []byte("x"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
python, script := ComfyLayout("windows", dir)
|
||||
if want := filepath.Join(dir, ".venv", "Scripts", "python.exe"); python != want {
|
||||
t.Errorf("python = %s, want %s", python, want)
|
||||
}
|
||||
if script != nested {
|
||||
t.Errorf("script = %s, want %s", script, nested)
|
||||
}
|
||||
cmd := DefaultComfyCommand("windows", dir, "http://127.0.0.1:8189")
|
||||
want := `"` + filepath.Join(dir, ".venv", "Scripts", "python.exe") + `" ` + filepath.Join("ComfyUI", "main.py") + " --port 8189"
|
||||
if cmd != want {
|
||||
t.Errorf("cmd = %q, want %q", cmd, want)
|
||||
}
|
||||
|
||||
// Flat layout (main.py directly under dir) is found too.
|
||||
flat := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(flat, "main.py"), []byte("x"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, script := ComfyLayout("linux", flat); script != filepath.Join(flat, "main.py") {
|
||||
t.Errorf("flat script = %s", script)
|
||||
}
|
||||
cmd = DefaultComfyCommand("linux", flat, "http://comfy.internal")
|
||||
if strings.Contains(cmd, "--port") {
|
||||
t.Errorf("cmd = %q, want no --port for a port-less URL", cmd)
|
||||
}
|
||||
if !strings.HasSuffix(cmd, `" main.py`) {
|
||||
t.Errorf("cmd = %q, want quoted python + relative main.py", cmd)
|
||||
}
|
||||
|
||||
// Neither exists yet: default to the documented nested form so the
|
||||
// startup warning points there.
|
||||
empty := t.TempDir()
|
||||
if _, script := ComfyLayout("windows", empty); script != filepath.Join(empty, "ComfyUI", "main.py") {
|
||||
t.Errorf("missing-layout script = %s", script)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user