DevWeave logoDevWeave
CommunitiesDiscoverHelp ForumFeaturesWhy DevWeaveAI & Verification
Log inGet started
Back to Issue Discovery
niyazmft/zulip-hermes-integration #315openPythonPython

refactor(policy): collapse the duplicated can_dm / check_dm

Opened by @niyazmft · Assignees: None

View on GitHub
good first issuepolicy

Solve & Merge Reward: Up to +210 XP & +60 Coins

+30 XP on PR open · +180 XP & +60 coins on merge

14 GitHub Stars

Claim Status & GitHub Signal

Unassigned with 0 comments. Open the workspace to inspect linked PRs before claiming or coding.

AI Issue Assessment · Grounded Analyzer
2.8 / 10 · 3–4 · Beginner

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.

Skill Match Breakdown

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.

Log in to receive your free level-adapted Hint #1 grounded in this repository's files.

Skill-Gap Learning

Gap-Targeted
Learn Linux

Shell navigation, process inspection, pipes, and CLI debugging.

Addresses skill gap: CLI & Shell

Learn Code in Python

Core Python syntax, functions, control flow, and debugging basics.

Addresses skill gap: Python

Learn Object Oriented Programming in Python

Designing clean classes, encapsulation, and testable Python modules.

Addresses skill gap: Testing & pytest

Hands-On CodeCrafters Practice
Skill-Gap Challenge
Build your own Shell
Python

Parse commands, manage PATH lookups, pipes, and process execution.

Practice skill gap: Python

Build your own HTTP Server
Python

Handle raw TCP connections, HTTP parsing, headers, and concurrent routes.

Practice skill gap: Python

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 under POLICY_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

  1. Fold can_dm into check_dm: either delete can_dm and update its tests to assert on check_dm(email)[0], or reimplement can_dm as a thin wrapper return self.check_dm(email)[0] with a docstring saying it is the boolean view.
  2. Keep check_dm's pairing-code behaviour byte-for-byte (the code-minting side effect and its _save_to_disk persist). The point is one mode switch, not a change in pairing semantics.
  3. Update the four test files that call can_dm to the new surface, or keep can_dm as the wrapper and leave the tests as-is (then add one test asserting can_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.py check_dm / can_dm / can_group_message (the group path is single-purpose already — do not touch it).
  • tests/test_policy.py TestPolicyModes (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 -q green
  • rg -n "def can_dm" zulip/policy.py is either gone or a one-line return self.check_dm(email)[0]
  • Full suite green; bash .githooks/pre-push regenerates 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.

Peer Help Forum · niyazmft/zulip-hermes-integration #315

Issue Troubleshooting Threads (0)

Ask Peers for Help

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.

Sign In

Contribution Workflow

Track your local progress before opening a pull request on GitHub.

Repository Context

Top Repository Paths

.env.example
[dir] .githooks
.githooks/pre-push
[dir] .github
.github/BRANCH_PROTECTION.md
.github/CODEOWNERS
[dir] .github/ISSUE_TEMPLATE
.github/ISSUE_TEMPLATE/bug_report.yml
.github/ISSUE_TEMPLATE/feature_request.yml
.github/ISSUE_TEMPLATE/question.yml
.github/PULL_REQUEST_TEMPLATE.md
.github/release.yml
[dir] .github/workflows
.github/workflows/ci.yml
.gitignore
.gitleaks.toml
AGENTS.md
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
README.md
SECURITY.md
SUPPORT.md

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

  1. Fork and clone:

    git clone https://github.com/YOUR_USERNAME/zulip-hermes-integration.git
    cd zulip-hermes-integration
    
  2. Install dependencies (Python 3.10+; CI runs the suite on 3.12):

    python3 -m pip install -r requirements.txt
    
  3. Install the pre-push hook:

    bash scripts/setup-hooks.sh
    

    This points core.hooksPath at .githooks. The hook regenerates checksums.txt and runs py_compile, the plugin.yaml parse 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).

  4. Verify:

    bash .githooks/pre-push
    

What CI runs, and how to run it yourself

Local commandCI
bash .githooks/pre-pushthe fast zulip-bridge job: checksums.txt freshness, py_compile, plugin.yaml, pytest
pip-audit -r requirements.txtthe fast job's dependency audit
gitleaks dir . (or git .)the fast job's secret scan; tuned by .gitleaks.toml
python3 scripts/check_compat.pythe compat matrix legs — see Testing
python3 scripts/parity_check.pynothing — 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.