Skip to content

fix(spectrum): report exhausted shared-line capacity - #98

Merged
Ryan Zhu (underthestars-zhy) merged 5 commits into
mainfrom
henry/eng-2164-report-exhausted-shared-imessage-capacity-in-photon-cli
Aug 4, 2026
Merged

fix(spectrum): report exhausted shared-line capacity#98
Ryan Zhu (underthestars-zhy) merged 5 commits into
mainfrom
henry/eng-2164-report-exhausted-shared-imessage-capacity-in-photon-cli

Conversation

@caezium

@caezium Henry Zhang (caezium) commented Aug 4, 2026

Copy link
Copy Markdown
Member

Summary

  • keep explicit iMessage project creation successful when the owner phone cannot receive another shared line, while printing an actionable warning
  • warn after successful spectrum platforms enable imessage when no phone is connected
  • fail spectrum users add visibly, with a structured non-zero JSON error when shared capacity is exhausted
  • preserve existing JSON shapes when no warning is present

Behavior

This PR does not change project platform selection. The existing CLI behavior remains: omitting --platforms creates a project with no enabled platform, and explicit --platforms imessage enables iMessage.

When iMessage is explicit and owner enrollment is exhausted, the command returns success for the new project and writes the warning to stderr; --json includes the warning in the successful result. Other platform enables and iMessage disablement do not show the warning.

The recovery copy offers another phone or a dedicated line. It does not suggest deleting a project or contacting support. Regression coverage keeps the warning after project deletion because deletion does not currently restore phone-wide shared-line capacity.

Upstream version

  • @photon-ai/dashboard-api@1.6.12 — unchanged
  • no generated API types were edited by hand; warning response fields are decoded through local runtime shapes

Routes added/removed/changed

  • (none) — this CLI PR adds no server routes
  • consumes the optional warning returned by POST /api/projects
  • consumes the optional warning returned by POST /api/projects/:id/platforms/toggle
  • consumes structured failures returned by POST /api/projects/:id/spectrum/users

Snapshot changes

  • (none)

New runtime dependencies

  • (none)

Testing

  • clean-worktree bun run check — typecheck, 107 tests, and build passed
  • hand-tested against the authenticated exhausted-capacity account

Checklist

  • API type changes come from a @photon-ai/dashboard-api version bump, not hand edits (no API type changes)
  • No new runtime deps
  • All snapshot diffs explained above
  • bun run check passes in a clean checkout

Dashboard/API companion: photon-hq/dashboard#279

Linear: ENG-2164

Summary by CodeRabbit

  • New Features

    • Project creation now detects and displays non-blocking warnings in standard and JSON output.
    • Platform toggling reports potential issues, including iMessage connection warnings.
    • Spectrum user operations provide clearer errors for unavailable shared lines and other failures.
  • Bug Fixes

    • Improved handling of empty or incomplete server responses.
  • Tests

    • Added comprehensive coverage for warnings, failures, JSON output, and exit codes.

Note

Low Risk
CLI-only UX and error handling around existing API fields; no auth or billing logic changes. Risk is mainly mis-decoding API warning/error shapes, which contract tests target.

Overview
Surfaces shared iMessage line capacity problems in the Photon CLI with CLI-owned recovery copy (another phone or a dedicated line), instead of silent success or generic API errors.

Project create still succeeds when owner enrollment hits shared-line limits; stderr and --json can include a mapped warning (shared_line_unavailable, owner_phone_missing, owner_enrollment_failed) keyed off the API warning code, not stale server text.

spectrum platforms enable imessage can warn after success when no phone is connected (imessage_connection_missing); other platforms and disabling iMessage stay warning-free, and JSON without a warning keeps the prior platform-map shape.

spectrum users add now fails visibly on structured API errors (shared_line_unavailable, imessage_not_enabled, etc.), with { error: { code, message } } on --json and exit code 1; incomplete success payloads are rejected instead of printing “Added”.

Local DTOs in types.ts and expanded contract mocks/tests cover warnings, JSON shapes, and empty responses.

Reviewed by Cursor Bugbot for commit 3d778a5. Bugbot is set up for automated code reviews on this repo. Configure here.

Copilot AI review requested due to automatic review settings August 4, 2026 15:09
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The CLI now handles typed warnings from project creation and platform toggles, plus structured Spectrum user-add failures. Mock-server support and contract tests cover JSON output, human-readable output, state changes, and exit codes.

Changes

Response handling and output

Layer / File(s) Summary
Typed response contracts
src/lib/types.ts
Shared contracts define project warnings, platform toggle warnings, Spectrum user failures, and response payloads.
Project warning handling
src/commands/projects.ts
Project creation validates response data, recognizes supported warnings, and reports warnings in JSON or stderr output. Helpers validate warning codes and extract canonical warning definitions from API results.
Platform toggle warning flow
src/commands/spectrum/platforms.ts
Platform toggling validates response data, recognizes iMessage connection warnings, and reports warnings in JSON or human-readable output.
Spectrum user-add failure handling
src/commands/spectrum/users.ts
Spectrum user creation parses nested structured failures, validates failure codes, identifies unavailable shared lines and disabled iMessage, and reports JSON or human-readable errors with failure exit status.

Test infrastructure and validation

