fix(startup): run recovery once and avoid scanning idle projects
This commit is contained in:
1 parent
45a9cc6e0c
commit
224f4e7c1e
6 files changed
+133
-22
No files matched your search
@@ -38,7 +38,7 @@ def test_explicit_data_root_still_overrides_frozen_portable_default(tmp_path: Pa
|
||||
assert application.resolve_data_root(override) == override.resolve()
|
||||
|
||||
|
||||
def test_main_configures_logging_before_qapplication_and_logs_recovery(tmp_path: Path, monkeypatch) -> None:
|
||||
def test_main_configures_logging_before_qapplication(tmp_path: Path, monkeypatch) -> None:
|
||||
"""Moving logging after Qt creation would lose startup and recovery diagnostics."""
|
||||
from dx_productivity.trial_task_center import application
|
||||
from dx_productivity.trial_task_center.logging_setup import configure_logging
|
||||
@@ -53,9 +53,6 @@ def test_main_configures_logging_before_qapplication_and_logs_recovery(tmp_path:
|
||||
assert events == ["logging"]
|
||||
self.path = path
|
||||
|
||||
def recover_interrupted_work(self) -> tuple[str, ...]:
|
||||
return ("project-1",)
|
||||
|
||||
def close(self) -> None:
|
||||
events.append("closed")
|
||||
|
||||
@@ -85,7 +82,6 @@ def test_main_configures_logging_before_qapplication_and_logs_recovery(tmp_path:
|
||||
|
||||
assert application.main(["--data-root", str(tmp_path)]) == 0
|
||||
assert events == ["logging", "window", "shown", "closed"]
|
||||
assert "recovered_interrupted_projects=project-1" in context.application_log_path.read_text(encoding="utf-8")
|
||||
assert f"version={application.VERSION}" in context.application_log_path.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import json
|
||||
|
||||
from dx_productivity.trial_task_center import application
|
||||
from dx_productivity.trial_task_center.logging_setup import configure_logging
|
||||
from dx_productivity.trial_task_center.models import ProjectStatus, TaskStatus
|
||||
from dx_productivity.trial_task_center.service import TaskCenterService
|
||||
from dx_productivity.trial_task_center.store import TaskStore
|
||||
|
||||
|
||||
def test_idle_startup_does_not_read_projects_of_every_task(tmp_path):
|
||||
store = TaskStore(tmp_path / 'tasks.db')
|
||||
for index in range(30):
|
||||
task = store.create_task(f'Board {index}')
|
||||
store.sync_projects(task.task_id, tmp_path, (tmp_path / f'{index}.prj',))
|
||||
queries = []
|
||||
store._connection.set_trace_callback(queries.append)
|
||||
try:
|
||||
TaskCenterService(store, configure_logging(tmp_path / 'data'))
|
||||
project_reads = [q for q in queries if q.startswith('SELECT * FROM projects WHERE task_id')]
|
||||
assert not project_reads, 'startup scans projects of every idle task'
|
||||
finally:
|
||||
store._connection.set_trace_callback(None)
|
||||
store.close()
|
||||
|
||||
|
||||
def test_application_restart_preserves_before_and_after_recovery_events(tmp_path, monkeypatch):
|
||||
store = TaskStore(tmp_path / 'task-center.db')
|
||||
task = store.create_task('Interrupted')
|
||||
project_path = tmp_path / 'board.prj'
|
||||
project_path.touch()
|
||||
project = store.sync_projects(task.task_id, tmp_path, (project_path,))[0]
|
||||
store.set_project_selected(project.project_id, True)
|
||||
store.add_rule(task.task_id, 'OLD', 'NEW')
|
||||
probe = tmp_path / 'probe.json'
|
||||
probe.write_text('baseline')
|
||||
service = TaskCenterService(store, configure_logging(tmp_path), probe_source_resolver=lambda *_: probe)
|
||||
service.start_task(task.task_id, disposable_copy_confirmed=True)
|
||||
store.close()
|
||||
|
||||
class Application:
|
||||
def __init__(self, _args):
|
||||
pass
|
||||
def exec(self):
|
||||
return 0
|
||||
|
||||
class Window:
|
||||
def __init__(self, service):
|
||||
assert service.get_task(task.task_id).status is TaskStatus.PAUSED
|
||||
assert service.projects(task.task_id)[0].status is ProjectStatus.FAILED
|
||||
def show(self):
|
||||
pass
|
||||
|
||||
monkeypatch.setattr(application, 'QApplication', Application)
|
||||
monkeypatch.setattr(application, '_load_window', lambda: Window)
|
||||
assert application.main(['--data-root', str(tmp_path)]) == 0
|
||||
events = [json.loads(line) for line in (tmp_path / 'tasks' / task.task_id / 'events.jsonl').read_text().splitlines()]
|
||||
recovery = [event for event in events if event['operation'] == 'recover_interrupted_work'
|
||||
and event['project_id'] == project.project_id]
|
||||
assert [event['details']['phase'] for event in recovery] == ['before', 'after']
|
||||
assert f'recovered_interrupted_projects={project.project_id}' in (tmp_path / 'logs/application.log').read_text()
|
||||
Reference in new issue
Block a user