Skip to content

Merge test to main - #172

Merged
sweetmantech merged 1 commit into
mainfrom
test
Jan 29, 2026
Merged

Merge test to main#172
sweetmantech merged 1 commit into
mainfrom
test

Conversation

@sweetmantech

@sweetmantechsweetmantech commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Merge test branch into main after PR #171

Summary by CodeRabbit

Release Notes

  • Tests

    • Comprehensive test coverage added for chat request validation, parameter building, and multi-account filtering scenarios
  • New Features

    • Enhanced authorization flows supporting personal keys, organization member access, and admin privileges
    • Improved chat filtering with support for multiple account IDs
  • Refactor

    • Streamlined request validation logic for chat retrieval endpoints
    • Updated chat query parameter handling for better maintainability

✏️ Tip: You can customize this high-level summary in your review settings.

* feat: restrict account_id in GET /api/chats to ORG/RECOUP keys
- Make account_id query parameter optional in /api/chats
- Personal API keys can no longer specify account_id (403 error)
- Org keys can only filter by account_id for org members
- Recoup admin keys can filter by any account_id
- Personal keys: Returns only their own chats
- Org keys: Returns all org member chats
- Recoup admin: Returns all chats
Uses snake_case naming (account_id, artist_id, org_id) to match API docs.
This matches the authorization pattern used in /api/pulses.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: org key without account_id now returns all org member chats
The rooms table has no FK from account_id to accounts, so the join
approach was silently returning empty results. Changed to fetch org
member account IDs via getAccountOrganizations first, then filter rooms.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
@vercel

vercelBot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentReviewUpdated (UTC)
recoup-apiBuildingBuildingPreviewJan 29, 2026 3:42pm

@sweetmantech
sweetmantech merged commit 9082f6d into mainJan 29, 2026
4 of 6 checks passed
@coderabbitai

coderabbitaiBot commented Jan 29, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR refactors chat retrieval request handling by introducing comprehensive request validation and authorization logic supporting three key types (personal, organization, and Recoup admin). It replaces direct query validation with a layered approach that validates authentication, checks organizational membership, and builds appropriate database query parameters using an updated selectRooms interface that supports multiple account IDs.

Changes

Cohort / File(s)Summary
New Request Validation & Authorization
lib/chats/validateGetChatsRequest.ts, lib/chats/buildGetChatsParams.ts
Introduces request validation that authenticates users, handles three key types (personal/org/admin), validates artist_account_id, enforces access control (403 for unauthorized filtering), and delegates parameter construction to buildGetChatsParams for database queries.
Updated Chat Handler
lib/chats/getChatsHandler.ts
Replaces separate validateAuthContext and validateGetChatsQuery calls with unified validateGetChatsRequest call, simplifying parameter handling and error flow.
Removed Legacy Validation
lib/chats/validateGetChatsQuery.ts
Deletes deprecated query-only validation module previously handling account_id and artist_account_id parsing.
Updated Database Interface
lib/supabase/rooms/selectRooms.ts
Exports SelectRoomsParams interface with account_ids (array) and artist_id fields; implements filtering by multiple account IDs using in-query for flexibility and edge-case handling (empty array returns early).
Test Coverage for Validation
lib/chats/__tests__/validateGetChatsRequest.test.ts, lib/chats/__tests__/buildGetChatsParams.test.ts
Comprehensive test suites covering authentication failures, personal/org/admin key flows, member access validation, cross-account filtering restrictions (403 for personal keys), and org-based membership checks.
Updated Handler & Selection Tests
lib/chats/__tests__/getChatsHandler.test.ts, lib/supabase/rooms/__tests__/selectRooms.test.ts
Handler tests refactored to cover unified validation; selectRooms tests updated to use account_ids array with in-filtering, empty array handling, and artist_id consistency.
Deleted Legacy Test
lib/chats/__tests__/validateGetChatsQuery.test.ts
Removes tests for deprecated validateGetChatsQuery function covering account_id/artist_account_id validation and error response format.
Minor Test Fixes
lib/chats/__tests__/validateCreateChatBody.test.ts, lib/chats/__tests__/generateChatTitle.test.ts, lib/supabase/rooms/__tests__/upsertRoom.test.ts
Formatting consistency, import reorganization, and line collapsing without functional changes.

Sequence Diagram(s)

