Skip to content

fix(member): AND --status against the whole --filter - #249

Open
esterkane wants to merge 1 commit into
TryGhost:mainfrom
esterkane:fix/member-list-filter-status-precedence
Open

fix(member): AND --status against the whole --filter#249
esterkane wants to merge 1 commit into
TryGhost:mainfrom
esterkane:fix/member-list-filter-status-precedence

Conversation

@esterkane

Copy link
Copy Markdown
Contributor

Problem

member list --filter <f> --status <s> combines the two into a single NQL filter, but does not parenthesize the user-supplied filter:

// src/commands/member.ts
`${parsed.data.filter}+status:${parsed.data.status}`

NQL binds + (AND) more tightly than , (OR), so any user filter containing a top-level OR is mis-grouped. For example:

ghst member list --filter 'label:vip,label:founders' --status paid

emits the filter label:vip,label:founders+status:paid, which NQL parses as:

label:vip OR (label:founders AND status:paid)

So the --status paid constraint is silently not applied to the label:vip branch — members with the wrong status are returned. AGENTS.md documents --status as composing with (AND-ing) --filter.

A second, minor issue: status also leaked through the ...parsed.data spread as a standalone status= query param (harmless — Ghost ignores it — but unintended).

Fix

Parenthesize the user filter so the status ANDs against the whole thing:

`(${parsed.data.filter})+status:${parsed.data.status}`

This is the same defensive-parenthesization pattern already used in src/lib/client.ts for the comment-thread filter. Also drop status from the params passed to listMembers, since it is folded into the filter.

Single-clause filters (no top-level OR) are unaffected — label:vip+status:paid and (label:vip)+status:paid are equivalent — which is why this went unnoticed.

Tests

Added a member list test that drives the CLI and asserts the outgoing filter query param is (label:vip,label:founders)+status:paid and that no standalone status param is sent. It fails on main (emits the unparenthesized form) and passes with this change. lint / format:check / typecheck / full test / build all pass.

🤖 Generated with Claude Code

`member list --filter <f> --status <s>` combined the two as
`<f>+status:<s>` without parenthesizing the user filter. NQL binds `+`
(AND) tighter than `,` (OR), so a filter containing a top-level OR was
mis-grouped: `--filter 'label:vip,label:founders' --status paid` emitted
`label:vip,label:founders+status:paid`, which parses as
`label:vip OR (label:founders AND status:paid)` — the status constraint
never applied to the first OR branch, returning members of the wrong
status. AGENTS.md documents `--status` as composing with (AND) `--filter`.

Parenthesize the user filter — `(<f>)+status:<s>` — the same defensive
pattern already used in src/lib/client.ts. Also drop `status` from the
params spread so it is not additionally sent as a standalone query param.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 19, 2026 10:55
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bc2fc32f-be22-4243-85cc-b8d735b38b65

📥 Commits

Reviewing files that changed from the base of the PR and between 6b68a45 and 37bfc48.

📒 Files selected for processing (2)
  • src/commands/member.ts
  • tests/commands-and-run.test.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

The member list command now wraps an existing comma-separated filter before appending status, preserving NQL precedence. It removes status from the request payload after adding it to filter. A regression test verifies the generated filter and confirms that no separate status parameter is sent.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: 🟡 Moderate · up to 37bfc

The filter fix is localized and the stated checks pass, but a reported duplicate requests declaration would make the test file uncompilable if present. Because this conflicts with the reported passing checks, confirm the declaration before merging.

Suggested reviewers: johnonolan

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary fix to apply --status to the whole --filter.
Description check ✅ Passed The description accurately explains the filter-grouping bug, the fix, the removed status parameter, and the regression test.
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 unit tests (beta)
  • Create PR with unit tests

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.

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 pull request fixes ghst member list filter composition so --status correctly ANDs against the entire user-supplied --filter expression (especially when the filter contains top-level ORs), aligning runtime behavior with the documented CLI contract.

Changes:

  • Parenthesizes the user-provided --filter before appending +status:<status> to preserve NQL operator grouping.
  • Prevents status from also being sent as a standalone query parameter (it is now solely encoded into filter).
  • Adds a CLI-driven regression test asserting the exact outgoing filter query param and absence of a separate status param.

Reviewed changes

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

File Description
src/commands/member.ts Fixes NQL grouping by parenthesizing --filter before AND-ing --status, and removes leaked status query param.
tests/commands-and-run.test.ts Adds regression coverage to ensure (filter)+status:… is sent and no standalone status param is included.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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