Commit eadcc21
fix(cli): wave 3 — BugHunt 2026-05-20 T16 P2/P3 fixes
T16 P2-1 — parse the structured error envelope from the api instead of
dumping the raw JSON body at the user. New apierror.go translates
{error, error_code, message, agent_action, upgrade_url, retry_after_seconds}
into a human-readable single-line error, with status-specific framing for
402 (tier wall), 429 (rate limited + retry hint), and 5xx (server error).
Wired into provisionResource, discover/resources, fetchExistingResources,
and provisionForUp — every code path that surfaced a raw body before.
T16 P2-2 — HTTPClient timeout raised from 10s to 60s (configurable via
INSTANT_TIMEOUT_SECONDS env var). Synchronous provisioning on the api can
legitimately exceed 10s under load; the previous timeout aborted slow-but-
successful requests AFTER the server created the resource, leaving an
orphan the user was billed for. 60s matches the api's documented
provisioning budget.
T16 P2-3 — `up`'s env default changes from "production" to "development"
to match the platform default (CLAUDE.md rule 11 / migration 026). New
upDefaultEnv constant. The auth gate now applies to any non-default env:
`--env=production` anonymously fails fast with ExitAuthRequired instead
of silently shipping live. New env resolution order:
--env > manifest.env > $INSTANT_ENV > "development".
T16 P2-4 — webhook REUSE preserves --emit-env output. Previously the
credentials endpoint returned 404 for webhooks (no connection_url) and
the REUSE path printed "credentials hidden" + dropped the export line,
breaking idempotent .env regeneration. Now the CLI reconstructs the
webhook receive URL deterministically from APIBaseURL + token, matching
the api's `receiveURL()` shape.
T16 P2-5 — fetchCredentials parameter renamed id → token with a load-
bearing doc comment pinning the contract: the api's
/api/v1/resources/:id/credentials path parameter is the resource's
TOKEN (UUID), not its database row id. Added mock idDifferentFromToken
mode + a regression test that drives the CLI through PROVISION → REUSE
when id and token are distinct values.
T16 P3 — --json output mode added to `resources`, `status`, and `whoami`.
Stable JSON schemas for agent consumption. The whoami JSON output NEVER
includes the bearer token (T16 P1-1 still holds for the machine-readable
surface) — only the truncated key_display + secret_backend name.
Tests (cmd/bughunt_p2_test.go, 11 new regression tests, hermetic):
TestBugHunt_T16_P2_1_402_TierWallSurfacesAgentAction
TestBugHunt_T16_P2_1_429_RateLimitedShowsRetry
TestBugHunt_T16_P2_1_5xxFallsBackToRawBodyOnNonJSON
TestBugHunt_T16_P2_2_ProvisionTimeoutAtLeast60s
TestBugHunt_T16_P2_3_UpDefaultsToDevelopmentNotProd
TestBugHunt_T16_P2_3_UpExplicitProductionStillNeedsAuth
TestBugHunt_T16_P2_4_WebhookReuseEmitsExportLine
TestBugHunt_T16_P2_5_CredentialsKeyedByTokenNotID
TestBugHunt_T16_P3_ResourcesJSONOutput
TestBugHunt_T16_P3_StatusJSONOutput
TestBugHunt_T16_P3_WhoamiJSONOutputNeverLeaksToken
Existing test fixtures updated env: production → env: development to
match the new platform default (the explicit auth-required-for-non-prod
test still uses --env=staging).
Build + vet + test (race) all green: 55 PASS, 0 FAIL.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent f3dbb06 commit eadcc21
10 files changed
Lines changed: 962 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | | - | |
| 219 | + | |
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | | - | |
| 263 | + | |
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
| |||
420 | 420 | | |
421 | 421 | | |
422 | 422 | | |
423 | | - | |
| 423 | + | |
424 | 424 | | |
425 | 425 | | |
426 | 426 | | |
| |||
0 commit comments