-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[CANONICALIZATION 4/4] Move server into it's own package (Resolves STG-1047) #1352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
## What Adds a comprehensive test harness for running integration tests against both local P2P servers and the remote Stagehand cloud API. ## Why Enables testing the full request flow through the HTTP API layer, ensuring the P2P server correctly handles session management, streaming, and all Stagehand operations (act, extract, observe, agentExecute, navigate). ## How ### Global Test Setup - `global-setup.stagehand.ts`: Vitest global setup that starts a local Stagehand server before tests and tears it down after - Configurable via STAGEHAND_TEST_TARGET (local/remote) env var - Injects baseUrl into test context via Vitest's provide() mechanism ### Integration Tests - `integration/integration.test.ts`: Full integration test suite covering: - Session creation and termination - Navigation via /navigate endpoint - Data extraction via /extract endpoint - Action observation and replay via /observe and /act - Agent execution via /agentExecute - Metrics retrieval via /replay - `integration/support/stagehandClient.ts`: Test harness factory for creating Stagehand instances configured for the active test target ### Test Configuration - `vitest.config.ts`: Updated to load env from tests/ dir and use global setup - `vitest.provided-context.d.ts`: TypeScript types for injected test context - Removed `disableAPI` references from existing tests (no longer needed) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Greptile OverviewGreptile SummaryAdds comprehensive integration test infrastructure for P2P server testing with support for both local and remote test targets. Key Changes
Critical Issues Found
Confidence Score: 1/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Test as Integration Test
participant Setup as Global Setup
participant Client as Test Harness
participant Server as P2P Server
participant Stagehand as Stagehand Instance
participant Browser as Browser Session
Note over Setup,Server: Test Initialization (beforeAll)
Setup->>Setup: Check STAGEHAND_TEST_TARGET env
alt target === "local"
Setup->>Stagehand: new Stagehand({env: "LOCAL"})
Setup->>Stagehand: init()
Setup->>Server: createServer({host, port})
Setup->>Server: listen()
Setup->>Setup: provide("STAGEHAND_BASE_URL", localUrl)
else target === "remote"
Setup->>Setup: provide("STAGEHAND_BASE_URL", remoteUrl)
end
Note over Test,Browser: Test Execution
Test->>Client: createStagehandHarness(target)
Client->>Client: inject("STAGEHAND_BASE_URL")
Client->>Client: set process.env.STAGEHAND_API_URL
Client->>Stagehand: new Stagehand({env: "BROWSERBASE"})
Test->>Stagehand: init()
Stagehand->>Server: POST /v1/start
Server->>Browser: Create session
Browser-->>Server: Session ID
Server-->>Stagehand: Session details
Stagehand-->>Test: Ready
Note over Test,Browser: Test Operations
Test->>Stagehand: page.goto(url)
Stagehand->>Server: POST /v1/navigate
Server->>Browser: Navigate
Browser-->>Server: Response
Server-->>Stagehand: Navigation result
Stagehand-->>Test: Success
Test->>Stagehand: extract(prompt, schema)
Stagehand->>Server: POST /v1/extract
Server->>Browser: Get page content
Server->>Server: LLM processing
Server-->>Stagehand: Extracted data
Stagehand-->>Test: Structured result
Test->>Stagehand: observe(instruction)
Stagehand->>Server: POST /v1/observe
Server->>Browser: Find elements
Server->>Server: LLM analysis
Server-->>Stagehand: Actions
Stagehand-->>Test: Action list
Test->>Stagehand: act(action)
Stagehand->>Server: POST /v1/act
Server->>Browser: Execute action
Browser-->>Server: Result
Server-->>Stagehand: Execution result
Stagehand-->>Test: Success
Note over Test,Browser: Test Cleanup
Test->>Stagehand: close()
Stagehand->>Server: POST /v1/end
Server->>Browser: Terminate session
Browser-->>Server: Closed
Server-->>Stagehand: Cleanup complete
Note over Setup,Server: Global Teardown
Setup->>Server: server.close()
Setup->>Stagehand: stagehand.close()
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9 files reviewed, 5 comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 issue found across 9 files
Prompt for AI agents (all 1 issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/core/tests/integration/support/stagehandClient.ts">
<violation number="1" location="packages/core/tests/integration/support/stagehandClient.ts:47">
P1: createStagehandHarness only returns when the target is local, so remote test runs receive `undefined` and immediately crash. Add logic that instantiates and returns a Stagehand client for the remote target instead of exiting this function without a value.</violation>
</file>
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
- added pnpm dev command to start server - moved shared types back into core - setup turborepo compatibility
Stack Position
What
This moves the fastify server implementation into it's own package.
There's also a few cleanup lines to remove disableAPI from old test files and stuff.