fix(spectrum): report exhausted shared-line capacity - #98
Conversation
📝 WalkthroughWalkthroughThe 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. ChangesResponse handling and output
Test infrastructure and validation
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ 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.
There was a problem hiding this comment.
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 + optionalwarningin 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.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/commands/spectrum/users.ts (1)
106-110: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMove 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
📒 Files selected for processing (6)
src/commands/projects.tssrc/commands/spectrum/platforms.tssrc/commands/spectrum/users.tssrc/lib/types.tstests/contract/projects.contract.test.tstests/helpers/mock-server.ts
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
src/commands/spectrum/users.tssrc/lib/types.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/commands/spectrum/users.ts

Summary
spectrum platforms enable imessagewhen no phone is connectedspectrum users addvisibly, with a structured non-zero JSON error when shared capacity is exhaustedBehavior
This PR does not change project platform selection. The existing CLI behavior remains: omitting
--platformscreates a project with no enabled platform, and explicit--platforms imessageenables iMessage.When iMessage is explicit and owner enrollment is exhausted, the command returns success for the new project and writes the warning to stderr;
--jsonincludes 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— unchangedRoutes added/removed/changed
POST /api/projectsPOST /api/projects/:id/platforms/togglePOST /api/projects/:id/spectrum/usersSnapshot changes
New runtime dependencies
Testing
bun run check— typecheck, 107 tests, and build passedChecklist
@photon-ai/dashboard-apiversion bump, not hand edits (no API type changes)bun run checkpasses in a clean checkoutDashboard/API companion: photon-hq/dashboard#279
Linear: ENG-2164
Summary by CodeRabbit
New Features
Bug Fixes
Tests
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
--jsoncan 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 imessagecan 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 addnow fails visibly on structured API errors (shared_line_unavailable,imessage_not_enabled, etc.), with{ error: { code, message } }on--jsonand exit code 1; incomplete success payloads are rejected instead of printing “Added”.Local DTOs in
types.tsand 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.