refactor: remove redundant comments and docstrings (#6527)
* refactor: remove redundant comments and docstrings * fix(signal): annotate async context manager as a generator
This commit is contained in:
1 parent
cb3ba45317
commit
a4d2430140
922 files changed
+406
-7738
No files matched your search
@@ -434,7 +434,6 @@ def test_add_job_preserves_origin_delivery_context(tmp_path) -> None:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_heals_runtime_context_from_pending_external_add(tmp_path) -> None:
|
||||
"""Flattened runtime blocks from older action files must not be replayed."""
|
||||
store_path = tmp_path / "cron" / "jobs.json"
|
||||
external = CronService(store_path)
|
||||
job = external.add_job(
|
||||
@@ -923,7 +922,6 @@ async def test_subsecond_job_not_delayed_to_one_second(tmp_path):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_running_service_picks_up_external_add(tmp_path):
|
||||
"""A running service should detect and execute a job added by another instance."""
|
||||
store_path = tmp_path / "cron" / "jobs.json"
|
||||
called: list[str] = []
|
||||
|
||||
@@ -1017,7 +1015,6 @@ async def test_external_update_preserves_run_history_records(tmp_path):
|
||||
|
||||
|
||||
def test_stale_instance_remove_preserves_external_add(tmp_path) -> None:
|
||||
"""A stopped instance must not save a stale snapshot over another instance's job."""
|
||||
store_path = tmp_path / "cron" / "jobs.json"
|
||||
schedule = CronSchedule(kind="every", every_ms=60_000)
|
||||
service_a = CronService(store_path)
|
||||
@@ -1030,7 +1027,6 @@ def test_stale_instance_remove_preserves_external_add(tmp_path) -> None:
|
||||
**_bound_chat("first"),
|
||||
)
|
||||
|
||||
# Prime service_b with a view that does not include later external changes.
|
||||
assert [job.name for job in service_b.list_jobs(include_disabled=True)] == ["first"]
|
||||
|
||||
service_a.add_job(
|
||||
@@ -1046,12 +1042,8 @@ def test_stale_instance_remove_preserves_external_add(tmp_path) -> None:
|
||||
assert [job.name for job in reloaded.list_jobs(include_disabled=True)] == ["second"]
|
||||
|
||||
|
||||
# ── timer race regression tests ──
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_save_store_failure_retries_without_replaying_job(tmp_path, monkeypatch):
|
||||
"""A failed post-run save must be retried before jobs can execute again."""
|
||||
store_path = tmp_path / "cron" / "jobs.json"
|
||||
calls: list[str] = []
|
||||
arm_calls: list[str] = []
|
||||
@@ -1063,8 +1055,6 @@ async def test_save_store_failure_retries_without_replaying_job(tmp_path, monkey
|
||||
service._running = True
|
||||
service._load_store()
|
||||
|
||||
# Spy on _arm_timer so we can assert the scheduler is re-armed even when
|
||||
# the tick fails, without actually scheduling a real timer task.
|
||||
def arm_spy() -> None:
|
||||
arm_calls.append("arm")
|
||||
|
||||
@@ -1094,8 +1084,6 @@ async def test_save_store_failure_retries_without_replaying_job(tmp_path, monkey
|
||||
monkeypatch.setattr(service, "_atomic_write", flaky_atomic_write)
|
||||
await service._on_timer()
|
||||
|
||||
# The failed tick stays alive and retains the advanced in-memory state,
|
||||
# including when a public read would normally reload from disk.
|
||||
assert arm_calls == ["arm"], "scheduler must re-arm after a failed tick"
|
||||
assert service._active_executions == 0
|
||||
assert calls == [job.id]
|
||||
@@ -1104,14 +1092,10 @@ async def test_save_store_failure_retries_without_replaying_job(tmp_path, monkey
|
||||
assert loaded is not None
|
||||
assert loaded.state.last_run_at_ms is not None
|
||||
|
||||
# Manual execution is a second side-effecting entrypoint. It must also
|
||||
# refuse to run until the previous result can be made durable.
|
||||
with pytest.raises(OSError, match="disk full"):
|
||||
await service.run_job(job.id, force=True)
|
||||
assert calls == [job.id]
|
||||
|
||||
# The next healthy tick is reserved for persisting the dirty snapshot. It
|
||||
# must not reload the stale due record or execute the side effect twice.
|
||||
writes_fail = False
|
||||
await service._on_timer()
|
||||
|
||||
@@ -1129,13 +1113,11 @@ async def test_save_store_failure_retries_without_replaying_job(tmp_path, monkey
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_timer_execution_is_not_rolled_back_by_list_jobs_reload(tmp_path):
|
||||
"""list_jobs() during _on_timer should not replace the active store and re-run the same due job."""
|
||||
store_path = tmp_path / "cron" / "jobs.json"
|
||||
calls: list[str] = []
|
||||
|
||||
async def on_job(job):
|
||||
calls.append(job.id)
|
||||
# Simulate frontend polling list_jobs while the timer callback is mid-execution.
|
||||
service.list_jobs(include_disabled=True)
|
||||
await asyncio.sleep(0)
|
||||
|
||||
@@ -1164,9 +1146,6 @@ async def test_timer_execution_is_not_rolled_back_by_list_jobs_reload(tmp_path):
|
||||
assert loaded.state.next_run_at_ms > loaded.state.last_run_at_ms
|
||||
|
||||
|
||||
# ── update_job tests ──
|
||||
|
||||
|
||||
def test_update_job_changes_name(tmp_path) -> None:
|
||||
service = CronService(tmp_path / "cron" / "jobs.json")
|
||||
job = service.add_job(
|
||||
@@ -1336,13 +1315,11 @@ async def test_list_jobs_during_on_job_does_not_cause_stale_reload(tmp_path) ->
|
||||
async def on_job_that_lists(job):
|
||||
nonlocal execution_count
|
||||
execution_count += 1
|
||||
# Simulate the bot calling cron(action=list) mid-execution
|
||||
service.list_jobs()
|
||||
|
||||
service = CronService(store_path, on_job=on_job_that_lists, max_sleep_ms=100)
|
||||
await service.start()
|
||||
|
||||
# Add two jobs scheduled in the past so they're immediately due
|
||||
now_ms = int(time.time() * 1000)
|
||||
for name in ("job-a", "job-b"):
|
||||
service.add_job(
|
||||
@@ -1351,20 +1328,16 @@ async def test_list_jobs_during_on_job_does_not_cause_stale_reload(tmp_path) ->
|
||||
message="test",
|
||||
**_bound_chat(name),
|
||||
)
|
||||
# Force next_run to the past so _on_timer picks them up
|
||||
for job in service._store.jobs:
|
||||
job.state.next_run_at_ms = now_ms - 1000
|
||||
service._save_store()
|
||||
service._arm_timer()
|
||||
|
||||
# Let the timer fire once
|
||||
await asyncio.sleep(0.3)
|
||||
service.stop()
|
||||
|
||||
# Each job should have run exactly once, not looped
|
||||
assert execution_count == 2
|
||||
|
||||
# Verify next_run_at_ms was persisted correctly (in the future)
|
||||
raw = json.loads(store_path.read_text())
|
||||
for j in raw["jobs"]:
|
||||
next_run = j["state"]["nextRunAtMs"]
|
||||
@@ -1414,7 +1387,6 @@ def test_load_jobs_accepts_null_run_history_ms(tmp_path) -> None:
|
||||
|
||||
|
||||
def test_load_jobs_skips_null_run_history_elements(tmp_path) -> None:
|
||||
"""Null runHistory elements must be skipped like LocalTrigger.from_dict."""
|
||||
store_path = tmp_path / "cron" / "jobs.json"
|
||||
store_path.parent.mkdir(parents=True)
|
||||
store_path.write_text(
|
||||
@@ -1510,10 +1482,7 @@ async def test_reregistering_system_job_keeps_pending_every_run(tmp_path, monkey
|
||||
service.stop()
|
||||
|
||||
assert await boot(t0, 120 * minute) == t0 + 120 * minute
|
||||
# A gateway restart before the interval elapses must not push Dream back.
|
||||
assert await boot(t0 + 90 * minute, 120 * minute) == t0 + 120 * minute
|
||||
# A changed interval is a new schedule and is computed from now.
|
||||
assert await boot(t0 + 100 * minute, 60 * minute) == t0 + 160 * minute
|
||||
assert await boot(t0 + 110 * minute, 60 * minute) == t0 + 160 * minute
|
||||
# An overdue interval keeps the existing no-catch-up behavior.
|
||||
assert await boot(t0 + 170 * minute, 60 * minute) == t0 + 230 * minute
|
||||
Reference in new issue
Block a user