Hồi quy đã vá
-------------
F-12 Kéo–thả hoặc dán tệp vào ô chat ném NameError. R08 tách `_Input` sang
`chat_input_box.py` nhưng để `_paths_from_mime()` ở lại
`composer_widget.py`, nên hai hàm sự kiện Qt gọi một cái tên không tồn
tại. Bốn hàm dùng chung chuyển sang `composer_mime.py` — module thứ ba
là chỗ duy nhất không lặp lại được lỗi này. Đo lại: cả thả lẫn dán đều
gắn 1 tệp, khớp bản trước refactor.
F-01 Đổi provider thì bộ chọn model AI-Edit không làm gì. Hook cũ kiểm
`folder.ai_model_combo`, thuộc tính R08-T12 đã dời sang
`ai_panel.resolver`. Làm mới vô điều kiện, đúng như tab cũ: lần lấy đầu
tiên hỏng thì đổi provider chính là lúc phải thử lại.
F-07 Hàng chọn kỳ của Dashboard bị đẩy xuống dưới các thẻ số liệu. Hàng này
lọc CẢ BA thẻ con chứ không riêng biểu đồ, nên để nó nằm dưới là bắt
người dùng đọc con số trước khi thấy con số đó tính cho kỳ nào. Kèm
theo: `TokenUsageCardWidget` bị bỏ sót `setContentsMargins(0,0,0,0)`
mà hai thẻ con còn lại đã có, đẩy cả hàng thẻ lệch 9px.
`check_layout_geometry` nay khớp TỪNG BYTE với bản trước refactor.
F-11 Hai lớp khai trùng tên phương thức; Python giữ bản sau nên bản đầu là
mã chết. `co4e_tab.py::showEvent` bản đầu gọi `_narrow_guard.attach()`
và không bao giờ chạy.
Tách file (F-09)
----------------
Bốn file chạm trần 400 dòng, mỗi lần cắt ra một trách nhiệm thật:
graph_renderer.py -> graph_scene_builder.py + graph_export.py
co4e_workflow_service.py -> co4e_run_history.py
json_config_repository.py -> config_sections.py
agents_admin_tab.py -> shared/agent_kind_visuals.py
File cuối còn xoá 3 bản sao của hàm đã có trong `shared/formatters.py`,
giống hệt đến từng dòng — nay định dạng thời gian và avatar không lệch nhau
giữa các bảng Giám sát nữa.
Docstring
---------
41,6% -> 100% (3.478/3.478 định nghĩa production), kể cả module dormant và
phương thức dunder. Toàn bộ phần bổ sung viết bằng tiếng Việt; comment tiếng
Anh có sẵn giữ nguyên — dịch ngược là một đợt riêng.
Seam chưa nối dây (F-05)
------------------------
9 seam mang nhãn `SEAM · dựng <ngày>` kèm hai câu: được nối khi nào, và để
dormant thì hỏng gì. Ngày lấy từ lịch sử git, không phải hạn tự đặt. Gate O
đọc nhãn đó và nhắc khi quá 30 ngày.
859 test xanh · 4/4 cổng CASAN · 19/24 checker khớp từng byte bản cũ.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
76 lines
3.3 KiB
Python
76 lines
3.3 KiB
Python
"""QtSchedulerClock - the ``QTimer``-backed periodic ticker `TaskScheduler`
|
|
needs, pulled out from ``core/task_scheduler.py`` into its own adapter
|
|
(R07-T03).
|
|
|
|
``core/task_scheduler.py::TaskScheduler`` is the only file in the scheduling
|
|
stack that imports Qt at all (confirmed by grep — ``core/tasks.py`` and
|
|
``core/task_executors.py`` are Qt-free). Everything it needs Qt FOR is small
|
|
and mechanical: an interval timer that calls back into ``tick()`` every
|
|
``TICK_MS``, plus, during ``stop()``, a way to pump the event loop so a
|
|
worker thread's queued ``finished_ok``/``failed`` signal still gets delivered
|
|
while draining running tasks (see the long comment on ``TaskScheduler.stop()``
|
|
for why that pump matters).
|
|
|
|
Wrapping exactly that surface — ``start(interval_ms, callback)``, ``stop()``,
|
|
``pump()`` — behind :class:`QtSchedulerClock` lets ``TaskScheduler`` take a
|
|
clock as a constructor parameter instead of constructing a ``QTimer``
|
|
itself. Production wiring is unchanged (``TaskScheduler`` defaults to a real
|
|
``QtSchedulerClock`` when no clock is passed); tests can inject
|
|
``tests/fakes/fake_clock.py::FakeClock`` to control ticks by hand with no Qt
|
|
event loop running at all.
|
|
|
|
See ``infrastructure/qt/__init__.py`` for why this lives under
|
|
``infrastructure/qt/`` and not the ``platform/qt/`` path the original plan
|
|
named.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Callable, Optional
|
|
|
|
from PySide6.QtCore import QCoreApplication, QObject, QTimer
|
|
|
|
|
|
class QtSchedulerClock:
|
|
"""Owns one ``QTimer``. Not itself a ``QObject`` subclass — it OWNS a
|
|
``QObject``-parented timer instead of inheriting from one, so callers
|
|
(like ``FakeClock`` in tests) can satisfy the same duck-typed interface
|
|
without any Qt base class at all."""
|
|
|
|
def __init__(self, parent: Optional[QObject] = None) -> None:
|
|
# Parented so the timer is torn down with its owner instead of
|
|
# outliving it — the same lifetime QTimer(self) gave it inside
|
|
# TaskScheduler before this extraction.
|
|
"""Dựng ``QTimer`` gắn vào ``parent`` để nó bị dọn cùng chủ sở hữu, đúng vòng
|
|
đời nó vốn có khi còn nằm trong ``TaskScheduler``.
|
|
"""
|
|
self._timer = QTimer(parent)
|
|
self._timer.timeout.connect(self._on_timeout)
|
|
self._callback: Optional[Callable[[], None]] = None
|
|
|
|
def _on_timeout(self) -> None:
|
|
"""Mỗi nhịp ``QTimer``: gọi callback đã đăng ký."""
|
|
if self._callback is not None:
|
|
self._callback()
|
|
|
|
def start(self, interval_ms: int, callback: Callable[[], None]) -> None:
|
|
"""Arm and start the timer. Calling this again while already
|
|
running re-arms it with the new interval/callback (matches
|
|
``QTimer.start()``'s own restart-on-repeat-call behaviour)."""
|
|
self._callback = callback
|
|
self._timer.setInterval(interval_ms)
|
|
self._timer.start()
|
|
|
|
def stop(self) -> None:
|
|
"""Dừng nhịp đếm."""
|
|
self._timer.stop()
|
|
|
|
def pump(self) -> None:
|
|
"""Process one batch of pending Qt events — used by
|
|
``TaskScheduler.stop()``'s bounded drain loop so a worker thread's
|
|
queued completion signal can still be delivered while we wait for it
|
|
to exit."""
|
|
QCoreApplication.processEvents()
|
|
|
|
|
|
__all__ = ["QtSchedulerClock"]
|