with one click
tusk-drift-analyze
// Analyze Tusk Drift API test deviations locally — classifies deviations as intended, unintended, or unrelated, and optionally fixes regressions.
// Analyze Tusk Drift API test deviations locally — classifies deviations as intended, unintended, or unrelated, and optionally fixes regressions.
Search, analyze, and debug recorded API traffic using the Tusk Drift CLI query commands. Use when users want to explore their API endpoints, investigate errors or latency, trace requests, or understand traffic patterns.
Discover and selectively adopt existing Tusk-generated unit tests. Only relevant once a branch has been pushed and a PR exists — Tusk generates runs in CI on PR push, not for unpushed local work. Use when iterating on a PR, reviewing CI, or when the user asks about adding the Tusk-generated tests for their current branch.
| name | tusk-drift-analyze |
| description | Analyze Tusk Drift API test deviations locally — classifies deviations as intended, unintended, or unrelated, and optionally fixes regressions. |
| allowed-tools | Bash(tusk drift run:*), Bash(git diff:*), Bash(git rev-parse:*) |
You are performing local deviation analysis for Tusk Drift. Your job is to analyze API test deviations, classify them, and optionally fix regressions.
Try running against Tusk Drift Cloud first:
tusk drift run --cloud --save-results agent --print
If the command fails with an authentication error (e.g., Error: not authenticated. Run tusk auth login or set TUSK_API_KEY):
Tell the user they need to authenticate and give them two options:
tusk auth login to authenticate interactivelyTUSK_API_KEY environment variableCheck if local traces exist at .tusk/traces/. If trace files are present, ask the user:
You're not authenticated with Tusk Drift Cloud, but I found local traces in
.tusk/traces/. Would you like to replay those instead?
If the user wants to replay local traces, drop the --cloud flag for all subsequent tusk drift run commands in this session:
tusk drift run --save-results agent --print
Capture the output directory path printed to stderr (e.g., .tusk/results/run-20260329-140532/).
Read index.md in the output directory to get the full picture: how many tests ran, how many passed, how many failed, and the list of deviation files.
If there are no deviations, report that all tests passed and stop.
Determine the base branch:
index.md for a Base Branch: line. If present, use that value.main, then master (check which exists with git rev-parse --verify).Get the PR diff to understand what this branch changed:
git diff <base-branch>...HEAD --stat
git diff <base-branch>...HEAD
If the diff is very large, use --stat first, then selectively read diffs for relevant files.
If there are 10 or more deviations, do NOT jump straight into analyzing each one individually. Instead, triage first:
Scan frontmatter only across all deviation files to build an overview. Read just the YAML frontmatter (between the --- markers) from each file — do not read the full body yet.
Group by endpoint — deviations on the same endpoint likely share a root cause. You only need to deeply analyze one representative per group, then apply the finding to the rest.
Fast-classify obvious cases — if has_mock_not_found: true and the endpoint does not appear in the PR diff, classify as UNRELATED without deep investigation. These are mock gaps, not code bugs.
Prioritize the remaining deviations:
Only read the full deviation file body for deviations that require deep investigation.
For each deviation (or group of similar deviations) that requires analysis:
Read the full .md file. Pay attention to:
Assign one of these types:
| Type | Meaning |
|---|---|
| INTENDED | The deviation directly aligns with what the PR is changing. Example: PR adds a verification_required field, and the deviation shows that field appearing in the response. |
| UNINTENDED | The deviation looks like a regression not matching the PR's intent. Example: PR refactors auth middleware, and an unrelated endpoint starts returning 500. |
| UNRELATED | The deviation is caused by environmental factors, mock issues, or flaky behavior unrelated to PR changes. |
| UNKNOWN | Cannot determine with available information. |
Mock-related heuristics (critical):
has_mock_not_found: true and the PR did NOT intentionally introduce the new outbound call, the deviation is likely UNRELATED — the missing mock is causing the deviation, not a code bug.NO_RESPONSE heuristics:
failure_type: NO_RESPONSE, look for infinite loops, crashes, deadlocks, or panics in the application code itself.General investigation guidance:
For each deviation, produce:
After analyzing all deviations, present a summary table:
## Deviation Analysis Summary
| # | Endpoint | Classification | Confidence | Root Cause |
| --- | -------------------- | -------------- | ---------- | --------------------------------------------------------------------- |
| 1 | POST /api/v1/users | INTENDED | HIGH | PR adds verification_required field to user creation response |
| 2 | GET /api/v1/orders | UNRELATED | HIGH | Mock not found for shipping-service; missing mock, not a code bug |
| 3 | PUT /api/v1/settings | UNINTENDED | MEDIUM | Auth middleware refactor broke header propagation in settings handler |
Then provide detailed analysis for each deviation.
If there are any UNINTENDED deviations, ask the user:
Found N unintended deviation(s) that may be regressions. Would you like me to attempt to fix them?
Wait for the user's response before proceeding to Phase 5.
Only proceed if the user confirms they want fixes.
For each UNINTENDED deviation:
Re-run the specific test (drop --cloud if replaying local traces):
tusk drift run --cloud --save-results agent --print --trace-id {deviation_id}
After re-running, read the new output and determine the outcome:
| Outcome | Meaning | Action |
|---|---|---|
| FIXED | Test passes now | Report success, move to next deviation |
| DEVIATION_IDENTICAL | Same deviation persists after fix | The code change had no effect. Likely a mock gap or environmental issue. Stop and reclassify as UNRELATED/UNFIXABLE. |
| DEVIATION_CHANGED | Different deviation now | Assess whether new deviation is a separate issue. Report it, don't chase it. |
| NEW_DEVIATION | Original fixed but new one appeared | Flag the new deviation as separate. Don't chase it in this loop. |
Present a summary of fix outcomes:
## Fix Results
| # | Endpoint | Outcome | Details |
| --- | -------------------- | -------------------- | ------------------------------------------------------------------ |
| 1 | PUT /api/v1/settings | FIXED | Fixed header propagation in auth middleware |
| 2 | DELETE /api/v1/cache | UNFIXABLE_MOCK_ISSUE | Deviation caused by missing mock for cache-service, not a code bug |
Outcome values:
Include reasoning for each outcome.