Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/cuttle/internal/serve/mcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,18 @@ func newMCPHarness(t *testing.T) *mcpHarness {
return newMCPHarnessViewer(t, testViewerAddr)
}

func newSynctestMCPHarness(t *testing.T) *mcpHarness {
t.Helper()
h := newMCPHarness(t)
t.Cleanup(func() {
h.r.close()
// Finish asynchronous session DELETEs while the upstream is still serving;
// fake time stops advancing once the bubble's main goroutine exits.
synctest.Wait()
})
return h
}

// newMCPHarnessViewer is newMCPHarness with the viewer proxy pointed at viewer.
func newMCPHarnessViewer(t *testing.T, viewer string) *mcpHarness {
t.Helper()
Expand Down Expand Up @@ -654,7 +666,7 @@ func TestAggregatorRelistsChangedTools(t *testing.T) {

func TestCaptureBindsOriginAndHoldsScreenshots(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
h := newMCPHarness(t)
h := newSynctestMCPHarness(t)
h.browser.value = "captured-value-1"
cs := h.connect(t, testAgentToken, nil)
callTool(t, cs, "browser_navigate", map[string]any{"url": "https://login.example:443/form"})
Expand Down Expand Up @@ -698,7 +710,7 @@ func TestScreenshotHoldSurvivesNavigation(t *testing.T) {

func TestCuttleWait(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
h := newMCPHarness(t)
h := newSynctestMCPHarness(t)
var progress atomic.Int32
cs := h.connect(t, testAgentToken, func(*mcp.ProgressNotificationParams) { progress.Add(1) })
callTool(t, cs, "browser_navigate", map[string]any{"url": "https://wait.example/"})
Expand Down Expand Up @@ -754,7 +766,7 @@ func TestCompileGlob(t *testing.T) {

func TestDownloadHandles(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
h := newMCPHarness(t)
h := newSynctestMCPHarness(t)
dir := driverDownloadsDir(h.r.m.pool.dataDir)
if err := os.MkdirAll(dir, 0o700); err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion packages/cuttle/internal/serve/mcpeval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestOriginReadFailureSkipsPrecheck(t *testing.T) {

func TestWaitReadsPageOnlyAtReturnAndProgress(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
h := newMCPHarness(t)
h := newSynctestMCPHarness(t)
cs := h.connect(t, testAgentToken, func(*mcp.ProgressNotificationParams) {})
callTool(t, cs, "browser_navigate", map[string]any{"url": "https://example.com"})
before := h.upstreamCalls("browser_evaluate")
Expand Down
8 changes: 4 additions & 4 deletions packages/cuttle/internal/serve/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func TestRemoteRouteFamilies(t *testing.T) {

func TestViewerTicketLifecycle(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
h := newMCPHarness(t)
h := newSynctestMCPHarness(t)
t.Cleanup(h.r.m.pool.shutdown)
cs := h.connect(t, testAgentToken, nil)
callTool(t, cs, "browser_navigate", map[string]any{"url": "https://login.example/"})
Expand Down Expand Up @@ -270,7 +270,7 @@ func TestViewerTicketLifecycle(t *testing.T) {

func TestTicketCap(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
h := newMCPHarness(t)
h := newSynctestMCPHarness(t)
t.Cleanup(h.r.m.pool.shutdown)
mint := func(principal string) error {
_, err := h.r.mintTicket(ticket{kind: ticketViewer, principal: principal, expires: time.Now().Add(time.Minute)})
Expand Down Expand Up @@ -1010,7 +1010,7 @@ func TestPrincipalSeedRebindRevokes(t *testing.T) {

func TestSeedBusyAndViewerRedeem(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
h := newMCPHarness(t)
h := newSynctestMCPHarness(t)
t.Cleanup(h.r.m.pool.shutdown)
h.r.principals.mu.Lock()
h.r.principals.entries[0].seed = "worker"
Expand Down Expand Up @@ -1080,7 +1080,7 @@ func TestViewerLaunchKeepsPinAndRechecksSession(t *testing.T) {
for _, revoked := range []bool{false, true} {
t.Run(strconv.FormatBool(revoked), func(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
h := newMCPHarness(t)
h := newSynctestMCPHarness(t)
t.Cleanup(h.r.m.pool.shutdown)
raised := false
h.r.raiseSeed = func(context.Context, string) bool { raised = true; return true }
Expand Down
Loading