Skip to content

Conversation

@monadoid
Copy link

@monadoid monadoid commented Nov 12, 2025

why

We want to be able to see what the public API shape looks like - which top level functions are exported.

what changed

Added vitest and a minimal test file that checks which functions are exported at the root level. If new functions are exported or removed, this test will catch that. I also added one example of drilling down and testing the parameters of StagehandMetrics — in the future we might want to do this for all exports.

Curious if this surfaces and exports that don't need to be exported or not.

test plan

Just added tests. They run in the CI pipeline or can be run with pnpm --filter @browserbasehq/stagehand run test:vitest

@changeset-bot
Copy link

changeset-bot bot commented Nov 12, 2025

⚠️ No Changeset found

Latest commit: 028ede8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 12, 2025

Greptile Overview

Greptile Summary

Adds vitest and a contract test suite to validate the public API surface of Stagehand. The test checks that exported types and functions match a documented snapshot, preventing accidental breaking changes to the public interface. The implementation includes a specific example test for StagehandMetrics type structure, demonstrating the pattern for future contract tests.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it adds non-invasive testing infrastructure
  • The changes are low-risk additions that enhance code quality: new test infrastructure, minimal configuration files, and CI integration. No production code is modified, only test and build tooling.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/core/tests/public-types.test.ts 5/5 New test file that validates public API exports and type definitions, ensuring no unexpected changes to the public interface
packages/core/vitest.config.ts 5/5 Minimal vitest configuration for running contract tests with node environment
.github/workflows/ci.yml 5/5 Added vitest test execution step after build to run contract tests in CI pipeline
packages/core/package.json 5/5 Added vitest as dev dependency and test:vitest script that builds JS before running tests

Sequence Diagram

sequenceDiagram
    participant CI as CI Pipeline
    participant Build as Build Step
    participant Vitest as Vitest Runner
    participant Test as Contract Test
    participant Dist as dist/index.js
    
    CI->>Build: Run pnpm run build
    Build->>Build: Compile TypeScript
    Build->>Dist: Generate dist/index.js
    
    CI->>Vitest: Run pnpm run test:vitest
    Vitest->>Build: Execute build-js first
    Build->>Dist: Ensure fresh build
    
    Vitest->>Test: Load public-types.test.ts
    Test->>Dist: Import * as Stagehand
    Dist-->>Test: Return all exports
    
    Test->>Test: Compare actual exports vs expected publicApiShape
    Test->>Test: Verify StagehandMetrics type structure
    
    alt Exports match expected shape
        Test-->>Vitest: ✓ Tests pass
        Vitest-->>CI: Success
    else Exports mismatch or type error
        Test-->>Vitest: ✗ Tests fail
        Vitest-->>CI: Failure (breaking API change detected)
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@monadoid monadoid changed the title Added minimal contract test for public api Addminimal contract test for public api Nov 12, 2025
@monadoid monadoid changed the title Addminimal contract test for public api Add minimal contract test for public api Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants