Skip to content

feat: add cast subscription command#2

Open
hmmhmmhm wants to merge 2 commits intoneosapience:mainfrom
hmmhmmhm:feat/subscription-cmd
Open

feat: add cast subscription command#2
hmmhmmhm wants to merge 2 commits intoneosapience:mainfrom
hmmhmmhm:feat/subscription-cmd

Conversation

@hmmhmmhm
Copy link
Copy Markdown
Member

@hmmhmmhm hmmhmmhm commented Apr 15, 2026

Summary

Adds cast subscription command to display the authenticated user's plan, credit usage, and concurrency limits via GET /v1/users/me/subscription.

Usage

cast subscription

Output:

Plan:        lite
Credits:     19,036 / 200,000 used
Remaining:   180,964
Concurrency: 5

Changes

  • internal/client/subscription.go: GetMySubscription() method + response types
  • internal/client/subscription_test.go: 2 tests (success + unauthorized)
  • cmd/subscription.go: cobra subcommand with formatted output

Test plan

  • go test ./... passes
  • Real API test against staging server

Summary by CodeRabbit

릴리스 노트

  • 새로운 기능

    • 구독 정보 조회 기능 추가: 현재 구독 플랜, 사용한 크레딧, 총 크레딧, 남은 크레딧, 동시성 한도를 확인할 수 있습니다.
  • 테스트

    • 구독 정보 조회 기능에 대한 단위 테스트 추가

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 15, 2026

Warning

Rate limit exceeded

@hmmhmmhm has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 11 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 7 minutes and 11 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 73f7d3ab-0b98-4b38-8d24-957f30f7a97f

📥 Commits

Reviewing files that changed from the base of the PR and between 61c02f9 and 6567ef9.

📒 Files selected for processing (2)
  • cmd/subscription.go
  • cmd/subscription_test.go

Walkthrough

새로운 구독(subscription) 기능을 추가합니다. CLI 명령어는 설정에서 기본 URL과 API 키를 읽고, API 클라이언트를 통해 사용자의 구독 정보를 조회하며, 요금제 이름, 사용/총 크레딧, 남은 크레딧, 동시성 제한을 표준 출력으로 표시합니다.

Changes

코호트 / 파일(s) 요약
CLI 구독 명령어
cmd/subscription.go
Cobra CLI 명령어를 추가하여 Viper 설정에서 기본 URL 및 API 키를 읽고, 클라이언트를 통해 구독 정보를 조회한 후 포맷된 결과를 출력합니다. 정수 포맷팅을 위한 formatInt 헬퍼 함수를 포함합니다.
클라이언트 구독 지원
internal/client/subscription.go
구독 정보 조회를 위한 GetMySubscription() 메서드와 응답 모델 타입(SubscriptionResponse, Credits, Limits)을 정의합니다. /v1/users/me/subscription 엔드포인트를 호출합니다.
구독 클라이언트 테스트
internal/client/subscription_test.go
GetMySubscription() 메서드에 대한 두 가지 테스트를 추가합니다: 성공 응답 처리 검증과 401 Unauthorized 오류 처리 검증.

Sequence Diagram

sequenceDiagram
    participant User as 사용자
    participant CLI as CLI 명령어
    participant Client as HTTP 클라이언트
    participant API as API 서버

    User->>CLI: subscription 명령 실행
    CLI->>CLI: 설정에서 base_url, api_key 읽기
    CLI->>Client: NewWithBaseURL() 또는 New()로 클라이언트 생성
    CLI->>Client: GetMySubscription() 호출
    Client->>API: GET /v1/users/me/subscription
    API-->>Client: JSON 응답 (요금제, 크레딧, 제한)
    Client->>Client: JSON 언마셜링
    Client-->>CLI: SubscriptionResponse 반환
    CLI->>CLI: remaining = PlanCredits - UsedCredits 계산
    CLI->>CLI: formatInt()로 정수 포맷팅
    CLI->>User: 요금제명, 사용/총 크레딧, 남은 크레딧, 동시성 제한 출력
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add cast subscription command' directly and concisely describes the main change—adding a new CLI command for subscription.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/client/subscription_test.go (1)

54-57: 인증 실패 테스트에서 에러 종류까지 고정해 주세요.

Line 55-57은 err != nil만 확인해서, 인증 에러 매핑이 깨져도 테스트가 통과할 수 있습니다. 인증 실패 메시지(또는 핵심 prefix)까지 확인하는 편이 안전합니다.

테스트 보강 예시
 import (
 	"encoding/json"
 	"net/http"
+	"strings"
 	"testing"
 )
@@
 	_, err := c.GetMySubscription()
 	if err == nil {
 		t.Fatal("expected error, got nil")
 	}
+	if !strings.Contains(err.Error(), "authentication failed") {
+		t.Fatalf("unexpected error: %v", err)
+	}
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/client/subscription_test.go` around lines 54 - 57, The test around
c.GetMySubscription() currently only asserts err != nil; update it to assert the
specific authentication error by checking the error value or message (e.g.,
using errors.Is(err, ErrAuthentication) or strings.HasPrefix(err.Error(),
"authentication")/expected prefix) so that authentication error mapping is
validated; locate the test in subscription_test.go where GetMySubscription() is
called and replace the loose nil-check with a concrete assertion against the
expected auth error symbol or message.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/subscription.go`:
- Around line 42-43: The negative branch in formatInt triggers infinite
recursion for math.MinInt64 because -math.MinInt64 overflows; fix by avoiding
negation on int64: either explicitly handle the sentinel (if n == math.MinInt64
return "-9223372036854775808") or convert to unsigned before magnitude
processing (e.g., set var u uint64; if n < 0 { u = uint64(-(n + 1)) + 1 } else {
u = uint64(n) } ) and then use u for the remaining formatting logic in
formatInt; update imports to include math only if you choose the sentinel
constant check.

---

Nitpick comments:
In `@internal/client/subscription_test.go`:
- Around line 54-57: The test around c.GetMySubscription() currently only
asserts err != nil; update it to assert the specific authentication error by
checking the error value or message (e.g., using errors.Is(err,
ErrAuthentication) or strings.HasPrefix(err.Error(), "authentication")/expected
prefix) so that authentication error mapping is validated; locate the test in
subscription_test.go where GetMySubscription() is called and replace the loose
nil-check with a concrete assertion against the expected auth error symbol or
message.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d07191ab-6187-4551-b858-467f97e87ba0

📥 Commits

Reviewing files that changed from the base of the PR and between 104f8af and 61c02f9.

📒 Files selected for processing (3)
  • cmd/subscription.go
  • internal/client/subscription.go
  • internal/client/subscription_test.go

Comment thread cmd/subscription.go Outdated
Use strconv.FormatInt instead of negating the value, which overflows
when n == math.MinInt64 since -MinInt64 cannot be represented in int64.
Sign up for free to 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