|
8 | 8 | * the row keeps the `type` its readers filter on (D2: `Kind.row_type`); |
9 | 9 | * two readings are one row; a falling edge ends it as the platform; |
10 | 10 | * a person's ending stands, and a re-reading inside the snooze files nothing; |
| 11 | + a new divergence episode is material and files (`diverged_since`); |
11 | 12 | * a condition that persists is re-read at most every 6 hours (R9), so its |
12 | 13 | deadline moves while it holds, and only a condition nobody re-read (a clear |
13 | 14 | lost to a fault) ends on its 30-day lifetime; |
@@ -367,6 +368,57 @@ async def test_a_persons_ending_stands(kind, service, seed_agent, db, clock, mon |
367 | 368 | assert len(_rows(db, sc["prefix"])) == 1 |
368 | 369 |
|
369 | 370 |
|
| 371 | +@pytest.mark.asyncio |
| 372 | +async def test_a_new_divergence_episode_files_inside_a_persons_snooze( |
| 373 | + service, seed_agent, db, clock, monkeypatch): |
| 374 | + """A person's ending snoozes the episode they ended, not the agent. Each |
| 375 | + reading carries `diverged_since`, a material key of `sync_diverged`: re-reads |
| 376 | + of the ended episode stay quiet, and a divergence that comes back after a |
| 377 | + recovery is a new episode that files its own row, inside the 7 days.""" |
| 378 | + seed_agent() |
| 379 | + await _raise(service, clock, SCENARIOS["sync_diverged"]) |
| 380 | + (first,) = _pending(db, "sync-diverged-") |
| 381 | + _person_ends(db, first) |
| 382 | + ended_at = clock.now |
| 383 | + seam = type(service)._sync_agent.__globals__["platform_alerts"] |
| 384 | + real, readings = seam.observe, [] |
| 385 | + monkeypatch.setattr(seam, "observe", lambda *a, **k: readings.append( |
| 386 | + (a[1], real(*a, **k))) or readings[-1][1]) |
| 387 | + |
| 388 | + for _ in range(8): # two days of re-reads of the SAME episode |
| 389 | + clock.advance(hours=6, minutes=1) |
| 390 | + await _poll(service, _AHEAD) |
| 391 | + assert [out for k, out in readings if k == "sync_diverged"] == ["snoozed"] * 8 |
| 392 | + assert _pending(db, "sync-diverged-") == [] |
| 393 | + |
| 394 | + clock.advance(**_MIN) |
| 395 | + await _poll(service, _OK) # the episode ends; the person's ending stands |
| 396 | + assert db.get_sync_state("alpha")["diverged_since"] is None |
| 397 | + readings.clear() |
| 398 | + await _raise(service, clock, SCENARIOS["sync_diverged"]) # a second episode |
| 399 | + assert clock.now - ended_at < timedelta(days=7) # still inside the snooze |
| 400 | + assert [out for k, out in readings if k == "sync_diverged"] == ["created"] |
| 401 | + (second,) = _pending(db, "sync-diverged-") |
| 402 | + assert second["id"] != first["id"] |
| 403 | + assert second["context"]["diverged_since"] == db.get_sync_state("alpha")["diverged_since"] |
| 404 | + assert second["context"]["diverged_since"] != first["context"]["diverged_since"] |
| 405 | + assert db.get_operator_queue_item(first["id"])["status"] == "acknowledged" |
| 406 | + |
| 407 | + |
| 408 | +def test_a_pre_move_divergence_row_a_person_ended_snoozes_its_own_episode_only(pa): |
| 409 | + """The pre-move emitter (ent#706) wrote `diverged_since` into every row's |
| 410 | + context, so a person-ended legacy row the sweep gave a subject carries the |
| 411 | + episode marker: the same episode stays snoozed, another one files.""" |
| 412 | + since = "2026-10-30T07:00:00.000000Z" |
| 413 | + ended = {"priority": "high", "context": { |
| 414 | + "ahead": 7, "behind": 0, "dirty_files": 0, "diverged_since": since, |
| 415 | + "divergence_age_s": 90000, "recommendation": "push"}} |
| 416 | + kind = pa.KINDS["sync_diverged"] |
| 417 | + assert pa._snoozed_by(kind, ended, "high", {**ended["context"], "divergence_age_s": 99000}) |
| 418 | + assert not pa._snoozed_by(kind, ended, "high", |
| 419 | + {**ended["context"], "diverged_since": "2026-11-02T09:00:00.000000Z"}) |
| 420 | + |
| 421 | + |
370 | 422 | # -------------------------------------------------------------------------- |
371 | 423 | # The other shape: the clock 30 days ahead |
372 | 424 | # -------------------------------------------------------------------------- |
|
0 commit comments