Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Zulip Feature Level Handling. #1462

Merged
merged 1 commit into from
Feb 27, 2024
Merged

Conversation

rsashank
Copy link
Member

@rsashank rsashank commented Jan 17, 2024

What does this PR do, and why?

Fixes #1364
Pure integer representation replacing the current None value when ZFL is absent.

Outstanding aspect(s)

  • [ ]

External discussion & connections

How did you test this?

  • Manually - Behavioral changes
  • Manually - Visual changes
  • Adapting existing automated tests
  • Adding automated tests for new behavior (or missing tests)
  • Existing automated tests should already cover this (only a refactor of tested code)

Self-review checklist for each commit

  • It is a minimal coherent idea
  • It has a commit summary following the documented style (title & body)
  • It has a commit summary describing the motivation and reasoning for the change
  • It individually passes linting and tests
  • It contains test additions for any new behavior
  • It flows clearly from a previous branch commit, and/or prepares for the next commit

Visual changes

@zulipbot zulipbot added size: L [Automatic label added by zulipbot] area: refactoring labels Jan 17, 2024
@zulipbot
Copy link
Member

Hello @zulip/server-refactoring members, this pull request was labeled with the "area: refactoring" label, so you may want to check it out!

Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rsashank Thanks for the moving the previous PR forward 👍

This certainly addresses some of the earlier points in that PR, though I did note that you dropped one change when comparing to it.

This turned out to be more work than I anticipated to complete fully, since we use various different names around the repo, including at least:

  • zulip_feature_level (server field name)
  • ZFL (abbreviation)
  • server_feature_level (in model, to distinguish from client)
  • feature_level (short variable, in tests)

That variation in names, and that they're not all code, certainly hasn't helped. Grepping through the repo, it seems there are a few outstanding unchanged parts remaining.

When you rebase and push this commit again, I suspect this will fail gitlint locally or in CI. A few other notes in that direction:

  • Fixes lines are good near the bottom after a blank line
  • This updates more than just the model, but you don't need to mention tests in the commit title (it's assumed they're always updated where necessary)
  • Since this builds upon the other PR it would be good to add a co-authored-by field near the bottom of the commit (see git log|grep -i co-au for examples)
  • For commit text, describing what the commit changes can be good, but just as important (if not more) is the reasoning (why is integer good? why is removing None good? what did None represent? when is ZFL absent?)

@@ -278,7 +278,7 @@ def test_register_initial_desired_events(self, mocker, initial_data):
None,
10,
{1: "Indefinite [Organization default]"},
id="ZFL=None_no_stream_retention_realm_retention=None",
id="ZFL=10_no_stream_retention_realm_retention=None",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The None->10 change looks appropriate for the test case 👍

My concern here is that the text (id) here previously indicated 'ZFL=None', when it clearly is not. That may have been a typo, or indicative that we should have test case for the ZFL=0 case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the ZFL=0 case with the same parameters as ZFL=10.

@neiljp neiljp added the PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback label Jan 27, 2024
@rsashank rsashank force-pushed the ZFLHandling branch 3 times, most recently from e42a6b8 to 373b6df Compare January 27, 2024 18:05
@rsashank rsashank changed the title refactor: model/tests: Simplify Zulip Feature Level Handling. refactor: model: Simplify Zulip Feature Level Handling. Jan 27, 2024
@rsashank rsashank changed the title refactor: model: Simplify Zulip Feature Level Handling. Simplify Zulip Feature Level Handling. Jan 27, 2024
Comment on lines -3258 to +3269
"remove_18_in_home_view:already_unmuted:ZFLNone",
"remove_19_in_home_view:muted:ZFLNone",
"add_19_in_home_view:already_muted:ZFLNone",
"add_30_in_home_view:unmuted:ZFLNone",
"remove_30_is_muted:already_unmutedZFL139",
"remove_18_in_home_view:already_unmuted:ZFL0",
"remove_19_in_home_view:muted:ZFL0",
"add_19_in_home_view:already_muted:ZFL0",
"add_30_in_home_view:unmuted:ZFL0",
"remove_30_is_muted:already_unmuted:ZFL139",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The absence of a ":" after already_unmuted seemed inconsistent with other ids. (line 3269)
While this change is unrelated to the commit/PR, it appears too minor to be a separate commit. Is that fine?

Comment on lines -3258 to +3268
"remove_18_in_home_view:already_unmuted:ZFLNone",
"remove_19_in_home_view:muted:ZFLNone",
"add_19_in_home_view:already_muted:ZFLNone",
"add_30_in_home_view:unmuted:ZFLNone",
"remove_30_is_muted:already_unmutedZFL139",
"remove_18_in_home_view:already_unmuted:ZFL0",
"remove_19_in_home_view:muted:ZFL0",
"add_19_in_home_view:already_muted:ZFL0",
"add_30_in_home_view:unmuted:ZFL0",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found these ones that weren't changed initially in the PR.

