fix(7735): a rule the session already read counts as opened when it arrives again
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 12s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 2m2s
CI & Build / integration (push) Successful in 2m10s
CI & Build / Build & push image (push) Successful in 34s

A delivery to a session that opened the rule within the open window is
stamped opened as it is written, and migration 0135 stamps the rows already
recorded the same way. The adherence readout, the ordering open rate and the
weighing pass read one definition: a rule read early in a long session is not
counted unread each time it is delivered later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 07:06:18 -05:00
co-authored by Claude Opus 5.5
parent c486524b48
commit 78fa165e67
4 changed files with 102 additions and 2 deletions
+25
View File
@@ -68,6 +68,31 @@ async def test_an_open_is_stamped_on_the_sessions_latest_delivery_only():
assert await rule_deliveries.mark_opened(uid, "s-1", RULE) is False
async def test_a_line_for_a_rule_the_session_already_read_is_recorded_opened():
uid = await _user()
await _record(uid, "s-1", "moment_rule", [(RULE, "work.start", "full"), (OTHER, "work.start", "full")])
assert await rule_deliveries.mark_opened(uid, "s-1", RULE) is True
await _record(uid, "s-1", "pre_tool_rule", [(RULE, "pre_tool_rule", "repeat"), (OTHER, "pre_tool_rule", "full")])
await _record(uid, "s-2", "pre_tool_rule", [(RULE, "pre_tool_rule", "full")])
later = {(r.session_id, r.rule_id): r.opened_at is not None
for r in await _rows(uid) if r.at == "pre_tool_rule"}
# Read in s-1, so it reached a reader who had it; OTHER was never read,
# and another session's read is not this one's.
assert later == {("s-1", RULE): True, ("s-1", OTHER): False, ("s-2", RULE): False}
async def test_a_read_older_than_the_open_window_does_not_carry():
uid = await _user()
await _record(uid, "s-1", "moment_rule", [(RULE, "work.start", "full")])
async with async_session() as s:
await s.execute(update(RuleDelivery).where(RuleDelivery.user_id == uid).values(
opened_at=datetime.now(timezone.utc) - rule_deliveries.OPEN_WINDOW - timedelta(minutes=1)))
await s.commit()
await _record(uid, "s-1", "moment_rule", [(RULE, "work.deliver", "full")])
latest = (await _rows(uid))[-1]
assert (latest.at, latest.opened_at) == ("work.deliver", None)
async def test_an_open_with_no_delivery_behind_it_stamps_nothing():
uid = await _user()
assert await rule_deliveries.mark_opened(uid, "s-1", OTHER) is False