Skip to content

fix(resources): check trial resource limits via the organization trial API#121

Open
pjcdawkins wants to merge 3 commits into
mainfrom
cli-158-resources-set-billing-profile
Open

fix(resources): check trial resource limits via the organization trial API#121
pjcdawkins wants to merge 3 commits into
mainfrom
cli-158-resources-set-billing-profile

Conversation

@pjcdawkins

Copy link
Copy Markdown
Contributor

Problem

resources:set fails with 403 Forbidden on GET /organizations/{id}/profile for organizations that have moved to a new billing system:

Permission denied. Check your permissions on the organization.
Client error: `GET https://api.upsun.com/organizations/.../profile` resulted in a `403 Forbidden` response:
{"title":"This organization profile has moved to the billing profile. ..."}

The profile was only fetched to check the trial resources_limit, which no longer exists there.

Changes

  • Trial resource limits are now read from GET /organizations/{id}/trial, which applies regardless of the organization's billing system, with current usage totals from GET /organizations/{id}/usage. The organization profile is no longer fetched.
  • The check runs only when the organization has an active trial. Individual limits may be null, meaning the resource is not capped.
  • Errors from the trial and usage requests are tolerated (with debug output) because the check is advisory; limits are enforced by the platform. This also covers vendors without trials.
  • With --force, the organization is no longer fetched at all.

Tests

Integration tests cover: no trial (the gated profile endpoint must not be requested), an active trial exceeding limits, an active trial within limits, null (uncapped) limits, and a vendor without trials.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 2, 2026 17:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the resources:set command’s trial resource-limit advisory check to use the organization trial API instead of the organization profile endpoint, avoiding 403s for orgs migrated to the new billing system.

Changes:

  • Replace organization profile-based trial limit checks with GET /organizations/{id}/trial (limits) + GET /organizations/{id}/usage (current totals), and skip the check unless there’s an active trial.
  • Tolerate trial/usage fetch errors (debug-only) because the check is advisory and platform-enforced.
  • Add integration tests covering no trial, active trial within/exceeding limits, null (uncapped) limits, and “trials not enabled”.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
legacy/src/Command/Resources/ResourcesSetCommand.php Switches trial limit detection to org /trial + /usage endpoints and skips org fetch with --force.
integration-tests/resources_set_trial_test.go Adds integration coverage for trial-limit behavior and error-tolerant trial endpoint handling.
integration-tests/resources_set_test.go Adjusts an existing test to avoid mocking the removed organization profile call.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread integration-tests/resources_set_trial_test.go
Comment thread legacy/src/Command/Resources/ResourcesSetCommand.php Outdated
@pjcdawkins pjcdawkins requested review from ahebrank and vitolkachova and removed request for ahebrank July 3, 2026 10:30
pjcdawkins and others added 2 commits July 3, 2026 20:05
…l API

GET /organizations/{id}/profile returns 403 Forbidden for organizations
that have moved to a new billing system, which made resources:set fail
before applying any changes. The profile was only fetched to check the
trial resources_limit, which no longer exists there.

Trial resource limits have moved to GET /organizations/{id}/trial,
regardless of the organization's billing system. Current usage totals
come from GET /organizations/{id}/usage. The check now uses those
endpoints: it applies when the organization has an active trial, and
individual limits may be null, meaning the resource is not capped.

Errors from the trial and usage requests are tolerated because the
check is advisory; limits are enforced by the platform. This also means
trials being unavailable (e.g. for other vendors) is not an error.

Adds integration tests covering: no trial (the gated profile endpoint
must not be requested), an active trial exceeding limits, an active
trial within limits, null (uncapped) limits, and a vendor without
trials.

Written with Claude Code.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The returned arrays are the raw resource_limit and usage totals
objects, which contain more keys than cpu, memory and storage.

Written with Claude Code.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vitolkachova vitolkachova force-pushed the cli-158-resources-set-billing-profile branch from 6d4894c to cd88981 Compare July 3, 2026 18:05
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.

3 participants