Skip to content

feat(status): --json always emits a JSON object for every auth/link state - #8335

Open
DavidWells wants to merge 2 commits into
mainfrom
split/status-json
Open

feat(status): --json always emits a JSON object for every auth/link state#8335
DavidWells wants to merge 2 commits into
mainfrom
split/status-json

Conversation

@DavidWells

Copy link
Copy Markdown
Contributor

Split from #8300 (7 of 9).

What

netlify status --json emitted 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 additive loggedIn/linked/error: null fields. Non-JSON output and exit semantics are unchanged.

Why it helps agents

status --json is the first command an agent runs to orient itself. Zero-byte stdout forces guessing between "not logged in" and "not linked"; a stable error.code + fix makes recovery a single deterministic step, and JSON.parse(stdout) never throws.

Testing

  • New unit tests covering all four states (logged out, expired session, unlinked, linked)
  • typecheck ✓ lint ✓ 412 unit tests ✓

…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.
@DavidWells
DavidWells requested a review from a team as a code owner July 6, 2026 18:00
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Expanded JSON status output to clearly indicate login and site-linking states.
    • Added structured error responses for unauthenticated and unlinked states, including actionable guidance.
    • Added explicit handling for expired sessions in JSON output.
    • Successful JSON responses now include login, linking, and error status fields.
  • Bug Fixes

    • Prevented authentication failures from producing inconsistent JSON or unstructured errors.
  • Tests

    • Added comprehensive coverage for JSON and standard status command behavior across authentication and linking scenarios.

Walkthrough

The 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: aitchiss

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: status --json now emits structured JSON across auth and link states.
Description check ✅ Passed The description is directly related to the changeset and accurately describes the new JSON status behavior and tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch split/status-json

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.

❤️ Share

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

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

📊 Benchmark results

Comparing with c97eb90

  • Dependency count: 1,127 (no change)
  • Package size: 379 MB (no change)
  • Number of ts-expect-error directives: 358 (no change)

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between c97eb90 and 9666dfc.

📒 Files selected for processing (2)
  • src/commands/status/status.ts
  • tests/unit/commands/status/status.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • netlify/blueprints (manual)

Comment on lines +170 to +178
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 },
})
})

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.

🗄️ 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.

Suggested change
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.

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.

2 participants