sequenceDiagram
participant Client
participant Handler as getChatsHandler
participant ValidateReq as validateGetChatsRequest
participant BuildParams as buildGetChatsParams
participant Auth as validateAuthContext
participant OrgService as getAccountOrganizations
participant DB as selectRooms
Client->>Handler: GET /api/chats?account_id=...
Handler->>ValidateReq: validateGetChatsRequest(request)
ValidateReq->>Auth: validateAuthContext(request)
Auth-->>ValidateReq: {account_id, org_id, ...}
alt Personal Key (no org_id)
ValidateReq->>BuildParams: buildGetChatsParams({account_id, org_id: null, target_account_id})
BuildParams-->>ValidateReq: {params: {account_ids: [account_id]}, error: null}
else Organization Key
ValidateReq->>BuildParams: buildGetChatsParams({account_id, org_id, target_account_id})
BuildParams->>OrgService: getAccountOrganizations(org_id)
OrgService-->>BuildParams: [member_ids...]
BuildParams-->>ValidateReq: {params: {account_ids: [members]}, error: null}
else Recoup Admin Key
ValidateReq->>BuildParams: buildGetChatsParams({account_id, org_id: RECOUP_ORG_ID})
BuildParams-->>ValidateReq: {params: {artist_id}, error: null}
end
ValidateReq-->>Handler: SelectRoomsParams | NextResponse
Handler->>DB: selectRooms(params)
DB-->>Handler: Room[] | null
Handler-->>Client: JSON response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Through three paths of keys, we now validate clear,
Personal, org, and admin, each path sincere,
With account_ids gathered from members so true,
The chats flow securely—authorization complete! ✨

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actionsBot commented Jan 29, 2026

Copy link
Copy Markdown

Braintrust eval report

Catalog Opportunity Analysis Evaluation (HEAD-1769701381)

ScoreAverageImprovementsRegressions
Catalog_availability48.9% (+37pp)3 🟢1 🔴
Llm_calls0 (+0)--
Tool_calls0 (+0)--
Errors0 (+0)--
Llm_errors0 (+0)--
Tool_errors0 (+0)--
Prompt_tokens0tok (+0tok)--
Prompt_cached_tokens0tok (+0tok)--
Prompt_cache_creation_tokens0tok (+0tok)--
Completion_tokens0tok (+0tok)--
Completion_reasoning_tokens0tok (+0tok)--
Total_tokens0tok (+0tok)--
Duration42.79s (+3.8s)2 🟢3 🔴

Catalog Songs Count Evaluation (HEAD-1769701381)

ScoreAverageImprovementsRegressions
AnswerCorrectness19.4% (+0pp)2 🟢1 🔴
Factuality33.3% (+0pp)1 🟢1 🔴
Llm_calls4 (+0)--
Tool_calls0 (+0)--
Errors0 (+0)--
Llm_errors0 (+0)--
Tool_errors0 (+0)--
Prompt_tokens0tok (+0tok)--
Prompt_cached_tokens0tok (+0tok)--
Prompt_cache_creation_tokens0tok (+0tok)--
Completion_tokens0tok (+0tok)--
Completion_reasoning_tokens0tok (+0tok)--
Completion_accepted_prediction_tokens0tok (+0tok)--
Completion_rejected_prediction_tokens0tok (+0tok)--
Completion_audio_tokens0tok (+0tok)--
Total_tokens0tok (+0tok)--
Duration17.97s (+0.43s)2 🟢1 🔴

First Week Album Sales Evaluation (HEAD-1769701381)

ScoreAverageImprovementsRegressions
Factuality65% (+40pp)3 🟢-
Llm_calls1 (+0)--
Tool_calls0 (+0)--
Errors0 (+0)--
Llm_errors0 (+0)--
Tool_errors0 (+0)--
Prompt_tokens0tok (+0tok)--
Prompt_cached_tokens0tok (+0tok)--
Prompt_cache_creation_tokens0tok (+0tok)--
Completion_tokens0tok (+0tok)--
Completion_reasoning_tokens0tok (+0tok)--
Completion_accepted_prediction_tokens0tok (+0tok)--
Completion_rejected_prediction_tokens0tok (+0tok)--
Completion_audio_tokens0tok (+0tok)--
Total_tokens0tok (+0tok)--
Duration15.4s (-0.84s)3 🟢1 🔴

Memory & Storage Tools Evaluation (HEAD-1769701381)

ScoreAverageImprovementsRegressions
Tools_called0% (+0pp)--
Llm_calls0 (+0)--
Tool_calls0 (+0)--
Errors0 (+0)--
Llm_errors0 (+0)--
Tool_errors0 (+0)--
Prompt_tokens0tok (+0tok)--
Prompt_cached_tokens0tok (+0tok)--
Prompt_cache_creation_tokens0tok (+0tok)--
Completion_tokens0tok (+0tok)--
Completion_reasoning_tokens0tok (+0tok)--
Total_tokens0tok (+0tok)--
Duration19.23s (+3.61s)-1 🔴

