Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

test: enhance profile creation test to verify directory existence

Mario279c6b6ce948
diff --git a/internal/profiles/profiles_test.go b/internal/profiles/profiles_test.go
index d11439c7..55136794 100644
--- a/internal/profiles/profiles_test.go
+++ b/internal/profiles/profiles_test.go
@@ -22,6 +22,18 @@ func TestProfileManagerCreateAndList(t *testing.T) {
t.Fatal(err)
}
+ // Verify profile directory exists on disk
+ profileDir := filepath.Join(dir, "test-profile")
+ if _, err := os.Stat(profileDir); err != nil {
+ t.Fatalf("profile directory not created: %s", profileDir)
+ }
+
+ // Verify Default subdirectory exists (required for Chrome)
+ defaultDir := filepath.Join(profileDir, "Default")
+ if _, err := os.Stat(defaultDir); err != nil {
+ t.Fatalf("Default directory not created: %s", defaultDir)
+ }
+
profiles, err := pm.List()
if err != nil {
t.Fatal(err)
@@ -35,6 +47,12 @@ func TestProfileManagerCreateAndList(t *testing.T) {
if profiles[0].Source != "created" {
t.Errorf("expected source created, got %s", profiles[0].Source)
}
+ if !profiles[0].PathExists {
+ t.Errorf("profile path should exist")
+ }
+ if profiles[0].Path != profileDir {
+ t.Errorf("expected path %s, got %s", profileDir, profiles[0].Path)
+ }
}
func TestProfileManagerCreateDuplicate(t *testing.T) {
diff --git a/tests/integration/orchestrator_test.go b/tests/integration/orchestrator_test.go
index e29f4995..cb5bb618 100644
--- a/tests/integration/orchestrator_test.go
+++ b/tests/integration/orchestrator_test.go
@@ -176,12 +176,7 @@ func TestOrchestrator_PortAllocation(t *testing.T) {
// TestOrchestrator_PortReuse verifies ports are released and can be reused
func TestOrchestrator_PortReuse(t *testing.T) {
// Create instance 1
- payload1 := map[string]any{
- "name": fmt.Sprintf("reuse-test-1-%d", time.Now().Unix()),
- "headless": true,
- }
-
- status, body := httpPost(t, "/instances/launch", payload1)
+ status, body := httpPost(t, "/instances/launch", map[string]any{"mode": "headless"})
if status != 201 {
t.Fatalf("instance 1 creation failed: %d", status)
}
@@ -189,21 +184,18 @@ func TestOrchestrator_PortReuse(t *testing.T) {
instID1 := jsonField(t, body, "id")
port1 := jsonField(t, body, "port")
- // Stop instance 1
+ // Stop instance 1 and wait for port release
status, _ = httpPost(t, fmt.Sprintf("/instances/%s/stop", instID1), nil)
if status != 200 {
t.Fatalf("stop instance 1 failed: %d", status)
}
+ time.Sleep(1 * time.Second) // give OS time to release the port
- time.Sleep(500 * time.Millisecond)
-
- // Create instance 2
- payload2 := map[string]any{
+ // Create instance 2 — register cleanup BEFORE any potential t.Fatal
+ status, body = httpPost(t, "/instances/launch", map[string]any{
"name": fmt.Sprintf("reuse-test-2-%d", time.Now().Unix()),
- "headless": true,
- }
-
- status, body = httpPost(t, "/instances/launch", payload2)
+ "mode": "headless",
+ })
if status != 201 {
t.Fatalf("instance 2 creation failed: %d", status)
}
@@ -211,13 +203,15 @@ func TestOrchestrator_PortReuse(t *testing.T) {
instID2 := jsonField(t, body, "id")
port2 := jsonField(t, body, "port")
+ // Always stop instance 2, even if the assertion below fails
+ t.Cleanup(func() {
+ httpPost(t, fmt.Sprintf("/instances/%s/stop", instID2), nil)
+ })
+
// Verify port2 == port1 (reused)
if port1 != port2 {
t.Fatalf("port not reused: old=%s, new=%s", port1, port2)
}
-
- // Cleanup
- httpPost(t, fmt.Sprintf("/instances/%s/stop", instID2), nil)
}
// TestOrchestrator_InstanceIsolation verifies instances have separate tabs