I'm still looking to identify any additional code that may need adjustments.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were others I saw previously that were missing overall 👍

@rsashank
Copy link
Member Author

Thanks for the detailed feedback! @neiljp

I've updated the PR, and I believe all of them have been addressed. I couldn't find any outliers, but please correct me if I'm mistaken. (Checked using VSCode, searched for ZFL and feature_level). I'll further check with grep as well.

Rebased and updated the commit message as per feedback as well.

@zulipbot add "PR needs review"
@zulipbot remove "PR awaiting update"

@zulipbot zulipbot added PR needs review PR requires feedback to proceed and removed PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback labels Jan 27, 2024
Copy link
Collaborator

@mounilKshah mounilKshah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @rsashank for updating the PR
I noticed that you have implemented all the suggestions given by @neiljp

As Neil mentioned in the PR feedback, we have addressed ZFL with multiple phrases like feature level, Zulip feature level, ZFL etc. in code comments or in test case IDs. How about we also add another commit to this PR which renames them to the same name? What do you think of this idea @neiljp and @rsashank ?

@rsashank
Copy link
Member Author

@mounilKshah That makes sense but what's the best way to ensure uniformity in variable names?

Would simply adding _ZFL to the end of variables where needed be sufficient (so you can grep through the repo with ZFL), or should we consider a more uniform rewrite across the repo?

@mounilKshah
Copy link
Collaborator

I was referring to comments and test IDs to have a uniform naming pattern across the repository, variables need not be changed. Naming all instances as ZFL can confuse a new contributor about its meaning, so maybe we can use the entire phrase Zulip Feature Level.

@rsashank
Copy link
Member Author

Oh my bad. Makes sense, @neiljp should I make another commit addressing this?

Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rsashank Thanks for the update 👍

This looks to have full coverage for the change, so I've just pushed back with a slightly adjusted commit message.

I'd like to merge this soon (once CI passes), since tests written in other PRs assume None is possible, so setting this new expectation would be useful!

For that reason I'd prefer to consider any followup on this refactor separately.

  • While abbreviations aren't great in general, expanding ZFL would make for very long test case ids or comments (and it is very common)
  • I think we could certainly expand some versions to a common form, eg. feature_level
  • Documenting what ZFL corresponds to would likely be well-placed in api_types.py? We shouldn't use it in docs without the expanded form first, or point to api_types perhaps.
  • We could rename ZFL/zulip_feature_level to reflect the server-provided name, ie. server_feature_level, but that would be less important in terms of making it easier to search for phrases; it may also be something we adjust if we namespace server and organization names, which has been discussed as a possible migration in the server already.

@@ -3449,7 +3456,7 @@ def test__handle_subscription_event_visual_notifications(
99,
[1001, 11, 12],
),
({"op": "peer_remove", "stream_id": 2, "user_id": 12}, None, 2, [1001, 11]),
({"op": "peer_remove", "stream_id": 2, "user_id": 12}, 0, 2, [1001, 11]),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was one removed line from the other PR I noticed.

Comment on lines -3258 to +3268
"remove_18_in_home_view:already_unmuted:ZFLNone",
"remove_19_in_home_view:muted:ZFLNone",
"add_19_in_home_view:already_muted:ZFLNone",
"add_30_in_home_view:unmuted:ZFLNone",
"remove_30_is_muted:already_unmutedZFL139",
"remove_18_in_home_view:already_unmuted:ZFL0",
"remove_19_in_home_view:muted:ZFL0",
"add_19_in_home_view:already_muted:ZFL0",
"add_30_in_home_view:unmuted:ZFL0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were others I saw previously that were missing overall 👍

@neiljp neiljp added PR ready to be merged PR has been reviewed & is ready to be merged and removed PR needs review PR requires feedback to proceed labels Feb 27, 2024
@neiljp neiljp added this to the Next Release milestone Feb 27, 2024
When the server originally did not provide `zulip_feature_level`, this
was previously represented by a `None` value in
`model.server_feature_level`.

This replaces the current potential `None` value with a zero value,
allowing a pure integer representation in the model. This enables
simplification of conditional statements when handling different server
versions.

The feature-level is represented by various strings in the repository,
including:
- server_feature_level
- zulip_feature_level
- ZFL
- feature_level

Tests updated, including test ids.
Additional test case added for realm retention.

Fixes zulip#1364.

Co-authored-by: Lucas.C.B <[email protected]>
@neiljp neiljp merged commit b71aec2 into zulip:main Feb 27, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: refactoring PR ready to be merged PR has been reviewed & is ready to be merged size: L [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify Zulip Feature Level (ZFL) handling (treat absent as zero)
4 participants