Repository navigation
Commit 5856b42
authored
fix(resolve): skip org/project discovery when the DSN already identifies the target (#1476)
Closes #1147
## Problem
When the CLI runs via an AI agent (MCP/skill), it redundantly discovered
org and project identity even though a DSN was already present, causing
unnecessary API calls and occasional re-auth.
## Root cause
A SaaS DSN (`oXXX.ingest…` host) encodes both the numeric org ID and
project ID, so it already identifies the target. But on a
`project_cache` miss, `resolveFromDsn` and `resolveDsnToTarget` still
fired a `getProject(orgId, projectId)` discovery call — routed through
the auth/SDK-config path — purely to translate the numeric IDs into
slugs/display names. That call recurs on every cold-cache invocation
(common in ephemeral agent environments), which is the redundant API
traffic and re-auth the issue reports.
## Fix
`resolveFromDsn` and `resolveDsnToTarget` (both in
`packages/cli/src/lib/resolve-target.ts`) now resolve without any
discovery API call for DSNs that carry an org ID:
1. use resolution the DSN detection layer already surfaced
(`dsn.resolved`), else
2. use locally cached slugs (`project_cache`), else
3. build the target from the DSN's numeric IDs via a new
`dsnTargetFromNumericIds` helper — the Sentry API accepts numeric IDs as
`{org,project}_id_or_slug`, and the org slug is enriched from the local
regions cache (`getOrgByNumericId`, no network) when available.
Public-key-only DSNs (self-hosted / no org ID) are unchanged — the DSN
does not encode identity there, so they still resolve via
`findProjectByDsnKey`.
## Tests
`packages/cli/test/lib/resolve-target.mocked.test.ts`:
- replaced the two obsolete cache-miss tests with regression tests
asserting `getProject` is **not** called when the DSN encodes identity
(detector-`resolved` path, numeric-ID fallback, and regions-cache slug
enrichment)
- added a `resolveAllTargets` test asserting orgId DSNs resolve with no
discovery call
- reworked the "resolution fails" test to use a public-key DSN, the only
path that can still fail
Verified locally: `tsc --noEmit` clean; all 50 `resolve-target.mocked`
tests pass.
<!-- jared:ci-checks=12 -->
Co-authored-by: jared-outpost[bot] <jared-outpost[bot]@users.noreply.github.com>1 parent f23250b commit 5856b42
2 files changed
Lines changed: 158 additions & 115 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
186 | 189 | | |
187 | 190 | | |
188 | 191 | | |
| |||
197 | 200 | | |
198 | 201 | | |
199 | 202 | | |
200 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
201 | 216 | | |
202 | 217 | | |
203 | 218 | | |
| |||
210 | 225 | | |
211 | 226 | | |
212 | 227 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
238 | 234 | | |
239 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
240 | 247 | | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
246 | 253 | | |
| 254 | + | |
247 | 255 | | |
248 | 256 | | |
249 | 257 | | |
| |||
389 | 397 | | |
390 | 398 | | |
391 | 399 | | |
392 | | - | |
393 | 400 | | |
394 | 401 | | |
395 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
396 | 405 | | |
397 | 406 | | |
398 | 407 | | |
| |||
404 | 413 | | |
405 | 414 | | |
406 | 415 | | |
407 | | - | |
| 416 | + | |
408 | 417 | | |
409 | 418 | | |
410 | | - | |
411 | 419 | | |
412 | 420 | | |
413 | 421 | | |
414 | 422 | | |
415 | | - | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
416 | 437 | | |
417 | 438 | | |
418 | 439 | | |
| |||
426 | 447 | | |
427 | 448 | | |
428 | 449 | | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
469 | 458 | | |
470 | 459 | | |
471 | 460 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
475 | 475 | | |
476 | 476 | | |
477 | 477 | | |
478 | | - | |
| 478 | + | |
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
| |||
484 | 484 | | |
485 | 485 | | |
486 | 486 | | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
498 | 492 | | |
499 | 493 | | |
500 | 494 | | |
501 | 495 | | |
502 | 496 | | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
509 | 504 | | |
510 | 505 | | |
511 | | - | |
| 506 | + | |
512 | 507 | | |
513 | 508 | | |
514 | 509 | | |
| |||
517 | 512 | | |
518 | 513 | | |
519 | 514 | | |
| 515 | + | |
520 | 516 | | |
521 | 517 | | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | | - | |
526 | | - | |
527 | | - | |
528 | 518 | | |
529 | 519 | | |
530 | 520 | | |
531 | | - | |
532 | | - | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
533 | 524 | | |
534 | | - | |
535 | | - | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
536 | 552 | | |
537 | 553 | | |
538 | 554 | | |
| |||
840 | 856 | | |
841 | 857 | | |
842 | 858 | | |
843 | | - | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
844 | 900 | | |
845 | 901 | | |
846 | 902 | | |
| |||
868 | 924 | | |
869 | 925 | | |
870 | 926 | | |
871 | | - | |
872 | | - | |
873 | | - | |
874 | | - | |
875 | | - | |
876 | | - | |
877 | 927 | | |
878 | 928 | | |
879 | 929 | | |
880 | | - | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
881 | 935 | | |
882 | 936 | | |
883 | 937 | | |
| |||
0 commit comments