-
Notifications
You must be signed in to change notification settings - Fork 259
python-math #16: feat(math): participant-ban leak replication in clojure-legacy mode (Q1) #2644
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
Draft
jucor
wants to merge
1
commit into
spr/edge/96c1f19e
Choose a base branch
from
spr/edge/d4116474
base: spr/edge/96c1f19e
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Participant-ban (participants.mod = -1) leak replication — CLOJURE_QUIRKS Q1. | ||
|
|
||
| The Clojure math worker NEVER honored participant bans: its ingest path has no | ||
| participants.mod filter, so mod_out_ptpts never reaches the conv and banned | ||
| participants keep influencing user-vote-counts, in-conv, PCA, clustering and | ||
| repness. Python gained a real ban feature (mod_out_ptpts row drop in | ||
| _apply_moderation, 2026-06-10) — correct, but a certification divergence. | ||
|
|
||
| Per Q1: 'clojure-legacy' mode must LEAK the ban exactly like Clojure (rows | ||
| kept everywhere); 'improved' mode keeps the fix. This supersedes the legacy- | ||
| mode premise of #2623's TestCarryPruneOnParticipantBan (banning can no longer | ||
| shrink the legacy clustering pool, so the carry-prune scenario cannot arise). | ||
| """ | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| import pytest | ||
|
|
||
| sys.path.append(os.path.abspath(os.path.dirname(__file__))) | ||
|
|
||
| from polismath.pca_kmeans_rep.pca import PCA_IMPL_ENV_VAR | ||
| from polismath.utils.engine_mode import ENGINE_MODE_ENV_VAR | ||
| from polismath.conversation.conversation import Conversation | ||
|
|
||
|
|
||
| N_CMTS = 8 | ||
|
|
||
|
|
||
| def _bloc_votes(): | ||
| """Two blocs of 6, everyone votes all comments (all above threshold).""" | ||
| votes = [] | ||
| for i in range(6): | ||
| for t in range(N_CMTS): | ||
| votes.append({'pid': f'a{i}', 'tid': f'c{t}', | ||
| 'vote': 1.0 if t < 4 else -1.0}) | ||
| votes.append({'pid': f'b{i}', 'tid': f'c{t}', | ||
| 'vote': -1.0 if t < 4 else 1.0}) | ||
| return {'votes': votes} | ||
|
|
||
|
|
||
| def _clustered_pids(conv): | ||
| return {m for bc in conv.base_clusters for m in bc['members']} | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def legacy_mode(monkeypatch): | ||
| monkeypatch.delenv(PCA_IMPL_ENV_VAR, raising=False) | ||
| monkeypatch.setenv(ENGINE_MODE_ENV_VAR, 'clojure-legacy') | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def improved_mode(monkeypatch): | ||
| monkeypatch.delenv(PCA_IMPL_ENV_VAR, raising=False) | ||
| monkeypatch.setenv(ENGINE_MODE_ENV_VAR, 'improved') | ||
|
|
||
|
|
||
| class TestLegacyBanLeak: | ||
|
|
||
| def test_banned_participant_rows_kept(self, legacy_mode): | ||
| conv = Conversation('leak').update_votes(_bloc_votes()) | ||
| conv = conv.update_moderation({'mod_out_ptpts': ['a0', 'b0']}) | ||
| # The ban is STORED (payload bookkeeping unchanged) ... | ||
| assert conv.mod_out_ptpts == {'a0', 'b0'} | ||
| # ... but NOT applied: Clojure's worker never drops banned rows. | ||
| assert 'a0' in conv.rating_mat.index | ||
| assert 'b0' in conv.rating_mat.index | ||
|
|
||
| def test_banned_participant_still_clustered(self, legacy_mode): | ||
| conv = Conversation('leak').update_votes(_bloc_votes()) | ||
| conv = conv.update_moderation({'mod_out_ptpts': ['a0', 'b0']}) | ||
| clustered = _clustered_pids(conv) | ||
| assert {'a0', 'b0'}.issubset(clustered) | ||
| # And they stay through a subsequent vote tick. | ||
| conv = conv.update_votes({'votes': [ | ||
| {'pid': 'a1', 'tid': 'c0', 'vote': 1.0}]}) | ||
| assert {'a0', 'b0'}.issubset(_clustered_pids(conv)) | ||
|
|
||
| def test_banned_participant_counted_in_user_vote_counts(self, legacy_mode): | ||
| conv = Conversation('leak').update_votes(_bloc_votes()) | ||
| conv = conv.update_moderation({'mod_out_ptpts': ['a0']}) | ||
| assert conv._compute_user_vote_counts().get('a0') == N_CMTS | ||
|
|
||
| def test_banned_participant_stays_in_conv(self, legacy_mode): | ||
| conv = Conversation('leak').update_votes(_bloc_votes()) | ||
| conv = conv.update_moderation({'mod_out_ptpts': ['a0']}) | ||
| assert 'a0' in conv.in_conv | ||
|
|
||
|
|
||
| class TestImprovedBanKept: | ||
| """Improved mode keeps the real ban feature byte-for-byte.""" | ||
|
|
||
| def test_banned_participant_dropped_and_not_clustered(self, improved_mode): | ||
| conv = Conversation('leak').update_votes(_bloc_votes()) | ||
| conv = conv.update_moderation({'mod_out_ptpts': ['a0']}) | ||
| assert 'a0' not in conv.rating_mat.index | ||
| assert 'a0' not in _clustered_pids(conv) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| pytest.main([__file__, '-v']) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.