-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add minimal contract test for public api #1255
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
base: main
Are you sure you want to change the base?
Conversation
|
Greptile OverviewGreptile SummaryAdds 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 Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
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
|
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.
6 files reviewed, no comments
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