fix(project-list): add pagination and flexible target parsing#221
fix(project-list): add pagination and flexible target parsing#221
Conversation
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Build
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ Patch coverage is 86.39%. Project has 3965 uncovered lines. Files with missing lines (71)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 68.44% 70.32% +1.88%
==========================================
Files 109 109 —
Lines 13249 13361 +112
Branches 0 0 —
==========================================
+ Hits 9068 9396 +328
- Misses 4181 3965 -216
- Partials 0 0 —Generated by Codecov Action |
d09e97c to
8ca6cff
Compare
- Follow API cursor pagination so --limit >100 actually works - Add org/ prefix syntax to list projects for a specific org - Add org/project syntax to show a single project directly - Add --cursor/--prev flags for manual page navigation - Add pagination_cursors table (schema v5) with composite PK - Cache cursors per (command_key, context) for independent paging - Clear pagination cursors on auth logout - Regenerate SKILL.md for updated command help
- Property-based tests for parseLinkHeader (RFC 5988 Link header parsing) - Model-based tests for pagination cursor storage (composite PK, TTL, upsert) - Unit + property tests for project list helpers (buildContextKey, filterByPlatform, resolveCursor) - Handler tests for handleExplicit, handleOrgAll, handleProjectSearch with fetch mocking - Verify clearAuth cross-cutting invariant clears pagination cursors - Export parseLinkHeader and project list helpers for testability
…ONFIG_DIR Falls back to creating a temp directory when the env var is not set, which can happen due to test file ordering and worker isolation in CI.
…AutoDetect - Test displayProjectTable (table formatting orchestrator) - Test fetchOrgProjects (attaches orgSlug context) - Test fetchOrgProjectsSafe (swallows non-auth errors, propagates AuthError) - Test fetchAllOrgProjects (fans out across orgs, skips access errors) - Test handleAutoDetect (auto-detect mode with platform filter, limit, JSON output) - Export additional functions from list.ts for testability
Address review comments: - Use single-page listProjectsPaginated for single-org auto-detect without platform filter, avoiding unnecessary full pagination (up to 5000 items) - Remove no-op identity mapping in handleProjectSearch
…-duplicate ProjectWithOrg Address review comments: - Track hasMore from listProjectsPaginated response in auto-detect fast path so truncation message appears when server has more results - Make ProjectWithOrg in list.ts private to eliminate duplicate exported type with conflicting orgSlug optionality (canonical export in api-client.ts)
…earch handleProjectSearch now shows 'No project X found matching platform Y' when projects exist but are filtered out, matching handleExplicit behavior. Previously it misleadingly said 'No project X found in any accessible org.'
…ojects findProjectsBySlug now calls getProject(org, slug) per org (1 API call each) instead of listProjects which auto-paginates up to 50 pages per org. For a user with 5 orgs, this reduces worst-case from ~250 API calls to 5.
… listProjects
Tests now mock /projects/{org}/{slug}/ (direct lookup) instead of
/organizations/{org}/projects/ (list all) to match the implementation change.
Both are only used internally within list.ts — no external imports exist.
…rove fast-path truncation message Address two BugBot review comments: 1. Test helpers in schema.test.ts and fix.test.ts now use hand-written DDL for pagination_cursors with the correct composite PRIMARY KEY (command_key, context), matching production behavior. Previously the auto-generated DDL from EXPECTED_TABLES lacked the composite PK. 2. Fast-path truncation message now suggests 'sentry project list <org>/' for paginated results instead of '--limit', since the API caps per_page at 100 and increasing --limit beyond that won't fetch more data.
handleProjectSearch was accepting flags.limit but never applying it, displaying all matches regardless. Now slices results to flags.limit and shows a truncation message when matches exceed the limit. Also applies limit to JSON output for consistency with handleAutoDetect and handleOrgAll.
246f781 to
4b056d5
Compare
…dRequestPaginated orgScopedRequest now delegates to orgScopedRequestPaginated and discards the pagination metadata, eliminating duplicated org-slug extraction, dynamic import, and region resolution boilerplate.
…tion_cursors to test coverage - Reorder TABLE_SCHEMAS.pagination_cursors columns to match PAGINATION_CURSORS_DDL: command_key, context, cursor, expires_at - Add 'pagination_cursors' to expectedTableNames in schema.test.ts so the test catches accidental removal of the table from the schema
…nation types, replace regexes
- buildContextKey: use type:<kind>[:<arg>] notation (type:org:X, type:auto, etc.)
- apiRequestToRegion: always return { data, headers }, remove wrapper
- PaginatedResponse: remove redundant hasMore field, derive from nextCursor
- parseLinkHeader: replace regexes with extractLinkAttr string parsing
- MAX_PAGINATION_PAGES: add JSDoc rationale + SENTRY_MAX_PAGINATION_PAGES env override
- CUSTOM_DDL_TABLES: add JSDoc explaining composite PK limitation
- listCommand docs: add --platform, --limit, --json examples
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Add compositePrimaryKey field to TableSchema so columnDefsToDDL can emit table-level PRIMARY KEY constraints. This eliminates all special-casing for pagination_cursors: CUSTOM_DDL_TABLES, PAGINATION_CURSORS_DDL, repairPaginationCursorsTable, and the hand-written DDL in test files. Net -67 lines of code removed.
…message - Lowercase platform in buildContextKey so --platform Python and --platform python resolve to the same cursor cache entry - When platform filter produces no results and there are no more pages, show "No projects matching platform 'X'" instead of the misleading "No projects found in organization"
…pollution Three test files (version-check, install-info, project-cache) were deleting process.env.SENTRY_CONFIG_DIR in afterEach without saving the original value set by preload.ts. When Bun's test runner shares a process across files, this poisons the env for subsequent tests that capture the var at module load time.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
When --platform is active in org-all mode, the next-page hints now include the flag so that following the hint preserves the filter and matches the correct cursor context key.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
…orrectly - Extract fetchPaginatedSafe() to handle non-auth API errors (403, network) in the single-org fast path, matching fetchOrgProjectsSafe behavior. Reduces handleAutoDetect complexity below lint threshold. - Fix createIsolatedDbContext cleanup to restore original env var value (including undefined) instead of leaking fallback path. - Add tests for fast-path error handling (non-auth swallowed, AuthError propagated).
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
…nation-v2 # Conflicts: # test/lib/db/install-info.test.ts # test/lib/db/project-cache.test.ts # test/lib/version-check.test.ts
b576c7a to
1085d5a
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
…nation-v2 # Conflicts: # src/lib/api-client.ts # src/lib/region.ts
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
findProjectsBySlug now uses getProject (SDK retrieveAProject) per org
instead of listing all projects. The mock was returning an array for
the /projects/{org}/{project}/ endpoint, causing the SDK to parse it
incorrectly. Return 404 for non-existent project detail requests.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Summary
Fixes three bugs in
sentry project list:--cursor/-cflag with alastmagic value that resumes from where you left off.-n 200still capped at 100 because the Sentry API paginates and we never followed cursor links. AddedorgScopedPaginateAll()solistProjects()transparently fetches all pages.project list sentry/sentrysaid "No projects found in organization 'sentry/sentry'" — now usesparseOrgProjectArg()(same asissue list) to handleorg/project,org/, and bare-word targets.Changes
src/lib/api-client.ts— Pagination infrastructurePaginatedResponse<T>type,parseLinkHeader(),orgScopedRequestPaginated(),orgScopedPaginateAll()listProjects()now auto-paginates transparently (all 6 callers unchanged)listProjectsPaginated()for explicit single-page fetches with cursor controlsrc/commands/project/list.ts— Rewritten commandauto-detect,explicit(org/project),org-all(org/),project-search(bare slug)--cursor/-cflag withlastmagic value for easy page navigation{ data, nextCursor?, hasMore }in paginated modesrc/lib/db/schema.ts— Schema v6pagination_cursorstable for cursor cachingsrc/lib/db/pagination.ts— New moduleTests
test/e2e/project.test.tsandtest/e2e/multiregion.test.tsfor neworg/syntax and paginated JSON format