feat(status): --json always emits a JSON object for every auth/link state - #8335
feat(status): --json always emits a JSON object for every auth/link state#8335DavidWells wants to merge 2 commits into
Conversation
…tate status --json emitted zero bytes of stdout when logged out or unlinked. Every state now produces a JSON object with loggedIn/linked booleans and a stable error code (NOT_LOGGED_IN, NOT_LINKED) plus suggested fix. Success payload gains additive loggedIn/linked/error fields.
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe status command now exports standardized JSON error codes and returns structured envelopes for unauthenticated, expired-session, unlinked, and successful states. A new Vitest suite mocks command helpers and validates JSON output, exit behavior, human-readable output, account and team data, site data, and expired-session handling. Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📊 Benchmark resultsComparing with c97eb90
|
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 `@tests/unit/commands/status/status.test.ts`:
- Around line 170-178: The test for the JSON expired-session response should
validate the complete standardized envelope rather than a partial match. Update
the assertion in the “with --json emits a NOT_LOGGED_IN error envelope before
throwing” test to check linked, account, siteData, and error.fix along with the
existing loggedIn and error.code fields, using the expected contract values.
🪄 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 Plus
Run ID: a4f92090-2664-404d-bd9b-37424d291b79
📒 Files selected for processing (2)
src/commands/status/status.tstests/unit/commands/status/status.test.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
netlify/blueprints(manual)
| test('with --json emits a NOT_LOGGED_IN error envelope before throwing', async () => { | ||
| await expect(status({ json: true }, createMockCommand())).rejects.toThrow('Your session has expired') | ||
|
|
||
| expect(jsonMessages).toHaveLength(1) | ||
| expect(jsonMessages[0]).toMatchObject({ | ||
| loggedIn: false, | ||
| error: { code: STATUS_ERROR_CODES.NOT_LOGGED_IN }, | ||
| }) | ||
| }) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Assert the complete expired-session envelope.
toMatchObject permits regressions to linked, account, siteData, and error.fix, despite those being part of the standardized response contract.
Proposed fix
- expect(jsonMessages[0]).toMatchObject({
+ expect(jsonMessages[0]).toEqual({
loggedIn: false,
- error: { code: STATUS_ERROR_CODES.NOT_LOGGED_IN },
+ linked: false,
+ account: null,
+ siteData: null,
+ error: {
+ code: STATUS_ERROR_CODES.NOT_LOGGED_IN,
+ fix: 'netlify login or NETLIFY_AUTH_TOKEN',
+ },
})📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| test('with --json emits a NOT_LOGGED_IN error envelope before throwing', async () => { | |
| await expect(status({ json: true }, createMockCommand())).rejects.toThrow('Your session has expired') | |
| expect(jsonMessages).toHaveLength(1) | |
| expect(jsonMessages[0]).toMatchObject({ | |
| loggedIn: false, | |
| error: { code: STATUS_ERROR_CODES.NOT_LOGGED_IN }, | |
| }) | |
| }) | |
| test('with --json emits a NOT_LOGGED_IN error envelope before throwing', async () => { | |
| await expect(status({ json: true }, createMockCommand())).rejects.toThrow('Your session has expired') | |
| expect(jsonMessages).toHaveLength(1) | |
| expect(jsonMessages[0]).toEqual({ | |
| loggedIn: false, | |
| linked: false, | |
| account: null, | |
| siteData: null, | |
| error: { | |
| code: STATUS_ERROR_CODES.NOT_LOGGED_IN, | |
| fix: 'netlify login or NETLIFY_AUTH_TOKEN', | |
| }, | |
| }) | |
| }) |
🤖 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 `@tests/unit/commands/status/status.test.ts` around lines 170 - 178, The test
for the JSON expired-session response should validate the complete standardized
envelope rather than a partial match. Update the assertion in the “with --json
emits a NOT_LOGGED_IN error envelope before throwing” test to check linked,
account, siteData, and error.fix along with the existing loggedIn and error.code
fields, using the expected contract values.
Split from #8300 (7 of 9).
What
netlify status --jsonemitted zero bytes of stdout when logged out or unlinked (exit 1 with no explanation of which). Now every state emits a JSON object:{ "loggedIn": true, "linked": false, "account": { "Name": "…", "Email": "…" }, "siteData": null, "error": { "code": "NOT_LINKED", "fix": "netlify link" } }Codes:
NOT_LOGGED_IN(no token or expired session),NOT_LINKED. The success payload gains additiveloggedIn/linked/error: nullfields. Non-JSON output and exit semantics are unchanged.Why it helps agents
status --jsonis the first command an agent runs to orient itself. Zero-byte stdout forces guessing between "not logged in" and "not linked"; a stableerror.code+fixmakes recovery a single deterministic step, andJSON.parse(stdout)never throws.Testing