Skip to content

feat: add named state snapshots for reproducible test scenarios#60

Open
mvanhorn wants to merge 2 commits intovercel-labs:mainfrom
mvanhorn:feat/state-snapshots
Open

feat: add named state snapshots for reproducible test scenarios#60
mvanhorn wants to merge 2 commits intovercel-labs:mainfrom
mvanhorn:feat/state-snapshots

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

@mvanhorn mvanhorn commented Apr 8, 2026

Summary

Add snapshot() and restore() methods to the Emulator interface so tests can save and restore emulator state at any point. Each running service also gets HTTP control endpoints at /_emulate/snapshot and /_emulate/health.

Why this matters

Integration tests often need to start from a specific state (e.g., "user has completed checkout"). Currently reset() wipes everything back to seed. There's no way to save a mid-test state and restore it later without re-running the setup.

LocalStack solves this with localstack state export/import. The core Store class already has snapshot()/restore() methods, and @emulators/adapter-next already implements cross-service snapshots internally. This PR exposes those primitives through the public API.

Changes

  • packages/@emulators/core/src/server.ts: Added /_emulate/snapshot (POST to save, PUT to restore) and /_emulate/health (GET) endpoints before plugin registration so they don't conflict with emulated routes
  • packages/emulate/src/api.ts: Extended Emulator interface with snapshot() and restore() methods that delegate to Store.snapshot()/restore()
  • packages/emulate/src/__tests__/api.test.ts: 3 new tests covering programmatic snapshots, HTTP control endpoints, and health check
  • README.md and skills/emulate/SKILL.md: documented the new API and endpoints

Demo

snapshot-demo

Creates a repo, saves a snapshot, creates a second repo, restores the snapshot, and verifies only the first repo remains.

Testing

All 7 tests pass (4 existing + 3 new):

  • snapshot saves and restore recovers state - programmatic API
  • health endpoint returns service status - health check
  • snapshot via HTTP control endpoint - HTTP save/restore flow

This contribution was developed with AI assistance (Claude Code).

Add snapshot() and restore() methods to the Emulator interface so tests
can save and restore emulator state. Each service also exposes HTTP
control endpoints at /_emulate/snapshot (POST to save, PUT to restore)
and /_emulate/health (GET for readiness checks).

This extends the existing Store.snapshot()/restore() primitives that
were already used internally by the Next.js adapter.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 8, 2026

@mvanhorn is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant