Skip to content

feat(cli): add account spending-cap commands [show] - #1613

Merged
ejanusevicius merged 3 commits into
mainfrom
edvinas/tree-1269-cli-spending-limit-in-the-cli
Nov 23, 2026
Merged

ejanusevicius merged 3 commits into
mainfrom
edvinas/tree-1269-cli-spending-limit-in-the-cli

Conversation

@ejanusevicius

@ejanusevicius ejanusevicius commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Affected Components

  • CLI
  • Create CLI
  • Test
  • Docs (AI context / skill reference)
  • Examples
  • Other

Implements TREE-1269 "[CLI] Spending limit in the CLI". Customers can check and manage their overage spending cap from the CLI. The API calls it "spending cap", so the commands and the wording use that name too.

checkly account spending-cap                  # show (readOnly, idempotent)
checkly account spending-cap set <dollars>    # e.g. 50 or 12.50, 0 to 10000 (idempotent)
checkly account spending-cap remove           # destructive, idempotent
  • Show: prints the cap ("No cap", or "$0.00 (no overage allowed)"), the overage so far, the cap status (under / close / reached), whether checks are stopped, and when runs were measured. When standing is null, overage reads "Not measured" and the stopped and measured lines are left out, so it never shows $0.
  • set / remove: fetch the current cap first, then go through confirmOrAbort with --force and --dry-run. The preview shows the change ("Change the spending cap from $50.00 to $12.50"). It also warns when the new cap is at or below the overage so far (checks stop at once), or when it is $0.
  • Dollar input: converted to integer cents from the digits (no float drift), at most 2 decimals, 0 to 10000. Anything else throws InvalidInputError (exit 2).
  • Output: every command takes -o detail|json|md. json prints the API response unchanged.
  • Errors:
    • 409: the plan can't hold a spending cap (e.g. prepaid or contract).
    • 403: the role needs billing:read / billing:update and the account must manage its plan in Checkly. The account-not-accessible 403 passes through unchanged.
    • 401: legacy account API keys are not accepted; use a user or service key.
  • Also adds the account:spending-cap oclif topic, the new commands in command-metadata.spec.ts, and a manage-spending-cap AI-context reference. skills/checkly/SKILL.md was regenerated with sync:skills.

Notes for the Reviewer

Depends on an backend API. GET / PUT /v1/billing/spending-cap live on branch edvinas/tree-1269-cli-spending-limit-in-the-cli in the backend monorepo and are not merged or deployed yet. This PR is blocked from merge and release until that API ships. It has only been tested against mocks.

