refactor(policy): collapse the duplicated can_dm / check_dm
Opened by @niyazmft · Assignees: None
Solve & Merge Reward: Up to +210 XP & +60 Coins
+30 XP on PR open · +180 XP & +60 coins on merge
Claim Status & GitHub Signal
Unassigned with 0 comments. Open the workspace to inspect linked PRs before claiming or coding.
Estimated from issue labels (good first issue, policy), Python context, and discussion depth. No comments are posted yet, so check repository conventions carefully. Note: this is an estimate, not a guarantee.
What It's About
refactor(policy): collapse the duplicated can_dm / check_dm. The smell zulip/policy.py has two near-identical mode switches: - can_dm(email) - bool (line 374) — pure "is this email allowed" answer. - check_dm(email) - (allowed, pairing_code_or_none) (line 420) — the production path, also mints/returns a pairing code und
Why It Matters
Resolving #315 improves reliability and developer experience in niyazmft/zulip-hermes-integration.
Expected Outcome
A focused pull request addressing #315 with relevant checks or tests verified locally.
Log in to compare this issue's requirements against your profile skills. Required concepts: Python, Testing & pytest, CLI & Shell.
Progressive AI Hints
Hint #1 is always free and calibrated to your experience level. Extra hints unlock with coins without spoiling the full solution.
Skill-Gap Learning
Shell navigation, process inspection, pipes, and CLI debugging.
Addresses skill gap: CLI & Shell
Core Python syntax, functions, control flow, and debugging basics.
Addresses skill gap: Python
Designing clean classes, encapsulation, and testable Python modules.
Addresses skill gap: Testing & pytest
Issue Description
The smell
zulip/policy.py has two near-identical mode switches:
can_dm(email) -> bool(line 374) — pure "is this email allowed" answer.check_dm(email) -> (allowed, pairing_code_or_none)(line 420) — the production path, also mints/returns a pairing code underPOLICY_PAIRING.
can_dm is exercised only by tests (tests/test_policy.py, tests/test_pairing.py,
tests/test_owner_allowlist.py, tests/test_profile_isolation.py); production (zulip/inbound.py)
calls check_dm. Two switches over the same four modes means a future mode or a change to one path
silently diverges from the other.
What to deliver
- Fold
can_dmintocheck_dm: either deletecan_dmand update its tests to assert oncheck_dm(email)[0], or reimplementcan_dmas a thin wrapperreturn self.check_dm(email)[0]with a docstring saying it is the boolean view. - Keep
check_dm's pairing-code behaviour byte-for-byte (the code-minting side effect and its_save_to_diskpersist). The point is one mode switch, not a change in pairing semantics. - Update the four test files that call
can_dmto the new surface, or keepcan_dmas the wrapper and leave the tests as-is (then add one test assertingcan_dm(x) == check_dm(x)[0]for all four modes).
Prefer the wrapper approach — it is the smallest diff and keeps the existing test surface stable.
Reference
zulip/policy.pycheck_dm/can_dm/can_group_message(the group path is single-purpose already — do not touch it).tests/test_policy.pyTestPolicyModes(the four-mode matrix).- CONTRIBUTING.md § "Commit Messages" —
refactor(policy): ….
Acceptance
-
python3 -m pytest tests/test_policy.py tests/test_pairing.py tests/test_owner_allowlist.py tests/test_profile_isolation.py -qgreen -
rg -n "def can_dm" zulip/policy.pyis either gone or a one-linereturn self.check_dm(email)[0] - Full suite green;
bash .githooks/pre-pushregenerates checksums with no re-run diff
Linked Pull Requests (0)
No linked or cross-referenced pull requests detected via GitHub timeline. Check comments below for informal claims before starting.
GitHub Comments (0)
No comments on this issue yet.
Issue Troubleshooting Threads (0)
No troubleshooting threads opened for this issue yet. If you hit a test, build, or navigation blocker, post what you've tried so fellow contributors can help.
PR Verification & Rewards
Sign in and link GitHub to verify your PR against this issue and earn XP + coins.
Contribution Workflow
Track your local progress before opening a pull request on GitHub.
Repository Context
Top Repository Paths
CONTRIBUTING.md Excerpt
Contributing
Thanks for taking the time to contribute. This document covers development setup, the checks CI will run on your PR, and the handful of repo-specific rules that are easy to trip over.
Table of Contents
- Development Setup
- Project Layout
- Rules That Bite
- Testing
- Documentation Claims Are Tested
- Commit Messages
- Pull Request Process
- Release Process
Development Setup
-
Fork and clone:
git clone https://github.com/YOUR_USERNAME/zulip-hermes-integration.git cd zulip-hermes-integration -
Install dependencies (Python 3.10+; CI runs the suite on 3.12):
python3 -m pip install -r requirements.txt -
Install the pre-push hook:
bash scripts/setup-hooks.shThis points
core.hooksPathat.githooks. The hook regenerateschecksums.txtand runspy_compile, theplugin.yamlparse and the full test suite before any push, mirroring the fast CI job. To bypass it in an emergency, push with--no-verify(not recommended). -
Verify:
bash .githooks/pre-push
What CI runs, and how to run it yourself
| Local command | CI |
|---|---|
bash .githooks/pre-push | the fast zulip-bridge job: checksums.txt freshness, py_compile, plugin.yaml, pytest |
pip-audit -r requirements.txt | the fast job's dependency audit |
gitleaks dir . (or git .) | the fast job's secret scan; tuned by .gitleaks.toml |
python3 scripts/check_compat.py | the compat matrix legs — see Testing |
python3 scripts/parity_check.py | nothing — the parity workflow was removed (#229); this is manual |
The fast job is the required status check. It runs for documentation-only PRs too, because
the doc claims are tested. The compat matrix is shaped so
it can be a required check as well (issue #241): it always starts and always reports, and only
its work is skipped for docs-only changes, because a required check that is skipped at the
job level never reports and would leave such a PR permanently unmergeable.
Project Layout
zulip/ the plugin package — one module per concern
... (truncated)
Advisory PR Assistant
Helps structure your PR description or unpack reviewer feedback. Does not perform GitHub actions.