Using GH actions provided Chrome for test speedup (#149)
OMG. This had wild behavior. Sometimes you'd log into tmate, and it
would work. Something about running Chrome manually would tickle some
dbus thing into working. The error would sometimes show up, but most
often it would be swallowed.
The punchline? We had a context timeout of 5 or 10 seconds in the tests
that would trigger silently, and we'd see nothing. Everything else
(including maybe the dbus stuff) was a red herring: the test executor
machine is swamped, and shit's slow, and the various timeouts needed
tweaking. I bet there are a few more timeouts to loosen eventually, but
it seems to be passing now.
Error message:
failed to start browser (please apt get chromium or equivalent): chrome failed to start:
diff --git a/claudetool/browse/browse_test.go b/claudetool/browse/browse_test.go
index 6a0a31d..d4c6b1e 100644
--- a/claudetool/browse/browse_test.go
+++ b/claudetool/browse/browse_test.go
@@ -18,6 +18,9 @@
func TestToolCreation(t *testing.T) {
// Create browser tools instance
tools := NewBrowseTools(context.Background())
+ t.Cleanup(func() {
+ tools.Close()
+ })
// Test each tool has correct name and description
toolTests := []struct {
@@ -68,6 +71,9 @@
func TestGetTools(t *testing.T) {
// Create browser tools instance
tools := NewBrowseTools(context.Background())
+ t.Cleanup(func() {
+ tools.Close()
+ })
// Test with screenshot tools included
t.Run("with screenshots", func(t *testing.T) {
@@ -102,10 +108,13 @@
}
// Create browser tools instance
- ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+ ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
tools := NewBrowseTools(ctx)
+ t.Cleanup(func() {
+ tools.Close()
+ })
// Initialize the browser
err := tools.Initialize()
@@ -118,9 +127,6 @@
}
}
- // Clean up
- defer tools.Close()
-
// Get browser context to verify it's working
browserCtx, err := tools.GetBrowserContext()
if err != nil {
@@ -148,11 +154,13 @@
}
// Create browser tools instance
- ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+ ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
tools := NewBrowseTools(ctx)
- defer tools.Close()
+ t.Cleanup(func() {
+ tools.Close()
+ })
// Check if browser initialization works
if err := tools.Initialize(); err != nil {
@@ -222,6 +230,9 @@
// Create browser tools instance
ctx := context.Background()
tools := NewBrowseTools(ctx)
+ t.Cleanup(func() {
+ tools.Close()
+ })
// Test SaveScreenshot function directly
testData := []byte("test image data")
@@ -256,6 +267,9 @@
// Create a test BrowseTools instance
ctx := context.Background()
browseTools := NewBrowseTools(ctx)
+ t.Cleanup(func() {
+ browseTools.Close()
+ })
// Create a test image
testDir := t.TempDir()
@@ -308,7 +322,7 @@
// TestDefaultViewportSize verifies that the browser starts with the correct default viewport size
func TestDefaultViewportSize(t *testing.T) {
- ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Skip if CI or headless testing environment
@@ -317,7 +331,9 @@
}
tools := NewBrowseTools(ctx)
- defer tools.Close()
+ t.Cleanup(func() {
+ tools.Close()
+ })
// Initialize browser (which should set default viewport to 1280x720)
err := tools.Initialize()
@@ -375,7 +391,7 @@
// TestResizeTool tests the browser resize functionality
func TestResizeTool(t *testing.T) {
- ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
// Skip if CI or headless testing environment
@@ -385,7 +401,9 @@
t.Run("ResizeWindow", func(t *testing.T) {
tools := NewBrowseTools(ctx)
- defer tools.Close()
+ t.Cleanup(func() {
+ tools.Close()
+ })
// Resize to mobile dimensions
resizeTool := tools.NewResizeTool()