Monthly Listeners Tracking Evaluation (HEAD-1769701381)

ScoreAverageImprovementsRegressions
AnswerSimilarity78.5% (+2pp)3 🟢2 🔴
Llm_calls2 (+0)--
Tool_calls0 (+0)--
Errors0 (+0)--
Llm_errors0 (+0)--
Tool_errors0 (+0)--
Prompt_tokens0tok (+0tok)--
Prompt_cached_tokens0tok (+0tok)--
Prompt_cache_creation_tokens0tok (+0tok)--
Completion_tokens0tok (+0tok)--
Completion_reasoning_tokens0tok (+0tok)--
Total_tokens0tok (+0tok)--
Duration12.16s (-3.3s)4 🟢1 🔴

Search Web Tool Evaluation (HEAD-1769701381)

ScoreAverageImprovementsRegressions
AnswerCorrectness24.6% (-3pp)3 🟢8 🔴
Llm_calls3 (+0)--
Tool_calls0 (+0)--
Errors0 (+0)--
Llm_errors0 (+0)--
Tool_errors0 (+0)--
Prompt_tokens0tok (+0tok)--
Prompt_cached_tokens0tok (+0tok)--
Prompt_cache_creation_tokens0tok (+0tok)--
Completion_tokens0tok (+0tok)--
Completion_reasoning_tokens0tok (+0tok)--
Completion_accepted_prediction_tokens0tok (+0tok)--
Completion_rejected_prediction_tokens0tok (+0tok)--
Completion_audio_tokens0tok (+0tok)--
Total_tokens0tok (+0tok)--
Duration24.03s (-6.07s)8 🟢3 🔴

Social Scraping Evaluation (HEAD-1769701381)

ScoreAverageImprovementsRegressions
Tools_called0% (+0pp)--
Llm_calls0 (+0)--
Tool_calls0 (+0)--
Errors0 (+0)--
Llm_errors0 (+0)--
Tool_errors0 (+0)--
Prompt_tokens0tok (+0tok)--
Prompt_cached_tokens0tok (+0tok)--
Prompt_cache_creation_tokens0tok (+0tok)--
Completion_tokens0tok (+0tok)--
Completion_reasoning_tokens0tok (+0tok)--
Total_tokens0tok (+0tok)--
Duration24.2s (-0.46s)3 🟢3 🔴

Spotify Followers Evaluation (HEAD-1769701381)

ScoreAverageImprovementsRegressions
AnswerCorrectness20.5% (0pp)1 🟢4 🔴
Llm_calls3 (+0)--
Tool_calls0 (+0)--
Errors0 (+0)--
Llm_errors0 (+0)--
Tool_errors0 (+0)--
Prompt_tokens0tok (+0tok)--
Prompt_cached_tokens0tok (+0tok)--
Prompt_cache_creation_tokens0tok (+0tok)--
Completion_tokens0tok (+0tok)--
Completion_reasoning_tokens0tok (+0tok)--
Completion_accepted_prediction_tokens0tok (+0tok)--
Completion_rejected_prediction_tokens0tok (+0tok)--
Completion_audio_tokens0tok (+0tok)--
Total_tokens0tok (+0tok)--
Duration15.46s (+0.7s)3 🟢2 🔴

Spotify Tools Evaluation (HEAD-1769701381)

ScoreAverageImprovementsRegressions
Tools_called0% (+0pp)--
Llm_calls0 (+0)--
Tool_calls0 (+0)--
Errors0 (+0)--
Llm_errors0 (+0)--
Tool_errors0 (+0)--
Prompt_tokens0tok (+0tok)--
Prompt_cached_tokens0tok (+0tok)--
Prompt_cache_creation_tokens0tok (+0tok)--
Completion_tokens0tok (+0tok)--
Completion_reasoning_tokens0tok (+0tok)--
Total_tokens0tok (+0tok)--
Duration34.21s (-2.35s)2 🟢-

TikTok Analytics Questions Evaluation (HEAD-1769701381)

ScoreAverageImprovementsRegressions
Question_answered0% (+0pp)--
Llm_calls0 (+0)--
Tool_calls0 (+0)--
Errors0 (+0)--
Llm_errors0 (+0)--
Tool_errors0 (+0)--
Prompt_tokens0tok (+0tok)--
Prompt_cached_tokens0tok (+0tok)--
Prompt_cache_creation_tokens0tok (+0tok)--
Completion_tokens0tok (+0tok)--
Completion_reasoning_tokens0tok (+0tok)--
Total_tokens0tok (+0tok)--
Duration15.74s (+2.07s)-2 🔴

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@sweetmantech