Layer / File(s) Summary
Mock server state and routes
tests/helpers/mock-server.ts
Mock server tracks project creation, deletion, platform toggles, and Spectrum user creation with configurable warnings and failures. Typed request interfaces, state initialization, accessors, and new API routes support deterministic test scenarios.
Contract tests for all features
tests/contract/projects.contract.test.ts
Comprehensive tests validate project warnings, platform toggles, Spectrum user failures, JSON output, human-readable output, state transitions, request tracking, and process exit codes.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • photon-hq/cli#96: Modifies project-create output and related contract tests, but addresses different behavior regarding platform guidance.
  • photon-hq/cli#97: Covers the same command handlers, shared types, mock infrastructure, and contract tests with the same warning and structured-failure implementation.

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the main change: reporting exhausted shared-line capacity in Spectrum.
Description check ✅ Passed The description covers the required sections, behavior changes, routes, snapshots, dependencies, testing, checklist, and related issue links.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch henry/eng-2164-report-exhausted-shared-imessage-capacity-in-photon-cli

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

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6a11088. Configure here.

Comment thread src/commands/projects.ts

Copilot AI 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.

Pull request overview

This PR updates the CLI’s handling of “exhausted shared iMessage capacity” and related Spectrum flows by decoding optional warning payloads from existing API responses and presenting actionable, CLI-owned recovery messaging (stderr for human output; optional warning fields in --json success payloads). It also makes spectrum users add fail more clearly with structured non-zero JSON output on known server-side failure codes.

Changes:

  • Add non-blocking warning handling for projects create --platforms imessage (stderr + optional warning in JSON success output).
  • Add non-fatal warning handling for spectrum platforms enable imessage (stderr + JSON wrapper only when warning is present; preserve prior JSON shape otherwise).
  • Add structured failure handling for spectrum users add (normalized messaging + { error: { code, message } } JSON output with exit code 1), with expanded mock-server support and contract tests.

Reviewed changes

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

Show a summary per file
File Description
tests/helpers/mock-server.ts Adds mock toggles and endpoints to simulate warning/specific failure payloads (project create, platform toggle, spectrum user add) and records request history for assertions.
tests/contract/projects.contract.test.ts Adds contract coverage asserting stderr/JSON behavior for warnings and structured failures while preserving existing JSON shapes when no warning is present.
src/lib/types.ts Introduces local DTOs/unions for warning/failure codes used to safely interpret API warning/error payloads at the command boundary.
src/commands/spectrum/users.ts Adds structured failure parsing/normalization and structured JSON error output for spectrum users add.
src/commands/spectrum/platforms.ts Adds optional warning decoding/output for enabling iMessage and preserves the prior JSON shape when no warning is present.
src/commands/projects.ts Adds optional warning decoding/output for projects create when iMessage enrollment/capacity warnings are returned.

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

Comment thread src/commands/spectrum/platforms.ts
Comment thread src/commands/projects.ts

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/commands/spectrum/users.ts (1)

106-110: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Move the user-add response DTO to src/lib/types.ts.

Line 106 adds a new API response DTO inside the command. Define the response type, and the referenced user DTO if needed, in src/lib/types.ts. Import it here and retain the cast at Line 106.

As per coding guidelines, “New DTOs go in src/lib/types.ts, cast at the API boundary.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/commands/spectrum/users.ts` around lines 106 - 110, Move the user-add
response DTO and any required SpectrumUser definition from the command into
src/lib/types.ts, export them there, and import the response type in the
command. Keep the existing cast at the API boundary in the user-add flow.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/commands/spectrum/users.ts`:
- Around line 106-110: Move the user-add response DTO and any required
SpectrumUser definition from the command into src/lib/types.ts, export them
there, and import the response type in the command. Keep the existing cast at
the API boundary in the user-add flow.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e9974571-78e4-44f5-8517-be4925bd7de4

📥 Commits

Reviewing files that changed from the base of the PR and between 84923b7 and 6a11088.

📒 Files selected for processing (6)
  • src/commands/projects.ts
  • src/commands/spectrum/platforms.ts
  • src/commands/spectrum/users.ts
  • src/lib/types.ts
  • tests/contract/projects.contract.test.ts
  • tests/helpers/mock-server.ts

Copilot AI review requested due to automatic review settings August 4, 2026 15:17

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings August 4, 2026 15:22

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/types.ts`:
- Around line 58-62: Update SpectrumUserAddResult to a required discriminated
union with success `{ success: true, user: SpectrumUser }` and failure `{ error:
SpectrumUserAddFailure }`, so empty or partial objects are invalid. Move
response validation and casting from the assertion near registerSpectrumUsers in
users.ts to the caller wrapping api.api.projects().spectrum.users.post(), and
pass only the validated result into registerSpectrumUsers.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 355cf604-c7c9-46bb-bdd9-f840fa8231d4

📥 Commits

Reviewing files that changed from the base of the PR and between a89a8af and 640ef21.

📒 Files selected for processing (2)
  • src/commands/spectrum/users.ts
  • src/lib/types.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/commands/spectrum/users.ts

Comment thread src/lib/types.ts Outdated
Copilot AI review requested due to automatic review settings August 4, 2026 15:31

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@underthestars-zhy Ryan Zhu (underthestars-zhy) added the release Just as it is label Aug 4, 2026
@underthestars-zhy
Ryan Zhu (underthestars-zhy) merged commit f662a98 into main Aug 4, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release Just as it is

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants