Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions delphi/polismath/conversation/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,8 @@ def recompute(self) -> 'Conversation':
prev_group_k_smoother = getattr(result, 'group_k_smoother', {})
# Q2: Clojure's :comment-priorities shadows its current-tick input
# with (:group-votes conv) — the PREVIOUS tick's stored group-votes
# (conversation.clj:658). Captured here, consumed in legacy mode only.
# (conversation.clj:658). Captured here, consumed by
# _compute_comment_priorities (Q2).
prev_group_votes = getattr(result, 'group_votes', {})

# Q15: Clojure's conv-update is a plumbing-graph compile whose output
Expand Down Expand Up @@ -1536,15 +1537,13 @@ def _compute_comment_priorities(
# every tick".
current_group_votes = self._compute_group_votes()
# Stored for the NEXT tick's prev capture (Clojure keeps :group-votes
# on the conv / in math_main) — in both modes, like self.pca.
# on the conv / in math_main) — like self.pca.
self.group_votes = current_group_votes
if resolve_engine_mode() == ENGINE_MODE_LEGACY:
# Q2: previous tick's group-votes (conversation.clj:658);
# {} on the first tick == Clojure's nil (reduce over nothing
# → A/P/S all 0).
group_votes = prev_group_votes if prev_group_votes is not None else {}
else:
group_votes = current_group_votes
# Q2: comment priorities read the PREVIOUS tick's group-votes
# (conversation.clj:658); {} on the first tick == Clojure's nil
# (reduce over nothing → A/P/S all 0). (The former improved-mode
# current-tick read is parked: POST_CUTOVER_IMPROVEMENTS.md item 5.)
group_votes = prev_group_votes if prev_group_votes is not None else {}

priorities: Dict[Any, float] = {}
for tid in self.rating_mat.columns:
Expand Down
19 changes: 3 additions & 16 deletions delphi/tests/test_priority_unmirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

Separately (CLOJURE_QUIRKS Q2): Clojure's :comment-priorities node SHADOWS
its current-tick group-votes input with `(:group-votes conv)` — the PREVIOUS
tick's stored value (conversation.clj:658). 'clojure-legacy' mode must do the
same; 'improved' mode keeps the current-tick read (the sane behavior).
tick's stored value (conversation.clj:658). The engine does the same. (The
former improved-mode current-tick read is parked:
POST_CUTOVER_IMPROVEMENTS.md item 5.)
"""

import os
Expand Down Expand Up @@ -86,10 +87,6 @@ def legacy_mode(monkeypatch):
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 TestPriorityMetricUnmirrored:
Expand Down Expand Up @@ -148,15 +145,5 @@ def test_legacy_stores_group_votes_for_next_tick(self, legacy_mode):
conv1 = Conversation('q2').update_votes(_bloc_votes())
assert conv1.group_votes == conv1._compute_group_votes()

def test_improved_uses_current_tick_group_votes(self, improved_mode):
conv1 = Conversation('q2').update_votes(_bloc_votes())
conv2 = conv1.update_votes(_tick2_votes())
expected_curr = _expected_priorities(conv2, conv2._compute_group_votes())
got = {f'c{k}' if not isinstance(k, str) else k: v
for k, v in conv2.comment_priorities.items()}
for tid in expected_curr:
assert abs(got[tid] - expected_curr[tid]) < 1e-9


if __name__ == '__main__':
pytest.main([__file__, '-v'])
Loading