feat(issue): add workspace-scoped alias cache#52
Merged
Conversation
The alias cache was global without workspace context. When switching between monorepos or using multiple terminals, aliases from one workspace would overwrite another, potentially resolving to the wrong project. This change adds workspace scoping to the alias cache: - Add workspace detection (git root, package.json, or cwd fallback) - Store workspace path when caching aliases in `issue list` - Validate workspace context when resolving aliases in `issue get` - Add org validation as additional safety measure - Maintain backward compatibility with legacy caches Closes getsentry/sentry-cli-next#31 (comment)
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Issue
Other
Bug Fixes 🐛
Documentation 📚
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
- Fix import order in get.ts and list.ts - Add biome-ignore for cognitive complexity in get.ts - Remove unnecessary undefined and collapse if in config.ts
Bun.file().exists() doesn't work correctly for directories. Use node:fs existsSync instead which handles both files and directories.
Contributor
Codecov Results 📊❌ Patch coverage is 62.20%. Project has 1564 uncovered lines. Files with missing lines (18)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 54.90% 55.07% +0.17%
==========================================
Files 33 33 —
Lines 3410 3481 +71
Branches 0 0 —
==========================================
+ Hits 1872 1917 +45
- Misses 1538 1564 +26
- Partials 0 0 —Generated by Codecov Action |
…ping Replace workspace path detection with DSN fingerprint validation for the project alias cache. This is simpler because: - No need for separate workspace detection logic - Aliases naturally invalidate when DSN detection changes - Uses existing DSN caching infrastructure The fingerprint is a sorted, comma-separated string of 'orgId:projectId' pairs, ensuring aliases are only valid when the same set of DSNs are detected. Changes: - Add createDsnFingerprint() in src/lib/dsn/parser.ts - Update setProjectAliases/getProjectByAlias to use dsnFingerprint - Update issue list/get commands to use DSN fingerprinting - Remove src/lib/workspace.ts (no longer needed) - Update tests for new fingerprint-based validation
Improves patch coverage by testing: - Multiple DSN fingerprint creation - Alphabetical sorting of fingerprint - Deduplication of same DSN from multiple sources - Filtering out self-hosted DSNs (no orgId) - Empty array handling
The fingerprint validation was using truthy checks which caused empty string fingerprints to bypass validation. Empty string is a valid fingerprint value (means no SaaS DSNs detected), so we now use explicit undefined checks instead. This prevents aliases from being incorrectly used across workspaces when one or both have only self-hosted DSNs or when DSN detection fails.
Add support for resolving DSNs that don't have an embedded org ID (self-hosted Sentry instances or some SaaS patterns) by: 1. Add findProjectByDsnKey() API using /api/0/projects?query=dsn:<key> 2. Update resolveDsnToTarget() to use DSN public key lookup as fallback 3. Add getCachedProjectByDsnKey/setCachedProjectByDsnKey for DSN-based caching 4. Update createDsnFingerprint() to use host:projectId for DSNs without orgId 5. Update error messages to be more generic (not self-hosted specific) This enables automatic project resolution for self-hosted users without requiring explicit --org and --project flags.
…-aliases # Conflicts: # src/commands/issue/get.ts # src/commands/project/view.ts
Member
|
closes #49 |
BYK
added a commit
that referenced
this pull request
Jan 23, 2026
Add missing tests for functions introduced in the workspace-scoped alias caching feature: - getCachedProject / setCachedProject / clearProjectCache - getConfigPath - createDetectedDsn with invalid DSN - inferPackagePath for various monorepo patterns This brings patch coverage to 100% for the changes in PR #52.
BYK
added a commit
that referenced
this pull request
Jan 23, 2026
## Summary Adds missing tests to achieve 100% patch coverage for the changes introduced in PR #52 (workspace-scoped alias caching). ## Tests Added ### `test/lib/config.test.ts` - `getCachedProject` / `setCachedProject` / `clearProjectCache` - project cache by orgId:projectId - `getConfigPath` - returns the config file path ### `test/lib/dsn.test.ts` - `createDetectedDsn` - creates DetectedDsn from valid/invalid DSN strings - `inferPackagePath` - infers package paths from monorepo directory patterns (packages/, apps/, libs/, modules/, services/) ## Coverage Improvement | File | Before | After | |------|--------|-------| | `src/lib/config.ts` | 86.01% | 97.11% | | `src/lib/dsn/parser.ts` | 94.52% | 98.63% |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds workspace-scoped alias caching using DSN fingerprinting to prevent cross-workspace conflicts, and adds support for self-hosted/non-standard DSN resolution.
Closes #49.
Problem
Alias cache conflicts: The alias cache was stored globally without workspace context. When switching between monorepos or using multiple terminals in different workspaces, aliases from one workspace would overwrite another, potentially resolving to the wrong project's issues.
Self-hosted DSN resolution: DSNs from self-hosted Sentry instances (or non-standard SaaS patterns) don't have an embedded org ID, so they couldn't be auto-resolved.
Solution
Workspace-scoped aliases via DSN fingerprinting
Instead of detecting workspace paths, we use a DSN fingerprint - a sorted string of
orgId:projectId(orhost:projectIdfor self-hosted) pairs from all detected DSNs. Aliases are only valid when the current workspace's DSN fingerprint matches what was stored.createDsnFingerprint()to generate fingerprint from detected DSNsissue listissue viewSelf-hosted DSN resolution
For DSNs without an embedded org ID, we now resolve projects by searching with the DSN's public key via
/api/0/projects?query=dsn:<publicKey>.findProjectByDsnKey()API functionresolveDsnByPublicKey()fallback in target resolutionhost:projectIdin fingerprints for non-SaaS DSNsChanges
New/Updated:
src/lib/dsn/parser.ts- AddcreateDsnFingerprint()src/lib/api-client.ts- AddfindProjectByDsnKey()src/lib/config.ts- Fingerprint-aware alias functions, DSN key cachingsrc/lib/resolve-target.ts- AddresolveDsnByPublicKey()fallbacksrc/lib/dsn/resolver.ts- Use public key lookup for DSNs without orgIdsrc/commands/issue/list.ts- Store fingerprint when cachingsrc/commands/issue/view.ts- Validate fingerprint when resolvingsrc/commands/project/view.ts- Generic error messagesTests:
test/lib/config.test.ts- DSN key cache, fingerprint validationtest/lib/dsn.test.ts- Fingerprint creation tests