Open questions:

  • I can't tell a missing billing:* permission apart from a missing STRIPE_PLAN_MANAGEMENT feature without a backend errorCode, so the 403 message names both.
  • A $0 cap with $0 overage gets the "$0 allows no overage" warning, not "checks stop at once". This depends on whether the backend treats 0 ≥ 0 as REACHED.
  • The -o default is detail (like account usage summary); members update uses table.
  • The per-pool breakdown is only in --output json, not in the terminal view.
  • AuthCommand authenticates before run(), so a bad amount is only rejected after the credential check. It never reaches the spending-cap API.
  • checkly account --help lists spending-cap both as a topic and as a command (oclif's behaviour for a command that is also a topic, below the root).

Follow-up idea (not in this PR): account usage summary could fetch the cap for the terminal and md views and add a line such as Spending cap: $30.00 · overage so far $18.06 (close to cap), keeping its JSON unchanged.

Verified: pnpm --filter checkly run prepare (incl. tsc --build), pnpm lint, pnpm --filter checkly test (255 files, 4897 passed, 8 skipped).

Testing

1. Configuration

Item Value
CLI Commit 4c62d696 (head of #1613). Clean build.
API Local backend at http://localhost:3000. Monorepo commit 8b2ae8a333.
Data Black-box seed. The accounts are the accounts of route-spending-cap.bb-spec.ts.
Environment CHECKLY_ENV=local, CHECKLY_API_URL=http://localhost:3000, CHECKLY_NO_DELEGATION=1.
Account Plan or condition Caller
accountUsageTeam TEAM. Cap $30.00. Overage $18.06. Owner
accountUsageHobby HOBBY. No standing. Owner
publicSpendingCapStarter STARTER. No cap. Overage $0.26. Owner, read-only user, legacy account key
spendingCapPrepaid PREPAID. Owner
spendingCapNoFeature No STRIPE_PLAN_MANAGEMENT. Owner

2. Procedure

  1. Start the backend: tilt up api-tests. Wait until the seed is complete.
  2. Build the CLI: pnpm install, then pnpm --filter checkly run prepare.
  3. Run each command in section 3, with CHECKLY_CLI_MODE=ci. Exceptions are marked.
  4. Record the exit code, stdout and stderr.
  5. Remove the cap of publicSpendingCapStarter at the end. This gives the seed state again.

3. Results

All 41 commands gave the expected result.

3.1 Show

Command Account Output Exit Result
account spending-cap -o detail|json|md TEAM Cap $30.00, overage $18.06, "Under the cap", checks not stopped. JSON is the API response. 0 Pass
account spending-cap -o detail|json|md HOBBY "No cap". Overage "Not measured". No $0 value. 0 Pass
account spending-cap -o detail|md STARTER, cap $0.30 "Close to the cap (from $0.24)". 0 Pass
account spending-cap -o detail|json|md STARTER, cap $0 "Cap reached". "Checks stopped: Yes". 0 Pass

Output: TEAM account with a cap.

-o detail:

Spending cap

Spending cap:    $30.00
Overage so far:  $18.06
Status:          Under the cap
Checks stopped:  No
Measured at:     2099-11-15 00:00:00 UTC

-o md:

# Spending cap

| Field | Value |
| --- | --- |
| Spending cap | $30.00 |
| Overage so far | $18.06 |
| Status | Under the cap |
| Checks stopped | No |
| Measured at | 2099-11-15 00:00:00 UTC |

-o json:

{
  "spendingCapCents": 3000,
  "standing": {
    "measuredAt": "2099-11-15T00:00:00.000Z",
    "pools": {
      "API": { "used": 17230, "included": 100000, "overageRuns": 0, "overageCents": 0 },
      "BROWSER": { "used": 14890, "included": 12000, "overageRuns": 2890, "overageCents": 1806.25 }
    },
    "overageCents": 1806.25,
    "limit": { "capCents": 3000, "state": "UNDER", "closeAtCents": 2400 }
  }
}

3.2 Set and remove

Command Output Exit Result
set 20 --dry-run Preview: "Set the spending cap to $20.00". 0 Pass
set 20 (agent mode) confirmation_required. Confirm command has --force. No change. 3 Pass
set 20 --force "Spending cap set to $20.00." 0 Pass
set 12.50 --force -o json {"spendingCapCents": 1250} 0 Pass
set 15 --force -o md "Spending cap set to $15.00." 0 Pass
set 0 --dry-run, set 0.20 --dry-run Warning: overage is at or above the new cap. Checks stop at once. 0 Pass
set 5 --dry-run No warning. $5.00 is above the overage. 0 Pass
set 0.20 (interactive, answer "no") Preview and prompt on stderr. No change. 0 Pass
remove --dry-run Preview: "Remove the spending cap of $0.00". 0 Pass
remove (agent mode) confirmation_required. No change. 3 Pass
remove --force [-o json|md] "Spending cap removed." JSON: {"spendingCapCents": null}. 0 Pass

3.3 Errors

Command Condition Output Exit Result
set abc, set 1.234, set -5 Incorrect amount "Invalid amount … at most 2 decimals". No API call. 2 Pass
set 10000.01 Amount too high "The spending cap can be at most $10,000.00." 2 Pass
set 1 --force [-o json] PREPAID plan (409) "This account's plan cannot have a spending cap". JSON error envelope on stdout. 1 Pass
account spending-cap [-o json] No feature (403) "Not allowed … billing:read …". 1 Pass
account spending-cap Read-only user Shows the cap. 0 Pass
set 1 --force Read-only user (403) "Not allowed … billing:update …". 1 Pass
account spending-cap Legacy account key (401) "Legacy account API keys are not accepted." 1 Pass

4. Defects and observations

No. Observation Effect
1 A 403 for a missing feature tells an owner that the role needs a permission. The API sends only "Forbidden". The message can cause confusion. The API must send an error code to fix this.
2 The API sends closeAtCents: null for a $0 cap. In #1613, the type is number. No effect on the output. Correct the type.
3 set and remove with -o md give the same success line as -o detail. Small. No Markdown output.

Show, set and remove the overage spending limit from the CLI
(`checkly account spending-limit [set <dollars> | remove]`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ejanusevicius
ejanusevicius marked this pull request as draft November 20, 2026 13:18
Match the API: `/v1/billing/spending-cap`, `checkly account spending-cap`,
"spending cap" in user-facing text. Explain the 401 legacy account API
keys get.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ejanusevicius ejanusevicius changed the title feat(cli): add account spending-limit commands feat(cli): add account spending-cap commands Nov 20, 2026
@ejanusevicius
ejanusevicius marked this pull request as ready for review November 23, 2026 08:58
@ejanusevicius ejanusevicius changed the title feat(cli): add account spending-cap commands feat(cli): add account spending-cap commands [show] Nov 23, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Auto-approved: ship/show PR from a same-repo branch.

@ejanusevicius
ejanusevicius merged commit c58d58c into main Nov 23, 2026
18 checks passed
@ejanusevicius
ejanusevicius deleted the edvinas/tree-1269-cli-spending-limit-in-the-cli branch November 23, 2026 13:50
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