Skip to content

test(api): cover RI-exchange scope in-scope and lookup-error paths (follow-up to #379) - #389

Merged
cristim merged 1 commit into
mainfrom
fix/93-ri-exchange-account-scope
Sep 28, 2026
Merged

cristim merged 1 commit into
mainfrom
fix/93-ri-exchange-account-scope

Conversation

@cristim

@cristim cristim commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #379 (issue #93). This commit was pushed to the #379 branch after #379 had already merged, so it never landed. It addresses the review findings on #379:

  • Adds a test that a restricted session whose allowed_accounts covers the deployment account reaches the constraint check.
  • Adds a test that a GetAllowedAccountsAPI error yields a 500, not a 403.
  • Fixes the stale caller list in the reshapeCloudAccountInScope comment and trims the new doc comments.

Covers item 4 of #384. Behavior is unchanged; this is tests and comments only.

Verification

CI on this branch, plus the independent review of the diff before merge.

Summary by CodeRabbit

  • Tests
    • Added coverage for account-scope permission checks, including matching deployment accounts and failures when retrieving allowed accounts.
    • Expanded verification that scope mismatches stop processing before permission constraints are checked.
  • Documentation
    • Clarified internal descriptions of account-scope checks and unattributed accounts.

Follow-up to the executeExchange session-scope fix for issue #93:

- Add TestExecuteExchange_SessionAccountScopeMatchReachesConstraintsCheck,
  the positive-path counterpart to the existing regression test: a
  session restricted to an allowed_accounts list that includes the
  deployment's own cloud account must clear the new scope gate and reach
  the pre-existing SEC-01/#1141 constraints check, proving the fix does
  not over-deny an in-scope request.
- Add TestExecuteExchange_SessionScopeLookupErrorFailsClosed: a failure
  resolving the session's allowed_accounts must propagate as a plain
  error, not collapse into a 403 that misreports a lookup failure as an
  out-of-scope denial.
- Document, in the existing regression test, why
  HasPermissionForConstraintsAPI is deliberately left unstubbed rather
  than stubbed-and-asserted-not-called.
- Note reshapeCloudAccountInScope's doc comment now lists executeExchange
  (via requireReshapeAccountScope) among its callers.
- Trim the requireReshapeAccountScope and
  resolveReshapeCloudAccountIDOrUnattributed doc comments to their
  essentials; the issue history and gocyclo rationale live in the PR
  description instead.
@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: LeanerCloud/cloud-commitments-platform/.coderabbit.yaml

Review profile: CHILL

Plan: Essentials

Run ID: f9b1c31e-dc47-4f42-869a-b67bfc9f6f63

📥 Commits

Reviewing files that changed from the base of the PR and between 5bfa1db and 3a0c9a8.

📒 Files selected for processing (2)
  • internal/api/handler_ri_exchange.go
  • internal/api/handler_ri_exchange_test.go

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour.


📝 Walkthrough

Walkthrough

Comments clarify the account-scope check and its callers. Tests verify that executeExchange reaches permission-constraint checks only after session scope passes, and that allowed-account lookup errors stop the request before those checks.

Changes

Account Scope Checks

Layer / File(s) Summary
Scope gate behavior and tests
internal/api/handler_ri_exchange.go, internal/api/handler_ri_exchange_test.go
Comments clarify the shared scope check and its execution behavior. Tests cover mismatched and matching session scope, permission-constraint ordering, and allowed-account lookup errors.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Merge Risk: ⚪ Minimal · up to 3a0c9

No actionable merge-blocking issue is identified; the change is ready for normal checks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the added RI-exchange scope tests and the two covered paths. It accurately describes the primary change and follow-up context.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

@cristim cristim added type/security Security finding severity/medium Moderate harm urgency/this-sprint Within the current sprint impact/many Affects most users effort/xs Trivial / one-liner priority/p1 Next up; this sprint triaged Item has been triaged labels Sep 28, 2026
@cristim

cristim commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review + local verification: MERGE at 3a0c9a8. Tests and comments only (comment-stripped diff of the source is empty); merges cleanly onto main; the in-scope and lookup-error tests each killed their targeted mutants (restricted always out of scope; lookup error swallowed to 403; lookup error fails open); internal/api race suite 2224 passed.

@cristim
cristim merged commit a9d64d9 into main Sep 28, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/xs Trivial / one-liner impact/many Affects most users priority/p1 Next up; this sprint severity/medium Moderate harm triaged Item has been triaged type/security Security finding urgency/this-sprint Within the current sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant