Snapshot
Stoobly Snapshot CLI - Questions & Answers
The snapshot CLI manages version-controlled snapshots of requests and scenarios. Snapshots create committable files that enable team collaboration, historical tracking, and reproducible testing through version control systems like Git.
Understanding Snapshots
Q: What are snapshots in Stoobly?
A: Snapshots are version-controlled, file-based representations of requests and scenarios that can be committed to Git. They enable team collaboration and historical tracking of API tests.
Example:
# Create snapshot of a request
stoobly-agent request snapshot "<REQUEST-KEY>"
# Create snapshot of a scenario
stoobly-agent scenario snapshot "<SCENARIO-KEY>"
# Snapshots are stored in .stoobly/snapshots/
ls .stoobly/snapshots/requests/
ls .stoobly/snapshots/scenarios/Q: Why should I use snapshots?
A: Snapshots enable version control of your tests, team collaboration through Git, reproducible testing across environments, and historical tracking of API changes.
Example:
Q: What's the difference between requests in the database and snapshots?
A: Database requests are local and ephemeral, while snapshots are file-based, version-controlled, and shareable across the team.
Example:
Listing Snapshots
Q: How do I view all snapshots?
A: Use snapshot list to display all snapshots.
Example:
Q: How do I list only request snapshots?
A: Use the --resource option to filter by resource type.
Example:
Q: How do I list only scenario snapshots?
A: Specify scenario as the resource type.
Example:
Q: How do I search for specific snapshots?
A: Use the --search option with a regex pattern to filter snapshots. The search behavior depends on the resource type:
For request snapshots (default): The regex matches from the start of the URL or the start of the path. For example,
docs.stoobly.comwill not matchhttps://docs.stoobly.combecause the search starts from the beginning of the URL. Usehttps://docs.stoobly.comor.*?docs.stoobly.comto match URLs containing the domain.For scenario snapshots (with
--resource scenario): The regex matches from the start of the scenario name or the start of the scenario description.
Example:
Q: How do I filter snapshots by scenario name?
A: Use the --scenario option with a regex pattern.
Example:
Q: How do I list pending (unprocessed) snapshots?
A: Use the --pending flag to show snapshots that haven't been applied yet.
Example:
Q: How do I limit the number of snapshots displayed?
A: Use the --size option to control the number of results.
Example:
Q: How do I format snapshot list output?
A: Use the --format option to change output format.
Example:
Q: How do I select specific columns to display?
A: Use the --select option to choose which columns to show.
Example:
Applying Snapshots
Q: How do I apply all snapshots?
A: Use snapshot apply without arguments to apply all available snapshots.
Example:
Q: How do I apply a specific snapshot?
A: Use snapshot apply with the snapshot UUID.
Example:
Q: What happens when I apply a snapshot?
A: Applying a snapshot creates or updates the corresponding request or scenario in your local database from the snapshot file.
Example:
Q: How do I force apply snapshots with hard delete?
A: Use the --force flag to hard delete existing resources when applying.
Example:
Q: What's the difference between apply and reset?
A: snapshot apply creates/updates from snapshots, while request reset or scenario reset restores a specific resource from its snapshot.
Example:
Updating Snapshots
Q: How do I update an existing snapshot?
A: Use snapshot update with the snapshot UUID to create a new version.
Example:
Q: How do I update a snapshot without verification?
A: Use the --no-verify flag to skip request verification.
Example:
Q: What does snapshot verification do?
A: Verification ensures the raw HTTP request format is valid and fixes any formatting issues before creating the snapshot.
Example:
Q: How do I format the output when updating?
A: Use the --format option to control display format.
Example:
Copying Snapshots
Q: How do I copy snapshots to a different directory?
A: Use snapshot copy with the destination path to copy snapshots between data directories.
Example:
Q: How do I copy multiple requests at once?
A: Use multiple --request-key options to copy several requests.
Example:
Q: How do I copy multiple scenarios at once?
A: Use multiple --scenario-key options to copy several scenarios.
Example:
Q: How do I copy both requests and scenarios together?
A: Combine both --request-key and --scenario-key options.
Example:
Q: Why would I copy snapshots to a different directory?
A: Copying snapshots is useful for moving tests between projects, creating backups, or setting up separate test environments.
Example:
Pruning Snapshots
Q: How do I clean up deleted snapshots?
A: Use snapshot prune to remove snapshot files for deleted resources.
Example:
Q: How do I preview what will be pruned without deleting?
A: Use the --dry-run flag to see what would be deleted.
Example:
Q: When should I prune snapshots?
A: Prune after deleting scenarios or requests to keep your snapshot directory clean and your Git repository size manageable.
Example:
Migrating Snapshots
Q: How do I migrate snapshots with custom transformations?
A: Use snapshot migrate with a lifecycle hooks script to transform snapshots during migration.
Example:
Q: How do I migrate snapshots for a specific scenario only?
A: Use the --scenario-key option to limit migration scope.
Example:
Q: What can I do in a migration script?
A: Migration scripts can modify requests, update headers, change hosts, transform response data, or apply any custom logic to snapshots.
Example:
Q: How do I debug migration scripts?
A: Add print statements or use Python debugging in your migration script.
Example:
Version Control Workflows
Q: How do I set up snapshots for Git?
A: Create snapshots and add the .stoobly/snapshots/ directory to Git.
Example:
Q: How do team members use snapshots from Git?
A: Pull the repository and apply snapshots to get the tests.
Example:
Q: How do I update existing snapshots in Git?
A: Re-create the snapshot and commit the changes.
Example:
Q: How do I handle merge conflicts in snapshots?
A: Resolve conflicts manually in snapshot files or re-create snapshots from one version.
Example:
Q: Should I commit snapshot files or the database?
A: Commit snapshot files in .stoobly/snapshots/, NOT the database files in .stoobly/db/. Add .stoobly/db/ to .gitignore.
Example:
Advanced Snapshot Operations
Q: How do I export snapshots for backup?
A: Copy the .stoobly/snapshots/ directory or use snapshot copy.
Example:
Q: How do I share snapshots across projects?
A: Use snapshot copy to move snapshots between project directories.
Example:
Q: How do I create snapshots in CI/CD?
A: Record requests during CI, create snapshots, and commit them back if needed.
Example:
Q: How do I validate snapshots in CI/CD?
A: Apply snapshots and run tests to ensure they're valid.
Example:
Troubleshooting
Q: What do I do if snapshot apply fails?
A: Check for errors, use force option, or manually inspect the snapshot files.
Example:
Q: How do I verify snapshot integrity?
A: Use snapshot update to verify and fix snapshot formatting.
Example:
Q: How do I find which snapshot corresponds to a request?
A: List snapshots with search or match request keys to UUIDs.
Example:
Best Practices
Q: When should I create snapshots?
A: Create snapshots after recording important test flows, before releases, and when sharing tests with the team.
Example:
Q: How often should I prune snapshots?
A: Prune after deleting old tests or periodically to keep the repository clean.
Example:
Q: When should I decode snapshots?
A: Use --decode when creating snapshots for better Git diffs and readability.
Example:
Quick Reference
Q: What are the most common snapshot commands?
A: Here's a quick reference of frequently used commands:
Example:
Integration Examples
Q: How do I automate snapshot creation?
A: Use a script to create snapshots for all scenarios.
Example:
Q: How do I sync snapshots across environments?
A: Use Git to sync and snapshot copy for different data directories.
Example:
Last updated
Was this helpful?